Author: norman
Date: Thu Dec 14 09:51:09 2006
New Revision: 487278

URL: http://svn.apache.org/viewvc?view=rev&rev=487278
Log:
Add config parameter to RemoteDelivery to configure helo. See JAMES-735

Modified:
    james/server/trunk/src/conf/james-config.xml
    
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java

Modified: james/server/trunk/src/conf/james-config.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-config.xml?view=diff&rev=487278&r1=487277&r2=487278
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Thu Dec 14 09:51:09 2006
@@ -697,6 +697,12 @@
             <gateway> otherserver.mydomain.com </gateway>
             <gatewayPort>25</gatewayPort>
             -->
+            
+            <!-- The name which will be used as HELO. If not set the heloName 
configured in James block -->
+            <!-- will be used. -->
+            <!--
+            <helloName> myMailServer </helloName> 
+            -->
          </mailet>
 
       </processor>

Modified: 
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java?view=diff&rev=487278&r1=487277&r2=487278
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
 Thu Dec 14 09:51:09 2006
@@ -228,6 +228,8 @@
     // The retry count dnsProblemErrors
     private int dnsProblemRetry = 0;
     
+    private String helloName = null;
+    
     /**
      * Initialize the mailet
      */
@@ -385,6 +387,9 @@
         if (dnsRetry != null && !dnsRetry.equals("")) {
             dnsProblemRetry = Integer.parseInt(dnsRetry); 
         }
+        
+        helloName = getInitParameter("helloName");
+        
     }
     
     /**
@@ -1110,26 +1115,43 @@
      * there are any
      */
     public void run() {
-
-        /* TODO: CHANGE ME!!! The problem is that we need to wait for James to
-         * finish initializing.  We expect the HELLO_NAME to be put into
-         * the MailetContext, but in the current configuration we get
-         * started before the SMTP Server, which establishes the value.
-         * Since there is no contractual guarantee that there will be a
-         * HELLO_NAME value, we can't just wait for it.  As a temporary
-         * measure, I'm inserting this philosophically unsatisfactory
-         * fix.
-         */
-        long stop = System.currentTimeMillis() + 60000;
-        while ((getMailetContext().getAttribute(Constants.HELLO_NAME) == null)
-               && stop > System.currentTimeMillis()) {
-            try {
-                Thread.sleep(1000);
-            } catch (Exception ignored) {} // wait for James to finish 
initializing
-        }
-
         //Checks the pool and delivers a mail message
         Properties props = new Properties();
+        
+        if (helloName == null) {
+            /* TODO: CHANGE ME!!! The problem is that we need to wait for 
James to
+             * finish initializing.  We expect the HELLO_NAME to be put into
+             * the MailetContext, but in the current configuration we get
+             * started before the SMTP Server, which establishes the value.
+             * Since there is no contractual guarantee that there will be a
+             * HELLO_NAME value, we can't just wait for it.  As a temporary
+             * measure, I'm inserting this philosophically unsatisfactory
+             * fix.
+             * 
+             * When we drop backward compatibility we can remove the waiting, 
cause if the heloName is configured
+             * in the james block it will be set in the attributes before the 
mailets get init
+             */
+            long stop = System.currentTimeMillis() + 60000;
+            while ((getMailetContext().getAttribute(Constants.HELLO_NAME) == 
null)
+                   && stop > System.currentTimeMillis()) {
+                try {
+                    Thread.sleep(1000);
+                } catch (Exception ignored) {} // wait for James to finish 
initializing
+            }
+            
+            String defaultDomain = (String) 
getMailetContext().getAttribute(Constants.HELLO_NAME);
+            if (defaultDomain != null) {
+                props.put("mail.smtp.localhost", defaultDomain);
+            } else {
+                defaultDomain = (String) 
getMailetContext().getAttribute(Constants.DEFAULT_DOMAIN);
+                if (defaultDomain != null) {
+                    props.put("mail.smtp.localhost", defaultDomain);
+                }
+            }
+        } else {
+            props.put("mail.smtp.localhost", helloName);
+        }
+        
         //Not needed for production environment
         props.put("mail.debug", "false");
         // Reactivated: javamail 1.3.2 should no more have problems with "250 
OK"
@@ -1145,17 +1167,6 @@
 
         props.put("mail.smtp.connectiontimeout", connectionTimeout + "");
         props.put("mail.smtp.sendpartial",String.valueOf(sendPartial));
-
-        //Set the hostname we'll use as this server
-        if (getMailetContext().getAttribute(Constants.HELLO_NAME) != null) {
-            props.put("mail.smtp.localhost", 
getMailetContext().getAttribute(Constants.HELLO_NAME));
-        }
-        else {
-            String defaultDomain = (String) 
getMailetContext().getAttribute(Constants.DEFAULT_DOMAIN);
-            if (defaultDomain != null) {
-                props.put("mail.smtp.localhost", defaultDomain);
-            }
-        }
 
         if (isBindUsed) {
             // undocumented JavaMail 1.2 feature, smtp transport will use



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

Reply via email to