noel        2003/09/23 12:04:35

  Modified:    src/conf Tag: branch_2_1_fcs james-fetchmail.xml
               src/java/org/apache/james/fetchmail Tag: branch_2_1_fcs
                        FetchMail.java ParsedConfiguration.java
                        StoreProcessor.java
               src/xdocs Tag: branch_2_1_fcs
                        fetchmail_configuration_2_2.xml
  Log:
  - Each fetch task now has its own JavaMail Session enabling each fetch task
  to have its own set of configuration properties. Previously all fetch tasks
  shared the default Session instance and the same configuration properties.
  
  - Configuration properties can now be set for each fetch task using the
  optional configuration tag <javaMailProperties> and any number of its child
  tag <property name="x" value="y">. The following example has been added to
  the default fetchmail configuration...
  
      <!-- Properties to be applied to the JavaMail Session. -->
      <!-- Properties are specific to the selected JavaMail provider. -->
      <!-- Any number may be specified. -->
      <javaMailProperties>
          <!-- Set the connection timeout to 3 minutes -->
          <property name="mail.pop3.connectiontimeout" value="180000"/>
          <!-- Set the I/O timeout to 3 minutes -->
          <property name="mail.pop3.timeout" value="180000"/>
      </javaMailProperties>
  
  Submitted by: Steve Brewin
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.3   +11 -1     james-server/src/conf/Attic/james-fetchmail.xml
  
  Index: james-fetchmail.xml
  ===================================================================
  RCS file: /home/cvs/james-server/src/conf/Attic/james-fetchmail.xml,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- james-fetchmail.xml       21 Sep 2003 20:03:36 -0000      1.1.2.2
  +++ james-fetchmail.xml       23 Sep 2003 19:04:35 -0000      1.1.2.3
  @@ -73,7 +73,17 @@
               <javaMailProviderName>pop3</javaMailProviderName>
   
               <!-- name of the folder to open -->
  -            <javaMailFolderName>INBOX</javaMailFolderName>        
  +            <javaMailFolderName>INBOX</javaMailFolderName>
  +            
  +            <!-- Properties to be applied to the JavaMail Session. -->
  +            <!-- Properties are specific to the selected JavaMail provider. -->
  +            <!-- Any number may be specified. -->
  +            <javaMailProperties>
  +                <!-- Set the connection timeout to 3 minutes -->
  +                <property name="mail.pop3.connectiontimeout" value="180000"/>
  +                <!-- Set the I/O timeout to 3 minutes -->                
  +                <property name="mail.pop3.timeout" value="180000"/>                
  +            </javaMailProperties>            
   
               <!-- Retrieve both old (seen) and new messages from mailserver.  The 
