You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/10/20 19:52:46 UTC

svn commit: r1025652 - in /james/server/trunk: core-api/src/main/java/org/apache/james/services/ core-function/src/main/java/org/apache/james/ core-library/src/test/java/org/apache/james/services/ mailetcontainer-library/ mailetcontainer-library/src/ma...

Author: norman
Date: Wed Oct 20 17:52:45 2010
New Revision: 1025652

URL: http://svn.apache.org/viewvc?rev=1025652&view=rev
Log:
Remove Configurable interface from JamesMailetContext (JAMES-1075)

Modified:
    james/server/trunk/core-api/src/main/java/org/apache/james/services/MailServer.java
    james/server/trunk/core-function/src/main/java/org/apache/james/JamesMailServer.java
    james/server/trunk/core-library/src/test/java/org/apache/james/services/MockMailServer.java
    james/server/trunk/mailetcontainer-library/pom.xml
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/JamesMailetContext.java
    james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java

Modified: james/server/trunk/core-api/src/main/java/org/apache/james/services/MailServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-api/src/main/java/org/apache/james/services/MailServer.java?rev=1025652&r1=1025651&r2=1025652&view=diff
==============================================================================
--- james/server/trunk/core-api/src/main/java/org/apache/james/services/MailServer.java (original)
+++ james/server/trunk/core-api/src/main/java/org/apache/james/services/MailServer.java Wed Oct 20 17:52:45 2010
@@ -24,6 +24,7 @@ package org.apache.james.services;
 import javax.mail.MessagingException;
 
 import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
 
 /**
  * The interface for Phoenix blocks to the James MailServer
@@ -94,4 +95,11 @@ public interface MailServer
      * @return the helloName
      */
     String getHelloName();
+    
+    /**
+     * Return the {@link MailAddress} of the postmaster
+     * 
+     * @return postmaster
+     */
+    public MailAddress getPostmaster();
 }

Modified: james/server/trunk/core-function/src/main/java/org/apache/james/JamesMailServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/JamesMailServer.java?rev=1025652&r1=1025651&r2=1025652&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/java/org/apache/james/JamesMailServer.java (original)
+++ james/server/trunk/core-function/src/main/java/org/apache/james/JamesMailServer.java Wed Oct 20 17:52:45 2010
@@ -42,6 +42,7 @@ import org.apache.james.queue.MailQueue;
 import org.apache.james.queue.MailQueueFactory;
 import org.apache.james.services.MailServer;
 import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
 
 /**
  * 
@@ -88,6 +89,8 @@ public class JamesMailServer
     
     private MailQueue queue;
 
+    private MailAddress postmaster;
+
     @Resource(name="domainlist")
     public void setDomainList(DomainList domains) {
         this.domains = domains;
@@ -120,7 +123,6 @@ public class JamesMailServer
     }
     
     
-    @SuppressWarnings("unchecked")
 	@PostConstruct
     public void init() throws Exception {
 
@@ -167,6 +169,7 @@ public class JamesMailServer
         }
 
 
+        initPostmaster();
         System.out.println(SOFTWARE_NAME_VERSION);
         logger.info("JAMES ...init end");
     }
@@ -306,5 +309,47 @@ public class JamesMailServer
         }
     }
     
+    
+    private void initPostmaster() throws Exception {
+        // Get postmaster
+        String postMasterAddress = conf.getString("postmaster", "postmaster").toLowerCase(Locale.US);
+        // if there is no @domain part, then add the first one from the
+        // list of supported domains that isn't localhost. If that
+        // doesn't work, use the hostname, even if it is localhost.
+        if (postMasterAddress.indexOf('@') < 0) {
+            String domainName = null; // the domain to use
+            // loop through candidate domains until we find one or exhaust the
+            // list
+            String[] doms = domains.getDomains();
+            if (doms != null) {
+                for (int i = 0; i < doms.length; i++) {
+                    String serverName = doms[i].toLowerCase(Locale.US);
+                    if (!("localhost".equals(serverName))) {
+                        domainName = serverName; // ok, not localhost, so use it
+                        continue;
+                    }
+                }
+            
+            }
+            // if we found a suitable domain, use it. Otherwise fallback to the
+            // host name.
+            postMasterAddress = postMasterAddress + "@" + (domainName != null ? domainName : getDefaultDomain());
+        }
+        this.postmaster = new MailAddress(postMasterAddress);
+
+        if (!isLocalServer(postmaster.getDomain())) {
+            StringBuffer warnBuffer = new StringBuffer(320).append("The specified postmaster address ( ").append(postmaster).append(
+                    " ) is not a local address.  This is not necessarily a problem, but it does mean that emails addressed to the postmaster will be routed to another server.  For some configurations this may cause problems.");
+            logger.warn(warnBuffer.toString());
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.services.MailServer#getPostmaster()
+     */
+    public MailAddress getPostmaster() {
+        return postmaster;
+    }
 
 }

Modified: james/server/trunk/core-library/src/test/java/org/apache/james/services/MockMailServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/test/java/org/apache/james/services/MockMailServer.java?rev=1025652&r1=1025651&r2=1025652&view=diff
==============================================================================
--- james/server/trunk/core-library/src/test/java/org/apache/james/services/MockMailServer.java (original)
+++ james/server/trunk/core-library/src/test/java/org/apache/james/services/MockMailServer.java Wed Oct 20 17:52:45 2010
@@ -22,10 +22,12 @@ package org.apache.james.services;
 import java.util.concurrent.LinkedBlockingQueue;
 
 import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
 
 import org.apache.james.lifecycle.Disposable;
 import org.apache.james.lifecycle.LifecycleUtil;
 import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.test.MailUtil;
 
 public class MockMailServer implements MailServer, Disposable {
@@ -97,6 +99,14 @@ public class MockMailServer implements M
     public String getHelloName() {
         return "localhost";
     }
+
+    public MailAddress getPostmaster() {
+        try {
+            return new MailAddress("postmaster", "localhost");
+        } catch (AddressException e) {
+            return null;
+        }
+    }
 }
 
 

