Author: bago
Date: Thu Aug 11 12:12:46 2005
New Revision: 231502

URL: http://svn.apache.org/viewcvs?rev=231502&view=rev
Log:
Added support for Additional "received for" headers to Fetchmail (JAMES-360)

Modified:
    james/server/trunk/src/java/org/apache/james/fetchmail/Account.java
    james/server/trunk/src/java/org/apache/james/fetchmail/DynamicAccount.java
    james/server/trunk/src/java/org/apache/james/fetchmail/FetchMail.java
    james/server/trunk/src/java/org/apache/james/fetchmail/MessageProcessor.java
    
james/server/trunk/src/java/org/apache/james/fetchmail/ProcessorAbstract.java

Modified: james/server/trunk/src/java/org/apache/james/fetchmail/Account.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/fetchmail/Account.java?rev=231502&r1=231501&r2=231502&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/fetchmail/Account.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/fetchmail/Account.java Thu Aug 
11 12:12:46 2005
@@ -75,8 +75,13 @@
     /**
      * The JavaMail Session for this Account.
      */ 
-    
     private Session fieldSession;
+
+    /**
+     * A custom header to be used as the recipient address
+     */
+    private String customRecipientHeader;
+
     /**
      * Constructor for Account.
      */
@@ -105,6 +110,7 @@
         String password,
         String recipient,
         boolean ignoreRecipientHeader,
+        String customRecipientHeader,
         Session session)
         throws ConfigurationException
     {
@@ -115,10 +121,19 @@
         setPassword(password);
         setRecipient(recipient);
         setIgnoreRecipientHeader(ignoreRecipientHeader);
+        setCustomRecipientHeader(customRecipientHeader);
         setSession(session);
     }   
 
     /**
+     * Returns the custom recipient header.
+     * @return String
+     */
+    public String getCustomRecipientHeader() {
+        return this.customRecipientHeader;
+    }
+
+    /**
      * Returns the password.
      * @return String
      */
@@ -143,6 +158,14 @@
     public String getUser()
     {
         return fieldUser;
+    }
+
+    /**
+     * Sets the custom recipient header.
+     * @param customRecipientHeader The header to be used
+     */
+    public void setCustomRecipientHeader(String customRecipientHeader) {
+        this.customRecipientHeader = customRecipientHeader;
     }
 
     /**

Modified: 
james/server/trunk/src/java/org/apache/james/fetchmail/DynamicAccount.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/fetchmail/DynamicAccount.java?rev=231502&r1=231501&r2=231502&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/fetchmail/DynamicAccount.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/fetchmail/DynamicAccount.java 
Thu Aug 11 12:12:46 2005
@@ -42,6 +42,7 @@
         String password,
         String recipient,
         boolean ignoreRecipientHeader,
+        String customRecipientHeader,
         Session session)
         throws ConfigurationException
     {
@@ -52,6 +53,7 @@
             password,
             recipient,
             ignoreRecipientHeader,
+            customRecipientHeader,
             session);
     }
 
@@ -79,6 +81,7 @@
         String recipientPrefix,
         String recipientSuffix,
         boolean ignoreRecipientHeader,
+        String customRecipientHeader,
         Session session)
         throws ConfigurationException
     {
@@ -89,6 +92,7 @@
             password,
             null,
             ignoreRecipientHeader,
+            customRecipientHeader,
             session);
 
         StringBuffer userBuffer = new StringBuffer(userPrefix);

Modified: james/server/trunk/src/java/org/apache/james/fetchmail/FetchMail.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/fetchmail/FetchMail.java?rev=231502&r1=231501&r2=231502&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/fetchmail/FetchMail.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/fetchmail/FetchMail.java Thu 
Aug 11 12:12:46 2005
@@ -179,6 +179,7 @@
         private boolean fieldIgnoreRecipientHeader;     
         private String fieldRecipientPrefix;
         private String fieldRecipientSuffix;
+        private String customRecipientHeader;
 
         /**
          * Constructor for ParsedDynamicAccountParameters.
@@ -205,9 +206,18 @@
             setPassword(configuration.getAttribute("password"));
             setIgnoreRecipientHeader(
                 configuration.getAttributeAsBoolean("ignorercpt-header"));
+            
setCustomRecipientHeader(configuration.getAttribute("customrcpt-header", ""));
         }                       
 
         /**
+         * Returns the custom recipient header.
+         * @return String
+         */
+        public String getCustomRecipientHeader() {
+            return this.customRecipientHeader;
+        }
+
+        /**
          * Returns the recipientprefix.
          * @return String
          */
@@ -244,6 +254,14 @@
         }
 
         /**
+         * Sets the custom recipient header.
+         * @param customRecipientHeader The header to be used
+         */
+        public void setCustomRecipientHeader(String customRecipientHeader) {
+            this.customRecipientHeader = customRecipientHeader;
+        }
+
+        /**
          * Sets the recipientprefix.
          * @param recipientprefix The recipientprefix to set
          */
@@ -448,6 +466,7 @@
                         accountsChild.getAttribute("recipient"),
                         accountsChild.getAttributeAsBoolean(
                             "ignorercpt-header"),
+                        accountsChild.getAttribute("customrcpt-header"),
                         getSession()));
                 continue;
             }
@@ -833,12 +852,14 @@
                         parameters.getRecipientPrefix(),
                         parameters.getRecipientSuffix(),
                         parameters.isIgnoreRecipientHeader(),
