You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2017/11/23 08:04:06 UTC

[1/6] james-project git commit: JAMES-2223 NPE in MessageContantExtractor when no content dispostion

Repository: james-project
Updated Branches:
  refs/heads/master 9fc7e722d -> ab677d05d


JAMES-2223 NPE in MessageContantExtractor when no content dispostion


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

Branch: refs/heads/master
Commit: 570996295199e4212bac6d9192ecaad93d64570b
Parents: 9fc7e72
Author: quynhn <qn...@linagora.com>
Authored: Mon Nov 20 15:57:10 2017 +0700
Committer: quynhn <qn...@linagora.com>
Committed: Thu Nov 23 09:26:07 2017 +0700

----------------------------------------------------------------------
 .../util/mime/MessageContentExtractor.java      |  3 +-
 .../cucumber/GetMessagesMethodStepdefs.java     |  5 ++
 .../test/resources/cucumber/GetMessages.feature | 10 ++-
 .../eml/inlinedWithoutContentDisposition.eml    | 69 ++++++++++++++++++++
 4 files changed, 85 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/57099629/server/container/util-java8/src/main/java/org/apache/james/util/mime/MessageContentExtractor.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/mime/MessageContentExtractor.java b/server/container/util-java8/src/main/java/org/apache/james/util/mime/MessageContentExtractor.java
