james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [2/5] james-project git commit: JAMES-1790 don't detect mailing lists on sender when none
Date Fri, 08 Jul 2016 14:46:37 GMT
JAMES-1790 don't detect mailing lists on sender when none


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a8d2de92
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a8d2de92
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a8d2de92

Branch: refs/heads/master
Commit: a8d2de92a8a3e7a09ddd08b8dd10f418183729e5
Parents: 2a7c50f
Author: Matthieu Baechler <matthieu.baechler@linagora.com>
Authored: Mon Jul 4 12:08:44 2016 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Fri Jul 8 14:24:55 2016 +0200

----------------------------------------------------------------------
 .../base/AutomaticallySentMailDetectorImpl.java | 37 ++++++++++++++------
 1 file changed, 27 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a8d2de92/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
b/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
index 72fad65..b6360fb 100644
--- a/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
+++ b/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
@@ -32,9 +32,19 @@ import org.apache.james.mime4j.parser.MimeStreamParser;
 import org.apache.james.mime4j.stream.BodyDescriptor;
 import org.apache.james.mime4j.stream.MimeConfig;
 import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
 
 public class AutomaticallySentMailDetectorImpl implements AutomaticallySentMailDetector {
 
+    private static final String[] MAILING_LIST_HEADERS = new String[] {
+            "List-Help",
+            "List-Subscribe",
+            "List-Unsubscribe",
+            "List-Owner",
+            "List-Post",
+            "List-Id",
+            "List-Archive" };
+
     public boolean isAutomaticallySent(Mail mail) throws MessagingException {
         return isMailingList(mail) ||
             isAutoSubmitted(mail) ||
@@ -42,20 +52,27 @@ public class AutomaticallySentMailDetectorImpl implements AutomaticallySentMailD
     }
 
     public boolean isMailingList(Mail mail) throws MessagingException {
-        String localPart = mail.getSender().getLocalPart();
+        return senderIsMailingList(mail)
+            || headerIsMailingList(mail);
+    }
+
+    private boolean senderIsMailingList(Mail mail) {
+        MailAddress sender = mail.getSender();
+        if (sender == null) {
+            return false;
+        }
+
+        String localPart = sender.getLocalPart();
         return localPart.startsWith("owner-")
             || localPart.endsWith("-request")
             || localPart.equalsIgnoreCase("MAILER-DAEMON")
             || localPart.equalsIgnoreCase("LISTSERV")
-            || localPart.equalsIgnoreCase("majordomo")
-            || mail.getMessage()
-            .getMatchingHeaders(new String[]{"List-Help",
-                "List-Subscribe",
-                "List-Unsubscribe",
-                "List-Owner",
-                "List-Post",
-                "List-Id",
-                "List-Archive"})
+            || localPart.equalsIgnoreCase("majordomo");
+    }
+
+    private boolean headerIsMailingList(Mail mail) throws MessagingException {
+        return mail.getMessage()
+            .getMatchingHeaders(MAILING_LIST_HEADERS)
             .hasMoreElements();
     }
 


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


Mime
View raw message