vincenzo 2003/07/06 23:17:43
Modified: src/java/org/apache/james/transport/mailets Tag:
branch_2_1_fcs 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
No revision
No revision
1.1.2.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.1.2.17
retrieving revision 1.1.2.18
diff -u -r1.1.2.17 -r1.1.2.18
--- AbstractRedirect.java 4 Jul 2003 16:42:17 -0000 1.1.2.17
+++ AbstractRedirect.java 7 Jul 2003 06:17:42 -0000 1.1.2.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.6.4.12 +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.6.4.11
retrieving revision 1.6.4.12
diff -u -r1.6.4.11 -r1.6.4.12
--- Forward.java 4 Jul 2003 16:42:17 -0000 1.6.4.11
+++ Forward.java 7 Jul 2003 06:17:42 -0000 1.6.4.12
@@ -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.10.4.13 +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.10.4.12
retrieving revision 1.10.4.13
diff -u -r1.10.4.12 -r1.10.4.13
--- NotifySender.java 4 Jul 2003 16:42:17 -0000 1.10.4.12
+++ NotifySender.java 7 Jul 2003 06:17:42 -0000 1.10.4.13
@@ -105,7 +105,7 @@
* <attachment><I>see [EMAIL PROTECTED] Resend},
default=message</I></attachment>
* <passThrough><I>true or false, default=true</I></passThrough>
* <fakeDomainCheck><I>true or false,
default=true</I></fakeDomainCheck>
- * <to><I>unaltered (optional, defaults to sender)</I></to>
+ * <to><I>unaltered or sender or from(optional, defaults to
sender)</I></to>
* <debug><I>true or false, default=false</I></debug>
* </mailet>
* </CODE></PRE>
@@ -120,7 +120,7 @@
* <prefix><I>a string</I></prefix>
* <passThrough>true</passThrough>
* <fakeDomainCheck><I>true or false</I></fakeDomainCheck>
- * <to><I>unaltered or sender<</I>;/to>
+ * <to><I>unaltered or sender or from<</I>;/to>
* <recipients><B>sender</B></recipients>
* <inline>none</inline>
* <attachment>message</attachment>
@@ -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.18.4.16 +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.18.4.15
retrieving revision 1.18.4.16
diff -u -r1.18.4.15 -r1.18.4.16
--- Redirect.java 4 Jul 2003 16:42:17 -0000 1.18.4.15
+++ Redirect.java 7 Jul 2003 06:17:42 -0000 1.18.4.16
@@ -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 "to" list is
* supplied.<BR>
- * It can include constants "sender", "postmaster",
"reversePath", "recipients" and "unaltered".
+ * It can include constants "sender", "from",
"postmaster", "reversePath", "recipients" and
"unaltered".
* </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.1.2.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.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- Resend.java 4 Jul 2003 16:42:17 -0000 1.1.2.3
+++ Resend.java 7 Jul 2003 06:17:42 -0000 1.1.2.4
@@ -114,7 +114,7 @@
* <TD width="20%"><to></TD>
* <TD width="80%">
* A comma delimited list of addresses to appear in the To: header;.<BR>
- * It can include constants "sender", "postmaster",
"reversePath", "to", "null" and "unaltered";
+ * It can include constants "sender", "from",
"postmaster", "reversePath", "to", "null" and
"unaltered";
* if "null" is specified alone it will remove this header.<BR>
* Default: "unaltered".
* </TD>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]