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/15 11:15:53 UTC

[12/19] james-project git commit: JAMES-2214 Only one From address is supported: the user name

JAMES-2214 Only one From address is supported: the user name


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

Branch: refs/heads/master
Commit: 46e520e621b6c0ae4a9ec8733cf2eb34c066a71e
Parents: 90f3fb7
Author: benwa <bt...@linagora.com>
Authored: Mon Nov 13 16:23:17 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Nov 15 18:05:45 2017 +0700

----------------------------------------------------------------------
 .../methods/integration/SetMessagesMethodTest.java    |  2 +-
 .../methods/MailboxSendingNotAllowedException.java    | 12 +++++-------
 .../org/apache/james/jmap/methods/MessageSender.java  | 14 +++++---------
 .../jmap/methods/SetMessagesCreationProcessor.java    |  5 ++---
 4 files changed, 13 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/46e520e6/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 97fbf15..ad99100 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
@@ -2290,7 +2290,7 @@ public abstract class SetMessagesMethodTest {
             .body(ARGUMENTS + ".notCreated[\""+messageCreationId+"\"].type", equalTo("invalidProperties"))
             .body(ARGUMENTS + ".notCreated[\""+messageCreationId+"\"].properties", hasSize(1))
             .body(ARGUMENTS + ".notCreated[\""+messageCreationId+"\"].properties", contains("from"))
-            .body(ARGUMENTS + ".notCreated[\""+messageCreationId+"\"].description", endsWith("Invalid 'from' field. Must be one of username@domain.tld"))
+            .body(ARGUMENTS + ".notCreated[\""+messageCreationId+"\"].description", endsWith("Invalid 'from' field. Must be username@domain.tld"))
             .body(ARGUMENTS + ".created", aMapWithSize(0));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/46e520e6/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MailboxSendingNotAllowedException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MailboxSendingNotAllowedException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MailboxSendingNotAllowedException.java
index 49d9141..83d36c8 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MailboxSendingNotAllowedException.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MailboxSendingNotAllowedException.java
@@ -19,20 +19,18 @@
 
 package org.apache.james.jmap.methods;
 
-import java.util.Collection;
-
 import org.apache.james.mailbox.exception.MailboxException;
 
 public class MailboxSendingNotAllowedException extends MailboxException {
 
-    private Collection<String> allowedFroms;
+    private String allowedFrom;
 
-    public MailboxSendingNotAllowedException(Collection<String> allowedFroms) {
+    public MailboxSendingNotAllowedException(String allowedFrom) {
         super();
-        this.allowedFroms = allowedFroms;
+        this.allowedFrom = allowedFrom;
     }
     
-    public Collection<String> getAllowedFroms() {
-        return allowedFroms;
+    public String getAllowedFrom() {
+        return allowedFrom;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/46e520e6/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 98e41d2..ab360ea 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
@@ -20,12 +20,10 @@
 package org.apache.james.jmap.methods;
 
 import java.io.IOException;
-import java.util.List;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
 
-import org.apache.james.jmap.model.CreationMessageId;
 import org.apache.james.jmap.model.Message;
 import org.apache.james.jmap.model.MessageFactory;
 import org.apache.james.jmap.send.MailFactory;
@@ -36,8 +34,6 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.mailet.Mail;
 
-import com.google.common.collect.ImmutableList;
-
 public class MessageSender {
     private final MailSpool mailSpool;
     private final MailFactory mailFactory;
@@ -70,16 +66,16 @@ public class MessageSender {
     }
 
     private void validateUserIsInSenders(Message message, MailboxSession session) throws MailboxSendingNotAllowedException {
-        List<String> allowedSenders = ImmutableList.of(session.getUser().getUserName());
-        if (!isAllowedFromAddress(message, allowedSenders)) {
-            throw new MailboxSendingNotAllowedException(allowedSenders);
+        String allowedSender = session.getUser().getUserName();
+        if (!isAllowedFromAddress(message, allowedSender)) {
+            throw new MailboxSendingNotAllowedException(allowedSender);
         }
     }
 
-    private boolean isAllowedFromAddress(Message message, List<String> allowedFromMailAddresses) {
+    private boolean isAllowedFromAddress(Message message, String allowedFromMailAddress) {
         return message.getFrom()
             .map(draftEmailer -> draftEmailer.getEmail()
-                .map(allowedFromMailAddresses::contains)
+                .map(allowedFromMailAddress::equals)
                 .orElse(false))
             .orElse(false);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/46e520e6/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 ac12072..19dc981 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
@@ -63,7 +63,6 @@ import org.slf4j.LoggerFactory;
 import com.github.fge.lambdas.Throwing;
 import com.github.fge.lambdas.functions.FunctionChainer;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Joiner;
 import com.google.common.base.Splitter;
 
 
@@ -117,8 +116,8 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
                     SetError.builder()
                         .type("invalidProperties")
                         .properties(MessageProperty.from)
-                        .description("Invalid 'from' field. Must be one of " + 
-                                Joiner.on(", ").join(e.getAllowedFroms()))
+                        .description("Invalid 'from' field. Must be " +
+                                e.getAllowedFrom())
                         .build());
 
         } catch (InvalidDraftKeywordsException e) {


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