vincenzo    2003/06/19 09:10:34

  Modified:    src/java/org/apache/james/transport/mailets
                        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
  1.9       +48 -5     
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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AbstractRedirect.java     16 Jun 2003 03:35:07 -0000      1.8
  +++ AbstractRedirect.java     19 Jun 2003 16:10:33 -0000      1.9
  @@ -479,16 +479,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 +536,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]

Reply via email to