Repository: james-project
Updated Branches:
  refs/heads/master daaa36a02 -> 238d1c799


JAMES-2135 IT from JMAP layer for converting from text/calendar bodies to 
attachment


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

Branch: refs/heads/master
Commit: 8aecdf03b9730a77446afd1d30db9592a187b521
Parents: ebad05e
Author: quynhn <qngu...@linagora.com>
Authored: Fri Sep 8 11:29:11 2017 +0700
Committer: Matthieu Baechler <matth...@apache.org>
Committed: Mon Sep 11 11:28:15 2017 +0200

----------------------------------------------------------------------
 .../cassandra-jmap-integration-testing/pom.xml  |  6 ++
 .../src/test/resources/mailetcontainer.xml      |  1 +
 .../jmap-integration-testing-common/pom.xml     |  6 ++
 .../integration/SetMessagesMethodTest.java      | 76 +++++++++++++++++---
 .../src/test/resources/eml/calendar.eml         | 42 +++++++++++
 .../memory-jmap-integration-testing/pom.xml     |  6 ++
 .../src/test/resources/mailetcontainer.xml      |  1 +
 7 files changed, 127 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8aecdf03/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
 
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
index b2e3329..745c0d1 100644
--- 
a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
+++ 
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
@@ -65,6 +65,12 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>apache-mailet-base</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-cassandra-guice</artifactId>
             <scope>test</scope>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/8aecdf03/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/resources/mailetcontainer.xml
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/resources/mailetcontainer.xml
 
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/resources/mailetcontainer.xml
index f26cd89..b998dcd 100644
--- 
a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/resources/mailetcontainer.xml
+++ 
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/resources/mailetcontainer.xml
@@ -50,6 +50,7 @@
             <mailet match="All" class="RemoveMimeHeader">
                 <name>bcc</name>
             </mailet>
+            <mailet match="All" 
class="org.apache.james.jmap.mailet.TextCalendarBodyToAttachment"/>
             <mailet match="RecipientIsLocal" 
class="org.apache.james.jmap.mailet.VacationMailet"/>
             <mailet match="RecipientIsLocal" class="Sieve"/>
             <mailet match="RecipientIsLocal" class="LocalDelivery"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/8aecdf03/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
index 84b1dbc..8e348ae 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
@@ -35,6 +35,12 @@
     <dependencies>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>apache-mailet-base</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-data-jmap</artifactId>
             <scope>test</scope>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/8aecdf03/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 4267638..a9efa83 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -39,6 +39,7 @@ import static org.hamcrest.Matchers.not;
 import static org.hamcrest.Matchers.nullValue;
 import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
 import static org.hamcrest.collection.IsMapWithSize.anEmptyMap;
+
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.time.ZonedDateTime;
@@ -47,9 +48,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
+
 import javax.mail.Flags;
 import javax.mail.Flags.Flag;
+import javax.mail.internet.MimeMessage;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.http.client.utils.URIBuilder;
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.jmap.DefaultMailboxes;
 import org.apache.james.jmap.HttpJmapAuthentication;
@@ -68,13 +73,22 @@ import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.probe.MailboxProbe;
 import org.apache.james.modules.MailboxProbeImpl;
-import org.apache.james.utils.MessageIdProbe;
 import org.apache.james.probe.DataProbe;
 import org.apache.james.util.ZeroedInputStream;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.JmapGuiceProbe;
-import org.apache.commons.io.IOUtils;
-import org.apache.http.client.utils.URIBuilder;
+import org.apache.james.utils.MessageIdProbe;
+import org.apache.james.utils.SMTPMessageSender;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.MimeMessageBuilder;
+import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
 
 import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
@@ -88,16 +102,11 @@ import com.jayway.restassured.builder.RequestSpecBuilder;
 import com.jayway.restassured.builder.ResponseSpecBuilder;
 import com.jayway.restassured.http.ContentType;
 import com.jayway.restassured.specification.ResponseSpecification;