index 5a19d5e..09d2916 100644
--- a/server/container/util-java8/src/main/java/org/apache/james/util/mime/MessageContentExtractor.java
+++ b/server/container/util-java8/src/main/java/org/apache/james/util/mime/MessageContentExtractor.java
@@ -173,7 +173,8 @@ public class MessageContentExtractor {
     }
 
     private boolean isInlinedWithoutCid(Entity part) {
-        return part.getDispositionType().equals(MimeMessage.INLINE) && part.getHeader().getField(CONTENT_ID) == null;
+        return Objects.equals(part.getDispositionType(), MimeMessage.INLINE)
+            && part.getHeader().getField(CONTENT_ID) == null;
     }
 
     public static class MessageContent {

http://git-wip-us.apache.org/repos/asf/james-project/blob/57099629/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
index cf9d51a..2717d7e 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
@@ -327,6 +327,11 @@ public class GetMessagesMethodStepdefs {
         appendMessage(messageName, mailbox, "eml/sameInlinedImages.eml");
     }
 
+    @Given("^\"([^\"]*)\" has a message \"([^\"]*)\" in the \"([^\"]*)\" mailbox with inlined attachments without content disposition$")
+    public void test(String username, String messageName, String mailbox) throws Exception {
+        userStepdefs.execWithUser(username, () -> appendMessage(messageName, mailbox, "eml/inlinedWithoutContentDisposition.eml"));
+    }
+
     @Given("^\"([^\"]*)\" has a message \"([^\"]*)\" in \"([^\"]*)\" mailbox with specific charset$")
     public void appendMessageWithSpecificCharset(String username, String messageName, String mailbox) throws Throwable {
         userStepdefs.execWithUser(username, () -> appendMessageWithSpecificCharset(messageName, mailbox));

http://git-wip-us.apache.org/repos/asf/james-project/blob/57099629/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
index c003096..fcf952f 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
@@ -419,4 +419,12 @@ Feature: GetMessages method
     When "alice@domain.tld" ask for messages "m1"
     Then no error is returned
     And the list should contain 1 message
-    And the isForwarded property of the message is "false"
\ No newline at end of file
+    And the isForwarded property of the message is "false"
+
+  Scenario: Retrieving message should be possible when message with inlined attachment but without content disposition
+    Given "alice@domain.tld" has a message "m1" in the "INBOX" mailbox with inlined attachments without content disposition
+    When "alice@domain.tld" ask for messages "m1"
+    Then no error is returned
+    And the list should contain 1 message
+    And the hasAttachment of the message is "true"
+    And the list of attachments of the message contains 1 attachments

http://git-wip-us.apache.org/repos/asf/james-project/blob/57099629/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/inlinedWithoutContentDisposition.eml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/inlinedWithoutContentDisposition.eml b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/inlinedWithoutContentDisposition.eml
new file mode 100644
index 0000000..a3713d6
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/inlinedWithoutContentDisposition.eml
@@ -0,0 +1,69 @@
+FCC: imap://user@localhost.com/Sent
+X-Identity-Key: id6
+X-Account-Key: account7
+Subject: Re: Excuse pour vendredi dernier
+To: To User <to...@localhost.com>
+From: From User <fr...@localhost.com>
+X-Enigmail-Draft-Status: N1110
+Message-ID: <55AE39CD.8050802>
+Date: Tue, 21 Jul 2015 14:23:41 +0200
+X-Mozilla-Draft-Info: internal/draft; vcard=0; receipt=0; DSN=0; uuencode=0;
+ attachmentreminder=0
+User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
+ Thunderbird/38.1.0
+MIME-Version: 1.0
+In-Reply-To: <dcc6e01637bbd527c411f34de96e6326>
+Content-Type: multipart/encrypted;
+ protocol="application/pgp-encrypted";
+ boundary="09AtNRN8t1bkTL9UtJde8HAiXSJ7dIX0X"
+
+This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)
+--09AtNRN8t1bkTL9UtJde8HAiXSJ7dIX0X
+Content-Type: application/pgp-encrypted
+Content-Description: PGP/MIME version identification
+
+Version: 1
+
+--09AtNRN8t1bkTL9UtJde8HAiXSJ7dIX0X
+Content-Type: application/octet-stream; name="encrypted.asc"
+Content-Description: OpenPGP encrypted message
+Content-Disposition: inline; filename="encrypted.asc"
+
+-----BEGIN PGP MESSAGE-----
+Version: GnuPG v2
+
+hQEMA047f/J68U5CAQf/XXJE8zpJa23r5HqXHRlWHIEQIYGebfzpa1KRy5nx6EB8
+Ku8K0UBIpIK9bxuYV1529jAWfx3iK7M5ekMrAobjbbE0ANB3MfEJX+SAl2m/pNY6
+RM7RoyVkYjzyaKXFshxRIxTIDXxq/YqeIre2yFSSnUYkM9k8mJZkt+f9KAm1CZ28
+YF7oE/+8JmsLBEkNnblb+3c8UiqQLGOywnIVlcv017+e175bq739fJaZgcugHKK5
+l4U7TIFXGHrR5OQO/ec52PZuVAGn4tFEza7ddVd4kdpW37d9DBgLEmUh1aZls0wY
+F6MzvsyUqvw9S1V/B6h8pIvDsfwQL04bGaaXnm5/9dLqAU8P4g8jVlgSdDPEvH7/
+WB1lZABZXgEUEE29/NXQNHYka2Ael4tK6dfDxikrHrsTK5NJUCptXLkaBKnd8+l9
+nKhkUoaJTpXFxuKRYNVDHhJLKGD8klLEsM8AKwk4wEDjJ2SqtdmEGgpGLq1Tje9d
+Ckb9W5NNaZJ0g5lyxtH3YbFNGs9YTP5D8WQ7k8TUxYrvgHiXRROKQwUDAVHIkLnm
+8AJcBwmFFbWSfok5JL1p91jSaYCe7vbqFsggbFO6/uRtSP+U80ZIsbtg+8jhY8x/
+2LAOD/UQopJV3ulIyWDeRmYjP4tiP2JJRuXoG9mYmnMnpBNulEqk0PCgoh9WTw+w
+dPQEHm9DnENCD5r4oBgHXizS14NlL4JbikQjpRhZSB+AZsT7Z2MczDWZ36T8k3cb
+o2ec7HjL4PNaNSpcHTXuuFoCtaKBw0C3oZVJIbSkjHKv80SD8B2+kZ3+uZSWqy6Q
+2t36KJuFwQFqvKeaw69XWjVrPEpkgR8YA7CVjUibYi5q4C81RF5wNIUMzjNO7BNu
+pMYI0w0Gvbmv7O/ekeuaRsClFJTMLxNKaTj1W/Ujeetnww6Ak0xbFSJHRVaR0m4y
+8m7vixRsC2RHI4XHddIdn7nkGE8Y28gRsUj3iH8fzJY1hD87DV1+pNjl3uVUWRm6
+yYrnlO7WVTpofHYWh5zQ5AEb7Y4kL30cvaCkBGYZs2hrXV7gtvpYZDIh4/w6fCtb
+9bY/fOTxeOeFvNFoKOmIfbeV9I3jn1fcMTWd1euyr6CvlZZw8s5+IaHY/x+QEI5w
+npb9RuENgY1dsI+SH6SlpFjl3m+3DwI9o9GiyLmub3cGBucPfOUfAnFLJ+/HMJHc
+WieveXLbqBnxrUMZ3VJVBU88QNMTD77Uyou2HAS2xbRVFAeIuIO6UE01f7CChY6X
+3KU+DYzbtY+zFNGBgR3dI+lraxIEXFD3EKRilLiSpI9ZrCNa15LVigiz7xzHWkKK
+16ZPZcvsMGvZSlXSw7JW2s9AixFxcm2uoQy4WgFMG2i89vkkln50cGx6VAdeAv+N
+uUqgFmvS9uaH36kIFUl2YOsjEMd37CbT7U1rqcOTDtOyTQ468UGtf31EUOwiLOQL
+/zVqk2qIKBgj723d585MCVI3uNrM2PkpETe8I0mIdUyPPAOIklVAdHaBRs956jzQ
+yUFFJk8iM4cGBJXgGLOxvvQPCxD06mulCYFqybgE0XqSu/K/lCALclSecxpoote4
+fHKS7UYlHcNfJ6W7z5BLVypUBATIdAn/Ea30f4EbkyqC/jlT7dhlVzYzeAWgJFs8
+F55FKPblV561TDZx4KrrL4Ya8QHHLPK4c4+z4NWJvlWStUrliWV4s1lHqg/8x1sU
+Hax5xAP2edb6LwKzmCs+CqYVL2IM0bPHCUikjAc9yEPU7C4a3ldk/kb9V4Y9N8Xl
+oANzbohWTTiQtqEKM0Q3kbxRJs6xGRhsUlE44OPkG8WcA+diadJIK7oGAkBHPHjY
+K/m92sPDptGdDvqCoXATyOQNwymBSQ5u9hQ8SHP9xwq/MAVrsZ8Zr9A4EhEtx5Dg
+AXkpM+PVXKS7FJEWA/T1clOBYZtj2rVwomL9yXJ2
+=4I6B
+-----END PGP MESSAGE-----
+
+--09AtNRN8t1bkTL9UtJde8HAiXSJ7dIX0X--
\ No newline at end of file


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


[5/6] james-project git commit: JAMES-2224 Assert that the sender of a message is the owner before putting it in outbox

Posted by ad...@apache.org.
JAMES-2224 Assert that the sender of a message is the owner before putting it in outbox


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

Branch: refs/heads/master
Commit: 564a1a60c21da6aae54ba78cbb1b6ad87b92003f
Parents: 9fc7e72
Author: Antoine Duprat <ad...@linagora.com>
Authored: Tue Nov 21 10:47:29 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Nov 23 09:02:51 2017 +0100

----------------------------------------------------------------------
 .../integration/SetMessagesMethodTest.java      | 85 ++++++++++++++++++++
 .../test/resources/cucumber/SetMessages.feature |  7 ++
 .../james/jmap/methods/MessageSender.java       | 15 ----
 .../methods/SetMessagesCreationProcessor.java   | 11 +++
 .../methods/SetMessagesUpdateProcessor.java     |  9 +++
 5 files changed, 112 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/564a1a60/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 1e78fa6..00a28d1 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
@@ -2213,6 +2213,91 @@ public abstract class SetMessagesMethodTest {
     }
 
     @Test
+    public void setMessagesShouldReturnNotCreatedWhenSendingMessageWithAnotherFromAddressThanTheConnectedUser() {
+        String messageCreationId = "creationId1337";
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"wrongaddress@otherdomain.org\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+        .when()
+            .post("/jmap")
+        .then()
+            .log().ifValidationFails()
+            .statusCode(200)
+            .body(NAME, equalTo("messagesSet"))
+            .body(ARGUMENTS + ".notCreated", aMapWithSize(1))
+            .body(ARGUMENTS + ".notCreated", hasKey(messageCreationId))
+            .body(ARGUMENTS + ".notCreated." + messageCreationId + ".type", equalTo("invalidProperties"))
+            .body(ARGUMENTS + ".notCreated." + messageCreationId + ".description", equalTo("Invalid 'from' field. Must be " + USERNAME));
+    }
+
+    @Test
+    public void setMessagesShouldNotCreateMessageInOutboxWhenSendingMessageWithAnotherFromAddressThanTheConnectedUser() {
+        String messageCreationId = "creationId1337";
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"email\": \"wrongaddress@otherdomain.org\"}," +
+            "        \"to\": [{ \"name\": \"BOB\", \"email\": \"someone@example.com\"}]," +
+            "        \"cc\": [{ \"name\": \"ALICE\"}]," +
+            "        \"subject\": \"Thank you for joining example.com!\"," +
+            "        \"textBody\": \"Hello someone, and thank you for joining example.com!\"," +
+            "        \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+        .when()
+            .post("/jmap")
+        .then()
+            .log().ifValidationFails()
+            .statusCode(200);
+
+        String outboxId = getMailboxId(accessToken, Role.OUTBOX);
+        assertThat(hasNoMessageIn(bobAccessToken, outboxId)).isTrue();
+    }
+    
+    private boolean hasNoMessageIn(AccessToken accessToken, String mailboxId) {
+        try {
+            with()
+                .header("Authorization", accessToken.serialize())
+                .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + mailboxId + "\"]}}, \"#0\"]]")
+            .when()
+                .post("/jmap")
+            .then()
+                .statusCode(200)
+                .body(NAME, equalTo("messageList"))
+                .body(ARGUMENTS + ".messageIds", empty());
+            return true;
+        } catch (AssertionError e) {
+            return false;
+        } 
+    }
+
+    @Test
     public void setMessagesShouldSucceedWhenSendingMessageWithOnlyFromAddress() {
         String messageCreationId = "creationId1337";
         String fromAddress = USERNAME;

http://git-wip-us.apache.org/repos/asf/james-project/blob/564a1a60/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature
index 2fdc88d..46ede38 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMessages.feature
@@ -141,6 +141,13 @@ Feature: SetMessages method on shared folders
     When the user moves "mDraft" to user mailbox "shared" and set flags ""
     Then message "mDraft" is updated
 
+  Scenario: A delegated user can not move draft from draft mailbox to outbox
+    Given "bob@domain.tld" has a mailbox "Drafts"
+    And "bob@domain.tld" tries to create a draft message "mDraft" in mailbox "Drafts"
+    When "alice@domain.tld" moves "mDraft" to mailbox "Outbox" of user "bob@domain.tld"
+    Then message "mDraft" is not updated
+    And message "mBob" has flags $Draft in mailbox "Drafts" of user "bob@domain.tld"
+
   Scenario: A user can move non-draft messages to draft mailbox when setting $Draft
     Given "bob@domain.tld" has a mailbox "Drafts"
     When the user moves "mBob" to user mailbox "Drafts" and set flags "$Draft"

http://git-wip-us.apache.org/repos/asf/james-project/blob/564a1a60/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageSender.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageSender.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageSender.java
index d6835c9..ef18346 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageSender.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageSender.java
@@ -22,7 +22,6 @@ package org.apache.james.jmap.methods;
 import javax.inject.Inject;
 import javax.mail.MessagingException;
 
-import org.apache.james.core.MailAddress;
 import org.apache.james.jmap.model.Envelope;
 import org.apache.james.jmap.model.MessageFactory;
 import org.apache.james.jmap.send.MailFactory;
@@ -47,7 +46,6 @@ public class MessageSender {
     public void sendMessage(MessageFactory.MetaDataWithContent message,
                             Envelope envelope,
                             MailboxSession session) throws MailboxException, MessagingException {
-        assertUserIsInSenders(envelope, session);
         Mail mail = mailFactory.build(message, envelope);
         try {
             MailMetadata metadata = new MailMetadata(message.getMessageId(), session.getUser().getUserName());
@@ -60,20 +58,7 @@ public class MessageSender {
     public void sendMessage(MessageId messageId,
                             Mail mail,
                             MailboxSession session) throws MailboxException, MessagingException {
-        assertUserIsSender(session, mail.getSender());
         MailMetadata metadata = new MailMetadata(messageId, session.getUser().getUserName());
         mailSpool.send(mail, metadata);
     }
-
-    private void assertUserIsInSenders(Envelope envelope, MailboxSession session) throws MailboxSendingNotAllowedException {
-        MailAddress sender = envelope.getFrom();
-        assertUserIsSender(session, sender);
-    }
-
-    private void assertUserIsSender(MailboxSession session, MailAddress sender) throws MailboxSendingNotAllowedException {
-        if (!session.getUser().isSameUser(sender.asString())) {
-            String allowedSender = session.getUser().getUserName();
-            throw new MailboxSendingNotAllowedException(allowedSender);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/564a1a60/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index f9cf560..964ceeb 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -36,6 +36,7 @@ import org.apache.james.jmap.exceptions.MailboxNotOwnedException;
 import org.apache.james.jmap.methods.ValueWithId.CreationMessageEntry;
 import org.apache.james.jmap.methods.ValueWithId.MessageWithId;
 import org.apache.james.jmap.model.CreationMessage;
+import org.apache.james.jmap.model.CreationMessage.DraftEmailer;
 import org.apache.james.jmap.model.Envelope;
 import org.apache.james.jmap.model.Keyword;
 import org.apache.james.jmap.model.Message;
@@ -243,6 +244,7 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
     }
 
     private MessageWithId handleOutboxMessages(CreationMessageEntry entry, MailboxSession session) throws MailboxException, MessagingException {
+        assertUserIsSender(session, entry.getValue().getFrom());
         MessageManager outbox = getMailboxWithRole(session, Role.OUTBOX).orElseThrow(() -> new MailboxNotFoundException(Role.OUTBOX.serialize()));
         MetaDataWithContent newMessage = messageAppender.appendMessageInMailbox(entry, outbox, session);
         Message jmapMessage = messageFactory.fromMetaDataWithContent(newMessage);
@@ -251,6 +253,15 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
         return new ValueWithId.MessageWithId(entry.getCreationId(), jmapMessage);
     }
 
+    private void assertUserIsSender(MailboxSession session, Optional<DraftEmailer> from) throws MailboxSendingNotAllowedException {
+        if (!from.flatMap(DraftEmailer::getEmail)
+                .filter(email -> session.getUser().isSameUser(email))
+                .isPresent()) {
+            String allowedSender = session.getUser().getUserName();
+            throw new MailboxSendingNotAllowedException(allowedSender);
+        }
+    }
+
     private MessageWithId handleDraftMessages(CreationMessageEntry entry, MailboxSession session) throws MailboxException, MessagingException {
         MessageManager draftMailbox = getMailboxWithRole(session, Role.DRAFTS).orElseThrow(() -> new MailboxNotFoundException(Role.DRAFTS.serialize()));
         MetaDataWithContent newMessage = messageAppender.appendMessageInMailbox(entry, draftMailbox, session);

http://git-wip-us.apache.org/repos/asf/james-project/blob/564a1a60/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
index e3865c0..e9de2f9 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
@@ -36,6 +36,7 @@ import javax.mail.MessagingException;
 import javax.mail.Session;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.james.core.MailAddress;
 import org.apache.james.jmap.exceptions.DraftMessageMailboxUpdateException;
 import org.apache.james.jmap.exceptions.InvalidOutboxMoveException;
 import org.apache.james.jmap.model.MessageProperties;
@@ -163,6 +164,7 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
                     .findFirst();
             if (messagesToSend.isPresent()) {
                 MailImpl mail = buildMailFromMessage(messagesToSend.get());
+                assertUserIsSender(mailboxSession, mail.getSender());
                 messageSender.sendMessage(messageId, mail, mailboxSession);
             } else {
                 addMessageIdNotFoundToResponse(messageId, builder);
@@ -170,6 +172,13 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
         }
     }
 
+    private void assertUserIsSender(MailboxSession session, MailAddress sender) throws MailboxSendingNotAllowedException {
+        if (!session.getUser().isSameUser(sender.asString())) {
+            String allowedSender = session.getUser().getUserName();
+            throw new MailboxSendingNotAllowedException(allowedSender);
+        }
+    }
+
     private void assertValidUpdate(List<MessageResult> messagesToBeUpdated, UpdateMessagePatch updateMessagePatch, MailboxSession session) throws MailboxException {
         List<MailboxId> draftMailboxes = mailboxIdFor(Role.DRAFTS, session);
         List<MailboxId> outboxMailboxes = mailboxIdFor(Role.OUTBOX, session);


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


[4/6] james-project git commit: Merge remote-tracking branch 'mine/JAMES-2227'

Posted by ad...@apache.org.
Merge remote-tracking branch 'mine/JAMES-2227'


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

Branch: refs/heads/master
Commit: 66e32270e192b95cc754228cdc0a1288a69e3ee3
Parents: 5709962 cc2e8f0
Author: Antoine Duprat <ad...@linagora.com>
Authored: Thu Nov 23 09:02:26 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Nov 23 09:02:26 2017 +0100

----------------------------------------------------------------------
 .../integration/SetMailboxesMethodTest.java     |  4 +-
 .../org/apache/james/jmap/DefaultMailboxes.java |  3 +
 .../apache/james/jmap/model/mailbox/Role.java   | 48 +++++++-----
 .../jmap/methods/GetMailboxesMethodTest.java    | 56 +++++++-------
 .../james/jmap/model/mailbox/RoleTest.java      | 78 +++++++++++++++++---
 5 files changed, 128 insertions(+), 61 deletions(-)
----------------------------------------------------------------------



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


[6/6] james-project git commit: Merge remote-tracking branch 'mine/JAMES-2224'

Posted by ad...@apache.org.
Merge remote-tracking branch 'mine/JAMES-2224'


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

Branch: refs/heads/master
Commit: ab677d05de9e800fab8b7df3f9cae09156ab8c2a
Parents: 66e3227 564a1a6
Author: Antoine Duprat <ad...@linagora.com>
Authored: Thu Nov 23 09:03:13 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Nov 23 09:03:13 2017 +0100

----------------------------------------------------------------------
 .../integration/SetMessagesMethodTest.java      | 85 ++++++++++++++++++++
 .../test/resources/cucumber/SetMessages.feature |  7 ++
 .../james/jmap/methods/MessageSender.java       | 15 ----
 .../methods/SetMessagesCreationProcessor.java   | 11 +++
 .../methods/SetMessagesUpdateProcessor.java     |  9 +++
 5 files changed, 112 insertions(+), 15 deletions(-)
----------------------------------------------------------------------



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


[2/6] james-project git commit: JAMES-2227 Add missing default mailboxes

Posted by ad...@apache.org.
JAMES-2227 Add missing default mailboxes


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

Branch: refs/heads/master
Commit: 314495a3bb1b80bb687f53108eb7084d8567292f
Parents: 9fc7e72
Author: Antoine Duprat <ad...@linagora.com>
Authored: Tue Nov 21 14:52:50 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Nov 23 09:01:13 2017 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/james/jmap/DefaultMailboxes.java    | 3 +++
 .../main/java/org/apache/james/jmap/model/mailbox/Role.java  | 8 ++++----
 2 files changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/314495a3/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxes.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxes.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxes.java
index 7a91514..2cdfbec 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxes.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxes.java
@@ -31,6 +31,9 @@ public interface DefaultMailboxes {
     String SENT = "Sent";
     String TRASH = "Trash";
     String DRAFTS = "Drafts";
+    String ARCHIVE = "Archive";
+    String SPAM = "Spam";
+    String TEMPLATES = "Templates";
 
     List<String> DEFAULT_MAILBOXES = ImmutableList.of(INBOX, OUTBOX, SENT, TRASH, DRAFTS);
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/314495a3/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
index cb769a5..6bac1f3 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
@@ -41,12 +41,12 @@ public class Role {
     public static final Role OUTBOX = new Role("outbox", DefaultMailboxes.OUTBOX);
     public static final Role SENT = new Role("sent", DefaultMailboxes.SENT);
     public static final Role TRASH = new Role("trash", DefaultMailboxes.TRASH);
-    public static final Role ARCHIVE = new Role("archive");
-    public static final Role SPAM = new Role("spam");
-    public static final Role TEMPLATES = new Role("templates");
+    public static final Role ARCHIVE = new Role("archive", DefaultMailboxes.ARCHIVE);
+    public static final Role SPAM = new Role("spam", DefaultMailboxes.SPAM);
+    public static final Role TEMPLATES = new Role("templates", DefaultMailboxes.TEMPLATES);
     
     private static final Map<String, Role> ROLES = 
-            ImmutableList.<Role>of(INBOX, ARCHIVE, DRAFTS, OUTBOX, SENT, TRASH, SPAM, TEMPLATES)
+            ImmutableList.<Role>of(INBOX, DRAFTS, OUTBOX, SENT, TRASH, ARCHIVE, SPAM, TEMPLATES)
                 .stream()
                 .collect(Collectors.toMap((Role x) -> x.name.toLowerCase(Locale.US), Function.identity()));
     


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


[3/6] james-project git commit: JAMES-2227 System mailboxes should be case sensitive

Posted by ad...@apache.org.
JAMES-2227 System mailboxes should be case sensitive


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

Branch: refs/heads/master
Commit: cc2e8f08219be18f40ea8f8786109ccdb154a82f
Parents: 314495a
Author: Antoine Duprat <ad...@linagora.com>
Authored: Tue Nov 21 15:25:27 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Nov 23 09:01:14 2017 +0100

----------------------------------------------------------------------
 .../integration/SetMailboxesMethodTest.java     |  4 +-
 .../apache/james/jmap/model/mailbox/Role.java   | 48 +++++++-----
 .../jmap/methods/GetMailboxesMethodTest.java    | 56 +++++++-------
 .../james/jmap/model/mailbox/RoleTest.java      | 78 +++++++++++++++++---
 4 files changed, 125 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/cc2e8f08/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
index 690de87..1f7aba8 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
@@ -2058,7 +2058,7 @@ public abstract class SetMailboxesMethodTest {
                     "    {" +
                     "      \"update\": {" +
                     "        \"" + mailboxId.serialize() + "\" : {" +
-                    "          \"name\" : \"outbox\"" +
+                    "          \"name\" : \"Outbox\"" +
                     "        }" +
                     "      }" +
                     "    }," +
@@ -2076,7 +2076,7 @@ public abstract class SetMailboxesMethodTest {
             .body(NAME, equalTo("mailboxesSet"))
             .body(ARGUMENTS + ".notUpdated", hasEntry(equalTo(mailboxId.serialize()), Matchers.allOf(
                     hasEntry(equalTo("type"), equalTo("invalidArguments")),
-                    hasEntry(equalTo("description"), equalTo("The mailbox 'outbox' is a system mailbox.")))));
+                    hasEntry(equalTo("description"), equalTo("The mailbox 'Outbox' is a system mailbox.")))));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/cc2e8f08/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
index 6bac1f3..44115e3 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Role.java
@@ -18,11 +18,9 @@
  ****************************************************************/
 package org.apache.james.jmap.model.mailbox;
 
-import java.util.Locale;
-import java.util.Map;
+import java.util.List;
 import java.util.Optional;
-import java.util.function.Function;
-import java.util.stream.Collectors;
+import java.util.function.BiFunction;
 
 import org.apache.james.jmap.DefaultMailboxes;
 
@@ -35,36 +33,40 @@ import com.google.common.collect.ImmutableList;
 public class Role {
 
     public static final String USER_DEFINED_ROLE_PREFIX = "x-";
+
+    private static final BiFunction<String, String, Boolean> CASE_SENSITIVE_COMPARATOR = (a, b) -> a.equals(b);
+    private static final BiFunction<String, String, Boolean> NON_CASE_SENSITIVE_COMPARATOR = (a, b) -> a.equalsIgnoreCase(b);
+
+    public static final Role INBOX = new Role("inbox", DefaultMailboxes.INBOX, NON_CASE_SENSITIVE_COMPARATOR);
+    public static final Role DRAFTS = new Role("drafts", DefaultMailboxes.DRAFTS, CASE_SENSITIVE_COMPARATOR);
+    public static final Role OUTBOX = new Role("outbox", DefaultMailboxes.OUTBOX, CASE_SENSITIVE_COMPARATOR);
+    public static final Role SENT = new Role("sent", DefaultMailboxes.SENT, CASE_SENSITIVE_COMPARATOR);
+    public static final Role TRASH = new Role("trash", DefaultMailboxes.TRASH, CASE_SENSITIVE_COMPARATOR);
+    public static final Role ARCHIVE = new Role("archive", DefaultMailboxes.ARCHIVE, CASE_SENSITIVE_COMPARATOR);
+    public static final Role SPAM = new Role("spam", DefaultMailboxes.SPAM, CASE_SENSITIVE_COMPARATOR);
+    public static final Role TEMPLATES = new Role("templates", DefaultMailboxes.TEMPLATES, CASE_SENSITIVE_COMPARATOR);
     
-    public static final Role INBOX = new Role("inbox", DefaultMailboxes.INBOX);
-    public static final Role DRAFTS = new Role("drafts", DefaultMailboxes.DRAFTS);
-    public static final Role OUTBOX = new Role("outbox", DefaultMailboxes.OUTBOX);
-    public static final Role SENT = new Role("sent", DefaultMailboxes.SENT);
-    public static final Role TRASH = new Role("trash", DefaultMailboxes.TRASH);
-    public static final Role ARCHIVE = new Role("archive", DefaultMailboxes.ARCHIVE);
-    public static final Role SPAM = new Role("spam", DefaultMailboxes.SPAM);
-    public static final Role TEMPLATES = new Role("templates", DefaultMailboxes.TEMPLATES);
-    
-    private static final Map<String, Role> ROLES = 
-            ImmutableList.<Role>of(INBOX, DRAFTS, OUTBOX, SENT, TRASH, ARCHIVE, SPAM, TEMPLATES)
-                .stream()
-                .collect(Collectors.toMap((Role x) -> x.name.toLowerCase(Locale.US), Function.identity()));
+    private static final List<Role> ROLES = 
+            ImmutableList.<Role>of(INBOX, DRAFTS, OUTBOX, SENT, TRASH, ARCHIVE, SPAM, TEMPLATES);
     
     private final String name;
     private final String defaultMailbox;
+    private final BiFunction<String, String, Boolean> comparator;
 
-    @VisibleForTesting Role(String name, String defaultMailbox) {
+    @VisibleForTesting Role(String name, String defaultMailbox, BiFunction<String, String, Boolean> comparator) {
         this.name = name;
         this.defaultMailbox = defaultMailbox;
+        this.comparator = comparator;
     }
 
     @VisibleForTesting Role(String name) {
         this.name = name;
         this.defaultMailbox = null;
+        this.comparator = NON_CASE_SENSITIVE_COMPARATOR;
     }
 
     public static Optional<Role> from(String name) {
-        Optional<Role> predefinedRole = Optional.ofNullable(ROLES.get(name.toLowerCase(Locale.US)));
+        Optional<Role> predefinedRole = predefinedRole(name);
         if (predefinedRole.isPresent()) {
             return predefinedRole;
         } else {
@@ -72,6 +74,12 @@ public class Role {
         }
     }
 
+    private static Optional<Role> predefinedRole(String name) {
+        return ROLES.stream()
+                .filter(role -> role.comparator.apply(role.defaultMailbox, name))
+                .findFirst();
+    }
+
     private static Optional<Role> tryBuildCustomRole(String name) {
         if (name.startsWith(USER_DEFINED_ROLE_PREFIX)) {
             return Optional.of(new Role(name));
@@ -80,7 +88,7 @@ public class Role {
     }
 
     public boolean isSystemRole() {
-        return ROLES.containsKey(name.toLowerCase(Locale.US));
+        return predefinedRole(defaultMailbox).isPresent();
     }
 
     @JsonValue

http://git-wip-us.apache.org/repos/asf/james-project/blob/cc2e8f08/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
index 9f6c4ce..1356a6b 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
@@ -232,13 +232,13 @@ public class GetMailboxesMethodTest {
     public void getMailboxesShouldReturnMailboxesWithSortOrder() throws Exception {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
         mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "INBOX"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "ARCHIVE"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "DRAFTS"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "OUTBOX"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "SENT"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "TRASH"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "SPAM"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "TEMPLATES"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Archive"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Drafts"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Outbox"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Sent"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Trash"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Spam"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Templates"), mailboxSession);
 
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();
@@ -254,13 +254,13 @@ public class GetMailboxesMethodTest {
                 .extracting(Mailbox::getName, Mailbox::getSortOrder)
                 .containsExactly(
                         Tuple.tuple("INBOX", SortOrder.of(10)),
-                        Tuple.tuple("ARCHIVE", SortOrder.of(20)),
-                        Tuple.tuple("DRAFTS", SortOrder.of(30)),
-                        Tuple.tuple("OUTBOX", SortOrder.of(40)),
-                        Tuple.tuple("SENT", SortOrder.of(50)),
-                        Tuple.tuple("TRASH", SortOrder.of(60)),
-                        Tuple.tuple("SPAM", SortOrder.of(70)),
-                        Tuple.tuple("TEMPLATES", SortOrder.of(80)));
+                        Tuple.tuple("Archive", SortOrder.of(20)),
+                        Tuple.tuple("Drafts", SortOrder.of(30)),
+                        Tuple.tuple("Outbox", SortOrder.of(40)),
+                        Tuple.tuple("Sent", SortOrder.of(50)),
+                        Tuple.tuple("Trash", SortOrder.of(60)),
+                        Tuple.tuple("Spam", SortOrder.of(70)),
+                        Tuple.tuple("Templates", SortOrder.of(80)));
     }
 
     @Test
@@ -339,13 +339,13 @@ public class GetMailboxesMethodTest {
     public void getMailboxesShouldReturnMailboxesWithRoles() throws Exception {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
         mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "INBOX"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "ARCHIVE"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "DRAFTS"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "OUTBOX"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "SENT"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "TRASH"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "SPAM"), mailboxSession);
-        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "TEMPLATES"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Archive"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Drafts"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Outbox"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Sent"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Trash"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Spam"), mailboxSession);
+        mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "Templates"), mailboxSession);
         mailboxManager.createMailbox(MailboxPath.forUser(USERNAME, "WITHOUT ROLE"), mailboxSession);
         
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
@@ -362,13 +362,13 @@ public class GetMailboxesMethodTest {
                 .extracting(Mailbox::getName, Mailbox::getRole)
                 .containsOnly(
                         Tuple.tuple("INBOX", Optional.of(Role.INBOX)),
-                        Tuple.tuple("ARCHIVE", Optional.of(Role.ARCHIVE)),
-                        Tuple.tuple("DRAFTS", Optional.of(Role.DRAFTS)),
-                        Tuple.tuple("OUTBOX", Optional.of(Role.OUTBOX)),
-                        Tuple.tuple("SENT", Optional.of(Role.SENT)),
-                        Tuple.tuple("TRASH", Optional.of(Role.TRASH)),
-                        Tuple.tuple("SPAM", Optional.of(Role.SPAM)),
-                        Tuple.tuple("TEMPLATES", Optional.of(Role.TEMPLATES)),
+                        Tuple.tuple("Archive", Optional.of(Role.ARCHIVE)),
+                        Tuple.tuple("Drafts", Optional.of(Role.DRAFTS)),
+                        Tuple.tuple("Outbox", Optional.of(Role.OUTBOX)),
+                        Tuple.tuple("Sent", Optional.of(Role.SENT)),
+                        Tuple.tuple("Trash", Optional.of(Role.TRASH)),
+                        Tuple.tuple("Spam", Optional.of(Role.SPAM)),
+                        Tuple.tuple("Templates", Optional.of(Role.TEMPLATES)),
                         Tuple.tuple("WITHOUT ROLE", Optional.empty()));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/cc2e8f08/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RoleTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RoleTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RoleTest.java
index 05c7928..fcdcede 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RoleTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RoleTest.java
@@ -28,18 +28,19 @@ import org.junit.Test;
 public class RoleTest {
 
     @Test
-    public void fromShouldReturnInbox() {
-        assertThat(Role.from("inbox")).isEqualTo(Optional.of(Role.INBOX));
+    public void fromShouldReturnEmptyWhenUnknownValue() {
+        assertThat(Role.from("jjjj")).isEqualTo(Optional.empty());
     }
 
     @Test
-    public void fromShouldReturnEmptyWhenUnknownValue() {
-        assertThat(Role.from("jjjj")).isEqualTo(Optional.empty());
+    public void fromShouldReturnSomethingWhenXPrefixedRole() {
+        assertThat(Role.from("x-client-specific-role")).isEqualTo(Optional.of(new Role("x-client-specific-role")));
     }
 
     @Test
-    public void fromShouldReturnInboxWhenContainsUppercaseValue() {
-        assertThat(Role.from("InBox")).isEqualTo(Optional.of(Role.INBOX));
+    public void isSystemRoleShouldReturnFalseWhenXPrefixedRole() {
+        Role role = Role.from("x-client-specific-role").get();
+        assertThat(role.isSystemRole()).isFalse();
     }
 
     @Test
@@ -54,11 +55,6 @@ public class RoleTest {
     }
 
     @Test
-    public void fromShouldReturnSomethingWhenXPrefixedRole() {
-        assertThat(Role.from("x-client-specific-role")).isEqualTo(Optional.of(new Role("x-client-specific-role")));
-    }
-
-    @Test
     public void isSystemRoleShouldBeTrueWhenInbox() {
         assertThat(Role.INBOX.isSystemRole()).isTrue();
     }
@@ -103,4 +99,64 @@ public class RoleTest {
         Role userRole = Role.from(Role.USER_DEFINED_ROLE_PREFIX + "myRole").get();
         assertThat(userRole.isSystemRole()).isFalse();
     }
+
+    @Test
+    public void theINBOXMailboxNameShouldBeASystemMailbox() {
+        Role role = Role.from("INBOX").get();
+        assertThat(role.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void theInBoXMailboxNameShouldBeASystemMailbox() {
+        Role role = Role.from("InBoX").get();
+        assertThat(role.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void theDraftsMailboxNameShouldBeASystemMailbox() {
+        Role role = Role.from("Drafts").get();
+        assertThat(role.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void theDrAfTsMailboxNameShouldNotBeASystemMailbox() {
+        Optional<Role> role = Role.from("DrAfTs");
+        assertThat(role).isEmpty();
+    }
+
+    @Test
+    public void theOutboxMailboxNameShouldBeASystemMailbox() {
+        Role role = Role.from("Outbox").get();
+        assertThat(role.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void theOuTbOxMailboxNameShouldNotBeASystemMailbox() {
+        Optional<Role> role = Role.from("OuTbOx");
+        assertThat(role).isEmpty();
+    }
+
+    @Test
+    public void theSentMailboxNameShouldBeASystemMailbox() {
+        Role role = Role.from("Sent").get();
+        assertThat(role.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void theSeNtMailboxNameShouldNotBeASystemMailbox() {
+        Optional<Role> role = Role.from("SeNt");
+        assertThat(role).isEmpty();
+    }
+
+    @Test
+    public void theTrashMailboxNameShouldBeASystemMailbox() {
+        Role role = Role.from("Trash").get();
+        assertThat(role.isSystemRole()).isTrue();
+    }
+
+    @Test
+    public void theTrAsHMailboxNameShouldNotBeASystemMailbox() {
+        Optional<Role> role = Role.from("TrAsH");
+        assertThat(role).isEmpty();
+    }
 }
\ No newline at end of file


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