vincenzo 2003/07/04 09:46:13
Modified: src/java/org/apache/james/transport/mailets
AbstractNotify.java AbstractRedirect.java
Bounce.java Forward.java NotifyPostmaster.java
NotifySender.java Redirect.java Resend.java
Log:
1) Added <forwardTo> to the Forward mailet, and <replyTo> to all mailets.
2) Better exception reporting.
3) Now throwing a MessagingException if a getX() ends up with an empty (not null)
list or array.
4) Changed consistently return-path (and its variations) to reverse-path (and
variations); the Return-Path header is always built from the reverse-path when this is
changed.
5) The <recipients> and the <to> parameters can accept SpecialAddress-es mixed with
real addresses.
6) Corrected all bounce-like functionality.
Revision Changes Path
1.9 +27 -20
james-server/src/java/org/apache/james/transport/mailets/AbstractNotify.java
Index: AbstractNotify.java
===================================================================
RCS file:
/home/cvs/james-server/src/java/org/apache/james/transport/mailets/AbstractNotify.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractNotify.java 30 Jun 2003 09:41:03 -0000 1.8
+++ AbstractNotify.java 4 Jul 2003 16:46:11 -0000 1.9
@@ -113,8 +113,8 @@
* <debug><I>true or false, default=false</I></debug>
* </mailet>
* </CODE></PRE>
- * <P><I>notice</I>, <I>senderAddress</I> and <I>attachStackTrace</I> can be used
instead of
- * <I><I>message</I>, <I>sender</I> and <I>attachError</I>; such names are kept for
backward compatibility.</P>
+ * <P><I>notice</I> and <I>senderAddress</I> can be used instead of
+ * <I>message</I> and <I>sender</I>; such names are kept for backward
compatibility.</P>
*
* @version CVS $Revision$ $Date$
* @since 2.2.0
@@ -260,7 +260,7 @@
/**
* @return [EMAIL PROTECTED] AbstractRedirect#getSender(Mail)}, meaning the new
requested sender if any
*/
- protected MailAddress getReturnPath(Mail originalMail) throws
MessagingException {
+ protected MailAddress getReversePath(Mail originalMail) throws
MessagingException {
return getSender(originalMail);
}
@@ -289,23 +289,30 @@
}
/**
- * @return the <CODE>attachStackTrace</CODE> init parameter,
- * or the <CODE>attachError</CODE> init parameter if missing,
- * or false if missing
- */
- protected boolean attachError() {
- boolean attachStackTrace = false;
- try {
- attachStackTrace = new
Boolean(getInitParameter("attachStackTrace")).booleanValue();
- } catch (Exception e) {
- // try with attachError
- try {
- attachStackTrace = new
Boolean(getInitParameter("attachError")).booleanValue();
- } catch (Exception e2) {
- // Ignore exception, default to false
- }
+ * @return the <CODE>prefix</CODE> init parameter or "Re:" if missing
+ */
+ protected String getSubjectPrefix() {
+ if(getInitParameter("prefix") == null) {
+ return "Re:";
+ } else {
+ return getInitParameter("prefix");
+ }
+ }
+
+ /**
+ * Builds the subject of <I>newMail</I> appending the subject
+ * of <I>originalMail</I> to <I>subjectPrefix</I>, but avoiding a duplicate.
+ */
+ protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail
originalMail) throws MessagingException {
+ String subject = originalMail.getMessage().getSubject();
+ if (subject == null) {
+ subject = "";
+ }
+ if (subject.indexOf(subjectPrefix) == 0) {
+ newMail.getMessage().setSubject(subject);
+ } else {
+ newMail.getMessage().setSubject(subjectPrefix + subject);
}
- return attachStackTrace;
}
/**
1.17 +231 -204
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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- AbstractRedirect.java 3 Jul 2003 08:32:50 -0000 1.16
+++ AbstractRedirect.java 4 Jul 2003 16:46:12 -0000 1.17
@@ -78,6 +78,7 @@
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
+import javax.mail.internet.AddressException;
import org.apache.mailet.RFC2822Headers;
import org.apache.mailet.dates.RFC822DateFormat;
@@ -101,7 +102,7 @@
* <LI>getMessage(), The text of the message itself</LI>
* <LI>getRecipients(), the recipients the mail is sent to</LI>
* <LI>getReplyTo(), where replies to this message will be sent</LI>
- * <LI>getReturnPath(), what to set the Return-Path to</LI>
+ * <LI>getReversePath(), what to set the reverse-path to</LI>
* <LI>getSender(), who the mail is from</LI>
* <LI>getSubject(), a string to replace the message subject</LI>
* <LI>getSubjectPrefix(), a prefix to be added to the message subject, possibly
already replaced by a new subject</LI>
@@ -191,7 +192,7 @@
private static class AddressMarker {
public static MailAddress SENDER;
- public static MailAddress RETURN_PATH;
+ public static MailAddress REVERSE_PATH;
public static MailAddress TO;
public static MailAddress RECIPIENTS;
public static MailAddress DELETE;
@@ -200,13 +201,13 @@
static {
try {
- SENDER = new MailAddress("sender","address.marker");
- RETURN_PATH = new MailAddress("return.path","address.marker");
- TO = new MailAddress("to","address.marker");
- RECIPIENTS = new MailAddress("recipients","address.marker");
- DELETE = new MailAddress("delete","address.marker");
- UNALTERED = new MailAddress("unaltered","address.marker");
- NULL = new MailAddress("null","address.marker");
+ SENDER = new MailAddress("sender","address.marker");
+ REVERSE_PATH = new MailAddress("reverse.path","address.marker");
+ TO = new MailAddress("to","address.marker");
+ RECIPIENTS = new MailAddress("recipients","address.marker");
+ DELETE = new MailAddress("delete","address.marker");
+ UNALTERED = new MailAddress("unaltered","address.marker");
+ NULL = new MailAddress("null","address.marker");
} catch (Exception _) {}
}
@@ -218,13 +219,13 @@
* by a "getX(Mail)" or "setX(Mail, Tx, Mail)".
*/
protected static class SpecialAddress {
- public static final MailAddress SENDER = AddressMarker.SENDER;
- public static final MailAddress RETURN_PATH = AddressMarker.RETURN_PATH;
- public static final MailAddress TO = AddressMarker.TO;
- public static final MailAddress RECIPIENTS = AddressMarker.RECIPIENTS;
- public static final MailAddress DELETE = AddressMarker.DELETE;
- public static final MailAddress UNALTERED = AddressMarker.UNALTERED;
- public static final MailAddress NULL = AddressMarker.NULL;
+ public static final MailAddress SENDER = AddressMarker.SENDER;
+ public static final MailAddress REVERSE_PATH =
AddressMarker.REVERSE_PATH;
+ public static final MailAddress TO = AddressMarker.TO;
+ public static final MailAddress RECIPIENTS = AddressMarker.RECIPIENTS;
+ public static final MailAddress DELETE = AddressMarker.DELETE;
+ public static final MailAddress UNALTERED = AddressMarker.UNALTERED;
+ public static final MailAddress NULL = AddressMarker.NULL;
}
// The values that indicate how to attach the original mail
@@ -249,7 +250,7 @@
private String messageText;
private Collection recipients;
private MailAddress replyTo;
- private MailAddress returnPath;
+ private MailAddress reversePath;
private MailAddress sender;
private String subject;
private String subjectPrefix;
@@ -265,7 +266,7 @@
/**
* <P>Gets the <CODE>static</CODE> property.</P>
- * <P>Return true to reduce calls to getTo, getSender, getRecipients,
getReplyTo, getReturnPath amd getMessage
+ * <P>Return true to reduce calls to getTo, getSender, getRecipients,
getReplyTo, getReversePath amd getMessage
* where these values don't change (eg hard coded, or got at startup from the
mailet config);
* return false where any of these methods generate their results dynamically
eg in response to the message being processed,
* or by reference to a repository of users.</P>
@@ -290,11 +291,7 @@
* @return the <CODE>passThrough</CODE> init parameter, or false if missing
*/
protected boolean getPassThrough() throws MessagingException {
- if(getInitParameter("passThrough") == null) {
- return false;
- } else {
- return new Boolean(getInitParameter("passThrough")).booleanValue();
- }
+ return new Boolean(getInitParameter("passThrough")).booleanValue();
}
/**
@@ -317,11 +314,7 @@
* @return the <CODE>fakeDomainCheck</CODE> init parameter, or true if missing
*/
protected boolean getFakeDomainCheck() throws MessagingException {
- if(getInitParameter("fakeDomainCheck") == null) {
- return true;
- } else {
- return new Boolean(getInitParameter("fakeDomainCheck")).booleanValue();
- }
+ return new Boolean(getInitParameter("fakeDomainCheck")).booleanValue();
}
/**
@@ -442,12 +435,14 @@
* @return the <CODE>recipients</CODE> init parameter
* or the postmaster address
* or <CODE>SpecialAddress.SENDER</CODE>
- * or <CODE>SpecialAddress.RETURN_PATH</CODE>
+ * or <CODE>SpecialAddress.REVERSE_PATH</CODE>
* or <CODE>SpecialAddress.UNALTERED</CODE>
+ * or <CODE>SpecialAddress.RECIPIENTS</CODE>
* or <CODE>null</CODE> if missing
*/
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
@@ -455,23 +450,30 @@
return null;
}
- MailAddress specialAddress = getSpecialAddress(addressList,
- new String[] {"postmaster", "sender",
"returnPath", "unaltered"});
- if (specialAddress != null) {
- newRecipients.add(specialAddress);
- return newRecipients;
- }
-
StringTokenizer st = new StringTokenizer(addressList, ",", false);
while(st.hasMoreTokens()) {
String token = null;
try {
token = st.nextToken();
- newRecipients.add(new MailAddress(token));
+ MailAddress specialAddress = getSpecialAddress(token,
+ new String[] {"postmaster",
"sender", "reversePath", "unaltered", "recipients"});
+ if (specialAddress != null) {
+ newRecipients.add(specialAddress);
+ } else {
+ newRecipients.add(new MailAddress(token));
+ }
} catch(Exception e) {
- throw new MessagingException("Exception thrown in getRecipients()
parsing: " + token, e);
+ error = true;
+ log("Exception thrown in getRecipients() parsing: " + token, e);
}
}
+ if (error) {
+ throw new MessagingException("Failed to initialize \"recipients\" list;
see mailet log.");
+ }
+ if (newRecipients.size() == 0) {
+ throw new MessagingException("Failed to initialize \"recipients\" list;
empty <recipients> init parameter found.");
+ }
+
return newRecipients;
}
@@ -480,31 +482,15 @@
* built dynamically using the original Mail object.
* Is a "getX(Mail)" method.
*
- * @return [EMAIL PROTECTED] #getRecipients()},
- * replacing <CODE>SpecialAddress.SENDER</CODE> if applicable with the original
sender
- * and <CODE>SpecialAddress.UNALTERED</CODE>
- * and <CODE>SpecialAddress.RECIPIENTS</CODE> if applicable with null
+ * @return [EMAIL PROTECTED] #replaceMailAddresses} on [EMAIL PROTECTED]
#getRecipients()},
*/
protected Collection getRecipients(Mail originalMail) throws MessagingException
{
Collection recipients = (isStatic()) ? this.recipients : getRecipients();
- if (recipients != null && recipients.size() == 1) {
- if (recipients.contains(SpecialAddress.UNALTERED) ||
recipients.contains(SpecialAddress.RECIPIENTS)) {
+ if (recipients != null) {
+ if (recipients.size() == 1 &&
(recipients.contains(SpecialAddress.UNALTERED) ||
recipients.contains(SpecialAddress.RECIPIENTS))) {
recipients = null;
- } else if (recipients.contains(SpecialAddress.SENDER)) {
- recipients = new ArrayList();
- recipients.add(originalMail.getSender());
- } else if (recipients.contains(SpecialAddress.RETURN_PATH)) {
- recipients = new ArrayList();
- MailAddress mailAddress = getExistingReturnPath(originalMail);
- if (mailAddress == SpecialAddress.NULL) {
- // should never get here
- throw new MessagingException("NULL return path found getting
recipients");
- }
- if (mailAddress == null) {
- recipients.add(originalMail.getSender());
- } else {
- recipients.add(mailAddress);
- }
+ } else {
+ recipients = replaceMailAddresses(originalMail, recipients);
}
}
return recipients;
@@ -533,37 +519,46 @@
* @return the <CODE>to</CODE> init parameter
* or the postmaster address
* or <CODE>SpecialAddress.SENDER</CODE>
- * or <CODE>SpecialAddress.RETURN_PATH</CODE>
+ * or <CODE>SpecialAddress.REVERSE_PATH</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;
String addressList = getInitParameter("to");
+
// if nothing was specified, return null meaning no change
if (addressList == null) {
return null;
}
- MailAddress specialAddress = getSpecialAddress(addressList,
- new String[] {"postmaster", "sender",
"returnPath", "unaltered"});
- if (specialAddress != null) {
- InternetAddress[] iaarray = new InternetAddress[1];
- iaarray[0] = specialAddress.toInternetAddress();
- return iaarray;
- }
-
- StringTokenizer rec = new StringTokenizer(addressList, ",");
- int tokensn = rec.countTokens();
- InternetAddress[] iaarray = new InternetAddress[tokensn];
- String tokenx = "";
- for(int i = 0; i < tokensn; ++i) {
+ StringTokenizer rec = new StringTokenizer(addressList, ",");
+ int tokenCount = rec.countTokens();
+ InternetAddress[] iaarray = new InternetAddress[tokenCount];
+ String token = "";
+ for(int i = 0; i < tokenCount; ++i) {
try {
- tokenx = rec.nextToken();
- iaarray[i] = new InternetAddress(tokenx);
+ token = rec.nextToken();
+ MailAddress specialAddress = getSpecialAddress(token,
+ new String[] {"postmaster",
"sender", "reversePath", "unaltered", "to", "null"});
+ if (specialAddress != null) {
+ iaarray[i] = specialAddress.toInternetAddress();
+ } else {
+ iaarray[i] = new InternetAddress(token);
+ }
} catch(Exception e) {
- throw new MessagingException("Exception thrown in getTo() parsing:
" + tokenx, e);
+ error = true;
+ log("Exception thrown in getTo() parsing: " + token, e);
}
}
+ if (error) {
+ throw new MessagingException("Failed to initialize \"to\" list; see
mailet log.");
+ }
+ if (tokenCount == 0) {
+ throw new MessagingException("Failed to initialize \"to\" list; empty
<to> init parameter found.");
+ }
+
return iaarray;
}
@@ -573,81 +568,29 @@
* Its outcome will be the the value the <I>TO:</I> header will be set to,
* that could be different from the real recipient (see [EMAIL PROTECTED]
#getRecipients}).
* Is a "getX(Mail)" method.
- * <P>The logic is the following, based on [EMAIL PROTECTED] #getTo()}:</P>
- * <UL>
- * <LI>
- * If <CODE>getTo()</CODE> returns null it returns null, meaning no
change.
- * </LI>
- * <LI>
- * If <CODE>getTo()</CODE> returns <CODE>SpecialAddress.SENDER</CODE>
- * it returns the <I>sender</I>;
- * if the <I>sender</I> is null it returns the <I>Return-Path:</I>
header;
- * if the <I>Return-Path:</I> header does not exist or ==
<CODE>SpecialAddress.NULL</CODE> ("<>") it returns "<>".
- * </LI>
- * <LI>
- * If <CODE>getTo()</CODE> returns
<CODE>SpecialAddress.UNALTERED</CODE>
- * or <CODE>SpecialAddress.TO</CODE>
- * it returns the original <I>TO:</I>.
- * </LI>
- * <LI>
- * If <CODE>getTo()</CODE> returns
<CODE>SpecialAddress.RETURN_PATH</CODE>
- * it returns the contents of the <I>Return-Path:</I> header;
- * if the <I>Return-Path:</I> header is
<CODE>SpecialAddress.NULL</CODE> it throws a <CODE>MessagingException</CODE>;
- * if the <I>Return-Path:</I> header does not exist it returns the
<I>sender</I>;
- * if the <I>sender</I> is null it returns "<>".
- * </LI>
- * </UL>
- *
- * @return [EMAIL PROTECTED] #getTo()}, replacing
<CODE>SpecialAddress.SENDER</CODE>,
- * <CODE>SpecialAddress.SENDER</CODE>,
- * <CODE>SpecialAddress.TO</CODE>,
- * and <CODE>SpecialAddress.UNALTERED</CODE> if applicable
+ *
+ * @return [EMAIL PROTECTED] #replaceInternetAddresses} on [EMAIL PROTECTED]
#getRecipients()},
*/
protected InternetAddress[] getTo(Mail originalMail) throws MessagingException {
InternetAddress[] apparentlyTo = (isStatic()) ? this.apparentlyTo : getTo();
- if (apparentlyTo != null && apparentlyTo.length == 1) {
- if (apparentlyTo[0].equals(SpecialAddress.SENDER.toInternetAddress())) {
- MailAddress mailAddress = originalMail.getSender();
- if (mailAddress == null) {
- mailAddress = getExistingReturnPath(originalMail);
- if (mailAddress == SpecialAddress.NULL) {
- mailAddress = null;
- }
- }
- if (mailAddress == null) {
- /* IMPORTANT: setTo() treats null differently from
- * an zero length array, so do not just use null
- */
- // set to <>
- apparentlyTo = new InternetAddress[0];
- } else {
- apparentlyTo = new InternetAddress[1];
- apparentlyTo[0] = mailAddress.toInternetAddress();
- }
- } else if
(apparentlyTo[0].equals(SpecialAddress.UNALTERED.toInternetAddress())
- ||
apparentlyTo[0].equals(SpecialAddress.TO.toInternetAddress())) {
- apparentlyTo = (InternetAddress[])
originalMail.getMessage().getRecipients(Message.RecipientType.TO);
- } else if
(apparentlyTo[0].equals(SpecialAddress.RETURN_PATH.toInternetAddress())) {
- MailAddress mailAddress = getExistingReturnPath(originalMail);
- if (mailAddress == SpecialAddress.NULL) {
- // should never get here
- throw new MessagingException("NULL return path found getting
recipients");
- }
- if (mailAddress == null) {
- mailAddress = originalMail.getSender();
- }
- if (mailAddress == null) {
- /* IMPORTANT: setTo() treats null differently from
- * an zero length array, so do not just use null
- */
- // set to <>
- apparentlyTo = new InternetAddress[0];
- } else {
- apparentlyTo = new InternetAddress[1];
- apparentlyTo[0] = mailAddress.toInternetAddress();
+ if (apparentlyTo != null) {
+ if ( apparentlyTo.length == 1
+ && (
apparentlyTo[0].equals(SpecialAddress.UNALTERED.toInternetAddress())
+ || apparentlyTo[0].equals(SpecialAddress.TO.toInternetAddress())
+ )) {
+ apparentlyTo = null;
+ } else {
+ Collection toList = new ArrayList(apparentlyTo.length);
+ for (int i = 0; i < apparentlyTo.length; i++) {
+ toList.add(apparentlyTo[i]);
}
+ /* IMPORTANT: setTo() treats null differently from a zero length
array,
+ so it's ok to get a zero length array from replaceSpecialAddresses
+ */
+ apparentlyTo = (InternetAddress[])
replaceInternetAddresses(originalMail, toList).toArray(new InternetAddress[0]);
}
}
+
return apparentlyTo;
}
@@ -679,7 +622,10 @@
* or <CODE>null</CODE> if missing
*/
protected MailAddress getReplyTo() throws MessagingException {
- String addressString = getInitParameter("replyto");
+ String addressString = getInitParameter("replyTo");
+ if (addressString == null) {
+ addressString = getInitParameter("replyto");
+ }
if(addressString != null) {
MailAddress specialAddress = getSpecialAddress(addressString,
new String[] {"postmaster", "sender",
"null", "unaltered"});
@@ -742,20 +688,20 @@
}
/**
- * Gets the <CODE>returnPath</CODE> property.
- * Returns the Return-Path of the new message,
+ * Gets the <CODE>reversePath</CODE> property.
+ * Returns the reverse-path of the new message,
* or null if no change is requested.
* Is a "getX()" method.
*
- * @return the <CODE>returnPath</CODE> init parameter
+ * @return the <CODE>reversePath</CODE> init parameter
* or the postmaster address
* or <CODE>SpecialAddress.SENDER</CODE>
* or <CODE>SpecialAddress.NULL</CODE>
* or <CODE>SpecialAddress.UNALTERED</CODE>
* or <CODE>null</CODE> if missing
*/
- protected MailAddress getReturnPath() throws MessagingException {
- String addressString = getInitParameter("returnPath");
+ protected MailAddress getReversePath() throws MessagingException {
+ String addressString = getInitParameter("reversePath");
if(addressString != null) {
MailAddress specialAddress = getSpecialAddress(addressString,
new String[] {"postmaster", "sender",
"null", "unaltered"});
@@ -766,7 +712,7 @@
try {
return new MailAddress(addressString);
} catch(Exception e) {
- throw new MessagingException("Exception thrown in getReturnPath()
parsing: " + addressString, e);
+ throw new MessagingException("Exception thrown in getReversePath()
parsing: " + addressString, e);
}
}
@@ -774,47 +720,49 @@
}
/**
- * Gets the <CODE>returnPath</CODE> property,
+ * Gets the <CODE>reversePath</CODE> property,
* built dynamically using the original Mail object.
* Is a "getX(Mail)" method.
*
- * @return [EMAIL PROTECTED] #getReturnPath()},
- * replacing <CODE>SpecialAddress.SENDER</CODE> if applicable with the original
sender,
+ * @return [EMAIL PROTECTED] #getReversePath()},
+ * replacing <CODE>SpecialAddress.SENDER</CODE> if applicable with null,
* replacing <CODE>SpecialAddress.UNALTERED</CODE>
- * and <CODE>SpecialAddress.UNALTERED</CODE> if applicable with null,
+ * and <CODE>SpecialAddress.REVERSE_PATH</CODE> if applicable with null,
* but not replacing <CODE>SpecialAddress.NULL</CODE>
- * that will be handled by [EMAIL PROTECTED] #setReturnPath}
+ * that will be handled by [EMAIL PROTECTED] #setReversePath}
*/
- protected MailAddress getReturnPath(Mail originalMail) throws
MessagingException {
- MailAddress returnPath = (isStatic()) ? this.returnPath : getReturnPath();
- if (returnPath != null) {
- if (returnPath == SpecialAddress.UNALTERED || returnPath ==
SpecialAddress.RETURN_PATH) {
- returnPath = null;
+ protected MailAddress getReversePath(Mail originalMail) throws
MessagingException {
+ MailAddress reversePath = (isStatic()) ? this.reversePath :
getReversePath();
+ if (reversePath != null) {
+ if (reversePath == SpecialAddress.UNALTERED || reversePath ==
SpecialAddress.REVERSE_PATH) {
+ reversePath = null;
}
- else if (returnPath == SpecialAddress.SENDER) {
- returnPath = originalMail.getSender();
+ else if (reversePath == SpecialAddress.SENDER) {
+ reversePath = null;
}
}
- return returnPath;
+ return reversePath;
}
/**
- * Sets the "Return-Path:" header of <I>newMail</I> to <I>returnPath</I>.
+ * Sets the "reverse-path" of <I>newMail</I> to <I>reversePath</I>.
* If the requested value is <CODE>SpecialAddress.NULL</CODE> sets it to "<>".
* If the requested value is null does nothing.
* Is a "setX(Mail, Tx, Mail)" method.
*/
- protected void setReturnPath(Mail newMail, MailAddress returnPath, Mail
originalMail) throws MessagingException {
- if(returnPath != null) {
- String returnPathString;
- if (returnPath == SpecialAddress.NULL) {
- returnPathString = "";
+ protected void setReversePath(Mail newMail, MailAddress reversePath, Mail
originalMail) throws MessagingException {
+ if(reversePath != null) {
+ String reversePathString;
+ if (reversePath == SpecialAddress.NULL) {
+ reversePath = null;
+ reversePathString = "";
} else {
- returnPathString = returnPath.toString();
+ reversePathString = reversePath.toString();
}
- newMail.getMessage().setHeader(RFC2822Headers.RETURN_PATH, "<" +
returnPathString + ">");
+ ((MailImpl) newMail).setSender(reversePath);
+ newMail.getMessage().setHeader(RFC2822Headers.RETURN_PATH, "<" +
reversePathString + ">");
if (isDebug) {
- log("returnPath set to: " + returnPath);
+ log("reversePath set to: " + reversePath);
}
}
}
@@ -870,14 +818,13 @@
}
/**
- * Sets the sender and the "From:" header of <I>newMail</I> to <I>sender</I>.
+ * Sets the "From:" header of <I>newMail</I> to <I>sender</I>.
* If the requested value is null does nothing.
* Is a "setX(Mail, Tx, Mail)" method.
*/
protected void setSender(Mail newMail, MailAddress sender, Mail originalMail)
throws MessagingException {
if (sender != null) {
newMail.getMessage().setFrom(sender.toInternetAddress());
- ((MailImpl) newMail).setSender(sender);
if (isDebug) {
log("sender set to: " + sender);
@@ -981,11 +928,7 @@
* @return the <CODE>attachError</CODE> init parameter; false if missing
*/
protected boolean attachError() throws MessagingException {
- if(getInitParameter("attachError") == null) {
- return false;
- } else {
- return new Boolean(getInitParameter("attachError")).booleanValue();
- }
+ return new Boolean(getInitParameter("attachError")).booleanValue();
}
/**
@@ -1010,9 +953,6 @@
* @return the <CODE>isReply</CODE> init parameter; false if missing
*/
protected boolean isReply() throws MessagingException {
- if(getInitParameter("isReply") == null) {
- return false;
- }
return new Boolean(getInitParameter("isReply")).booleanValue();
}
@@ -1066,20 +1006,20 @@
checkInitParameters(getAllowedInitParameters());
if(isStatic()) {
- passThrough = getPassThrough();
- fakeDomainCheck = getFakeDomainCheck();
- attachmentType = getAttachmentType();
- inLineType = getInLineType();
- messageText = getMessage();
- recipients = getRecipients();
- replyTo = getReplyTo();
- returnPath = getReturnPath();
- sender = getSender();
- subject = getSubject();
- subjectPrefix = getSubjectPrefix();
- apparentlyTo = getTo();
- attachError = attachError();
- isReply = isReply();
+ passThrough = getPassThrough();
+ fakeDomainCheck = getFakeDomainCheck();
+ attachmentType = getAttachmentType();
+ inLineType = getInLineType();
+ messageText = getMessage();
+ recipients = getRecipients();
+ replyTo = getReplyTo();
+ reversePath = getReversePath();
+ sender = getSender();
+ subject = getSubject();
+ subjectPrefix = getSubjectPrefix();
+ apparentlyTo = getTo();
+ attachError = attachError();
+ isReply = isReply();
if (isDebug) {
StringBuffer logBuffer =
new StringBuffer(1024)
@@ -1088,7 +1028,7 @@
.append(", fakeDomainCheck=").append(fakeDomainCheck)
.append(", sender=").append(sender)
.append(", replyTo=").append(replyTo)
- .append(", returnPath=").append(returnPath)
+ .append(", reversePath=").append(reversePath)
.append(", message=").append(messageText)
.append(",
recipients=").append(arrayToString(recipients == null ? null : recipients.toArray()))
.append(", subject=").append(subject)
@@ -1182,7 +1122,7 @@
setReplyTo(newMail, getReplyTo(originalMail), originalMail);
- setReturnPath(newMail, getReturnPath(originalMail), originalMail);
+ setReversePath(newMail, getReversePath(originalMail), originalMail);
setSender(newMail, getSender(originalMail), originalMail);
@@ -1283,7 +1223,7 @@
}
/**
- * Gets the MailAddress corresponding to the existing "Return-Path" header of
+ * Gets the MailAddress corresponding to the existing "Return-Path" of
* <I>mail</I>.
* If empty returns <CODE>SpecialAddress.NULL</CODE>,
* if missing return <CODE>null</CODE>.
@@ -1581,8 +1521,8 @@
if(addressString.compareTo("sender") == 0) {
specialAddress = SpecialAddress.SENDER;
}
- if(addressString.compareTo("returnpath") == 0) {
- specialAddress = SpecialAddress.RETURN_PATH;
+ if(addressString.compareTo("reversepath") == 0) {
+ specialAddress = SpecialAddress.REVERSE_PATH;
}
if(addressString.compareTo("to") == 0) {
specialAddress = SpecialAddress.TO;
@@ -1760,6 +1700,93 @@
if (-1 == rawText.indexOf("?=", iThirdQuestionMark + 1)) return null; //
closing tag
String mimeCharset = rawText.substring(iCharsetBegin, iSecondQuestionMark);
return mimeCharset;
+ }
+
+ /**
+ * 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.RECIPIENTS</CODE>,
+ * <CODE>SpecialAddress.NULL</CODE> and <CODE>SpecialAddress.UNALTERED</CODE>.
+ * Any other address is not replaced.
+ */
+ protected Collection replaceMailAddresses(Mail mail, Collection list) {
+ Collection newList = new HashSet(list.size());
+ Iterator iterator = list.iterator();
+ while (iterator.hasNext()) {
+ MailAddress mailAddress = (MailAddress) iterator.next();
+ if (!mailAddress.getHost().equalsIgnoreCase("address.marker")) {
+ newList.add(mailAddress);
+ } else if (mailAddress == SpecialAddress.SENDER) {
+ MailAddress sender = mail.getSender();
+ if (sender != null) {
+ newList.add(sender);
+ }
+ } else if (mailAddress == SpecialAddress.REVERSE_PATH) {
+ MailAddress reversePath = mail.getSender();
+ if (reversePath != null) {
+ newList.add(reversePath);
+ }
+ } else if (mailAddress == SpecialAddress.RECIPIENTS) {
+ newList.addAll(mail.getRecipients());
+ } else if (mailAddress == SpecialAddress.UNALTERED) {
+ continue;
+ } else {
+ newList.add(mailAddress);
+ }
+ }
+ return newList;
+ }
+
+ /**
+ * 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.NULL</CODE> and <CODE>SpecialAddress.UNALTERED</CODE>.
+ * Any other address is not replaced.
+ */
+ protected Collection replaceInternetAddresses(Mail mail, Collection list)
throws MessagingException {
+ Collection newList = new HashSet(list.size());
+ Iterator iterator = list.iterator();
+ while (iterator.hasNext()) {
+ InternetAddress internetAddress = (InternetAddress) iterator.next();
+ MailAddress mailAddress = new MailAddress(internetAddress);
+ if (!mailAddress.getHost().equalsIgnoreCase("address.marker")) {
+ newList.add(internetAddress);
+ } else if
(internetAddress.equals(SpecialAddress.SENDER.toInternetAddress())) {
+ MailAddress sender = mail.getSender();
+ if (sender != null) {
+ newList.add(sender.toInternetAddress());
+ }
+ } else if
(internetAddress.equals(SpecialAddress.REVERSE_PATH.toInternetAddress())) {
+ MailAddress reversePath = mail.getSender();
+ if (reversePath != null) {
+ newList.add(reversePath.toInternetAddress());
+ }
+ } else if
(internetAddress.equals(SpecialAddress.TO.toInternetAddress())) {
+ String[] toHeaders = mail.getMessage().getHeader(RFC2822Headers.TO);
+ if (toHeaders != null) {
+ for (int i = 0; i < toHeaders.length; i++) {
+ try {
+ InternetAddress[] originalToInternetAddresses =
InternetAddress.parse(toHeaders[i], false);
+ for (int j = 0; j < originalToInternetAddresses.length;
j++) {
+ newList.add(originalToInternetAddresses[j]);
+ }
+ } catch (AddressException ae) {
+ log("Unable to parse the \"TO\" header in the original
message: " + toHeaders[i] + "; ignoring.");
+ }
+ }
+ }
+ } else if
(internetAddress.equals(SpecialAddress.UNALTERED.toInternetAddress())) {
+ continue;
+ } else if
(internetAddress.equals(SpecialAddress.NULL.toInternetAddress())) {
+ continue;
+ } else {
+ newList.add(internetAddress);
+ }
+ }
+ return newList;
}
}
1.9 +15 -16
james-server/src/java/org/apache/james/transport/mailets/Bounce.java
Index: Bounce.java
===================================================================
RCS file:
/home/cvs/james-server/src/java/org/apache/james/transport/mailets/Bounce.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Bounce.java 30 Jun 2003 09:41:03 -0000 1.8
+++ Bounce.java 4 Jul 2003 16:46:12 -0000 1.9
@@ -58,6 +58,7 @@
package org.apache.james.transport.mailets;
+import org.apache.mailet.RFC2822Headers;
import org.apache.mailet.GenericMailet;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
@@ -82,13 +83,12 @@
import java.util.ArrayList;
/**
- * <P>Generates a response to the Return-Path address, or the
- * address of the message's sender if the Return-Path is not
- * available. Note that this is different than a mail-client's
+ * <P>Generates a response to the reverse-path address.
+ * Note that this is different than a mail-client's
* reply, which would use the Reply-To or From header.</P>
* <P>Bounced messages are attached in their entirety (headers and
* content) and the resulting MIME part type is "message/rfc822".<BR>
- * The Return-Path header of the response is set to "null" ("<>"),
+ * The reverse-path and the Return-Path header of the response is set to "null"
("<>"),
* meaning that no reply should be sent.</P>
* <P>A sender of the notification message can optionally be specified.
* If one is not specified, the postmaster's address will be used.<BR>
@@ -125,15 +125,15 @@
* <passThrough>true or false</passThrough>
* <fakeDomainCheck><I>true or false</I></fakeDomainCheck>
* <recipients><B>sender</B></recipients>
- * <returnPath>null</returnPath>
+ * <reversePath>null</reversePath>
* <inline>see [EMAIL PROTECTED] Resend}</inline>
* <attachment>see [EMAIL PROTECTED] Resend}</attachment>
* <isReply>true</isReply>
* <debug><I>true or false</I></debug>
* </mailet>
* </CODE></PRE>
- * <P><I>notice</I>, <I>sendingAddress</I> and <I>attachStackTrace</I> can be used
instead of
- * <I><I>message</I>, <I>sender</I> and <I>attachError</I>; such names are kept for
backward compatibility.</P>
+ * <P><I>notice</I> and <I>sendingAddress</I> can be used instead of
+ * <I>message</I> and <I>sender</I>; such names are kept for backward
compatibility.</P>
*
* @version CVS $Revision$ $Date$
* @since 2.2.0
@@ -164,7 +164,6 @@
"sendingAddress",
"prefix",
"attachError",
- "attachStackTrace"
};
return allowedArray;
}
@@ -174,27 +173,27 @@
/* ******************************************************************** */
/**
- * @return <CODE>SpecialAddress.RETURN_PATH</CODE>
+ * @return <CODE>SpecialAddress.REVERSE_PATH</CODE>
*/
protected Collection getRecipients() {
Collection newRecipients = new HashSet();
- newRecipients.add(SpecialAddress.RETURN_PATH);
+ newRecipients.add(SpecialAddress.REVERSE_PATH);
return newRecipients;
}
/**
- * @return <CODE>SpecialAddress.RETURN_PATH</CODE>
+ * @return <CODE>SpecialAddress.REVERSE_PATH</CODE>
*/
protected InternetAddress[] getTo() {
InternetAddress[] apparentlyTo = new InternetAddress[1];
- apparentlyTo[0] = SpecialAddress.RETURN_PATH.toInternetAddress();
+ apparentlyTo[0] = SpecialAddress.REVERSE_PATH.toInternetAddress();
return apparentlyTo;
}
/**
* @return <CODE>SpecialAddress.NULL</CODE> (the meaning of bounce)
*/
- protected MailAddress getReturnPath(Mail originalMail) {
+ protected MailAddress getReversePath(Mail originalMail) {
return SpecialAddress.NULL;
}
@@ -214,13 +213,13 @@
MailAddress returnAddress = getExistingReturnPath(originalMail);
if (returnAddress == SpecialAddress.NULL) {
if (isDebug)
- log("Processing a bounce request for a message with an empty return
path. No bounce will be sent.");
+ log("Processing a bounce request for a message with an empty
reverse-path. No bounce will be sent.");
if(!getPassThrough(originalMail)) {
originalMail.setState(Mail.GHOST);
}
return;
} else if (returnAddress == null) {
- log("WARNING: Mail to be bounced does not contain a Return-Path
header.");
+ log("WARNING: Mail to be bounced does not contain a reverse-path.");
} else {
if (isDebug)
log("Processing a bounce request for a message with a return path
header. The bounce will be sent to " + returnAddress);
1.18 +36 -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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Forward.java 3 Jul 2003 05:27:45 -0000 1.17
+++ Forward.java 4 Jul 2003 16:46:12 -0000 1.18
@@ -76,7 +76,7 @@
* <P>Sample configuration:</P>
* <PRE><CODE>
* <mailet match="All" class="Forward">
- * <forwardto><I>comma delimited list of email
addresses</I></forwardto>
+ * <forwardTo><I>comma delimited list of email
addresses</I></forwardTo>
* <passThrough><I>true or false, default=false</I></passThrough>
* <fakeDomainCheck><I>true or false,
default=true</I></fakeDomainCheck>
* <debug><I>true or false, default=false</I></debug>
@@ -93,6 +93,8 @@
* <debug><I>true or false</I></debug>
* </mailet>
* </CODE></PRE>
+ * <P><I>forwardto</I> can be used instead of
+ * <I>forwardTo</I>; such name is kept for backward compatibility.</P>
*
* @version CVS $Revision$ $Date$
*/
@@ -115,6 +117,7 @@
"passThrough",
"fakeDomainCheck",
"forwardto",
+ "forwardTo"
};
return allowedArray;
}
@@ -148,24 +151,40 @@
* @return the <CODE>recipients</CODE> init parameter or null if missing
*/
protected Collection getRecipients() throws MessagingException {
- Collection newRecipients = null;
+ Collection newRecipients = new HashSet();
boolean error = false;
String addressList = getInitParameter("forwardto");
- if (addressList != null) {
- newRecipients = new HashSet();
- StringTokenizer st = new StringTokenizer(addressList, ",", false);
- while(st.hasMoreTokens()) {
- String recipient = st.nextToken();
- try {
- newRecipients.add(new MailAddress(recipient));
- } catch(Exception e) {
- log("Add \"" + recipient + "\" failed", e);
- error = true;
+ if (addressList == null) {
+ addressList = getInitParameter("forwardTo");
+ }
+
+ // if nothing was specified, throw an exception
+ if (addressList == null) {
+ 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"});
+ if (specialAddress != null) {
+ newRecipients.add(specialAddress);
+ } else {
+ newRecipients.add(new MailAddress(token));
}
+ } catch(Exception e) {
+ error = true;
+ log("Exception thrown in getRecipients() parsing: " + token, e);
}
}
- if (error || newRecipients == null || newRecipients.size() == 0) {
- throw new MessagingException("Failed to initialize recipient list; see
mailet log.");
+ if (error) {
+ throw new MessagingException("Failed to initialize \"recipients\" list;
see mailet log.");
+ }
+ if (newRecipients.size() == 0) {
+ throw new MessagingException("Failed to initialize \"recipients\" list;
empty <forwardTo> or <forwardto> init parameter found.");
}
return newRecipients;
@@ -188,7 +207,7 @@
/**
* @return null
*/
- protected MailAddress getReturnPath() throws MessagingException {
+ protected MailAddress getReversePath() throws MessagingException {
return null;
}
@@ -216,7 +235,7 @@
/**
* @return false
*/
- protected boolean attachError() throws MessagingException {
+ protected boolean attachError() {
return false;
}
1.21 +11 -25
james-server/src/java/org/apache/james/transport/mailets/NotifyPostmaster.java
Index: NotifyPostmaster.java
===================================================================
RCS file:
/home/cvs/james-server/src/java/org/apache/james/transport/mailets/NotifyPostmaster.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- NotifyPostmaster.java 30 Jun 2003 09:41:03 -0000 1.20
+++ NotifyPostmaster.java 4 Jul 2003 16:46:12 -0000 1.21
@@ -130,7 +130,7 @@
* </mailet>
* </CODE></PRE>
* <P><I>notice</I>, <I>sendingAddress</I> and <I>attachStackTrace</I> can be used
instead of
- * <I><I>message</I>, <I>sender</I> and <I>attachError</I>; such names are kept for
backward compatibility.</P>
+ * <I>message</I>, <I>sender</I> and <I>attachError</I>; such names are kept for
backward compatibility.</P>
*
* @version CVS $Revision$ $Date$
*/
@@ -199,30 +199,16 @@
}
/**
- * @return the <CODE>prefix</CODE> init parameter or "Re:" if missing
+ * @return the <CODE>attachStackTrace</CODE> init parameter,
+ * or the <CODE>attachError</CODE> init parameter if missing,
+ * or false if missing
*/
- protected String getSubjectPrefix() {
- if(getInitParameter("prefix") == null) {
- return "Re:";
- } else {
- return getInitParameter("prefix");
- }
- }
-
- /**
- * Builds the subject of <I>newMail</I> appending the subject
- * of <I>originalMail</I> to <I>subjectPrefix</I>, but avoiding a duplicate.
- */
- protected void setSubjectPrefix(Mail newMail, String subjectPrefix, Mail
originalMail) throws MessagingException {
- String subject = originalMail.getMessage().getSubject();
- if (subject == null) {
- subject = "";
- }
- if (subject.indexOf(subjectPrefix) == 0) {
- newMail.getMessage().setSubject(subject);
- } else {
- newMail.getMessage().setSubject(subjectPrefix + subject);
- }
+ protected boolean attachError() throws MessagingException {
+ String parameter = getInitParameter("attachStackTrace");
+ if (parameter == null) {
+ return super.attachError();
+ }
+ return new Boolean(parameter).booleanValue();
}
/* ******************************************************************** */
1.24 +15 -2
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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- NotifySender.java 30 Jun 2003 09:41:03 -0000 1.23
+++ NotifySender.java 4 Jul 2003 16:46:12 -0000 1.24
@@ -129,7 +129,7 @@
* </mailet>
* </CODE></PRE>
* <P><I>notice</I>, <I>sendingAddress</I> and <I>attachStackTrace</I> can be used
instead of
- * <I><I>message</I>, <I>sender</I> and <I>attachError</I>; such names are kept for
backward compatibility.</P>
+ * <I>message</I>, <I>sender</I> and <I>attachError</I>; such names are kept for
backward compatibility.</P>
*
* @version CVS $Revision$ $Date$
*/
@@ -195,6 +195,19 @@
}
}
return iaarray;
+ }
+
+ /**
+ * @return the <CODE>attachStackTrace</CODE> init parameter,
+ * or the <CODE>attachError</CODE> init parameter if missing,
+ * or false if missing
+ */
+ protected boolean attachError() throws MessagingException {
+ String parameter = getInitParameter("attachStackTrace");
+ if (parameter == null) {
+ return super.attachError();
+ }
+ return new Boolean(parameter).booleanValue();
}
/* ******************************************************************** */
1.33 +69 -46
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.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- Redirect.java 30 Jun 2003 09:41:03 -0000 1.32
+++ Redirect.java 4 Jul 2003 16:46:12 -0000 1.33
@@ -93,7 +93,7 @@
* <P>It differs from [EMAIL PROTECTED] Resend} because
* (i) some defaults are different,
* notably for the following parameters: <I><recipients></I>,
<I><to></I>,
- * <I><returnPath></I> and <I><inline></I>;
+ * <I><reversePath></I> and <I><inline></I>;
* (ii) because it allows the use of the <I><static></I> parameter;.<BR>
* Use <CODE>Resend</CODE> if you need full control, <CODE>Redirect</CODE> if
* the more automatic behaviour of some parameters is appropriate.</P>
@@ -112,7 +112,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",
"returnPath" and "unaltered".
+ * It can include constants "sender", "postmaster",
"reversePath", "recipients" and "unaltered".
* </TD>
* </TR>
* <TR valign=top>
@@ -123,7 +123,8 @@
* list.<BR>
* The recipients list will be used if this list is not supplied;
* if none of the lists is specified it will be "unaltered".<BR>
- * It can include constants "sender", "postmaster",
"returnPath" and "unaltered".
+ * It can include constants "sender", "postmaster",
"reversePath", "recipients", "null" and
"unaltered";
+ * if "null" is specified alone it will remove this header.
* </TD>
* </TR>
* <TR valign=top>
@@ -206,7 +207,7 @@
* </TD>
* </TR>
* <TR valign=top>
- * <TD width="20%"><replyto></TD>
+ * <TD width="20%"><replyTo></TD>
* <TD width="80%">
* A single email address to appear in the Reply-To: header.<BR>
* It can include constants "sender", "postmaster"
"null" and "unaltered";
@@ -216,7 +217,7 @@
* </TR>
* </TR>
* <TR valign=top>
- * <TD width="20%"><returnPath></TD>
+ * <TD width="20%"><reversePath></TD>
* <TD width="80%">
* A single email address to appear in the Return-Path: header.<BR>
* It can include constants "sender", "postmaster" and
"null";
@@ -279,7 +280,7 @@
* <message>sent on from James</message>
* <inline>unaltered</inline>
* <passThrough>FALSE</passThrough>
- * <replyto>postmaster</replyto>
+ * <replyTo>postmaster</replyTo>
* <prefix xml:space="preserve">[test mailing] </prefix>
* <!-- note the xml:space="preserve" to preserve whitespace -->
* <static>TRUE</static>
@@ -297,11 +298,13 @@
* <attachment>message</attachment>
* <passThrough>FALSE</passThrough>
* <attachError>TRUE</attachError>
- * <replyto>postmaster</replyto>
+ * <replyTo>postmaster</replyTo>
* <prefix>[spam notification]</prefix>
* <static>TRUE</static>
* </mailet>
* </CODE></PRE>
+ * <P><I>replyto</I> can be used instead of
+ * <I>replyTo</I>; such name is kept for backward compatibility.</P>
*
* @version CVS $Revision$ $Date$
*/
@@ -329,8 +332,9 @@
"message",
"recipients",
"to",
+ "replyTo",
"replyto",
- "returnPath",
+ "reversePath",
"sender",
"subject",
"prefix",
@@ -366,36 +370,47 @@
* @return the <CODE>recipients</CODE> init parameter
* or the postmaster address
* or <CODE>SpecialAddress.SENDER</CODE>
- * or <CODE>SpecialAddress.RETURN_PATH</CODE>
+ * or <CODE>SpecialAddress.REVERSE_PATH</CODE>
* or <CODE>SpecialAddress.UNALTERED</CODE>
* or the <CODE>to</CODE> init parameter if missing
* or <CODE>null</CODE> if also the latter is missing
*/
protected Collection getRecipients() throws MessagingException {
Collection newRecipients = new HashSet();
+ boolean error = false;
String addressList = (getInitParameter("recipients") == null)
? getInitParameter("to")
: getInitParameter("recipients");
+
// if nothing was specified, return <CODE>null</CODE> meaning no change
if (addressList == null) {
return null;
}
- MailAddress specialAddress = getSpecialAddress(addressList,
- new String[] {"postmaster", "sender",
"returnPath", "unaltered"});
- if (specialAddress != null) {
- newRecipients.add(specialAddress);
- return newRecipients;
- }
-
StringTokenizer st = new StringTokenizer(addressList, ",", false);
while(st.hasMoreTokens()) {
+ String token = null;
try {
- newRecipients.add(new MailAddress(st.nextToken()));
+ token = st.nextToken();
+ MailAddress specialAddress = getSpecialAddress(token,
+ new String[] {"postmaster",
"sender", "reversePath", "unaltered", "recipients"});
+ if (specialAddress != null) {
+ newRecipients.add(specialAddress);
+ } else {
+ newRecipients.add(new MailAddress(token));
+ }
} catch(Exception e) {
- log("add recipient failed in getRecipients");
+ error = true;
+ log("Exception thrown in getRecipients() parsing: " + token, e);
}
}
+ if (error) {
+ throw new MessagingException("Failed to initialize \"recipients\" list;
see mailet log.");
+ }
+ if (newRecipients.size() == 0) {
+ throw new MessagingException("Failed to initialize \"recipients\" list;
empty <recipients> init parameter found.");
+ }
+
return newRecipients;
}
@@ -403,52 +418,60 @@
* @return the <CODE>to</CODE> init parameter
* or the postmaster address
* or <CODE>SpecialAddress.SENDER</CODE>
- * or <CODE>SpecialAddress.RETURN_PATH</CODE>
+ * or <CODE>SpecialAddress.REVERSE_PATH</CODE>
* or <CODE>SpecialAddress.UNALTERED</CODE>
* or the <CODE>recipients</CODE> init parameter if missing
* or <CODE>null</CODE> if also the latter is missing
*/
protected InternetAddress[] getTo() throws MessagingException {
+ boolean error = false;
String addressList = (getInitParameter("to") == null)
? getInitParameter("recipients")
: getInitParameter("to");
+
// if nothing was specified, return null meaning no change
if (addressList == null) {
return null;
}
- MailAddress specialAddress = getSpecialAddress(addressList,
- new String[] {"postmaster", "sender",
"returnPath", "unaltered"});
- if (specialAddress != null) {
- InternetAddress[] iaarray = new InternetAddress[1];
- iaarray[0] = specialAddress.toInternetAddress();
- return iaarray;
- }
-
- StringTokenizer rec = new StringTokenizer(addressList, ",");
- int tokensn = rec.countTokens();
- InternetAddress[] iaarray = new InternetAddress[tokensn];
- String tokenx = "";
- for(int i = 0; i < tokensn; ++i) {
+ StringTokenizer rec = new StringTokenizer(addressList, ",");
+ int tokenCount = rec.countTokens();
+ InternetAddress[] iaarray = new InternetAddress[tokenCount];
+ String token = "";
+ for(int i = 0; i < tokenCount; ++i) {
try {
- tokenx = rec.nextToken();
- iaarray[i] = new InternetAddress(tokenx);
+ token = rec.nextToken();
+ MailAddress specialAddress = getSpecialAddress(token,
+ new String[] {"postmaster",
"sender", "reversePath", "unaltered", "to", "null"});
+ if (specialAddress != null) {
+ iaarray[i] = specialAddress.toInternetAddress();
+ } else {
+ iaarray[i] = new InternetAddress(token);
+ }
} catch(Exception e) {
- log("Internet address exception in getTo()");
+ error = true;
+ log("Exception thrown in getTo() parsing: " + token, e);
}
}
+ if (error) {
+ throw new MessagingException("Failed to initialize \"to\" list; see
mailet log.");
+ }
+ if (tokenCount == 0) {
+ throw new MessagingException("Failed to initialize \"to\" list; empty
<to> init parameter found.");
+ }
+
return iaarray;
}
/**
- * @return the <CODE>returnPath</CODE> init parameter
+ * @return the <CODE>reversePath</CODE> init parameter
* or the postmaster address
* or <CODE>SpecialAddress.SENDER</CODE>
* or <CODE>SpecialAddress.NULL</CODE>
* or <CODE>null</CODE> if missing
*/
- protected MailAddress getReturnPath() throws MessagingException {
- String addressString = getInitParameter("returnPath");
+ protected MailAddress getReversePath() throws MessagingException {
+ String addressString = getInitParameter("reversePath");
if(addressString != null) {
MailAddress specialAddress = getSpecialAddress(addressString,
new String[] {"postmaster", "sender",
"null"});
@@ -459,7 +482,7 @@
try {
return new MailAddress(addressString);
} catch(Exception e) {
- throw new MessagingException("Exception thrown in getReturnPath()
parsing: " + addressString, e);
+ throw new MessagingException("Exception thrown in getReversePath()
parsing: " + addressString, e);
}
}
@@ -467,16 +490,16 @@
}
/**
- * @return [EMAIL PROTECTED] AbstractRedirect#getReturnPath()};
+ * @return [EMAIL PROTECTED] AbstractRedirect#getReversePath()};
* if null return [EMAIL PROTECTED] AbstractRedirect#getSender(Mail)},
* meaning the new requested sender if any
*/
- protected MailAddress getReturnPath(Mail originalMail) throws
MessagingException {
- MailAddress returnPath = super.getReturnPath(originalMail);
- if (returnPath == null) {
- returnPath = getSender(originalMail);
+ protected MailAddress getReversePath(Mail originalMail) throws
MessagingException {
+ MailAddress reversePath = super.getReversePath(originalMail);
+ if (reversePath == null) {
+ reversePath = getSender(originalMail);
}
- return returnPath;
+ return reversePath;
}
/* ******************************************************************** */
1.3 +12 -8
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Resend.java 30 Jun 2003 09:41:04 -0000 1.2
+++ Resend.java 4 Jul 2003 16:46:12 -0000 1.3
@@ -106,7 +106,7 @@
* <TD width="80%">
* A comma delimited list of email addresses for recipients of
* this message;.<BR>
- * It can include constants "sender", "postmaster",
"returnPath" and "unaltered".<BR>
+ * It can include constants "sender", "postmaster",
"reversePath", "recipients" and "unaltered".<BR>
* Default: "unaltered".
* </TD>
* </TR>
@@ -114,7 +114,8 @@
* <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",
"returnPath" and "unaltered".
+ * It can include constants "sender", "postmaster",
"reversePath", "to", "null" and "unaltered";
+ * if "null" is specified alone it will remove this header.<BR>
* Default: "unaltered".
* </TD>
* </TR>
@@ -198,7 +199,7 @@
* </TD>
* </TR>
* <TR valign=top>
- * <TD width="20%"><replyto></TD>
+ * <TD width="20%"><replyTo></TD>
* <TD width="80%">
* A single email address to appear in the Reply-To: header.<BR>
* It can include constants "sender", "postmaster"
"null" and "unaltered";
@@ -207,7 +208,7 @@
* </TD>
* </TR>
* <TR valign=top>
- * <TD width="20%"><returnPath></TD>
+ * <TD width="20%"><reversePath></TD>
* <TD width="80%">
* A single email address to appear in the Return-Path: header.<BR>
* It can include constants "sender", "postmaster"
"null" and "unaltered";
@@ -258,7 +259,7 @@
* <message>sent on from James</message>
* <inline>unaltered</inline>
* <passThrough>FALSE</passThrough>
- * <replyto>postmaster</replyto>
+ * <replyTo>postmaster</replyTo>
* <prefix xml:space="preserve">[test mailing] </prefix>
* <!-- note the xml:space="preserve" to preserve whitespace -->
* <static>TRUE</static>
@@ -276,7 +277,7 @@
* <attachment>message</attachment>
* <passThrough>FALSE</passThrough>
* <attachError>TRUE</attachError>
- * <replyto>postmaster</replyto>
+ * <replyTo>postmaster</replyTo>
* <prefix>[spam notification]</prefix>
* </mailet>
* </CODE></PRE>
@@ -285,6 +286,8 @@
* <PRE><CODE>
* <mailet match="All" class="Resend"/;>
* </CODE></PRE>
+ * <P><I>replyto</I> can be used instead of
+ * <I>replyTo</I>; such name is kept for backward compatibility.</P>
* <P><B>WARNING: as the message (or a copy of it) is reinjected in the spool
without any modification,
* the preceding example is very likely to cause a "configuration loop" in your
system,
* unless some other mailet has previously modified something (a header for
instance) that could force the resent
@@ -317,8 +320,9 @@
"message",
"recipients",
"to",
+ "replyTo",
"replyto",
- "returnPath",
+ "reversePath",
"sender",
"subject",
"prefix",
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]