default -->
               <!-- is to fetch only messages the server has not marked as seen -->
  
  
  
  No                   revision
  No                   revision
  1.9.2.3   +127 -12   james-server/src/java/org/apache/james/fetchmail/FetchMail.java
  
  Index: FetchMail.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/fetchmail/FetchMail.java,v
  retrieving revision 1.9.2.2
  retrieving revision 1.9.2.3
  diff -u -r1.9.2.2 -r1.9.2.3
  --- FetchMail.java    21 Sep 2003 20:03:35 -0000      1.9.2.2
  +++ FetchMail.java    23 Sep 2003 19:04:35 -0000      1.9.2.3
  @@ -59,12 +59,15 @@
   
   import java.util.ArrayList;
   import java.util.Collections;
  +import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +import java.util.Properties;
   
   import javax.mail.MessagingException;
  +import javax.mail.Session;
   
   import org.apache.avalon.cornerstone.services.scheduler.Target;
   import org.apache.avalon.framework.configuration.Configurable;
  @@ -74,8 +77,8 @@
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.james.services.MailServer;
  -import org.apache.james.services.UsersStore;
   import org.apache.james.services.UsersRepository;
  +import org.apache.james.services.UsersStore;
   
   /**
    * <p>Class <code>FetchMail</code> is an Avalon task that is periodically
  @@ -109,12 +112,7 @@
   public class FetchMail extends AbstractLogEnabled implements Configurable, Target
   {
       /**
  -     * Enter description here
  -     * 
  -     * Creation Date: 29-Aug-03
  -     * @author sbrewin
  -     * 
  -     * Copyright 2003, Synergy Systems Limited
  +     * Key fields for DynamicAccounts.
        */
       private class DynamicAccountKey
       {
  @@ -399,6 +397,12 @@
       private List fieldStaticAccounts;
       
       /**
  +     * The JavaMail Session for this fetch task.
  +     */ 
  +
  +    private Session fieldSession;
  +    
  +    /**
        * The Dynamic Accounts for this task.
        * These are setup each time the fetchtask is run.
        */
  @@ -433,6 +437,10 @@
       public void configure(Configuration configuration)
           throws ConfigurationException
       {
  +        // Set any Session parameters passed in the Configuration
  +        setSessionParameters(configuration);
  +
  +        // Create the ParsedConfiguration used in the delegation chain
           ParsedConfiguration parsedConfiguration =
               new ParsedConfiguration(
                   configuration,
  @@ -440,7 +448,8 @@
                   getServer(),
                   getLocalUsers());
           setConfiguration(parsedConfiguration);
  -
  +        
  +        // Setup the Accounts
           Configuration[] allAccounts = configuration.getChildren("accounts");
           if (allAccounts.length < 1)
               throw new ConfigurationException("Missing <accounts> section.");
  @@ -506,6 +515,26 @@
               setFetching(true);
               getLogger().info("Fetcher starting fetches");
   
  +            // if debugging, list the JavaMail property key/value pairs
  +            // for this Session
  +            if (getLogger().isDebugEnabled())
  +            {
  +                getLogger().debug("Session properties:");
  +                Properties properties = getSession().getProperties();
  +                Enumeration e = properties.keys();
  +                while (e.hasMoreElements())
  +                {
  +                    String key = (String) e.nextElement();
  +                    String val = (String) properties.get(key);
  +                    if (val.length() > 40)
  +                    {
  +                        val = val.substring(0, 37) + "...";
  +                    }
  +                    getLogger().debug(key + "=" + val);
  +
  +                }
  +            }
  +
               // Update the dynamic accounts,
               // merge with the static accounts and
               // sort the accounts so they are in the order
  @@ -517,22 +546,23 @@
               mergedAccounts.addAll(getDynamicAccounts().values());
               mergedAccounts.addAll(getStaticAccounts());
               Collections.sort(mergedAccounts);
  -            
  +
               StringBuffer logMessage = new StringBuffer(64);
               logMessage.append("Processing ");
               logMessage.append(getStaticAccounts().size());
               logMessage.append(" static accounts and ");
               logMessage.append(getDynamicAccounts().size());
               logMessage.append(" dynamic accounts.");
  -            getLogger().info(logMessage.toString());            
  -            
  +            getLogger().info(logMessage.toString());
  +
               // Fetch each account
               Iterator accounts = mergedAccounts.iterator();
               while (accounts.hasNext())
               {
                   try
                   {
  -                    new StoreProcessor((Account) accounts.next()).process();
  +                    new StoreProcessor((Account) accounts.next(), getSession())
  +                        .process();
                   }
                   catch (MessagingException ex)
                   {
  @@ -882,5 +912,90 @@
       {
           fieldParsedDynamicAccountParameters = parsedDynamicAccountParameters;
       }
  +
  +    /**
  +     * Returns the session, lazily initialized if required.
  +     * @return Session
  +     */
  +    protected Session getSession()
  +    {
  +        Session session = null;
  +        if (null == (session = getSessionBasic()))
  +        {
  +            updateSession();
  +            return getSession();
  +        }    
  +        return session;
  +    }
  +    
  +    /**
  +     * Returns the session.
  +     * @return Session
  +     */
  +    private Session getSessionBasic()
  +    {
  +        return fieldSession;
  +    }    
  +
  +    /**
  +     * Answers a new Session.
  +     * @return Session
  +     */
  +    protected Session computeSession()
  +    {
  +        return Session.getInstance(System.getProperties());
  +    }
  +    
  +    /**
  +     * Updates the current Session.
  +     */
  +    protected void updateSession()
  +    {
  +        setSession(computeSession());
  +    }    
  +
  +    /**
  +     * Sets the session.
  +     * @param session The session to set
  +     */
  +    protected void setSession(Session session)
  +    {
  +        fieldSession = session;
  +    }
  +    
  +    
  +    /**
  +     * Propogate any Session parameters in the configuration to the Session.
  +     * @param configuration The configuration containing the parameters
  +     * @throws ConfigurationException
  +     */
  +    protected void setSessionParameters(Configuration configuration)
  +        throws ConfigurationException
  +    {
  +        Configuration javaMailProperties =
  +            configuration.getChild("javaMailProperties", false);
  +        if (null != javaMailProperties)
  +        {
  +            Properties properties = getSession().getProperties();
  +            Configuration[] allProperties =
  +                javaMailProperties.getChildren("property");
  +            for (int i = 0; i < allProperties.length; i++)
  +            {
  +                properties.setProperty(
  +                    allProperties[i].getAttribute("name"),
  +                    allProperties[i].getAttribute("value"));
  +                if (getLogger().isDebugEnabled())
  +                {
  +                    StringBuffer messageBuffer =
  +                        new StringBuffer("Set property name: ");
  +                    messageBuffer.append(allProperties[i].getAttribute("name"));
  +                    messageBuffer.append(" to: ");
  +                    messageBuffer.append(
  +                        allProperties[i].getAttribute("value"));
  +                    getLogger().debug(messageBuffer.toString());
  +                }
  +            }
  +        }
  +    }    
   
   }
  
  
  
  1.1.2.3   +0 -7      
james-server/src/java/org/apache/james/fetchmail/Attic/ParsedConfiguration.java
  
  Index: ParsedConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/james-server/src/java/org/apache/james/fetchmail/Attic/ParsedConfiguration.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- ParsedConfiguration.java  21 Sep 2003 20:03:35 -0000      1.1.2.2
  +++ ParsedConfiguration.java  23 Sep 2003 19:04:35 -0000      1.1.2.3
  @@ -326,8 +326,6 @@
       protected void configure(Configuration conf) throws ConfigurationException
       {   
           setHost(conf.getChild("host").getValue());
  -//      setUser(conf.getChild("user").getValue());
  -//      setPassword(conf.getChild("password").getValue());
   
           setFetchTaskName(conf.getAttribute("name"));
           setJavaMailProviderName(
  @@ -335,11 +333,6 @@
           setJavaMailFolderName(conf.getChild("javaMailFolderName").getValue());
           setRecurse(conf.getChild("recursesubfolders").getValueAsBoolean());
   
  -//      Configuration recipient = conf.getChild("recipient");
  -//      setRecipient(recipient.getValue());
  -//      setIgnoreOriginalRecipient(
  -//          recipient.getAttributeAsBoolean("ignorercpt-header"));
  -            
           Configuration recipientNotFound = conf.getChild("recipientnotfound");
           setDeferRecipientNotFound(
               recipientNotFound.getAttributeAsBoolean("defer"));         
  
  
  
  1.1.2.3   +38 -7     
james-server/src/java/org/apache/james/fetchmail/Attic/StoreProcessor.java
  
  Index: StoreProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/james-server/src/java/org/apache/james/fetchmail/Attic/StoreProcessor.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- StoreProcessor.java       21 Sep 2003 20:03:35 -0000      1.1.2.2
  +++ StoreProcessor.java       23 Sep 2003 19:04:35 -0000      1.1.2.3
  @@ -71,14 +71,29 @@
    */
   public class StoreProcessor extends ProcessorAbstract
   {
  +    /**
  +     * The Session to use.
  +     */ 
  +    private Session fieldSession;
   
       /**
        * Constructor for StoreProcessor.
  +     * @param account 
  +     */
  +    private StoreProcessor(Account account)
  +    {
  +        super(account);        
  +    }
  +    
  +    /**
  +     * Constructor for StoreProcessor.
        * @param account
  +     * @param session
        */
  -    protected StoreProcessor(Account account)
  +    protected StoreProcessor(Account account, Session session)
       {
  -        super(account);
  +        this(account);
  +        setSession(session);
       }
   
       /**
  @@ -106,11 +121,8 @@
   
           try
           {
  -            // Get a Session object
  -            session = Session.getDefaultInstance(System.getProperties(), null);
  -
               // Get a Store object
  -            store = session.getStore(getJavaMailProviderName());
  +            store = getSession().getStore(getJavaMailProviderName());
   
               // Connect
               if (getHost() != null
  @@ -144,7 +156,8 @@
               {
                   getLogger().error(ex.getMessage());
               }
  -            logMessageBuffer = new StringBuffer("Finished fetching mail from server 
'");
  +            logMessageBuffer =
  +                new StringBuffer("Finished fetching mail from server '");
               logMessageBuffer.append(getHost());
               logMessageBuffer.append("' for user '");
               logMessageBuffer.append(getUser());
  @@ -153,6 +166,24 @@
               logMessageBuffer.append("'");
               getLogger().info(logMessageBuffer.toString());
           }
  +    }
  +
  +    /**
  +     * Returns the session.
  +     * @return Session
  +     */
  +    protected Session getSession()
  +    {
  +        return fieldSession;
  +    }
  +
  +    /**
  +     * Sets the session.
  +     * @param session The session to set
  +     */
  +    protected void setSession(Session session)
  +    {
  +        fieldSession = session;
       }
   
   }
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +80 -13    james-server/src/xdocs/Attic/fetchmail_configuration_2_2.xml
  
  Index: fetchmail_configuration_2_2.xml
  ===================================================================
  RCS file: /home/cvs/james-server/src/xdocs/Attic/fetchmail_configuration_2_2.xml,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- fetchmail_configuration_2_2.xml   22 Sep 2003 13:23:03 -0000      1.1.2.1
  +++ fetchmail_configuration_2_2.xml   23 Sep 2003 19:04:35 -0000      1.1.2.2
  @@ -126,6 +126,7 @@
   <li><strong><a href="#host">host</a></strong> (1, 1)</li>
   <li><strong><a href="#interval">interval</a></strong> (1, 1)</li>
   <li><strong><a href="#javaMailFolderName">javaMailFolderName</a></strong> (1, 
1)</li>
  +<li><strong><a href="#javaMailProperties">javaMailProperties</a></strong> (0, 
1)</li>
   <li><strong><a href="#javaMailProviderName">javaMailProviderName</a></strong> (1, 
1)</li>
   <li><strong><a href="#recipientnotfound">recipientnotfound</a></strong> (1, 1)</li>
   <li><strong><a href="#recursesubfolders">recursesubfolders</a></strong> (1, 1)</li>
  @@ -305,12 +306,52 @@
   </p>
   </subsection>
   
  +<subsection name="javaMailProperties">
  +<p>The <strong>javaMailProperties</strong> tag declares the properties to be
  +applied to the JavaMail Session used by the fetch task. These override the
  +properties answered by <code>System.getProperties()</code>. Many JavaMail
  +properties are specific to the JavaMail Provider selected by the 
  +<a href="#javaMailProviderName">javaMailProviderName</a> tag.</p>
  +
  +<p><strong>Relying on the default values selected by the Provider can be
  +inappropriate.</strong> For instance, the default connection and I/O timeout 
  +values of infinite for the default IMAP and POP3 Providers is rarely what is
  +required. Consult the documentation of the Provider for details and options.</p>
  +
  +<p>Documentation for the default Provider for IMAP is located
  +<a 
href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/imap/package-summary.html";>
  +here</a>.</p>
  +
  +<p>Documentation for the default Provider for POP3 is located
  +<a 
href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/pop3/package-summary.html";>
  +here</a>.</p>
  +
  +<p>Details of how to change a Provider are located
  +<a href="http://java.sun.com/products/javamail/javadocs/javax/mail/Session.html";>
  +here</a>.</p>
  +
  +<p>The tag has these child tags (minimum cardinality, maximum cardinality):
  +<ul>
  +<li><strong><a href="#property">property</a></strong> (0, *)</li>
  +</ul>
  +</p>
  +
  +<p>
  +<source>
  +&lt;javaMailProperties&gt;
  +...
  +&lt;/javaMailProperties&gt;
  +</source>
  +</p>
  +</subsection>
  +
   <subsection name="javaMailProviderName">
  -<p>The <strong>javaMailProviderName</strong> tag declares the protocol used to
  -interact with the external server.</p>
  +<p>The <strong>javaMailProviderName</strong> tag selects the JavaMail protocol
  +Provider used to interact with the external server.</p>
   
  -<p>The tag value is the  name of a JavaMail supported protocol, such as
  -<code>pop3</code> or <code>imap</code>.</p>
  +<p>The tag value is the name of a JavaMail supported protocol, such as 
  +<code>pop3</code> or <code>imap</code>. The name is used to select the default
  +Provider for the protocol.</p>
   
   <p>
   <source>
  @@ -563,6 +604,28 @@
   </p>
   </subsection>
   
  +<subsection name="property">
  +<p>The <strong>property</strong> tag declares a name/value pair.</p>
  +
  +<p>The tag has these attributes:
  +<dl>
  +<dt><strong>name</strong></dt>
  +<dd>The name of the property.
  +</dd>
  +<dt><strong>value</strong></dt>
  +<dd>The value of the property.</dd>
  +</dl>
  +</p>
  +
  +<p>
  +<source>
  +&lt;property
  +    name=&quot;mail.pop3.connectiontimeout&quot;
  +    value=&quot;180000&quot;/&gt;
  +</source>
  +</p>
  +</subsection>
  +
   </section>
   
   <section name="fetchmail Examples">
  @@ -732,8 +795,9 @@
   </li>
   
   <li>When using dynamic accounts, an account is generated and an attempt made to
  -fetch mail for all James users even if there is no such mailbox on the server.
  -This is inefficient but not fatal. The solution is the same as described above.
  +fetch mail for all James users defined to James even if there is no such mailbox
  +on the server. This is inefficient but not fatal. The solution is the same as 
  +described above.
   </li>
   
   <li>When using dynamic accounts, as described in the
  @@ -744,13 +808,16 @@
   has an opportunity to run!
   </li>
   
  -<li>The now deprecated fetchPOP supported a subset of the features of fetchmail.
  -fetchPOP interacted with the <code>FetchedFrom</code> matcher to detect mail
  -injected by fetchPOP. This will not work with fetchmail. Compared to fetchPOP,
  -there are far fewer occasions when mail injected by fetchmail requires special
  -processing. When it does, use the HasMailAttribute matcher to detect the 
  -attribute named <code>org.apache.james.fetchmail.taskName</code>. The value of 
  -the attribute is the name of the fetch task.
  +<li>The now deprecated fetchPOP interacted with the <code>FetchedFrom</code> 
  +matcher to detect mail injected by fetchPOP. This will not work with fetchmail. 
  +Compared to fetchPOP, there are far fewer occasions when mail injected by 
  +fetchmail requires special processing. When it does, use the HasMailAttribute 
  +matcher to match the attribute named 
  +<code>org.apache.james.fetchmail.taskName</code> to detect all mail injected by
  +fetchmail. To detect mail injected by a specific fetch task, use one of the 
  +HasMailAttributeWithValue matchers to match on the attribute name and the
  +attribute value. The attribute value is the name of the fetch task that 
  +injected the mail.
   </li>
   
   <li>The POP3 protocol does not enforce support of any of the Flags associated 
  
  
  

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

Reply via email to