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 pg...@apache.org on 2002/08/23 10:53:36 UTC

cvs commit: jakarta-james/src/java/org/apache/james/transport/mailets RemoteDelivery.java

pgoldstein    2002/08/23 01:53:36

  Modified:    src/conf james-assembly.xml
               src/java/org/apache/james Constants.java
               src/java/org/apache/james/smtpserver SMTPHandler.java
                        SMTPServer.xinfo
               src/java/org/apache/james/transport/mailets
                        RemoteDelivery.java
  Log:
  Adding the hello name for the SMTP server to the mailet context.
  Modified RemoteDelivery.java to load the hello name into the Javamail
  SMTP properties
  
  Note: It might be desirable to refactor this submission so the
  hello name is set once by the SMTPServer, rather than on each
  initialize() of the SMTPHandler.  Changes coming to the SMTP code
  should make this easier.  To be addressed shortly.
  
  Thanks to Noel Bergman for the submission
  
  Revision  Changes    Path
  1.8       +1 -0      jakarta-james/src/conf/james-assembly.xml
  
  Index: james-assembly.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/conf/james-assembly.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- james-assembly.xml	18 Nov 2001 01:14:21 -0000	1.7
  +++ james-assembly.xml	23 Aug 2002 08:53:36 -0000	1.8
  @@ -59,6 +59,7 @@
   
     <!-- SMTP Server -->
     <block class="org.apache.james.smtpserver.SMTPServer" name="smtpserver" >
  +    <provide name="James" role="org.apache.mailet.MailetContext"/>
       <provide name="mailstore" role="org.apache.james.services.MailStore"/>
       <provide name="users-store" role="org.apache.james.services.UsersStore"/>
       <provide name="sockets"
  
  
  
  1.6       +8 -2      jakarta-james/src/java/org/apache/james/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/Constants.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Constants.java	18 Aug 2002 07:32:38 -0000	1.5
  +++ Constants.java	23 Aug 2002 08:53:36 -0000	1.6
  @@ -36,6 +36,12 @@
       public static final String SERVER_NAMES = "SERVER_NAMES";
   
       /**
  +     * Context key used to store the Mailet/SMTP "hello name" for this
  +     * James instance in the context.
  +     */
  +    public static final String HELLO_NAME = "HELLO_NAME";
  +
  +    /**
        * Context key used to store the postmaster address for
        * this James instance in the context.
        */
  
  
  
  1.23      +38 -17    jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java
  
  Index: SMTPHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- SMTPHandler.java	15 Aug 2002 21:37:34 -0000	1.22
  +++ SMTPHandler.java	23 Aug 2002 08:53:36 -0000	1.23
  @@ -10,6 +10,7 @@
   import org.apache.avalon.cornerstone.services.scheduler.PeriodicTimeTrigger;
   import org.apache.avalon.cornerstone.services.scheduler.Target;
   import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
  +import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
  @@ -25,6 +26,7 @@
   import org.apache.james.services.UsersStore;
   import org.apache.james.util.*;
   import org.apache.mailet.MailAddress;
  +import org.apache.mailet.MailetContext;
   import javax.mail.MessagingException;
   import java.io.*;
   import java.net.Socket;
  @@ -48,7 +50,7 @@
    */
   public class SMTPHandler
       extends BaseConnectionHandler
  -    implements ConnectionHandler, Composable, Configurable, Target {
  +    implements ConnectionHandler, Composable, Configurable, Initializable, Target {
   
       /**SMTP Server identification string used in SMTP headers*/
       private static final String softwaretype = "JAMES SMTP Server "
  @@ -110,10 +112,35 @@
   
       private MailServer mailServer;      // The internal mail server service
   
  +    /**
  +     * The system-wide component manager
  +     */
  +    private ComponentManager componentManager;
  +
       private HashMap state = new HashMap();  // The hash map that holds variables for the SMTP
                                               // session in progress.
   
       /**
  +     * Pass the <code>ComponentManager</code> to the <code>composer</code>.
  +     * The instance uses the specified <code>ComponentManager</code> to 
  +     * acquire the components it needs for execution.
  +     *
  +     * @param componentManager The <code>ComponentManager</code> which this
  +     *                <code>Composable</code> uses.
  +     * @throws ComponentException if an error occurs
  +     */
  +    public void compose(final ComponentManager componentManager) throws ComponentException {
  +        mailServer = (MailServer) componentManager.lookup("org.apache.james.services.MailServer");
  +        scheduler =
  +            (TimeScheduler) componentManager.lookup(
  +                "org.apache.avalon.cornerstone.services.scheduler.TimeScheduler");
  +        UsersStore usersStore =
  +            (UsersStore) componentManager.lookup("org.apache.james.services.UsersStore");
  +        users = usersStore.getRepository("LocalUsers");
  +        this.componentManager = componentManager;
  +     }
  +
  +    /**
        * Pass the <code>Configuration</code> to the instance.
        *
        * @param configuration the class configurations.
  @@ -134,22 +161,16 @@
       }
   
       /**
  -     * Pass the <code>ComponentManager</code> to the <code>composer</code>.
  -     * The instance uses the specified <code>ComponentManager</code> to 
  -     * acquire the components it needs for execution.
  +     * Initialize the component. In the SMTPHandler this looks up the mailet
  +     * context and sets the appropriate value for the hello name.
        *
  -     * @param componentManager The <code>ComponentManager</code> which this
  -     *                <code>Composable</code> uses.
  -     * @throws ComponentException if an error occurs
  +     * @throws Exception if an error occurs
        */
  -    public void compose(final ComponentManager componentManager) throws ComponentException {
  -        mailServer = (MailServer) componentManager.lookup("org.apache.james.services.MailServer");
  -        scheduler =
  -            (TimeScheduler) componentManager.lookup(
  -                "org.apache.avalon.cornerstone.services.scheduler.TimeScheduler");
  -        UsersStore usersStore =
  -            (UsersStore) componentManager.lookup("org.apache.james.services.UsersStore");
  -        users = usersStore.getRepository("LocalUsers");
  +    public void initialize() throws Exception {
  +        // make our "helloName" available through the MailetContext
  +        MailetContext mailetcontext
  +                = (MailetContext) componentManager.lookup("org.apache.mailet.MailetContext");
  +        mailetcontext.setAttribute(Constants.HELLO_NAME, this.helloName);
       }
   
       /**
  
  
  
  1.3       +3 -0      jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.xinfo
  
  Index: SMTPServer.xinfo
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.xinfo,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SMTPServer.xinfo	25 Sep 2001 04:51:19 -0000	1.2
  +++ SMTPServer.xinfo	23 Aug 2002 08:53:36 -0000	1.3
  @@ -14,6 +14,9 @@
   
     <dependencies>
       <dependency>
  +      <service name="org.apache.mailet.MailetContext" version="1.0"/>
  +    </dependency>
  +    <dependency>
         <service name="org.apache.james.services.MailStore" version="1.0"/>
       </dependency>
       <dependency>
  
  
  
  1.24      +21 -5     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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- RemoteDelivery.java	18 Aug 2002 07:27:51 -0000	1.23
  +++ RemoteDelivery.java	23 Aug 2002 08:53:36 -0000	1.24
  @@ -42,6 +42,14 @@
    * 3. More efficiently handle numerous recipients
    * 4. Migrate to use Phoenix for the delivery threads
    *
  + * You really want to read the JavaMail documentation if you are
  + * working in here, and you will want to view the list of JavaMail
  + * attributes, which are documented here:
  + * 
  + * http://java.sun.com/products/javamail/1.3/docs/javadocs/com/sun/mail/smtp/package-summary.html
  + *
  + * as well as other places.
  + * 
    * @author Serge Knystautas <se...@lokitech.com>
    * @author Federico Barbieri <sc...@pop.systemy.it>
    *
  @@ -61,6 +69,9 @@
       private MailServer mailServer;
       private boolean destroyed = false; //Flag that the run method will check and end itself if set to true
   
  +    /**
  +     * Initialize the mailet
  +     */
       public void init() throws MessagingException {
           try {
               if (getInitParameter("delayTime") != null) {
  @@ -495,9 +506,14 @@
           //Sets timeout on going connections
           props.put("mail.smtp.timeout", smtpTimeout + "");
           //Set the hostname we'll use as this server
  -        Collection servernames = (Collection) getMailetContext().getAttribute(Constants.SERVER_NAMES);
  -        if (servernames.size() > 0) {
  -            props.put("mail.smtp.localhost", (String) servernames.iterator().next());
  +        if (getMailetContext().getAttribute(Constants.HELLO_NAME) != null) {
  +            props.put("mail.smtp.localhost", (String) getMailetContext().getAttribute(Constants.HELLO_NAME));
  +        }
  +        else {
  +            Collection servernames = (Collection) getMailetContext().getAttribute(Constants.SERVER_NAMES);
  +            if ((servernames != null) && (servernames.size() > 0)) {
  +                props.put("mail.smtp.localhost", (String) servernames.iterator().next());
  +            }
           }
   
           //If there's a gateway port, we can just set it here
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>