james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject james-project git commit: MAILET-121 MailAddressColectionReader should consider coma, space and tabulation as delimiters
Date Thu, 15 Sep 2016 22:39:21 GMT
Repository: james-project
Updated Branches:
  refs/heads/master ee6589d5d -> 3a8592d67


MAILET-121 MailAddressColectionReader should consider coma, space and tabulation as delimiters


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

Branch: refs/heads/master
Commit: 3a8592d67a9478ac679191e1cb6cfc05fac471ca
Parents: ee6589d
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Sep 8 16:42:06 2016 +0200
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Sep 15 12:12:52 2016 +0200

----------------------------------------------------------------------
 .../utils/MailAddressCollectionReader.java      | 27 +++++++++++++-------
 .../util/MailAddressCollectionReaderTest.java   | 21 ++++++++++-----
 2 files changed, 33 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3a8592d6/mailet/standard/src/main/java/org/apache/james/transport/matchers/utils/MailAddressCollectionReader.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/utils/MailAddressCollectionReader.java
b/mailet/standard/src/main/java/org/apache/james/transport/matchers/utils/MailAddressCollectionReader.java
index 17ee09e..3855ed1 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/utils/MailAddressCollectionReader.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/utils/MailAddressCollectionReader.java
@@ -27,6 +27,7 @@ import org.apache.mailet.MailAddress;
 
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
 import com.google.common.base.Throwables;
@@ -38,16 +39,24 @@ public class MailAddressCollectionReader {
 
     public static Set<MailAddress> read(String condition) {
         Preconditions.checkArgument(!Strings.isNullOrEmpty(condition));
-        return FluentIterable.from(Splitter.onPattern(",( |\t)").split(condition)).transform(new
Function<String, MailAddress>() {
-            @Override
-            public MailAddress apply(String s) {
-                try {
-                    return new MailAddress(s);
-                } catch (AddressException e) {
-                    throw Throwables.propagate(e);
+        return FluentIterable.from(Splitter.onPattern("(,| |\t)")
+            .split(condition))
+            .filter(new Predicate<String>() {
+                @Override
+                public boolean apply(String s) {
+                    return !Strings.isNullOrEmpty(s);
                 }
-            }
-        }).toSet();
+            })
+            .transform(new Function<String, MailAddress>() {
+                @Override
+                public MailAddress apply(String s) {
+                    try {
+                        return new MailAddress(s);
+                    } catch (AddressException e) {
+                        throw Throwables.propagate(e);
+                    }
+                }
+            }).toSet();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3a8592d6/mailet/standard/src/test/java/org/apache/james/transport/matchers/util/MailAddressCollectionReaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/util/MailAddressCollectionReaderTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/util/MailAddressCollectionReaderTest.java
index 46cc41e..c7c0494 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/util/MailAddressCollectionReaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/util/MailAddressCollectionReaderTest.java
@@ -65,30 +65,39 @@ public class MailAddressCollectionReaderTest {
     }
 
     @Test
-    public void readShouldParseTwoEmail() throws Exception {
+    public void readShouldParseTwoEmailSeparatedByComaOnly() throws Exception {
         MailAddress mailAddress1 = new MailAddress("valid@apache.org");
         MailAddress mailAddress2 = new MailAddress("bis@apache.org");
 
-        assertThat(MailAddressCollectionReader.read(mailAddress1.toString() + ", " + mailAddress2.toString()))
+        assertThat(MailAddressCollectionReader.read(mailAddress1.toString() + "," + mailAddress2.toString()))
             .containsExactly(mailAddress1, mailAddress2);
     }
 
     @Test
-    public void readShouldParseTwoEmailTabSeparated() throws Exception {
+    public void readShouldParseTwoEmailSeparatedBySpaceOnly() throws Exception {
         MailAddress mailAddress1 = new MailAddress("valid@apache.org");
         MailAddress mailAddress2 = new MailAddress("bis@apache.org");
 
-        assertThat(MailAddressCollectionReader.read(mailAddress1.toString() + ",\t" + mailAddress2.toString()))
+        assertThat(MailAddressCollectionReader.read(mailAddress1.toString() + " " + mailAddress2.toString()))
+            .containsExactly(mailAddress1, mailAddress2);
+    }
+
+    @Test
+    public void readShouldParseTwoEmailSeparatedByTabOnly() throws Exception {
+        MailAddress mailAddress1 = new MailAddress("valid@apache.org");
+        MailAddress mailAddress2 = new MailAddress("bis@apache.org");
+
+        assertThat(MailAddressCollectionReader.read(mailAddress1.toString() + "\t" + mailAddress2.toString()))
             .containsExactly(mailAddress1, mailAddress2);
     }
 
 
     @Test
-    public void readShouldParseTwoEmailTabAndSpaceCombinaison() throws Exception {
+    public void readShouldParseTwoEmailSeparatorsCombination() throws Exception {
         MailAddress mailAddress1 = new MailAddress("valid@apache.org");
         MailAddress mailAddress2 = new MailAddress("bis@apache.org");
 
-        assertThat(MailAddressCollectionReader.read(mailAddress1.toString() + ",\t  \t\t
\t " + mailAddress2.toString()))
+        assertThat(MailAddressCollectionReader.read(mailAddress1.toString() + ",\t  \t,\t
\t " + mailAddress2.toString()))
             .containsExactly(mailAddress1, mailAddress2);
     }
 


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