-import org.hamcrest.Matcher;
-import org.hamcrest.Matchers;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
 
 public abstract class SetMessagesMethodTest {
-
-    private final static String FORWARDED = "$Forwarded";
+    private static final String LOCALHOST_IP = "127.0.0.1";
+    private static final int SMTP_PORT = 1025;
+    private static final String FORWARDED = "$Forwarded";
     private static final int _1MB = 1024*1024;
     private static final String NAME = "[0][0]";
     private static final String ARGUMENTS = "[0][1]";
@@ -3688,4 +3697,49 @@ public abstract class SetMessagesMethodTest {
             .body(ARGUMENTS + ".type", equalTo("invalidArguments"))
             .body(ARGUMENTS + ".description", containsString("Does not allow 
to update 'Deleted' or 'Recent' flag"));
     }
+
+    @Test
+    public void 
textBodyOfMessageWithTextCalendarShouldBeConvertedToAttachment() throws 
Exception {
+        MimeMessage calendarMessage = 
MimeMessageBuilder.mimeMessageFromStream(ClassLoader.getSystemResourceAsStream("eml/calendar.eml"));
+        String fromAddress = USERNAME;
+
+        Mail mail = FakeMail.builder()
+            .mimeMessage(calendarMessage)
+            .sender(new MailAddress(fromAddress))
+            .recipient(new MailAddress(fromAddress))
+            .build();
+        try (SMTPMessageSender messageSender = 
SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, USERS_DOMAIN);) {
+            messageSender.sendMessage(mail);
+            
calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent);
+        }
+
+        calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> 
isAnyMessageFoundInInbox(accessToken));
+
+        String message = ARGUMENTS + ".list[0]";
+        String firstAttachment = message + ".attachments[0]";
+
+        String inboxId = getMailboxId(accessToken, Role.INBOX);
+        String receivedMessageId =
+            with()
+                .header("Authorization", accessToken.serialize())
+                .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" 
+ inboxId + "\"]}}, \"#0\"]]")
+                .post("/jmap")
+            .then()
+                .extract()
+                .path(ARGUMENTS + ".messageIds[0]");
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMessages\", {\"ids\": [\"" + receivedMessageId + 
"\"]}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .log().ifValidationFails()
+            .body(NAME, equalTo("messages"))
+            .body(ARGUMENTS + ".list", hasSize(1))
+            .body(message + ".attachments", hasSize(1))
+            .body(firstAttachment + ".type", equalTo("text/calendar"))
+            .body(firstAttachment + ".blobId", not(isEmptyOrNullString()));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/8aecdf03/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/calendar.eml
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/calendar.eml
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/calendar.eml
new file mode 100644
index 0000000..2ae4533
--- /dev/null
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/calendar.eml
@@ -0,0 +1,42 @@
+Return-Path: <lo...@localhost.com>
+MIME-Version: 1.0
+Delivered-To: t...@localhost.com
+From: User From <fromu...@localhost.com>
+Message-ID: <2d0fa16c-4c37-58de-1acc-50b5f6a23...@localhost.com>
+To: User To <tou...@linagora.com>
+Date: Wed, 26 Jul 2017 10:34:02 +0200
+Subject: Any subject
+Content-class: urn:content-classes:calendarmessage
+Content-Type: text/calendar; method=REPLY; charset=UTF-8
+Content-transfer-encoding: 8BIT
+
+BEGIN:VCALENDAR
+PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
+VERSION:2.0
+METHOD:REPLY
+BEGIN:VEVENT
+CREATED:20170726T081145Z
+LAST-MODIFIED:20170726T083402Z
+DTSTAMP:20170726T083402Z
+UID:f1514f44bf39311568d6407249cb76c48103fcd1fb398c3c501cb72b2d293f36e04
+ b2aab16e43439a608f28671ab7c10e754cbc85ddee4a07fa8cf8f4f7af05bfb502b8f6
+
+SUMMARY:[A CONFIRMER] Call OVH
+PRIORITY:5
+ORGANIZER;CN=User;X-OBM-ID=id:mailto:use...@localhost.com
+ATTENDEE;CN=User;PARTSTAT=ACCEPTED;CUTYPE=INDIVIDUAL;X-OBM-ID=810:
+ mailto:user...@linagora.com
+DTSTART:20170727T130000Z
+DURATION:PT1H
+TRANSP:OPAQUE
+SEQUENCE:2
+X-LIC-ERROR;X-LIC-ERRORTYPE=VALUE-PARSE-ERROR:No value for X property. Rem
+ oving entire property:
+CLASS:PUBLIC
+X-OBM-DOMAIN:linagora.com
+X-OBM-DOMAIN-UUID:uuid_value
+LOCATION:01.78.14.42.61 / 1586
+X-OBM-ALERT;X-OBM-ID=486:600
+END:VEVENT
+END:VCALENDAR
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/8aecdf03/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
 
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
index 2522c75..dd8daa7 100644
--- 
a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
+++ 
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
@@ -35,6 +35,12 @@
     <dependencies>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>apache-mailet-base</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-dnsservice-api</artifactId>
             <type>test-jar</type>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/8aecdf03/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/mailetcontainer.xml
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/mailetcontainer.xml
 
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/mailetcontainer.xml
index 8e66ed5..7b421ca 100644
--- 
a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/mailetcontainer.xml
+++ 
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/mailetcontainer.xml
@@ -50,6 +50,7 @@
             <mailet match="All" class="RemoveMimeHeader">
                 <name>bcc</name>
             </mailet>
+            <mailet match="All" 
class="org.apache.james.jmap.mailet.TextCalendarBodyToAttachment"/>
             <mailet match="RecipientIsLocal" 
class="org.apache.james.jmap.mailet.VacationMailet"/>
             <mailet match="RecipientIsLocal" class="Sieve"/>
             <mailet match="RecipientIsLocal" class="LocalDelivery"/>


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