pgoldstein    2002/10/03 22:00:34

  Modified:    src/java/org/apache/james/transport/mailets
                        RemoteDelivery.java
  Log:
  Modifying RemoteDelivery so that it doesn't split recipient addresses on a per 
domain basis if the James server is forwarding to a gateway server.
  Thanks to Brad Walker and Noel Bergman
  
  Revision  Changes    Path
  1.30      +58 -41    
jakarta-james/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
  
  Index: RemoteDelivery.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-james/src/java/org/apache/james/transport/mailets/RemoteDelivery.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- RemoteDelivery.java       2 Oct 2002 07:27:44 -0000       1.29
  +++ RemoteDelivery.java       4 Oct 2002 05:00:34 -0000       1.30
  @@ -60,7 +60,7 @@
       /**
        * Controls certain log messages
        */
  -    private final boolean DEBUG = false;
  +    private boolean isDebug = false;
   
       private SpoolRepository outgoing; // The spool of outgoing mail
       private long delayTime = 21600000; // default is 6*60*60*1000 millis (6 hours)
  @@ -77,6 +77,7 @@
        * Initialize the mailet
        */
       public void init() throws MessagingException {
  +        isDebug = (getInitParameter("debug") == null) ? false : new 
Boolean(getInitParameter("debug")).booleanValue();
           try {
               if (getInitParameter("delayTime") != null) {
                   delayTime = Long.parseLong(getInitParameter("delayTime"));
  @@ -151,8 +152,8 @@
        */
       private boolean deliver(MailImpl mail, Session session) {
           try {
  -            if (DEBUG) {
  -                log("attempting to deliver " + mail.getName());
  +            if (isDebug) {
  +                log("Attempting to deliver " + mail.getName());
               }
               MimeMessage message = mail.getMessage();
   
  @@ -442,51 +443,67 @@
       public void service(Mail genericmail) throws AddressException {
           MailImpl mail = (MailImpl)genericmail;
   
  -        //Do I want to give the internal key, or the message's Message ID
  -        if (DEBUG) {
  +        // Do I want to give the internal key, or the message's Message ID
  +        if (isDebug) {
               log("Remotely delivering mail " + mail.getName());
           }
           Collection recipients = mail.getRecipients();
   
  -        //Must first organize the recipients into distinct servers (name made case 
insensitive)
  -        Hashtable targets = new Hashtable();
  -        for (Iterator i = recipients.iterator(); i.hasNext();) {
  -            MailAddress target = (MailAddress)i.next();
  -            String targetServer = target.getHost().toLowerCase(Locale.US);
  -            Collection temp = (Collection)targets.get(targetServer);
  -            if (temp == null) {
  -                temp = new Vector();
  -                targets.put(targetServer, temp);
  -            }
  -            temp.add(target);
  -        }
  -
  -        //We have the recipients organized into distinct servers... put them into 
the
  -        //delivery store organized like this... this is ultra inefficient I think...
  -
  -        //store the new message containers, organized by server, in the outgoing 
mail repository
  -        String name = mail.getName();
  -        for (Iterator i = targets.keySet().iterator(); i.hasNext(); ) {
  -            String host = (String) i.next();
  -            Collection rec = (Collection) targets.get(host);
  -            if (DEBUG) {
  -                StringBuffer logMessageBuffer =
  +        if (gatewayServer == null) {
  +            // Must first organize the recipients into distinct servers (name made 
case insensitive)
  +            Hashtable targets = new Hashtable();
  +            for (Iterator i = recipients.iterator(); i.hasNext();) {
  +                MailAddress target = (MailAddress)i.next();
  +                String targetServer = target.getHost().toLowerCase(Locale.US);
  +                Collection temp = (Collection)targets.get(targetServer);
  +                if (temp == null) {
  +                    temp = new Vector();
  +                    targets.put(targetServer, temp);
  +                }
  +                temp.add(target);
  +            }
  +
  +            //We have the recipients organized into distinct servers... put them 
into the
  +            //delivery store organized like this... this is ultra inefficient I 
think...
  +
  +            // Store the new message containers, organized by server, in the 
outgoing mail repository
  +            String name = mail.getName();
  +            for (Iterator i = targets.keySet().iterator(); i.hasNext(); ) {
  +                String host = (String) i.next();
  +                Collection rec = (Collection) targets.get(host);
  +                if (isDebug) {
  +                    StringBuffer logMessageBuffer =
  +                        new StringBuffer(128)
  +                                .append("Sending mail to ")
  +                                .append(rec)
  +                                .append(" on host ")
  +                                .append(host);
  +                    log(logMessageBuffer.toString());
  +                }
  +                mail.setRecipients(rec);
  +                StringBuffer nameBuffer =
                       new StringBuffer(128)
  -                            .append("Sending mail to ")
  -                            .append(rec)
  -                            .append(" on host ")
  +                            .append(name)
  +                            .append("-to-")
                               .append(host);
  +                mail.setName(nameBuffer.toString());
  +                outgoing.store(mail);
  +                //Set it to try to deliver (in a separate thread) immediately 
(triggered by storage)
  +            }
  +        } else {
  +            // Store the mail unaltered for processing by the gateway server
  +            if (isDebug) {
  +                StringBuffer logMessageBuffer =
  +                    new StringBuffer(128)
  +                        .append("Sending mail to ")
  +                        .append(mail.getRecipients())
  +                        .append(" via ")
  +                        .append(gatewayServer);
                   log(logMessageBuffer.toString());
               }
  -            mail.setRecipients(rec);
  -            StringBuffer nameBuffer =
  -                new StringBuffer(128)
  -                        .append(name)
  -                        .append("-to-")
  -                        .append(host);
  -            mail.setName(nameBuffer.toString());
  +
  +             //Set it to try to deliver (in a separate thread) immediately 
(triggered by storage)
               outgoing.store(mail);
  -            //Set it to try to deliver (in a separate thread) immediately 
(triggered by storage)
           }
           mail.setState(Mail.GHOST);
       }
  @@ -550,7 +567,7 @@
               try {
                   String key = outgoing.accept(delayTime);
                   try {
  -                    if (DEBUG) {
  +                    if (isDebug) {
                           StringBuffer logMessageBuffer = 
                               new StringBuffer(128)
                                       .append(Thread.currentThread().getName())
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to