JAMES-1836 MessageFactoryTest should accept invalid address

Note : they should be reported to the user in the nicest way possible


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

Branch: refs/heads/master
Commit: 4ea49d3a2cb2d3b0239e1e577e5379c5af9efc4e
Parents: b512797
Author: Benoit Tellier <btell...@linagora.com>
Authored: Mon Oct 17 17:33:14 2016 +0200
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Mon Oct 17 17:33:14 2016 +0200

----------------------------------------------------------------------
 .../apache/james/jmap/model/MessageFactory.java |  6 ++--
 .../james/jmap/model/MessageFactoryTest.java    | 32 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4ea49d3a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
index 125c680..e3e09e7 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
@@ -146,9 +146,9 @@ public class MessageFactory {
     
     private Emailer fromMailbox(Mailbox mailbox) {
         return Emailer.builder()
-                    .name(getNameOrAddress(mailbox))
-                    .email(mailbox.getAddress())
-                    .build();
+            .name(getNameOrAddress(mailbox))
+            .email(mailbox.getAddress())
+            .buildInvalidAllowed();
     }
 
     private String getNameOrAddress(Mailbox mailbox) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/4ea49d3a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
index 9ac47f9..0006a39 100644
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
@@ -260,4 +260,36 @@ public class MessageFactoryTest {
         assertThat(testee.getAttachments()).hasSize(1);
         
assertThat(testee.getAttachments().get(0)).isEqualToComparingFieldByField(expectedAttachment);
     }
+
+    @Test
+    public void invalidAddressesShouldBeAllowed() throws Exception {
+        String headers = "From: user <userdomain>\n"
+            + "To: user1 <user1domain>, user2 <user2domain>\n"
+            + "Cc: usercc <userccdomain>\n"
+            + "Bcc: userbcc <userbccdomain>\n"
+            + "Subject: test subject\n";
+        MetaDataWithContent testMail = MetaDataWithContent.builder()
+            .uid(MessageUid.of(2))
+            .flags(new Flags(Flag.SEEN))
+            .size(headers.length())
+            .internalDate(INTERNAL_DATE)
+            .content(new 
ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
+            .attachments(ImmutableList.of())
+            .mailboxId(MAILBOX_ID)
+            .messageId(MessageId.of("user|box|2"))
+            .build();
+
+        Message testee = messageFactory.fromMetaDataWithContent(testMail);
+
+        Emailer user = 
Emailer.builder().name("user").email("userdomain").buildInvalidAllowed();
+        Emailer user1 = 
Emailer.builder().name("user1").email("user1domain").buildInvalidAllowed();
+        Emailer user2 = 
Emailer.builder().name("user2").email("user2domain").buildInvalidAllowed();
+        Emailer usercc = 
Emailer.builder().name("usercc").email("userccdomain").buildInvalidAllowed();
+        Emailer userbcc = 
Emailer.builder().name("userbcc").email("userbccdomain").buildInvalidAllowed();
+
+        assertThat(testee.getFrom()).contains(user);
+        assertThat(testee.getTo()).contains(user1, user2);
+        assertThat(testee.getCc()).contains(usercc);
+        assertThat(testee.getBcc()).contains(userbcc);
+    }
 }


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

Reply via email to