james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [03/11] james-project git commit: MAILET-121 SenderIsTest should match our coding conventions
Date Fri, 02 Sep 2016 06:23:28 GMT
MAILET-121 SenderIsTest should match our coding conventions


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

Branch: refs/heads/master
Commit: 5eb9b61d28e55200ab643a09d8f6dc4237f1b921
Parents: 260b5ec
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Aug 31 15:12:18 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Sep 2 13:22:32 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/SenderIs.java      | 47 ++++++++++++++------
 1 file changed, 34 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5eb9b61d/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIs.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIs.java
b/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIs.java
index 3438689..60cb5ea 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIs.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderIs.java
@@ -17,30 +17,51 @@
  * under the License.                                           *
  ****************************************************************/
 
+package org.apache.james.transport.matchers;
 
+import java.util.Collection;
+import java.util.Set;
 
-package org.apache.james.transport.matchers;
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
 
-import org.apache.mailet.base.GenericMatcher;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.GenericMatcher;
 
-import java.util.Collection;
-import java.util.StringTokenizer;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import com.google.common.base.Throwables;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 
-/**
- * Matches mail where the sender is contained in a configurable list.
- * @version 1.0.0, 24/04/1999
- */
 public class SenderIs extends GenericMatcher {
 
-    private Collection<MailAddress> senders;
+    private Set<MailAddress> senders;
+
+    @VisibleForTesting
+    Set<MailAddress> getSenders() {
+        return senders;
+    }
 
     public void init() throws javax.mail.MessagingException {
-        StringTokenizer st = new StringTokenizer(getCondition(), ", \t", false);
-        senders = new java.util.HashSet<MailAddress>();
-        while (st.hasMoreTokens()) {
-            senders.add(new MailAddress(st.nextToken()));
+        if (Strings.isNullOrEmpty(getCondition())) {
+            throw new MessagingException("SenderIs should have at least one address as parameter");
+        }
+        senders = FluentIterable.from(Splitter.on(", ").split(getCondition())).transform(new
Function<String, MailAddress>() {
+            public MailAddress apply(String s) {
+                try {
+                    return new MailAddress(s);
+                } catch (AddressException e) {
+                    throw Throwables.propagate(e);
+                }
+            }
+        }).toSet();
+        if (senders.size() < 1) {
+            throw new MessagingException("SenderIs should have at least one address as parameter");
         }
     }
 


---------------------------------------------------------------------
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