+                        parameters.getCustomRecipientHeader(),
                         getSession());
             }
             accounts.put(key, account);
         }
         return accounts;
     }
+    
     /**
      * Resets the dynamicAccounts.
      */

Modified: 
james/server/trunk/src/java/org/apache/james/fetchmail/MessageProcessor.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/fetchmail/MessageProcessor.java?rev=231502&r1=231501&r2=231502&view=diff
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/fetchmail/MessageProcessor.java 
(original)
+++ 
james/server/trunk/src/java/org/apache/james/fetchmail/MessageProcessor.java 
Thu Aug 11 12:12:46 2005
@@ -985,68 +985,79 @@
 
     protected String getEnvelopeRecipient(MimeMessage msg) throws 
MessagingException
     {
-        try
-        {
-            Enumeration enumeration =
-                msg.getMatchingHeaderLines(new String[] { "Received" });
-            while (enumeration.hasMoreElements())
+        String res = getCustomRecipientHeader();
+        if (res != null && res.length() > 0) {
+            String[] headers = msg.getHeader(getCustomRecipientHeader());
+            if (headers != null) {
+                String mailFor = headers[0];
+              if (mailFor.startsWith("<") && mailFor.endsWith(">"))
+                  mailFor = mailFor.substring(1, (mailFor.length() - 1));
+              return mailFor;
+              }
+          } else {
+            try
             {
-                String received = (String) enumeration.nextElement();
-
-                int nextSearchAt = 0;
-                int i = 0;
-                int start = 0;
-                int end = 0;
-                boolean hasBracket = false;
-                boolean usableAddress = false;
-                while (!usableAddress && (i != -1))
+                Enumeration enumeration =
+                    msg.getMatchingHeaderLines(new String[] { "Received" });
+                while (enumeration.hasMoreElements())
                 {
-                    hasBracket = false;
-                    i = received.indexOf("for ", nextSearchAt);
-                    if (i > 0)
+                    String received = (String) enumeration.nextElement();
+    
+                    int nextSearchAt = 0;
+                    int i = 0;
+                    int start = 0;
+                    int end = 0;
+                    boolean hasBracket = false;
+                    boolean usableAddress = false;
+                    while (!usableAddress && (i != -1))
                     {
-                        start = i + 4;
-                        end = 0;
-                        nextSearchAt = start;
-                        for (int c = start; c < received.length(); c++)
+                        hasBracket = false;
+                        i = received.indexOf("for ", nextSearchAt);
+                        if (i > 0)
                         {
-                            char ch = received.charAt(c);
-                            switch (ch)
+                            start = i + 4;
+                            end = 0;
+                            nextSearchAt = start;
+                            for (int c = start; c < received.length(); c++)
                             {
-                                case '<' :
-                                    hasBracket = true;
-                                    continue;
-                                case '@' :
-                                    usableAddress = true;
-                                    continue;
-                                case ' ' :
-                                    end = c;
-                                    break;
-                                case ';' :
-                                    end = c;
+                                char ch = received.charAt(c);
+                                switch (ch)
+                                {
+                                    case '<' :
+                                        hasBracket = true;
+                                        continue;
+                                    case '@' :
+                                        usableAddress = true;
+                                        continue;
+                                    case ' ' :
+                                        end = c;
+                                        break;
+                                    case ';' :
+                                        end = c;
+                                        break;
+                                }
+                                if (end > 0)
                                     break;
                             }
-                            if (end > 0)
-                                break;
                         }
                     }
+                    if (usableAddress)
+                    {
+                        // lets try and grab the email address
+                        String mailFor = received.substring(start, end);
+    
+                        // strip the <> around the address if there are any
+                        if (mailFor.startsWith("<") && mailFor.endsWith(">"))
+                            mailFor = mailFor.substring(1, (mailFor.length() - 
1));
+    
+                        return mailFor;
+                    }
                 }
-                if (usableAddress)
-                {
-                    // lets try and grab the email address
-                    String mailFor = received.substring(start, end);
-
-                    // strip the <> around the address if there are any
-                    if (mailFor.startsWith("<") && mailFor.endsWith(">"))
-                        mailFor = mailFor.substring(1, (mailFor.length() - 1));
-
-                    return mailFor;
-                }
             }
-        }
-        catch (MessagingException me)
-        {
-            logStatusWarn("No Received headers found.");
+            catch (MessagingException me)
+            {
+                logStatusWarn("No Received headers found.");
+            }
         }
         return null;
     }

Modified: 
james/server/trunk/src/java/org/apache/james/fetchmail/ProcessorAbstract.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/fetchmail/ProcessorAbstract.java?rev=231502&r1=231501&r2=231502&view=diff
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/fetchmail/ProcessorAbstract.java 
(original)
+++ 
james/server/trunk/src/java/org/apache/james/fetchmail/ProcessorAbstract.java 
Thu Aug 11 12:12:46 2005
@@ -251,6 +251,14 @@
         return getAccount().isIgnoreRecipientHeader();
     }
 
+    /**
+     * Returns the customRecipientHeader.
+     * @return String
+     */
+    protected String getCustomRecipientHeader()
+    {
+        return getAccount().getCustomRecipientHeader();
+    }
 
     /**
      * Returns the leave.



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

Reply via email to