Modified: james/server/trunk/mailetcontainer-library/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/pom.xml?rev=1025652&r1=1025651&r2=1025652&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-library/pom.xml (original)
+++ james/server/trunk/mailetcontainer-library/pom.xml Wed Oct 20 17:52:45 2010
@@ -69,9 +69,5 @@
       <groupId>org.apache.james</groupId>
       <artifactId>james-server-dnsservice-api</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.apache.james</groupId>
-      <artifactId>james-server-domain-api</artifactId>
-    </dependency>
   </dependencies>
 </project>

Modified: james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/JamesMailetContext.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/JamesMailetContext.java?rev=1025652&r1=1025651&r2=1025652&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/JamesMailetContext.java (original)
+++ james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/JamesMailetContext.java Wed Oct 20 17:52:45 2010
@@ -27,10 +27,8 @@ import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
-import java.util.Locale;
 import java.util.Vector;
 
-import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
 import javax.mail.Address;
 import javax.mail.Message;
@@ -39,15 +37,11 @@ import javax.mail.internet.InternetAddre
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.ParseException;
 
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.logging.Log;
-import org.apache.james.api.domainlist.DomainList;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.core.MailImpl;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.dnsservice.api.TemporaryResolutionException;
-import org.apache.james.lifecycle.Configurable;
 import org.apache.james.lifecycle.LifecycleUtil;
 import org.apache.james.lifecycle.LogEnabled;
 import org.apache.james.services.MailServer;
@@ -57,7 +51,7 @@ import org.apache.mailet.MailAddress;
 import org.apache.mailet.MailetContext;
 import org.apache.mailet.base.RFC2822Headers;
 
-public class JamesMailetContext implements MailetContext, LogEnabled, Configurable {
+public class JamesMailetContext implements MailetContext, LogEnabled {
 
     private MailServer mailServer;
 
@@ -71,15 +65,6 @@ public class JamesMailetContext implemen
 
     private UsersRepository localusers;
 
-    /**
-     * The address of the postmaster for this server
-     */
-    private MailAddress postmaster;
-
-    private DomainList domains;
-
-    private HierarchicalConfiguration conf;
-
     @Resource(name = "mailserver")
     public void setMailServer(MailServer mailServer) {
         this.mailServer = mailServer;
@@ -94,18 +79,8 @@ public class JamesMailetContext implemen
     public void setUsersRepository(UsersRepository localusers) {
         this.localusers = localusers;
     }
-
-    @Resource(name = "domainlist")
-    public void setDomainList(DomainList domains) {
-        this.domains = domains;
-    }
-
-    @PostConstruct
-    public void init() throws Exception {
-
-        initPostmaster();
-    }
-
+    
+    
     /**
      * @see org.apache.mailet.MailetContext#getMailServers(String)
      */
@@ -276,7 +251,7 @@ public class JamesMailetContext implemen
      * @see org.apache.mailet.MailetContext#getPostmaster()
      */
     public MailAddress getPostmaster() {
-        return postmaster;
+        return mailServer.getPostmaster();
     }
 
     /**
@@ -435,49 +410,4 @@ public class JamesMailetContext implemen
     public void setLog(Log log) {
         this.log = log;
     }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.lifecycle.Configurable#configure(org.apache.commons.
-     * configuration.HierarchicalConfiguration)
-     */
-    public void configure(HierarchicalConfiguration conf) throws ConfigurationException {
-        this.conf = conf;
-    }
-
-    private void initPostmaster() throws Exception {
-        // Get postmaster
-        String postMasterAddress = conf.getString("postmaster", "postmaster").toLowerCase(Locale.US);
-        // if there is no @domain part, then add the first one from the
-        // list of supported domains that isn't localhost. If that
-        // doesn't work, use the hostname, even if it is localhost.
-        if (postMasterAddress.indexOf('@') < 0) {
-            String domainName = null; // the domain to use
-            // loop through candidate domains until we find one or exhaust the
-            // list
-            String[] doms = domains.getDomains();
-            if (doms != null) {
-            	for (int i = 0; i < doms.length; i++) {
-                    String serverName = doms[i].toLowerCase(Locale.US);
-                    if (!("localhost".equals(serverName))) {
-                        domainName = serverName; // ok, not localhost, so use it
-                        continue;
-                    }
-            	}
-            
-            }
-            // if we found a suitable domain, use it. Otherwise fallback to the
-            // host name.
-            postMasterAddress = postMasterAddress + "@" + (domainName != null ? domainName : mailServer.getDefaultDomain());
-        }
-        this.postmaster = new MailAddress(postMasterAddress);
-
-        if (!isLocalServer(postmaster.getDomain())) {
-            StringBuffer warnBuffer = new StringBuffer(320).append("The specified postmaster address ( ").append(postmaster).append(
-                    " ) is not a local address.  This is not necessarily a problem, but it does mean that emails addressed to the postmaster will be routed to another server.  For some configurations this may cause problems.");
-            log.warn(warnBuffer.toString());
-        }
-    }
 }

Modified: james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java?rev=1025652&r1=1025651&r2=1025652&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java (original)
+++ james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java Wed Oct 20 17:52:45 2010
@@ -97,6 +97,11 @@ public class ValidRcptHandlerTest extend
                 // TODO Auto-generated method stub
                 return false;
             }
+
+            public MailAddress getPostmaster() {
+                // TODO Auto-generated method stub
+                return null;
+            }
             
         });
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org