vincenzo 2003/06/19 09:08:28
Modified: src/java/org/apache/james/transport/mailets Tag:
branch_2_1_fcs AbstractRedirect.java
Log:
Was getting a NPE in getTo(Mail) when SpecialAddress.SENDER was returned by getTo(),
and the sender was null. Fixed together with a better "fail over", also when
SpecialAddress.RETURN_PATH was returned.
Revision Changes Path
No revision
No revision
1.1.2.10 +48 -6
jakarta-james/src/java/org/apache/james/transport/mailets/AbstractRedirect.java
Index: AbstractRedirect.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/transport/mailets/AbstractRedirect.java,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -u -r1.1.2.9 -r1.1.2.10
--- AbstractRedirect.java 15 Jun 2003 18:40:20 -0000 1.1.2.9
+++ AbstractRedirect.java 19 Jun 2003 16:08:27 -0000 1.1.2.10
@@ -162,8 +162,7 @@
* <P>Supports by default the <CODE>passThrough</CODE> init parameter (false if
missing).
* Subclasses can override this behaviour overriding [EMAIL PROTECTED]
#getPassThrough()}.</P>
*
- * <P>CVS $Id$</P>
- * @version 2.2.0
+ * @version CVS $Revision$ $Date$
* @since 2.2.0
*/
@@ -479,16 +478,54 @@
/**
* Gets the <CODE>to</CODE> property,
* built dynamically using the original Mail object.
+ * 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>
+ * 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> and <CODE>SpecialAddress.UNALTERED</CODE> if
applicable
+ * @return [EMAIL PROTECTED] #getTo()}, replacing
<CODE>SpecialAddress.SENDER</CODE>,
+ * <CODE>SpecialAddress.SENDER</CODE> and <CODE>SpecialAddress.UNALTERED</CODE>
if applicable
*/
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())) {
- apparentlyTo = new InternetAddress[1];
- apparentlyTo[0] = originalMail.getSender().toInternetAddress();
+ MailAddress mailAddress = originalMail.getSender();
+ if (mailAddress == null) {
+ mailAddress = getExistingReturnPath(originalMail);
+ if (mailAddress == SpecialAddress.NULL) {
+ mailAddress = null;
+ }
+ }
+ if (mailAddress == 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 = (InternetAddress[])
originalMail.getMessage().getRecipients(Message.RecipientType.TO);
} else if
(apparentlyTo[0].equals(SpecialAddress.RETURN_PATH.toInternetAddress())) {
@@ -498,8 +535,13 @@
throw new MessagingException("NULL return path found getting
recipients");
}
if (mailAddress == null) {
- apparentlyTo[0] = originalMail.getSender().toInternetAddress();
+ mailAddress = originalMail.getSender();
+ }
+ if (mailAddress == null) {
+ // set to <>
+ apparentlyTo = new InternetAddress[0];
} else {
+ apparentlyTo = new InternetAddress[1];
apparentlyTo[0] = mailAddress.toInternetAddress();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]