geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlaskow...@apache.org
Subject svn commit: r384286 - in /geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet: InternetHeaders.java MimeMessage.java
Date Wed, 08 Mar 2006 17:57:37 GMT
Author: jlaskowski
Date: Wed Mar  8 09:57:35 2006
New Revision: 384286

URL: http://svn.apache.org/viewcvs?rev=384286&view=rev
Log:
GERONIMO-1708 javax.mail.internet.MimeMessage use of private methods short circuits lazy loading
by MimeMessage subclasses

Modified:
    geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/InternetHeaders.java
    geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeMessage.java

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/InternetHeaders.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/InternetHeaders.java?rev=384286&r1=384285&r2=384286&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/InternetHeaders.java
(original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/InternetHeaders.java
Wed Mar  8 09:57:35 2006
@@ -363,44 +363,6 @@
         return new HeaderLineEnumeration(getNonMatchingHeaders(names));
     }
 
-
-    /**
-     * Return a header as a list of InternetAddresses
-     *
-     * @param name   the header to get
-     * @param strict whether the header should be strictly parser; see {@link InternetAddress#parseHeader(java.util.List,
String, boolean, boolean)}
-     * @return
-     */
-    Address[] getHeaderAsAddresses(String name, boolean strict) throws MessagingException
{
-        List addrs = new ArrayList();
-        List headers = getHeaderList(name);
-        if (headers == null) {
-            return null;
-        }
-        // news groups are a special case.  Those are NewsAddress items, not InternetAddress.
-        boolean isNewsGroup = name.equals("Newsgroups");
-
-        for (Iterator i = headers.iterator(); i.hasNext();) {
-            InternetHeader header = (InternetHeader) i.next();
-            Address[] addresses = null;
-            // removed headers may show up as value-less entities, so we need to make
-            // sure this is real before attempting to parse the value.
-            String headerValue = header.getValue();
-            if (headerValue != null) {
-                if (isNewsGroup) {
-                    addresses = NewsAddress.parse(header.getValue());
-                }
-                else {
-                    addresses = InternetAddress.parseHeader(header.getValue(), strict);
-                }
-                for (int j = 0; j < addresses.length; j++) {
-                    addrs.add(addresses[j]);
-                }
-            }
-        }
-        return (Address[]) addrs.toArray(new Address[addrs.size()]);
-    }
-
     void setHeader(String name, Address[] addresses) {
         List list = new ArrayList(addresses.length);
         for (int i = 0; i < addresses.length; i++) {

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeMessage.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeMessage.java?rev=384286&r1=384285&r2=384286&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeMessage.java
(original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeMessage.java
Wed Mar  8 09:57:35 2006
@@ -266,9 +266,9 @@
     public Address[] getFrom() throws MessagingException {
         // strict addressing controls this.
         boolean strict = isStrictAddressing();
-        Address[] result = getHeaderAsAddresses("From", strict);
+        Address[] result = getHeaderAsInternetAddresses("From", strict);
         if (result == null) {
-            result = getHeaderAsAddresses("Sender", strict);
+            result = getHeaderAsInternetAddresses("Sender", strict);
         }
         return result;
     }
@@ -318,7 +318,7 @@
      * @throws MessagingException if there was a problem parsing the header
      */
     public Address getSender() throws MessagingException {
-        Address[] addrs = getHeaderAsAddresses("Sender", isStrictAddressing());
+        Address[] addrs = getHeaderAsInternetAddresses("Sender", isStrictAddressing());
         return addrs.length > 0 ? addrs[0] : null;
     }
 
@@ -350,7 +350,13 @@
      * @exception MessagingException
      */
     public Address[] getRecipients(Message.RecipientType type) throws MessagingException
{
-        return getHeaderAsAddresses(getHeaderForRecipientType(type), isStrictAddressing());
+        // is this a NEWSGROUP request?  We need to handle this as a special case here, because
+        // this needs to return NewsAddress instances instead of InternetAddress items.
+        if (type == RecipientType.NEWSGROUPS) {
+            return getHeaderAsNewsAddresses(getHeaderForRecipientType(type));
+        }
+        // the other types are all internet addresses.
+        return getHeaderAsInternetAddresses(getHeaderForRecipientType(type), isStrictAddressing());
     }
 
     /**
@@ -386,7 +392,14 @@
      * @exception MessagingException
      */
     private void addRecipientsToList(List list, Message.RecipientType type) throws MessagingException
{
-        Address[] recipients = getHeaderAsAddresses(getHeaderForRecipientType(type), isStrictAddressing());
+
+        Address[] recipients;
+        if (type == RecipientType.NEWSGROUPS) {
+            recipients = getHeaderAsNewsAddresses(getHeaderForRecipientType(type));
+        }
+        else {
+            recipients = getHeaderAsInternetAddresses(getHeaderForRecipientType(type), isStrictAddressing());
+        }
         if (recipients != null) {
             list.addAll(Arrays.asList(recipients));
         }
@@ -454,7 +467,7 @@
      * @exception MessagingException
      */
     public Address[] getReplyTo() throws MessagingException {
-         Address[] addresses = getHeaderAsAddresses("Reply-To", isStrictAddressing());
+         Address[] addresses = getHeaderAsInternetAddresses("Reply-To", isStrictAddressing());
          if (addresses == null) {
              addresses = getFrom();
          }
@@ -1355,8 +1368,32 @@
         return new InternetHeaders(in);
     }
 
-    private Address[] getHeaderAsAddresses(String header, boolean strict) throws MessagingException
{
-        return headers.getHeaderAsAddresses(header, strict);
+    /**
+     * Convert a header into an array of NewsAddress items.
+     *
+     * @param header The name of the source header.
+     *
+     * @return The parsed array of addresses.
+     * @exception MessagingException
+     */
+    private Address[] getHeaderAsNewsAddresses(String header) throws MessagingException {
+        // NB:  We're using getHeader() here to allow subclasses an opportunity to perform
lazy loading
+        // of the headers.
+        String mergedHeader = getHeader(header, ",");
+        if (mergedHeader != null) {
+            return NewsAddress.parse(mergedHeader);
+        }
+        return null;
+    }
+
+    private Address[] getHeaderAsInternetAddresses(String header, boolean strict) throws
MessagingException {
+        // NB:  We're using getHeader() here to allow subclasses an opportunity to perform
lazy loading
+        // of the headers.
+        String mergedHeader = getHeader(header, ",");
+        if (mergedHeader != null) {
+            return InternetAddress.parseHeader(mergedHeader, strict);
+        }
+        return null;
     }
 
     /**



Mime
View raw message