james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vince...@apache.org
Subject cvs commit: james-server/src/java/org/apache/james/transport/mailets AbstractRedirect.java Forward.java NotifySender.java Redirect.java Resend.java
Date Mon, 07 Jul 2003 06:16:22 GMT
vincenzo    2003/07/06 23:16:22

  Modified:    src/java/org/apache/james/transport/mailets
                        AbstractRedirect.java Forward.java
                        NotifySender.java Redirect.java Resend.java
  Log:
  1) Added "from" value to the <to> parameter.
  2) Added "full name" support to the <recipients and <to> parameters.
  
  Revision  Changes    Path
  1.18      +39 -37    james-server/src/java/org/apache/james/transport/mailets/AbstractRedirect.java
  
  Index: AbstractRedirect.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/transport/mailets/AbstractRedirect.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- AbstractRedirect.java	4 Jul 2003 16:46:12 -0000	1.17
  +++ AbstractRedirect.java	7 Jul 2003 06:16:21 -0000	1.18
  @@ -67,7 +67,6 @@
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Locale;
  -import java.util.StringTokenizer;
   import java.util.ArrayList;
   
   
  @@ -193,6 +192,7 @@
       private static class AddressMarker {
           public static MailAddress SENDER;
           public static MailAddress REVERSE_PATH;
  +        public static MailAddress FROM;
           public static MailAddress TO;
           public static MailAddress RECIPIENTS;
           public static MailAddress DELETE;
  @@ -203,6 +203,7 @@
               try {
                   SENDER          = new MailAddress("sender","address.marker");
                   REVERSE_PATH    = new MailAddress("reverse.path","address.marker");
  +                FROM            = new MailAddress("from","address.marker");
                   TO              = new MailAddress("to","address.marker");
                   RECIPIENTS      = new MailAddress("recipients","address.marker");
                   DELETE          = new MailAddress("delete","address.marker");
  @@ -221,6 +222,7 @@
       protected static class SpecialAddress {
           public static final MailAddress SENDER          = AddressMarker.SENDER;
           public static final MailAddress REVERSE_PATH    = AddressMarker.REVERSE_PATH;
  +        public static final MailAddress FROM            = AddressMarker.FROM;
           public static final MailAddress TO              = AddressMarker.TO;
           public static final MailAddress RECIPIENTS      = AddressMarker.RECIPIENTS;
           public static final MailAddress DELETE          = AddressMarker.DELETE;
  @@ -442,7 +444,6 @@
        */
       protected Collection getRecipients() throws MessagingException {
           Collection newRecipients = new HashSet();
  -        boolean error = false;
           String addressList = getInitParameter("recipients");
           
           // if nothing was specified, return <CODE>null</CODE> meaning no change
  @@ -450,25 +451,20 @@
               return null;
           }
   
  -        StringTokenizer st = new StringTokenizer(addressList, ",", false);
  -        while(st.hasMoreTokens()) {
  -            String token = null;
  -            try {
  -                token = st.nextToken();
  -                MailAddress specialAddress = getSpecialAddress(token,
  -                                                new String[] {"postmaster", "sender", "reversePath",
"unaltered", "recipients"});
  +        try {
  +            InternetAddress[] iaarray = InternetAddress.parse(addressList, false);
  +            for (int i = 0; i < iaarray.length; i++) {
  +                String addressString = iaarray[i].getAddress();
  +                MailAddress specialAddress = getSpecialAddress(addressString,
  +                new String[] {"postmaster", "sender", "reversePath", "unaltered", "recipients"});
                   if (specialAddress != null) {
                       newRecipients.add(specialAddress);
                   } else {
  -                    newRecipients.add(new MailAddress(token));
  +                    newRecipients.add(new MailAddress(iaarray[i]));
                   }
  -            } catch(Exception e) {
  -                error = true;
  -                log("Exception thrown in getRecipients() parsing: " + token, e);
               }
  -        }
  -        if (error) {
  -            throw new MessagingException("Failed to initialize \"recipients\" list; see
mailet log.");
  +        } catch (Exception e) {
  +            throw new MessagingException("Exception thrown in getRecipients() parsing:
" + addressList, e);
           }
           if (newRecipients.size() == 0) {
               throw new MessagingException("Failed to initialize \"recipients\" list; empty
<recipients> init parameter found.");
  @@ -520,12 +516,13 @@
        * or the postmaster address
        * or <CODE>SpecialAddress.SENDER</CODE>
        * or <CODE>SpecialAddress.REVERSE_PATH</CODE>
  +     * or <CODE>SpecialAddress.FROM</CODE>
        * or <CODE>SpecialAddress.UNALTERED</CODE>
        * or <CODE>SpecialAddress.TO</CODE>
        * or <CODE>null</CODE> if missing
        */
       protected InternetAddress[] getTo() throws MessagingException {
  -        boolean error = false;
  +        InternetAddress[] iaarray = null;
           String addressList = getInitParameter("to");
           
           // if nothing was specified, return null meaning no change
  @@ -533,29 +530,20 @@
               return null;
           }
   
  -        StringTokenizer rec = new StringTokenizer(addressList, ",");
  -        int tokenCount = rec.countTokens();
  -        InternetAddress[] iaarray = new InternetAddress[tokenCount];
  -        String token = "";
  -        for(int i = 0; i < tokenCount; ++i) {
  -            try {
  -                token = rec.nextToken();
  -                MailAddress specialAddress = getSpecialAddress(token,
  -                                                new String[] {"postmaster", "sender", "reversePath",
"unaltered", "to", "null"});
  +        try {
  +            iaarray = InternetAddress.parse(addressList, false);
  +            for(int i = 0; i < iaarray.length; ++i) {
  +                String addressString = iaarray[i].getAddress();
  +                MailAddress specialAddress = getSpecialAddress(addressString,
  +                                                new String[] {"postmaster", "sender", "from",
"reversePath", "unaltered", "to", "null"});
                   if (specialAddress != null) {
                       iaarray[i] = specialAddress.toInternetAddress();
  -                } else {
  -                    iaarray[i] = new InternetAddress(token);
                   }
  -            } catch(Exception e) {
  -                error = true;
  -                log("Exception thrown in getTo() parsing: " + token, e);
               }
  +        } catch (Exception e) {
  +            throw new MessagingException("Exception thrown in getTo() parsing: " + addressList,
e);
           }
  -        if (error) {
  -            throw new MessagingException("Failed to initialize \"to\" list; see mailet
log.");
  -        }
  -        if (tokenCount == 0) {
  +        if (iaarray.length == 0) {
               throw new MessagingException("Failed to initialize \"to\" list; empty <to>
init parameter found.");
           }
   
  @@ -1524,6 +1512,9 @@
           if(addressString.compareTo("reversepath") == 0) {
               specialAddress = SpecialAddress.REVERSE_PATH;
           }
  +        if(addressString.compareTo("from") == 0) {
  +            specialAddress = SpecialAddress.FROM;
  +        }
           if(addressString.compareTo("to") == 0) {
               specialAddress = SpecialAddress.TO;
           }
  @@ -1742,7 +1733,7 @@
        * Returns a new Collection built over <I>list</I> replacing special addresses
        * with real ones.
        * Manages <CODE>SpecialAddress.SENDER</CODE>, <CODE>SpecialAddress.REVERSE_PATH</CODE>,
  -     * <CODE>SpecialAddress.TO</CODE>, 
  +     * <CODE>SpecialAddress.FROM</CODE>, <CODE>SpecialAddress.TO</CODE>,

        * <CODE>SpecialAddress.NULL</CODE> and <CODE>SpecialAddress.UNALTERED</CODE>.
        * Any other address is not replaced.
        */
  @@ -1763,6 +1754,17 @@
                   MailAddress reversePath = mail.getSender();
                   if (reversePath != null) {
                       newList.add(reversePath.toInternetAddress());
  +                }
  +            } else if (internetAddress.equals(SpecialAddress.FROM.toInternetAddress()))
{
  +                try {
  +                    InternetAddress[] fromArray = (InternetAddress[]) mail.getMessage().getFrom();
  +                    if (fromArray != null) {
  +                        for (int i = 0; i < fromArray.length; i++) {
  +                            newList.add(fromArray[i]);
  +                        }
  +                    }
  +                } catch (AddressException ae) {
  +                    log("Unable to parse the \"FROM\" header in the original message; ignoring.");
                   }
               } else if (internetAddress.equals(SpecialAddress.TO.toInternetAddress())) {
                   String[] toHeaders = mail.getMessage().getHeader(RFC2822Headers.TO);
  
  
  
  1.19      +11 -17    james-server/src/java/org/apache/james/transport/mailets/Forward.java
  
  Index: Forward.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/transport/mailets/Forward.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Forward.java	4 Jul 2003 16:46:12 -0000	1.18
  +++ Forward.java	7 Jul 2003 06:16:21 -0000	1.19
  @@ -66,7 +66,6 @@
   import javax.mail.internet.InternetAddress;
   import java.util.Collection;
   import java.util.HashSet;
  -import java.util.StringTokenizer;
   
   /**
    * <P>Replaces incoming recipients with those specified, and resends the message
unaltered.</P>
  @@ -163,28 +162,23 @@
               throw new MessagingException("Failed to initialize \"recipients\" list: no
<forwardTo> or <forwardto> init parameter found");
           }
   
  -        StringTokenizer st = new StringTokenizer(addressList, ",", false);
  -        while(st.hasMoreTokens()) {
  -            String token = null;
  -            try {
  -                token = st.nextToken();
  -                MailAddress specialAddress = getSpecialAddress(token,
  -                                                new String[] {"postmaster", "sender", "reversePath",
"unaltered", "recipients"});
  +        try {
  +            InternetAddress[] iaarray = InternetAddress.parse(addressList, false);
  +            for (int i = 0; i < iaarray.length; i++) {
  +                String addressString = iaarray[i].getAddress();
  +                MailAddress specialAddress = getSpecialAddress(addressString,
  +                new String[] {"postmaster", "sender", "reversePath", "unaltered", "recipients"});
                   if (specialAddress != null) {
                       newRecipients.add(specialAddress);
                   } else {
  -                    newRecipients.add(new MailAddress(token));
  +                    newRecipients.add(new MailAddress(iaarray[i]));
                   }
  -            } catch(Exception e) {
  -                error = true;
  -                log("Exception thrown in getRecipients() parsing: " + token, e);
               }
  -        }
  -        if (error) {
  -            throw new MessagingException("Failed to initialize \"recipients\" list; see
mailet log.");
  +        } catch (Exception e) {
  +            throw new MessagingException("Exception thrown in getRecipients() parsing:
" + addressList, e);
           }
           if (newRecipients.size() == 0) {
  -            throw new MessagingException("Failed to initialize \"recipients\" list; empty
<forwardTo> or <forwardto> init parameter found.");
  +            throw new MessagingException("Failed to initialize \"recipients\" list; empty
<recipients> init parameter found.");
           }
   
           return newRecipients;
  
  
  
  1.25      +4 -4      james-server/src/java/org/apache/james/transport/mailets/NotifySender.java
  
  Index: NotifySender.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/transport/mailets/NotifySender.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- NotifySender.java	4 Jul 2003 16:46:12 -0000	1.24
  +++ NotifySender.java	7 Jul 2003 06:16:21 -0000	1.25
  @@ -105,7 +105,7 @@
    *   &lt;attachment&gt;<I>see {@link Resend}, default=message</I>&lt;/attachment&gt;
    *   &lt;passThrough&gt;<I>true or false, default=true</I>&lt;/passThrough&gt;
    *   &lt;fakeDomainCheck&gt;<I>true or false, default=true</I>&lt;/fakeDomainCheck&gt;
  - *   &lt;to&gt;<I>unaltered (optional, defaults to sender)</I>&lt;/to&gt;
  + *   &lt;to&gt;<I>unaltered or sender or from(optional, defaults to sender)</I>&lt;/to&gt;
    *   &lt;debug&gt;<I>true or false, default=false</I>&lt;/debug&gt;
    * &lt;/mailet&gt;
    * </CODE></PRE>
  @@ -120,7 +120,7 @@
    *   &lt;prefix&gt;<I>a string</I>&lt;/prefix&gt;
    *   &lt;passThrough&gt;true&lt;/passThrough&gt;
    *   &lt;fakeDomainCheck&gt;<I>true or false</I>&lt;/fakeDomainCheck&gt;
  - *   &lt;to&gt;<I>unaltered or sender&lt</I>;/to&gt;
  + *   &lt;to&gt;<I>unaltered or sender or from&lt</I>;/to&gt;
    *   &lt;recipients&gt;<B>sender</B>&lt;/recipients&gt;
    *   &lt;inline&gt;none&lt;/inline&gt;
    *   &lt;attachment&gt;message&lt;/attachment&gt;
  @@ -187,7 +187,7 @@
           iaarray[0] = SpecialAddress.SENDER.toInternetAddress();
           if (addressList != null) {
               MailAddress specialAddress = getSpecialAddress(addressList,
  -                                            new String[] {"sender", "unaltered"});
  +                                            new String[] {"sender", "unaltered", "from"});
               if (specialAddress != null) {
                   iaarray[0] = specialAddress.toInternetAddress();
               } else {
  
  
  
  1.34      +22 -38    james-server/src/java/org/apache/james/transport/mailets/Redirect.java
  
  Index: Redirect.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/transport/mailets/Redirect.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- Redirect.java	4 Jul 2003 16:46:12 -0000	1.33
  +++ Redirect.java	7 Jul 2003 06:16:21 -0000	1.34
  @@ -67,7 +67,6 @@
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Locale;
  -import java.util.StringTokenizer;
   import java.util.ArrayList;
   
   
  @@ -112,7 +111,7 @@
    * if none of the lists is specified.<BR>
    * These addresses will only appear in the To: header if no &quot;to&quot; list
is
    * supplied.<BR>
  - * It can include constants &quot;sender&quot;, &quot;postmaster&quot;,
&quot;reversePath&quot;, &quot;recipients&quot; and &quot;unaltered&quot;.
  + * It can include constants &quot;sender&quot;, &quot;from&quot;, &quot;postmaster&quot;,
&quot;reversePath&quot;, &quot;recipients&quot; and &quot;unaltered&quot;.
    * </TD>
    * </TR>
    * <TR valign=top>
  @@ -377,7 +376,6 @@
        */
       protected Collection getRecipients() throws MessagingException {
           Collection newRecipients = new HashSet();
  -        boolean error = false;
           String addressList = (getInitParameter("recipients") == null)
                                    ? getInitParameter("to")
                                    : getInitParameter("recipients");
  @@ -387,30 +385,25 @@
               return null;
           }
   
  -        StringTokenizer st = new StringTokenizer(addressList, ",", false);
  -        while(st.hasMoreTokens()) {
  -            String token = null;
  -            try {
  -                token = st.nextToken();
  -                MailAddress specialAddress = getSpecialAddress(token,
  -                                                new String[] {"postmaster", "sender", "reversePath",
"unaltered", "recipients"});
  +        try {
  +            InternetAddress[] iaarray = InternetAddress.parse(addressList, false);
  +            for (int i = 0; i < iaarray.length; i++) {
  +                String addressString = iaarray[i].getAddress();
  +                MailAddress specialAddress = getSpecialAddress(addressString,
  +                new String[] {"postmaster", "sender", "reversePath", "unaltered", "recipients"});
                   if (specialAddress != null) {
                       newRecipients.add(specialAddress);
                   } else {
  -                    newRecipients.add(new MailAddress(token));
  +                    newRecipients.add(new MailAddress(iaarray[i]));
                   }
  -            } catch(Exception e) {
  -                error = true;
  -                log("Exception thrown in getRecipients() parsing: " + token, e);
               }
  -        }
  -        if (error) {
  -            throw new MessagingException("Failed to initialize \"recipients\" list; see
mailet log.");
  +        } catch (Exception e) {
  +            throw new MessagingException("Exception thrown in getRecipients() parsing:
" + addressList, e);
           }
           if (newRecipients.size() == 0) {
               throw new MessagingException("Failed to initialize \"recipients\" list; empty
<recipients> init parameter found.");
           }
  -        
  +
           return newRecipients;
       }
   
  @@ -424,7 +417,7 @@
        * or <CODE>null</CODE> if also the latter is missing
        */
       protected InternetAddress[] getTo() throws MessagingException {
  -        boolean error = false;
  +        InternetAddress[] iaarray = null;
           String addressList = (getInitParameter("to") == null)
                                    ? getInitParameter("recipients")
                                    : getInitParameter("to");
  @@ -434,29 +427,20 @@
               return null;
           }
   
  -        StringTokenizer rec = new StringTokenizer(addressList, ",");
  -        int tokenCount = rec.countTokens();
  -        InternetAddress[] iaarray = new InternetAddress[tokenCount];
  -        String token = "";
  -        for(int i = 0; i < tokenCount; ++i) {
  -            try {
  -                token = rec.nextToken();
  -                MailAddress specialAddress = getSpecialAddress(token,
  -                                                new String[] {"postmaster", "sender", "reversePath",
"unaltered", "to", "null"});
  +        try {
  +            iaarray = InternetAddress.parse(addressList, false);
  +            for(int i = 0; i < iaarray.length; ++i) {
  +                String addressString = iaarray[i].getAddress();
  +                MailAddress specialAddress = getSpecialAddress(addressString,
  +                                                new String[] {"postmaster", "sender", "from",
"reversePath", "unaltered", "to", "null"});
                   if (specialAddress != null) {
                       iaarray[i] = specialAddress.toInternetAddress();
  -                } else {
  -                    iaarray[i] = new InternetAddress(token);
                   }
  -            } catch(Exception e) {
  -                error = true;
  -                log("Exception thrown in getTo() parsing: " + token, e);
               }
  +        } catch (Exception e) {
  +            throw new MessagingException("Exception thrown in getTo() parsing: " + addressList,
e);
           }
  -        if (error) {
  -            throw new MessagingException("Failed to initialize \"to\" list; see mailet
log.");
  -        }
  -        if (tokenCount == 0) {
  +        if (iaarray.length == 0) {
               throw new MessagingException("Failed to initialize \"to\" list; empty <to>
init parameter found.");
           }
   
  
  
  
  1.4       +2 -2      james-server/src/java/org/apache/james/transport/mailets/Resend.java
  
  Index: Resend.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/transport/mailets/Resend.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Resend.java	4 Jul 2003 16:46:12 -0000	1.3
  +++ Resend.java	7 Jul 2003 06:16:21 -0000	1.4
  @@ -114,7 +114,7 @@
    * <TD width="20%">&lt;to&gt;</TD>
    * <TD width="80%">
    * A comma delimited list of addresses to appear in the To: header;.<BR>
  - * It can include constants &quot;sender&quot;, &quot;postmaster&quot;,
&quot;reversePath&quot;, &quot;to&quot;, &quot;null&quot; and &quot;unaltered&quot;;
  + * It can include constants &quot;sender&quot;, &quot;from&quot;, &quot;postmaster&quot;,
&quot;reversePath&quot;, &quot;to&quot;, &quot;null&quot; and &quot;unaltered&quot;;
    * if &quot;null&quot; is specified alone it will remove this header.<BR>
    * Default: &quot;unaltered&quot;.
    * </TD>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message