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 2018/08/23 12:12:46 UTC
[1/4] james-project git commit: JAMES-2457 Add JMAP test for large
mail handling
Repository: james-project
Updated Branches:
refs/heads/master 2db93fb01 -> d125ba97a
JAMES-2457 Add JMAP test for large mail handling
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/efdd8508
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/efdd8508
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/efdd8508
Branch: refs/heads/master
Commit: efdd850877543afd2c75ae8ca04d10ff2e3c618c
Parents: 2db93fb
Author: Gautier DI FOLCO <gd...@linagora.com>
Authored: Fri Jul 6 15:28:13 2018 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Aug 23 13:57:29 2018 +0200
----------------------------------------------------------------------
.../integration/SetMessagesMethodTest.java | 71 ++++++++++++++++++++
1 file changed, 71 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/efdd8508/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 6f100b2..deb4245 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
@@ -120,6 +120,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
+import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.io.ByteStreams;
@@ -136,6 +137,7 @@ public abstract class SetMessagesMethodTest {
private static final String PASSWORD = "password";
private static final MailboxPath USER_MAILBOX = MailboxPath.forUser(USERNAME, "mailbox");
private static final String NOT_UPDATED = ARGUMENTS + ".notUpdated";
+ private static final int BIG_MESSAGE_SIZE = 20 * 1024 * 1024;
private AccessToken bobAccessToken;
@@ -1353,6 +1355,75 @@ public abstract class SetMessagesMethodTest {
}
@Test
+ public void setMessagesWithABigBodyShouldReturnCreatedMessageWhenSendingMessage() {
+ String messageCreationId = "creationId1337";
+ String fromAddress = USERNAME;
+ String body = Strings.repeat("d", BIG_MESSAGE_SIZE);
+ {
+ String requestBody = "[" +
+ " [" +
+ " \"setMessages\"," +
+ " {" +
+ " \"create\": { \"" + messageCreationId + "\" : {" +
+ " \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}," +
+ " \"to\": [{ \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}]," +
+ " \"subject\": \"Thank you for joining example.com!\"," +
+ " \"textBody\": \"" + body + "\"," +
+ " \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" +
+ " }}" +
+ " }," +
+ " \"#0\"" +
+ " ]" +
+ "]";
+
+ given()
+ .header("Authorization", accessToken.serialize())
+ .body(requestBody)
+ .when()
+ .post("/jmap")
+ .then()
+ .statusCode(200)
+ .body(NAME, equalTo("messagesSet"))
+ .body(ARGUMENTS + ".notCreated", aMapWithSize(0))
+ .body(ARGUMENTS + ".created", aMapWithSize(1))
+ .body(ARGUMENTS + ".created", hasEntry(equalTo(messageCreationId), hasEntry(equalTo("textBody"), equalTo(body))));
+ }
+
+ calmlyAwait
+ .pollDelay(Duration.FIVE_HUNDRED_MILLISECONDS)
+ .atMost(30, TimeUnit.SECONDS).until(() -> hasANewMailWithBody(accessToken, body));
+ }
+
+ private boolean hasANewMailWithBody(AccessToken recipientToken, String body) {
+ try {
+ 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)
+ .body(NAME, equalTo("messages"))
+ .body(ARGUMENTS + ".list", hasSize(1))
+ .body(ARGUMENTS + ".list[0].textBody", equalTo(body));
+ return true;
+
+ } catch (AssertionError e) {
+ return false;
+ }
+ }
+
+ @Test
public void setMessagesShouldNotAllowCopyWhenOverQuota() throws MailboxException {
QuotaProbe quotaProbe = jmapServer.getProbe(QuotaProbesImpl.class);
String inboxQuotaRoot = quotaProbe.getQuotaRoot("#private", USERNAME, DefaultMailboxes.INBOX);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[4/4] james-project git commit: Merge branch 'JAMES-2167-null-sender'
Posted by ad...@apache.org.
Merge branch 'JAMES-2167-null-sender'
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d125ba97
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d125ba97
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d125ba97
Branch: refs/heads/master
Commit: d125ba97ac74fad094215d9f7d36b28ae3c633d7
Parents: efdd850 09b5cb5
Author: Antoine Duprat <ad...@linagora.com>
Authored: Thu Aug 23 13:59:44 2018 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Aug 23 13:59:44 2018 +0200
----------------------------------------------------------------------
.../java/org/apache/james/core/MailAddress.java | 37 +++++++++++++++-----
.../org/apache/james/core/MailAddressTest.java | 16 +++++++++
.../james/queue/api/MailQueueContract.java | 17 +++++++++
.../apache/james/queue/jms/JMSMailQueue.java | 30 ++++++++--------
4 files changed, 78 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/4] james-project git commit: JAMES-2167 Correct MailAdress equals
Posted by ad...@apache.org.
JAMES-2167 Correct MailAdress equals
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/09b5cb56
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/09b5cb56
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/09b5cb56
Branch: refs/heads/master
Commit: 09b5cb567e3292b1739993559bc93d37bd99a478
Parents: ec911c1
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Aug 21 10:31:02 2018 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Aug 23 13:59:17 2018 +0200
----------------------------------------------------------------------
.../java/org/apache/james/core/MailAddress.java | 30 +++++++++++++++-----
.../org/apache/james/core/MailAddressTest.java | 16 +++++++++++
2 files changed, 39 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/09b5cb56/core/src/main/java/org/apache/james/core/MailAddress.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/MailAddress.java b/core/src/main/java/org/apache/james/core/MailAddress.java
index e53f5bc..cd206ef 100644
--- a/core/src/main/java/org/apache/james/core/MailAddress.java
+++ b/core/src/main/java/org/apache/james/core/MailAddress.java
@@ -20,6 +20,8 @@
package org.apache.james.core;
import java.util.Locale;
+import java.util.Objects;
+import java.util.Optional;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
@@ -108,11 +110,12 @@ public class MailAddress implements java.io.Serializable {
return NULL_SENDER;
}
- private String localPart = null;
- private Domain domain = null;
+ private final String localPart;
+ private final Domain domain;
private MailAddress() {
-
+ localPart = null;
+ domain = null;
}
/**
@@ -317,7 +320,9 @@ public class MailAddress implements java.io.Serializable {
@Override
public String toString() {
- return localPart + "@" + domain.asString();
+ return localPart + "@" + Optional.ofNullable(domain)
+ .map(Domain::asString)
+ .orElse("");
}
public String asPrettyString() {
@@ -350,7 +355,7 @@ public class MailAddress implements java.io.Serializable {
* @returns true if the given object is equal to this one, false otherwise
*/
@Override
- public boolean equals(Object obj) {
+ public final boolean equals(Object obj) {
if (obj == null) {
return false;
} else if (obj instanceof String) {
@@ -361,11 +366,22 @@ public class MailAddress implements java.io.Serializable {
if (isNullSender() && addr.isNullSender()) {
return true;
}
- return getLocalPart().equalsIgnoreCase(addr.getLocalPart()) && getDomain().equals(addr.getDomain());
+ return equalsIgnoreCase(getLocalPart(), addr.getLocalPart())
+ && Objects.equals(getDomain(), addr.getDomain());
}
return false;
}
+ private boolean equalsIgnoreCase(String a, String b) {
+ if (a == null ^ b == null) {
+ return false;
+ }
+ if (a == null) {
+ return true;
+ }
+ return a.equalsIgnoreCase(b);
+ }
+
/**
* Returns a hash code value for this object.
* <p/>
@@ -376,7 +392,7 @@ public class MailAddress implements java.io.Serializable {
* @return the hashcode.
*/
@Override
- public int hashCode() {
+ public final int hashCode() {
return toString().toLowerCase(Locale.US).hashCode();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/09b5cb56/core/src/test/java/org/apache/james/core/MailAddressTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/james/core/MailAddressTest.java b/core/src/test/java/org/apache/james/core/MailAddressTest.java
index edb1cfa..f7cfc02 100644
--- a/core/src/test/java/org/apache/james/core/MailAddressTest.java
+++ b/core/src/test/java/org/apache/james/core/MailAddressTest.java
@@ -19,6 +19,8 @@
package org.apache.james.core;
+import static org.assertj.core.api.Assertions.assertThat;
+
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
@@ -26,6 +28,8 @@ import org.assertj.core.api.Assertions;
import org.junit.Assert;
import org.junit.Test;
+import nl.jqno.equalsverifier.EqualsVerifier;
+
public class MailAddressTest {
private static final String GOOD_LOCAL_PART = "\"quoted@local part\"";
@@ -222,4 +226,16 @@ public class MailAddressTest {
Assert.assertTrue(a.toString() + " != " + b.toString(), a.equals(b));
Assert.assertFalse(a.toString() + " != " + null, a.equals(null));
}
+
+ @Test
+ public void equalsShouldReturnTrueWhenBothNullSender() {
+ assertThat(MailAddress.nullSender())
+ .isEqualTo(MailAddress.nullSender());
+ }
+
+ @Test
+ public void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(MailAddress.class)
+ .verify();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/4] james-project git commit: JAMES-2167 MailQueue should preserve
null sender
Posted by ad...@apache.org.
JAMES-2167 MailQueue should preserve null sender
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ec911c13
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ec911c13
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ec911c13
Branch: refs/heads/master
Commit: ec911c1317aab016e4eb8bc999572e579590f0fd
Parents: 2db93fb
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Aug 17 15:52:06 2018 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Thu Aug 23 13:59:16 2018 +0200
----------------------------------------------------------------------
.../java/org/apache/james/core/MailAddress.java | 7 ++++-
.../james/queue/api/MailQueueContract.java | 17 +++++++++++
.../apache/james/queue/jms/JMSMailQueue.java | 30 +++++++++++---------
3 files changed, 39 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/ec911c13/core/src/main/java/org/apache/james/core/MailAddress.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/MailAddress.java b/core/src/main/java/org/apache/james/core/MailAddress.java
index aaf2abb..e53f5bc 100644
--- a/core/src/main/java/org/apache/james/core/MailAddress.java
+++ b/core/src/main/java/org/apache/james/core/MailAddress.java
@@ -72,6 +72,8 @@ public class MailAddress implements java.io.Serializable {
private static final char[] SPECIAL =
{'<', '>', '(', ')', '[', ']', '\\', '.', ',', ';', ':', '@', '\"'};
+ public static final String NULL_SENDER_AS_STRING = "<>";
+
private static final MailAddress NULL_SENDER = new MailAddress() {
@Override
@@ -91,7 +93,7 @@ public class MailAddress implements java.io.Serializable {
@Override
public String asString() {
- return "<>";
+ return NULL_SENDER_AS_STRING;
}
@Override
@@ -356,6 +358,9 @@ public class MailAddress implements java.io.Serializable {
return toString().equalsIgnoreCase(theString);
} else if (obj instanceof MailAddress) {
MailAddress addr = (MailAddress) obj;
+ if (isNullSender() && addr.isNullSender()) {
+ return true;
+ }
return getLocalPart().equalsIgnoreCase(addr.getLocalPart()) && getDomain().equals(addr.getDomain());
}
return false;
http://git-wip-us.apache.org/repos/asf/james-project/blob/ec911c13/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueContract.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueContract.java b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueContract.java
index 205c58b..377cf3f 100644
--- a/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueContract.java
+++ b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueContract.java
@@ -38,10 +38,12 @@ import java.util.concurrent.TimeoutException;
import javax.mail.internet.MimeMessage;
+import org.apache.james.core.MailAddress;
import org.apache.james.core.builder.MimeMessageBuilder;
import org.apache.james.junit.ExecutorExtension;
import org.apache.mailet.Mail;
import org.apache.mailet.PerRecipientHeaders;
+import org.apache.mailet.base.test.FakeMail;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -82,6 +84,21 @@ public interface MailQueueContract {
}
@Test
+ default void queueShouldPreserveNullSender() throws Exception {
+ getMailQueue().enQueue(FakeMail.builder()
+ .name("name")
+ .mimeMessage(createMimeMessage())
+ .recipients(RECIPIENT1, RECIPIENT2)
+ .sender(MailAddress.nullSender())
+ .lastUpdated(new Date())
+ .build());
+
+ MailQueue.MailQueueItem mailQueueItem = getMailQueue().deQueue();
+ assertThat(mailQueueItem.getMail().getSender())
+ .isEqualTo(MailAddress.nullSender());
+ }
+
+ @Test
default void queueShouldPreserveMailSender() throws Exception {
getMailQueue().enQueue(defaultMail()
.sender(SENDER)
http://git-wip-us.apache.org/repos/asf/james-project/blob/ec911c13/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
index f6f9838..a60bde2 100644
--- a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
+++ b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
@@ -412,22 +412,24 @@ public class JMSMailQueue implements ManageableMailQueue, JMSSupport, MailPriori
splitter.split(attributeNames)
.forEach(name -> setMailAttribute(message, mail, name));
- String sender = message.getStringProperty(JAMES_MAIL_SENDER);
- if (sender == null || sender.trim().length() <= 0) {
- mail.setSender(null);
- } else {
- try {
- mail.setSender(new MailAddress(sender));
- } catch (AddressException e) {
- // Should never happen as long as the user does not modify the
- // the header by himself
- LOGGER.error("Unable to parse the sender address {} for mail {}, so we fallback to a null sender", sender, mail.getName(), e);
- mail.setSender(null);
- }
- }
-
+ mail.setSender(getMailSender(message.getStringProperty(JAMES_MAIL_SENDER), mail));
mail.setState(message.getStringProperty(JAMES_MAIL_STATE));
+ }
+ private MailAddress getMailSender(String sender, Mail mail) {
+ if (sender == null || sender.trim().length() <= 0) {
+ return null;
+ }
+ if (sender.equals(MailAddress.NULL_SENDER_AS_STRING)) {
+ return MailAddress.nullSender();
+ }
+ try {
+ return new MailAddress(sender);
+ } catch (AddressException e) {
+ // Should never happen as long as the user does not modify the header by himself
+ LOGGER.error("Unable to parse the sender address {} for mail {}, so we fallback to a null sender", sender, mail.getName(), e);
+ return MailAddress.nullSender();
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org