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 ma...@apache.org on 2017/09/28 07:58:25 UTC
[1/9] james-project git commit: JAMES-2159 Support String in
AmqpForwardAttribute
Repository: james-project
Updated Branches:
refs/heads/master 4c3e0403c -> 8c4606360
JAMES-2159 Support String in AmqpForwardAttribute
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4c5cc6a4
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4c5cc6a4
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4c5cc6a4
Branch: refs/heads/master
Commit: 4c5cc6a485a0b9904dfccafae70a1b1492bb7584
Parents: c5bf071
Author: Matthieu Baechler <ma...@apache.org>
Authored: Wed Sep 13 14:51:29 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Sep 27 16:07:08 2017 +0200
----------------------------------------------------------------------
.../transport/mailets/AmqpForwardAttribute.java | 6 +++++-
.../mailets/AmqpForwardAttributeTest.java | 22 ++++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c5cc6a4/mailet/standard/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
index e0cb8f1..0c6fb7d 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.mailets;
import java.io.IOException;
import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
@@ -126,8 +127,11 @@ public class AmqpForwardAttribute extends GenericMailet {
if (attributeContent instanceof List) {
return ((List<byte[]>) attributeContent).stream();
}
+ if (attributeContent instanceof String) {
+ return Stream.of(((String) attributeContent).getBytes(StandardCharsets.UTF_8));
+ }
throw new MailetException("Invalid attribute found into attribute "
- + attribute + "class Map or List expected but "
+ + attribute + "class Map or List or String expected but "
+ attributeContent.getClass() + " found.");
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4c5cc6a4/mailet/standard/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
index c8f201e..27ce10b 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;
import javax.mail.MessagingException;
@@ -245,4 +246,25 @@ public class AmqpForwardAttributeTest {
verify(channel).basicPublish(eq(EXCHANGE_NAME), eq(ROUTING_KEY), basicPropertiesCaptor.capture(), eq(ATTACHMENT_CONTENT));
assertThat(basicPropertiesCaptor.getValue()).isEqualToComparingFieldByField(expectedProperties);
}
+
+ @Test
+ public void serviceShouldPublishAttributeContentWhenAttributeInMailAndIsAString() throws Exception {
+ mailet.init(mailetConfig);
+ Channel channel = mock(Channel.class);
+ Connection connection = mock(Connection.class);
+ when(connection.createChannel()).thenReturn(channel);
+ ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
+ when(connectionFactory.newConnection()).thenReturn(connection);
+ mailet.setConnectionFactory(connectionFactory);
+ Mail mail = mock(Mail.class);
+ String content = "Attachment content";
+ when(mail.getAttribute(MAIL_ATTRIBUTE)).thenReturn(content);
+ BasicProperties expectedProperties = new AMQP.BasicProperties();
+
+ mailet.service(mail);
+
+ ArgumentCaptor<BasicProperties> basicPropertiesCaptor = ArgumentCaptor.forClass(BasicProperties.class);
+ verify(channel).basicPublish(eq(EXCHANGE_NAME), eq(ROUTING_KEY), basicPropertiesCaptor.capture(), eq(content.getBytes(StandardCharsets.UTF_8)));
+ assertThat(basicPropertiesCaptor.getValue()).isEqualToComparingFieldByField(expectedProperties);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/9] james-project git commit: JAMES-2159 Support List in
AmqpForwardAttribute
Posted by ma...@apache.org.
JAMES-2159 Support List in AmqpForwardAttribute
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c803800d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c803800d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c803800d
Branch: refs/heads/master
Commit: c803800dd43439316e64a635271f6dcbe1e93fcd
Parents: 605ab57
Author: Matthieu Baechler <ma...@apache.org>
Authored: Tue Sep 12 18:16:45 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Sep 27 16:07:08 2017 +0200
----------------------------------------------------------------------
.../transport/mailets/AmqpForwardAttribute.java | 36 ++++++++++++--------
.../mailets/AmqpForwardAttributeTest.java | 26 ++++++++++++--
2 files changed, 44 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c803800d/mailet/standard/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
index 7d1b104..e0cb8f1 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/AmqpForwardAttribute.java
@@ -21,8 +21,10 @@ package org.apache.james.transport.mailets;
import java.io.IOException;
import java.io.Serializable;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
+import java.util.stream.Stream;
import org.apache.mailet.Mail;
import org.apache.mailet.MailetException;
@@ -30,6 +32,7 @@ import org.apache.mailet.base.GenericMailet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.github.fge.lambdas.Throwing;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.rabbitmq.client.AMQP;
@@ -104,7 +107,7 @@ public class AmqpForwardAttribute extends GenericMailet {
if (mail.getAttribute(attribute) == null) {
return;
}
- Map<String, byte[]> content = getAttributeContent(mail);
+ Stream<byte[]> content = getAttributeContent(mail);
try {
sendContent(content);
} catch (IOException e) {
@@ -115,17 +118,20 @@ public class AmqpForwardAttribute extends GenericMailet {
}
@SuppressWarnings("unchecked")
- private Map<String, byte[]> getAttributeContent(Mail mail) throws MailetException {
+ private Stream<byte[]> getAttributeContent(Mail mail) throws MailetException {
Serializable attributeContent = mail.getAttribute(attribute);
- if (! (attributeContent instanceof Map)) {
- throw new MailetException("Invalid attribute found into attribute "
- + attribute + "class Map expected but "
- + attributeContent.getClass() + " found.");
+ if (attributeContent instanceof Map) {
+ return ((Map<String, byte[]>) attributeContent).values().stream();
}
- return (Map<String, byte[]>) attributeContent;
+ if (attributeContent instanceof List) {
+ return ((List<byte[]>) attributeContent).stream();
+ }
+ throw new MailetException("Invalid attribute found into attribute "
+ + attribute + "class Map or List expected but "
+ + attributeContent.getClass() + " found.");
}
- private void sendContent(Map<String, byte[]> content) throws IOException, TimeoutException {
+ private void sendContent(Stream<byte[]> content) throws IOException, TimeoutException {
Connection connection = null;
Channel channel = null;
try {
@@ -143,13 +149,13 @@ public class AmqpForwardAttribute extends GenericMailet {
}
}
- private void sendContentOnChannel(Channel channel, Map<String, byte[]> content) throws IOException {
- for (byte[] body: content.values()) {
- channel.basicPublish(exchange,
- routingKey,
- new AMQP.BasicProperties(),
- body);
- }
+ private void sendContentOnChannel(Channel channel, Stream<byte[]> content) throws IOException {
+ content.forEach(
+ Throwing.consumer(message ->
+ channel.basicPublish(exchange,
+ routingKey,
+ new AMQP.BasicProperties(),
+ message)));
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/c803800d/mailet/standard/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
index 0af1e67..c8f201e 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttributeTest.java
@@ -172,10 +172,10 @@ public class AmqpForwardAttributeTest {
}
@Test
- public void serviceShouldThrowWhenAttributeContentIsNotAMap() throws MessagingException {
+ public void serviceShouldThrowWhenAttributeContentIsNotAMapAListOrAString() throws MessagingException {
mailet.init(mailetConfig);
Mail mail = mock(Mail.class);
- when(mail.getAttribute(MAIL_ATTRIBUTE)).thenReturn(ImmutableList.of());
+ when(mail.getAttribute(MAIL_ATTRIBUTE)).thenReturn(2);
expectedException.expect(MailetException.class);
@@ -207,7 +207,7 @@ public class AmqpForwardAttributeTest {
}
@Test
- public void serviceShouldPublishAttributeContentWhenAttributeInMail() throws Exception {
+ public void serviceShouldPublishAttributeContentWhenAttributeInMailAndIsAMap() throws Exception {
mailet.init(mailetConfig);
Channel channel = mock(Channel.class);
Connection connection = mock(Connection.class);
@@ -225,4 +225,24 @@ public class AmqpForwardAttributeTest {
verify(channel).basicPublish(eq(EXCHANGE_NAME), eq(ROUTING_KEY), basicPropertiesCaptor.capture(), eq(ATTACHMENT_CONTENT));
assertThat(basicPropertiesCaptor.getValue()).isEqualToComparingFieldByField(expectedProperties);
}
+
+ @Test
+ public void serviceShouldPublishAttributeContentWhenAttributeInMailAndIsAList() throws Exception {
+ mailet.init(mailetConfig);
+ Channel channel = mock(Channel.class);
+ Connection connection = mock(Connection.class);
+ when(connection.createChannel()).thenReturn(channel);
+ ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
+ when(connectionFactory.newConnection()).thenReturn(connection);
+ mailet.setConnectionFactory(connectionFactory);
+ Mail mail = mock(Mail.class);
+ when(mail.getAttribute(MAIL_ATTRIBUTE)).thenReturn(ImmutableList.of(ATTACHMENT_CONTENT));
+ BasicProperties expectedProperties = new AMQP.BasicProperties();
+
+ mailet.service(mail);
+
+ ArgumentCaptor<BasicProperties> basicPropertiesCaptor = ArgumentCaptor.forClass(BasicProperties.class);
+ verify(channel).basicPublish(eq(EXCHANGE_NAME), eq(ROUTING_KEY), basicPropertiesCaptor.capture(), eq(ATTACHMENT_CONTENT));
+ assertThat(basicPropertiesCaptor.getValue()).isEqualToComparingFieldByField(expectedProperties);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[6/9] james-project git commit: JAMES-2159 Use logback in mailet
integration tests
Posted by ma...@apache.org.
JAMES-2159 Use logback in mailet integration tests
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/605ab57f
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/605ab57f
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/605ab57f
Branch: refs/heads/master
Commit: 605ab57f57fe77c4edf5989ef8fe8935f582006d
Parents: 1fe32b9
Author: Antoine Duprat <ad...@linagora.com>
Authored: Mon Sep 25 11:44:45 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Sep 27 16:07:08 2017 +0200
----------------------------------------------------------------------
.../src/test/resources/logback-test.xml | 15 +++++++++++++++
1 file changed, 15 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/605ab57f/server/mailet/integration-testing/src/test/resources/logback-test.xml
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/resources/logback-test.xml b/server/mailet/integration-testing/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..665c8be
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/resources/logback-test.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %highlight([%-5level]) %logger{15} - %msg%n%rEx</pattern>
+ <immediateFlush>false</immediateFlush>
+ </encoder>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="CONSOLE" />
+ </root>
+
+</configuration>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[8/9] james-project git commit: JAMES-2159 Declare json-unit-fluent
dependency at top level
Posted by ma...@apache.org.
JAMES-2159 Declare json-unit-fluent dependency at top level
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c15f403a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c15f403a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c15f403a
Branch: refs/heads/master
Commit: c15f403a33bef01cac3b80b3b3db616b3005a90a
Parents: dfdb2d0
Author: Antoine Duprat <ad...@linagora.com>
Authored: Tue Sep 26 11:59:30 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Sep 27 16:09:13 2017 +0200
----------------------------------------------------------------------
mailbox/cassandra/pom.xml | 1 -
mailbox/elasticsearch/pom.xml | 1 -
mailbox/store/pom.xml | 1 -
mailet/icalendar/pom.xml | 1 -
pom.xml | 5 +++++
server/mailet/integration-testing/pom.xml | 1 -
server/protocols/jmap/pom.xml | 1 -
7 files changed, 5 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c15f403a/mailbox/cassandra/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/pom.xml b/mailbox/cassandra/pom.xml
index a36043b..dbec700 100644
--- a/mailbox/cassandra/pom.xml
+++ b/mailbox/cassandra/pom.xml
@@ -111,7 +111,6 @@
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-fluent</artifactId>
- <version>1.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/c15f403a/mailbox/elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/pom.xml b/mailbox/elasticsearch/pom.xml
index 75df1b9..5ac7989 100644
--- a/mailbox/elasticsearch/pom.xml
+++ b/mailbox/elasticsearch/pom.xml
@@ -131,7 +131,6 @@
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-fluent</artifactId>
- <version>1.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/c15f403a/mailbox/store/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/store/pom.xml b/mailbox/store/pom.xml
index 1a86149..9106f09 100644
--- a/mailbox/store/pom.xml
+++ b/mailbox/store/pom.xml
@@ -104,7 +104,6 @@
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-fluent</artifactId>
- <version>1.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/c15f403a/mailet/icalendar/pom.xml
----------------------------------------------------------------------
diff --git a/mailet/icalendar/pom.xml b/mailet/icalendar/pom.xml
index e28e341..7695135 100644
--- a/mailet/icalendar/pom.xml
+++ b/mailet/icalendar/pom.xml
@@ -84,7 +84,6 @@
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-fluent</artifactId>
- <version>1.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/c15f403a/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 08610af..11d1d90 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1724,6 +1724,11 @@
<version>${log4j.version}</version>
</dependency>
<dependency>
+ <groupId>net.javacrumbs.json-unit</groupId>
+ <artifactId>json-unit-fluent</artifactId>
+ <version>1.5.5</version>
+ </dependency>
+ <dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>1.7.6</version>
http://git-wip-us.apache.org/repos/asf/james-project/blob/c15f403a/server/mailet/integration-testing/pom.xml
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/pom.xml b/server/mailet/integration-testing/pom.xml
index c2359ee..336e5b6 100644
--- a/server/mailet/integration-testing/pom.xml
+++ b/server/mailet/integration-testing/pom.xml
@@ -132,7 +132,6 @@
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-fluent</artifactId>
- <version>1.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/c15f403a/server/protocols/jmap/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/pom.xml b/server/protocols/jmap/pom.xml
index 16292dc..52ea6f1 100644
--- a/server/protocols/jmap/pom.xml
+++ b/server/protocols/jmap/pom.xml
@@ -212,7 +212,6 @@
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-fluent</artifactId>
- <version>1.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[9/9] james-project git commit: Merge remote-tracking branch
'linagora/pr/986'
Posted by ma...@apache.org.
Merge remote-tracking branch 'linagora/pr/986'
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8c460636
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8c460636
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8c460636
Branch: refs/heads/master
Commit: 8c46063609ed9ea8e1a189d83342e7865c55a788
Parents: 4c3e040 c15f403
Author: Matthieu Baechler <ma...@apache.org>
Authored: Thu Sep 28 09:57:50 2017 +0200
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Thu Sep 28 09:57:50 2017 +0200
----------------------------------------------------------------------
mailbox/cassandra/pom.xml | 1 -
mailbox/elasticsearch/pom.xml | 1 -
mailbox/store/pom.xml | 1 -
mailet/icalendar/pom.xml | 1 -
mailet/standard/pom.xml | 13 ++
.../transport/mailets/AmqpForwardAttribute.java | 40 +++--
.../transport/mailets/ContactExtractor.java | 130 +++++++++++++++
.../mailets/AmqpForwardAttributeTest.java | 48 +++++-
.../transport/mailets/ContactExtractorTest.java | 142 ++++++++++++++++
pom.xml | 5 +
server/mailet/integration-testing/pom.xml | 5 +
.../mailets/configuration/CommonProcessors.java | 161 ++++++++++--------
.../configuration/MailetConfiguration.java | 66 +++++---
.../configuration/MailetConfigurationTest.java | 70 ++++++++
.../crypto/SMIMEDecryptIntegrationTest.java | 26 +--
.../crypto/SMIMESignIntegrationTest.java | 54 +++---
.../mailets/AmqpForwardAttachmentTest.java | 41 ++---
.../transport/mailets/ContactExtractorTest.java | 166 +++++++++++++++++++
.../transport/mailets/GroupMappingTest.java | 42 +++--
.../mailets/ICSAttachmentWorkflowTest.java | 50 +++---
.../transport/mailets/StripAttachmentTest.java | 33 ++--
.../src/test/resources/logback-test.xml | 15 ++
server/protocols/jmap/pom.xml | 1 -
.../apache/james/utils/SMTPMessageSender.java | 11 +-
24 files changed, 905 insertions(+), 218 deletions(-)
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[7/9] james-project git commit: JAMES-2159 Introduce ContactExtractor
mailet
Posted by ma...@apache.org.
JAMES-2159 Introduce ContactExtractor mailet
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/dfdb2d0a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/dfdb2d0a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/dfdb2d0a
Branch: refs/heads/master
Commit: dfdb2d0a9ab733e8956a48845f9a292ab17ab240
Parents: 4c5cc6a
Author: Matthieu Baechler <ma...@apache.org>
Authored: Fri Sep 22 09:48:40 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Sep 27 16:09:13 2017 +0200
----------------------------------------------------------------------
mailet/standard/pom.xml | 13 ++
.../transport/mailets/ContactExtractor.java | 130 +++++++++++++++
.../transport/mailets/ContactExtractorTest.java | 142 ++++++++++++++++
server/mailet/integration-testing/pom.xml | 6 +
.../transport/mailets/ContactExtractorTest.java | 166 +++++++++++++++++++
5 files changed, 457 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/dfdb2d0a/mailet/standard/pom.xml
----------------------------------------------------------------------
diff --git a/mailet/standard/pom.xml b/mailet/standard/pom.xml
index 9ebfd19..4c52812 100644
--- a/mailet/standard/pom.xml
+++ b/mailet/standard/pom.xml
@@ -57,6 +57,14 @@
<artifactId>james-server-util-java8</artifactId>
</dependency>
<dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.datatype</groupId>
+ <artifactId>jackson-datatype-jdk8</artifactId>
+ </dependency>
+ <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
@@ -78,6 +86,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>net.javacrumbs.json-unit</groupId>
+ <artifactId>json-unit-fluent</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/dfdb2d0a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ContactExtractor.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ContactExtractor.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ContactExtractor.java
new file mode 100644
index 0000000..468d355
--- /dev/null
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ContactExtractor.java
@@ -0,0 +1,130 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.transport.mailets;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+import javax.mail.Address;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.Mailet;
+import org.apache.mailet.MailetException;
+import org.apache.mailet.base.GenericMailet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.github.fge.lambdas.Throwing;
+import com.github.steveash.guavate.Guavate;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
+
+/**
+ * <p>Collects the sender and the recipients of a message and store them as JSON in a specified message attribute.</p>
+ * <p>Here is the JSON format:</p>
+ * <pre><code>
+ * {
+ * "userEmail" : "sender@james.org",
+ * "emails" : [ "to@james.org", "cc@james.org" ]
+ * }
+ * </code></pre>
+ *
+ * <p>Sample configuration:</p>
+ *
+ * <pre><code>
+ * <mailet match="All" class="ContactExtractor">
+ * <attribute>ExtractedContacts</attribute>
+ * </mailet>
+ * </code></pre>
+ */
+public class ContactExtractor extends GenericMailet implements Mailet {
+
+ public interface Configuration {
+ String ATTRIBUTE = "attribute";
+ }
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ContactExtractor.class);
+
+ @VisibleForTesting ObjectMapper objectMapper;
+ private String extractAttributeTo;
+
+ @Override
+ public void init() throws MessagingException {
+ extractAttributeTo = getInitParameterAsOptional(Configuration.ATTRIBUTE)
+ .orElseThrow(() -> new MailetException("No value for " + Configuration.ATTRIBUTE + " parameter was provided."));
+
+ objectMapper = new ObjectMapper().registerModule(new Jdk8Module());
+ }
+
+ @Override
+ public String getMailetInfo() {
+ return "ContactExtractor Mailet" ;
+ }
+
+ @Override
+ public void service(Mail mail) throws MessagingException {
+ try {
+ Optional<String> payload = extractContacts(mail.getMessage());
+ LOGGER.debug("payload : {}", payload);
+ payload.ifPresent(x -> mail.setAttribute(extractAttributeTo, x));
+ } catch (Exception e) {
+ LOGGER.error("Error while extracting contacts", e);
+ }
+ }
+
+ private Optional<String> extractContacts(MimeMessage mimeMessage) throws MessagingException {
+ return Optional.ofNullable(mimeMessage.getSender())
+ .map(Address::toString)
+ .filter(Throwing.predicate(sender -> hasRecipients(mimeMessage)))
+ .map(Throwing.function(sender -> new ExtractedContacts(sender, recipients(mimeMessage))))
+ .map(Throwing.function(message -> objectMapper.writeValueAsString(message)));
+ }
+
+ private boolean hasRecipients(MimeMessage mimeMessage) throws MessagingException {
+ return mimeMessage.getAllRecipients().length > 0;
+ }
+
+ private ImmutableList<String> recipients(MimeMessage mimeMessage) throws MessagingException {
+ return Arrays.stream(mimeMessage.getAllRecipients())
+ .map(Address::toString)
+ .collect(Guavate.toImmutableList());
+ }
+
+ public static class ExtractedContacts {
+ private final String userEmail;
+ private final ImmutableList<String> emails;
+
+ public ExtractedContacts(String userEmail, ImmutableList<String> emails) {
+ this.emails = emails;
+ this.userEmail = userEmail;
+ }
+
+ public ImmutableList<String> getEmails() {
+ return emails;
+ }
+
+ public String getUserEmail() {
+ return userEmail;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/dfdb2d0a/mailet/standard/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
new file mode 100644
index 0000000..9eda1f2
--- /dev/null
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
@@ -0,0 +1,142 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.transport.mailets;
+
+import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.core.MailAddress;
+import org.apache.mailet.MailetContext;
+import org.apache.mailet.MailetException;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMailContext;
+import org.apache.mailet.base.test.FakeMailetConfig;
+import org.apache.mailet.base.test.MimeMessageBuilder;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class ContactExtractorTest {
+
+ private static final String ATTRIBUTE = "ExtractedContacts";
+ private static final String SENDER = "sender@james.org";
+ private static final String TO = "to@james.org";
+
+ private ContactExtractor mailet;
+ private MailetContext mailetContext;
+ private FakeMailetConfig mailetConfig;
+
+ @Before
+ public void setUp() throws Exception {
+ mailet = new ContactExtractor();
+ mailetContext = FakeMailContext.builder()
+ .build();
+ mailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .mailetContext(mailetContext)
+ .setProperty(ContactExtractor.Configuration.ATTRIBUTE, ATTRIBUTE)
+ .build();
+ }
+
+ @Test
+ public void initShouldThrowWhenNoAttributeParameter() throws MessagingException {
+ FakeMailetConfig customMailetConfig = FakeMailetConfig.builder()
+ .mailetName("Test")
+ .mailetContext(mailetContext)
+ .build();
+
+ assertThatThrownBy(() -> mailet.init(customMailetConfig))
+ .isInstanceOf(MailetException.class);
+ }
+
+ @Test
+ public void initShouldNotThrowWithAllParameters() throws MessagingException {
+ mailet.init(mailetConfig);
+ }
+
+ @Test
+ public void getMailetInfoShouldReturnInfo() {
+ assertThat(mailet.getMailetInfo()).isEqualTo("ContactExtractor Mailet");
+ }
+
+ @Test
+ public void serviceShouldNotThrowWhenJsonProcessingFails() throws Exception {
+ FakeMail mail = FakeMail.builder().mimeMessage(MimeMessageBuilder.defaultMimeMessage())
+ .sender(new MailAddress(SENDER))
+ .recipient(new MailAddress(TO))
+ .build();
+
+ ObjectMapper objectMapper = mock(ObjectMapper.class);
+ when(objectMapper.writeValueAsString(any(ContactExtractor.ExtractedContacts.class)))
+ .thenThrow(new JsonGenerationException(""));
+
+ mailet.init(mailetConfig);
+ mailet.objectMapper = objectMapper;
+
+ mailet.service(mail);
+ }
+
+ @Test
+ public void serviceShouldAddTheAttribute() throws Exception {
+ MimeMessage message = MimeMessageBuilder.mimeMessageBuilder()
+ .setSender(SENDER)
+ .addToRecipient(TO)
+ .setSubject("Contact collection Rocks")
+ .setText("This is my email")
+ .build();
+ FakeMail mail = FakeMail.builder().mimeMessage(message)
+ .sender(new MailAddress(SENDER))
+ .recipient(new MailAddress(TO))
+ .build();
+ mailet.init(mailetConfig);
+
+ String expectedMessage = "{\"userEmail\" : \"" + SENDER + "\", \"emails\" : [ \"" + TO + "\" ]}";
+ mailet.service(mail);
+
+ assertThatJson(mail.getAttribute(ATTRIBUTE).toString()).isEqualTo(expectedMessage);
+
+ }
+
+ @Test
+ public void serviceShouldNotAddTheAttributeWhenNoRecipient() throws Exception {
+ MimeMessage message = MimeMessageBuilder.mimeMessageBuilder()
+ .setSender(SENDER)
+ .setSubject("Contact collection Rocks")
+ .setText("This is my email")
+ .build();
+ FakeMail mail = FakeMail.builder().mimeMessage(message)
+ .sender(new MailAddress(SENDER))
+ .build();
+ mailet.init(mailetConfig);
+
+ mailet.service(mail);
+
+ assertThat(mail.getAttribute(ATTRIBUTE)).isNull();
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/dfdb2d0a/server/mailet/integration-testing/pom.xml
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/pom.xml b/server/mailet/integration-testing/pom.xml
index 02858f8..c2359ee 100644
--- a/server/mailet/integration-testing/pom.xml
+++ b/server/mailet/integration-testing/pom.xml
@@ -130,6 +130,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>net.javacrumbs.json-unit</groupId>
+ <artifactId>json-unit-fluent</artifactId>
+ <version>1.5.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/james-project/blob/dfdb2d0a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
new file mode 100644
index 0000000..16eeb89
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
@@ -0,0 +1,166 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.transport.mailets;
+
+import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.core.MailAddress;
+import org.apache.james.jmap.mailet.VacationMailet;
+import org.apache.james.mailets.TemporaryJamesServer;
+import org.apache.james.mailets.configuration.CommonProcessors;
+import org.apache.james.mailets.configuration.MailetConfiguration;
+import org.apache.james.mailets.configuration.MailetContainer;
+import org.apache.james.mailets.configuration.ProcessorConfiguration;
+import org.apache.james.transport.mailets.amqp.AmqpRule;
+import org.apache.james.transport.matchers.All;
+import org.apache.james.transport.matchers.RecipientIsLocal;
+import org.apache.james.transport.matchers.SMTPAuthSuccessful;
+import org.apache.james.util.streams.SwarmGenericContainer;
+import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.utils.SMTPMessageSender;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.MimeMessageBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TemporaryFolder;
+
+import com.jayway.awaitility.Awaitility;
+import com.jayway.awaitility.Duration;
+
+public class ContactExtractorTest {
+
+ public static final String JAMES_ORG = "james.org";
+ public static final String SENDER = "sender@" + JAMES_ORG;
+ public static final String TO = "to@" + JAMES_ORG;
+ public static final String TO2 = "to2@" + JAMES_ORG;
+ public static final String CC = "cc@" + JAMES_ORG;
+ public static final String CC2 = "cc2@" + JAMES_ORG;
+ public static final String BCC = "bcc@" + JAMES_ORG;
+ public static final String BCC2 = "bcc2@" + JAMES_ORG;
+ public static final String PASSWORD = "secret";
+ public static final String EXCHANGE = "collector:email";
+ public static final String ROUTING_KEY = "";
+
+ public SwarmGenericContainer rabbit = new SwarmGenericContainer("rabbitmq:3");
+ public AmqpRule amqpRule = new AmqpRule(rabbit, EXCHANGE, ROUTING_KEY);
+ public TemporaryFolder folder = new TemporaryFolder();
+
+ @Rule
+ public RuleChain chain = RuleChain.outerRule(rabbit).around(amqpRule).around(folder);
+
+ private TemporaryJamesServer jamesServer;
+
+ @Before
+ public void setup() throws Exception {
+ String attribute = "ExtractedContacts";
+ MailetContainer mailets = MailetContainer
+ .builder()
+ .threads(5)
+ .postmaster(SENDER)
+ .addProcessor(CommonProcessors.root())
+ .addProcessor(CommonProcessors.error())
+ .addProcessor(
+ ProcessorConfiguration.builder()
+ .state("transport")
+ .addMailet(MailetConfiguration.builder()
+ .matcher(SMTPAuthSuccessful.class)
+ .mailet(ContactExtractor.class)
+ .addProperty(ContactExtractor.Configuration.ATTRIBUTE, attribute)
+ .build())
+ .addMailet(MailetConfiguration.builder()
+ .matcher(All.class)
+ .mailet(AmqpForwardAttribute.class)
+ .addProperty(AmqpForwardAttribute.URI_PARAMETER_NAME, amqpRule.getAmqpUri())
+ .addProperty(AmqpForwardAttribute.EXCHANGE_PARAMETER_NAME, EXCHANGE)
+ .addProperty(AmqpForwardAttribute.ATTRIBUTE_PARAMETER_NAME, attribute)
+ .build())
+ .addMailet(MailetConfiguration.builder()
+ .matcher(All.class)
+ .mailet(RemoveMimeHeader.class)
+ .addProperty("name", "bcc")
+ .build())
+ .addMailet(MailetConfiguration.builder()
+ .matcher(RecipientIsLocal.class)
+ .mailet(VacationMailet.class)
+ .build())
+ .addMailet(MailetConfiguration.builder()
+ .matcher(RecipientIsLocal.class)
+ .mailet(LocalDelivery.class)
+ .build())
+ .build())
+ .build();
+ jamesServer = new TemporaryJamesServer(folder, mailets);
+ DataProbeImpl probe = jamesServer.getProbe(DataProbeImpl.class);
+ probe.addDomain(JAMES_ORG);
+ probe.addUser(SENDER, PASSWORD);
+ probe.addUser(TO, PASSWORD);
+ probe.addUser(TO2, PASSWORD);
+ probe.addUser(CC, PASSWORD);
+ probe.addUser(CC2, PASSWORD);
+ probe.addUser(BCC, PASSWORD);
+ probe.addUser(BCC2, PASSWORD);
+ }
+
+ @After
+ public void tearDown() {
+ jamesServer.shutdown();
+ }
+
+ @Test
+ public void recipientsShouldBePublishedToAmqpWhenSendingEmail() throws Exception {
+ MimeMessage message = MimeMessageBuilder.mimeMessageBuilder()
+ .setSender(SENDER)
+ .addToRecipient(TO, "John To2 <" + TO2 + ">")
+ .addCcRecipient(CC, "John Cc2 <" + CC2 + ">")
+ .addBccRecipient(BCC, "John Bcc2 <" + BCC2 + ">")
+ .setSubject("Contact collection Rocks")
+ .setText("This is my email")
+ .build();
+ FakeMail mail = FakeMail.builder()
+ .mimeMessage(message)
+ .sender(new MailAddress(SENDER))
+ .recipients(new MailAddress(TO), new MailAddress(TO2), new MailAddress(CC), new MailAddress(CC2), new MailAddress(BCC), new MailAddress(BCC2))
+ .build();
+ try (SMTPMessageSender messageSender = SMTPMessageSender.authentication("localhost", 1025, JAMES_ORG, SENDER, PASSWORD);
+ IMAPMessageReader imap = new IMAPMessageReader("localhost", 1143)) {
+
+ messageSender.sendMessage(mail);
+ Awaitility.await().pollDelay(Duration.FIVE_HUNDRED_MILLISECONDS)
+ .atMost(Duration.ONE_MINUTE)
+ .until(() -> imap.userReceivedMessage(TO, PASSWORD));
+
+ Optional<String> actual = amqpRule.readContent();
+ assertThat(actual).isNotEmpty();
+ assertThatJson(actual.get()).isEqualTo("{"
+ + "\"userEmail\" : \"sender@james.org\", "
+ + "\"emails\" : [ \"to@james.org\", \"John To2 <to...@james.org>\", \"cc@james.org\", \"John Cc2 <cc...@james.org>\", \"bcc@james.org\", \"John Bcc2 <bc...@james.org>\" ]"
+ + "}");
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[4/9] james-project git commit: JAMES-2159 Use strong objects in
MailetConfiguration
Posted by ma...@apache.org.
JAMES-2159 Use strong objects in MailetConfiguration
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1fe32b91
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1fe32b91
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1fe32b91
Branch: refs/heads/master
Commit: 1fe32b9170f1f11e433f0a1f915f216b6c71302e
Parents: 4c3e040
Author: Matthieu Baechler <ma...@apache.org>
Authored: Mon Sep 11 15:22:18 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Sep 27 16:07:08 2017 +0200
----------------------------------------------------------------------
.../mailets/configuration/CommonProcessors.java | 161 +++++++++++--------
.../configuration/MailetConfiguration.java | 66 +++++---
.../configuration/MailetConfigurationTest.java | 70 ++++++++
.../crypto/SMIMEDecryptIntegrationTest.java | 26 +--
.../crypto/SMIMESignIntegrationTest.java | 54 ++++---
.../mailets/AmqpForwardAttachmentTest.java | 41 ++---
.../transport/mailets/GroupMappingTest.java | 42 ++---
.../mailets/ICSAttachmentWorkflowTest.java | 50 +++---
.../transport/mailets/StripAttachmentTest.java | 33 ++--
9 files changed, 352 insertions(+), 191 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/1fe32b91/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
index 3af7fd0..130dae7 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
@@ -20,6 +20,29 @@
package org.apache.james.mailets.configuration;
+import org.apache.james.jmap.mailet.VacationMailet;
+import org.apache.james.transport.mailets.AddDeliveredToHeader;
+import org.apache.james.transport.mailets.Bounce;
+import org.apache.james.transport.mailets.DSNBounce;
+import org.apache.james.transport.mailets.LocalDelivery;
+import org.apache.james.transport.mailets.Null;
+import org.apache.james.transport.mailets.PostmasterAlias;
+import org.apache.james.transport.mailets.RecipientRewriteTable;
+import org.apache.james.transport.mailets.RemoteDelivery;
+import org.apache.james.transport.mailets.RemoveMimeHeader;
+import org.apache.james.transport.mailets.SetMailAttribute;
+import org.apache.james.transport.mailets.SetMimeHeader;
+import org.apache.james.transport.mailets.Sieve;
+import org.apache.james.transport.mailets.ToProcessor;
+import org.apache.james.transport.mailets.ToRepository;
+import org.apache.james.transport.mailets.managesieve.ManageSieveMailet;
+import org.apache.james.transport.matchers.All;
+import org.apache.james.transport.matchers.HasMailAttribute;
+import org.apache.james.transport.matchers.InSpammerBlacklist;
+import org.apache.james.transport.matchers.RecipientIs;
+import org.apache.james.transport.matchers.RecipientIsLocal;
+import org.apache.james.transport.matchers.RelayLimit;
+import org.apache.james.transport.matchers.SMTPAuthSuccessful;
import org.apache.mailet.Mail;
public class CommonProcessors {
@@ -29,47 +52,52 @@ public class CommonProcessors {
.state("root")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("PostmasterAlias")
+ .matcher(All.class)
+ .mailet(PostmasterAlias.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RelayLimit=30")
- .clazz("Null")
+ .matcher(RelayLimit.class)
+ .matcherCondition("30")
+ .mailet(Null.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIs=sievemanager@james.linagora.com")
- .clazz("ToProcessor")
+ .matcher(RecipientIs.class)
+ .matcherCondition("sievemanager@james.linagora.com")
+ .mailet(ToProcessor.class)
.addProperty("processor", "sieve-manager-check")
.build())
.addMailet(MailetConfiguration.builder()
- .match("HasMailAttribute=spamChecked")
- .clazz("ToProcessor")
+ .matcher(HasMailAttribute.class)
+ .matcherCondition("spamChecked")
+ .mailet(ToProcessor.class)
.addProperty("processor", "transport")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("SetMailAttribute")
+ .matcher(All.class)
+ .mailet(SetMailAttribute.class)
.addProperty("spamChecked", "true")
.build())
.addMailet(MailetConfiguration.builder()
- .match("SMTPAuthSuccessful")
- .clazz("ToProcessor")
+ .matcher(SMTPAuthSuccessful.class)
+ .mailet(ToProcessor.class)
.addProperty("processor", "transport")
.build())
.addMailet(MailetConfiguration.builder()
- .match("InSpammerBlacklist=query.bondedsender.org.")
- .clazz("ToProcessor")
+ .matcher(InSpammerBlacklist.class)
+ .matcherCondition("query.bondedsender.org.")
+ .mailet(ToProcessor.class)
.addProperty("processor", "transport")
.build())
.addMailet(MailetConfiguration.builder()
- .match("InSpammerBlacklist=dnsbl.njabl.org.")
- .clazz("ToProcessor")
+ .matcher(InSpammerBlacklist.class)
+ .matcherCondition("dnsbl.njabl.org.")
+ .mailet(ToProcessor.class)
.addProperty("processor", "spam")
.addProperty("notice", "550 Requested action not taken: rejected - see http://njabl.org/")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ToProcessor")
+ .matcher(All.class)
+ .mailet(ToProcessor.class)
.addProperty("processor", "transport")
.build())
.build();
@@ -80,12 +108,12 @@ public class CommonProcessors {
.state("error")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("Bounce")
+ .matcher(All.class)
+ .mailet(Bounce.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ToRepository")
+ .matcher(All.class)
+ .mailet(ToRepository.class)
.addProperty("repositoryPath", "file://var/mail/error/")
.build())
.build();
@@ -96,45 +124,46 @@ public class CommonProcessors {
.state("transport")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("SMTPAuthSuccessful")
- .clazz("SetMimeHeader")
+ .matcher(SMTPAuthSuccessful.class)
+ .mailet(SetMimeHeader.class)
.addProperty("name", "X-UserIsAuth")
.addProperty("value", "true")
.build())
.addMailet(MailetConfiguration.builder()
- .match("HasMailAttribute=org.apache.james.SMIMECheckSignature")
- .clazz("SetMimeHeader")
+ .matcher(HasMailAttribute.class)
+ .matcherCondition("org.apache.james.SMIMECheckSignature")
+ .mailet(SetMimeHeader.class)
.addProperty("name", "X-WasSigned")
.addProperty("value", "true")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RemoveMimeHeader")
+ .matcher(All.class)
+ .mailet(RemoveMimeHeader.class)
.addProperty("name", "bcc")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RecipientRewriteTable")
+ .matcher(All.class)
+ .mailet(RecipientRewriteTable.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("org.apache.james.jmap.mailet.VacationMailet")
+ .matcher(RecipientIsLocal.class)
+ .mailet(VacationMailet.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("Sieve")
+ .matcher(RecipientIsLocal.class)
+ .mailet(Sieve.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("AddDeliveredToHeader")
+ .matcher(RecipientIsLocal.class)
+ .mailet(AddDeliveredToHeader.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("LocalDelivery")
+ .matcher(RecipientIsLocal.class)
+ .mailet(LocalDelivery.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("SMTPAuthSuccessful")
- .clazz("RemoteDelivery")
+ .matcher(SMTPAuthSuccessful.class)
+ .mailet(RemoteDelivery.class)
.addProperty("outgoingQueue", "outgoing")
.addProperty("delayTime", "5000, 100000, 500000")
.addProperty("maxRetries", "25")
@@ -144,8 +173,8 @@ public class CommonProcessors {
.addProperty("bounceProcessor", "bounces")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ToProcessor")
+ .matcher(All.class)
+ .mailet(ToProcessor.class)
.addProperty("processor", "relay-denied")
.build())
.build();
@@ -156,8 +185,8 @@ public class CommonProcessors {
.state("spam")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ToRepository")
+ .matcher(All.class)
+ .mailet(ToRepository.class)
.addProperty("repositoryPath", "file://var/mail/spam/")
.build())
.build();
@@ -168,13 +197,13 @@ public class CommonProcessors {
.state("local-address-error")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("Bounce")
+ .matcher(All.class)
+ .mailet(Bounce.class)
.addProperty("attachment", "none")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ToRepository")
+ .matcher(All.class)
+ .mailet(ToRepository.class)
.addProperty("repositoryPath", "file://var/mail/address-error/")
.build())
.build();
@@ -185,13 +214,13 @@ public class CommonProcessors {
.state("replay-denied")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("Bounce")
+ .matcher(All.class)
+ .mailet(Bounce.class)
.addProperty("attachment", "none")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ToRepository")
+ .matcher(All.class)
+ .mailet(ToRepository.class)
.addProperty("repositoryPath", "file://var/mail/relay-denied/")
.addProperty("notice", "Warning: You are sending an e-mail to a remote server. You must be authentified to perform such an operation")
.build())
@@ -203,8 +232,8 @@ public class CommonProcessors {
.state("bounces")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("DSNBounce")
+ .matcher(All.class)
+ .mailet(DSNBounce.class)
.addProperty("passThrough", "false")
.build())
.build();
@@ -215,13 +244,13 @@ public class CommonProcessors {
.state("sieve-manager-check")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("ToProcessor")
+ .matcher(RecipientIsLocal.class)
+ .mailet(ToProcessor.class)
.addProperty("processor", "sieve-manager")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("Bounce")
+ .matcher(All.class)
+ .mailet(Bounce.class)
.addProperty("inline", "heads")
.addProperty("attachment", "none")
.addProperty("passThrough", "false")
@@ -229,8 +258,8 @@ public class CommonProcessors {
.addProperty("notice", "You can't send messages to configure SIEVE on this serveur unless you are the official SIEVE manager.")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("Null")
+ .matcher(All.class)
+ .mailet(Null.class)
.build())
.build();
}
@@ -240,18 +269,18 @@ public class CommonProcessors {
.state("sieve-manager")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("SetMailAttribute")
+ .matcher(All.class)
+ .mailet(SetMailAttribute.class)
.addProperty(Mail.SMTP_AUTH_USER_ATTRIBUTE_NAME, "true")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("org.apache.james.transport.mailets.managesieve.ManageSieveMailet")
+ .matcher(All.class)
+ .mailet(ManageSieveMailet.class)
.addProperty("helpURL", "file:/root/james-server-app-3.0.0-beta5-SNAPSHOT/conf/managesieve.help.txt")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("Null")
+ .matcher(All.class)
+ .mailet(Null.class)
.build())
.build();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1fe32b91/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/MailetConfiguration.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/MailetConfiguration.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/MailetConfiguration.java
index f841bfb..ae91bc4 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/MailetConfiguration.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/MailetConfiguration.java
@@ -21,9 +21,13 @@
package org.apache.james.mailets.configuration;
import java.util.Map;
+import java.util.Optional;
+import org.apache.mailet.Mailet;
+import org.apache.mailet.Matcher;
+
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
public class MailetConfiguration implements SerializableAsXml {
@@ -34,21 +38,28 @@ public class MailetConfiguration implements SerializableAsXml {
public static class Builder {
- private String match;
- private String clazz;
+ private Class<? extends Matcher> matcher;
+ private Optional<String> matcherCondition;
+ private Class<? extends Mailet> mailet;
private ImmutableMap.Builder<String, String> properties;
private Builder() {
properties = ImmutableMap.builder();
+ matcherCondition = Optional.empty();
+ }
+
+ public Builder matcher(Class<? extends Matcher> matcher) {
+ this.matcher = matcher;
+ return this;
}
- public Builder match(String match) {
- this.match = match;
+ public Builder matcherCondition(String condition) {
+ this.matcherCondition = Optional.ofNullable(condition);
return this;
}
- public Builder clazz(String clazz) {
- this.clazz = clazz;
+ public Builder mailet(Class<? extends Mailet> mailet) {
+ this.mailet = mailet;
return this;
}
@@ -58,28 +69,34 @@ public class MailetConfiguration implements SerializableAsXml {
}
public MailetConfiguration build() {
- Preconditions.checkState(!Strings.isNullOrEmpty(match), "'match' is mandatory");
- Preconditions.checkState(!Strings.isNullOrEmpty(clazz), "'class' is mandatory");
- return new MailetConfiguration(match, clazz, properties.build());
+ Preconditions.checkState(matcher != null, "'matcher' is mandatory");
+ Preconditions.checkState(mailet != null, "'mailet' is mandatory");
+ return new MailetConfiguration(matcher, matcherCondition, mailet, properties.build());
}
}
- private final String match;
- private final String clazz;
+ private final Class<? extends Matcher> matcher;
+ private final Optional<String> matcherCondition;
+ private final Class<? extends Mailet> mailet;
private final Map<String, String> properties;
- private MailetConfiguration(String match, String clazz, ImmutableMap<String, String> properties) {
- this.match = match;
- this.clazz = clazz;
+ private MailetConfiguration(Class<? extends Matcher> matcher, Optional<String> matcherCondition, Class<? extends Mailet> mailet, ImmutableMap<String, String> properties) {
+ this.matcher = matcher;
+ this.matcherCondition = matcherCondition;
+ this.mailet = mailet;
this.properties = properties;
}
- public String getMatch() {
- return match;
+ public Class<? extends Matcher> getMatcher() {
+ return matcher;
}
- public String getClazz() {
- return clazz;
+ public Optional<String> getMatcherCondition() {
+ return matcherCondition;
+ }
+
+ public Class<? extends Mailet> getMailet() {
+ return mailet;
}
public Map<String, String> getProperties() {
@@ -89,11 +106,20 @@ public class MailetConfiguration implements SerializableAsXml {
@Override
public String serializeAsXml() {
StringBuilder builder = new StringBuilder();
- builder.append("<mailet match=\"").append(getMatch()).append("\" class=\"").append(getClazz()).append("\">\n");
+ builder
+ .append("<mailet match=\"").append(matcherWithCondition())
+ .append("\" class=\"").append(getMailet().getCanonicalName())
+ .append("\">\n");
for (Map.Entry<String, String> entry : getProperties().entrySet()) {
builder.append("<").append(entry.getKey()).append(">").append(entry.getValue()).append("</").append(entry.getKey()).append(">\n");
}
builder.append("</mailet>\n");
return builder.toString();
}
+
+ @VisibleForTesting String matcherWithCondition() {
+ StringBuilder match = new StringBuilder().append(matcher.getCanonicalName());
+ matcherCondition.ifPresent(condition -> match.append("=").append(condition));
+ return match.toString();
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1fe32b91/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/MailetConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/MailetConfigurationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/MailetConfigurationTest.java
new file mode 100644
index 0000000..3144adf
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/MailetConfigurationTest.java
@@ -0,0 +1,70 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.mailets.configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.transport.mailets.ToProcessor;
+import org.apache.james.transport.matchers.All;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class MailetConfigurationTest {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void builderShouldThrowWhenMatcherIsNull() {
+ expectedException.expect(IllegalStateException.class);
+ MailetConfiguration.builder()
+ .mailet(ToProcessor.class)
+ .build();
+ }
+
+ @Test
+ public void builderShouldThrowWhenMailetIsNull() {
+ expectedException.expect(IllegalStateException.class);
+ MailetConfiguration.builder()
+ .matcher(All.class)
+ .build();
+ }
+
+ @Test
+ public void matcherWithConditionShouldReturnMatcherWhenNoCondition() {
+ MailetConfiguration mailetConfiguration = MailetConfiguration.builder()
+ .matcher(All.class)
+ .mailet(ToProcessor.class)
+ .build();
+
+ assertThat(mailetConfiguration.matcherWithCondition()).isEqualTo("org.apache.james.transport.matchers.All");
+ }
+
+ @Test
+ public void matcherWithConditionShouldReturnMatcherWithConditionWhenSomeCondition() {
+ MailetConfiguration mailetConfiguration = MailetConfiguration.builder()
+ .matcher(All.class)
+ .matcherCondition("condition")
+ .mailet(ToProcessor.class)
+ .build();
+
+ assertThat(mailetConfiguration.matcherWithCondition()).isEqualTo("org.apache.james.transport.matchers.All=condition");
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1fe32b91/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java
index 7055506..3d09a73 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMEDecryptIntegrationTest.java
@@ -25,17 +25,23 @@ import java.nio.charset.StandardCharsets;
import java.time.ZonedDateTime;
import org.apache.commons.io.IOUtils;
+import org.apache.james.jmap.mailet.VacationMailet;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailets.TemporaryJamesServer;
import org.apache.james.mailets.configuration.CommonProcessors;
import org.apache.james.mailets.configuration.MailetConfiguration;
import org.apache.james.mailets.configuration.MailetContainer;
import org.apache.james.mailets.configuration.ProcessorConfiguration;
-import org.apache.james.utils.SMTPMessageSender;
import org.apache.james.modules.MailboxProbeImpl;
+import org.apache.james.transport.mailets.LocalDelivery;
+import org.apache.james.transport.mailets.RemoveMimeHeader;
+import org.apache.james.transport.mailets.SMIMEDecrypt;
+import org.apache.james.transport.matchers.All;
+import org.apache.james.transport.matchers.RecipientIsLocal;
import org.apache.james.util.date.ZonedDateTimeProvider;
-import org.apache.james.utils.IMAPMessageReader;
import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.utils.SMTPMessageSender;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -75,25 +81,25 @@ public class SMIMEDecryptIntegrationTest {
.state("transport")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RemoveMimeHeader")
+ .matcher(All.class)
+ .mailet(RemoveMimeHeader.class)
.addProperty("name", "bcc")
.build())
.addMailet(MailetConfiguration.builder()
- .clazz("SMIMEDecrypt")
- .match("All")
+ .mailet(SMIMEDecrypt.class)
+ .matcher(All.class)
.addProperty("keyStoreFileName", temporaryFolder.getRoot().getAbsoluteFile().getAbsolutePath() + "/conf/smime.p12")
.addProperty("keyStorePassword", "secret")
.addProperty("keyStoreType", "PKCS12")
.addProperty("debug", "true")
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("org.apache.james.jmap.mailet.VacationMailet")
+ .matcher(RecipientIsLocal.class)
+ .mailet(VacationMailet.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("LocalDelivery")
+ .matcher(RecipientIsLocal.class)
+ .mailet(LocalDelivery.class)
.build())
.build())
.build();
http://git-wip-us.apache.org/repos/asf/james-project/blob/1fe32b91/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java
index d84a28d..bee6474 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/crypto/SMIMESignIntegrationTest.java
@@ -23,18 +23,31 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.time.ZonedDateTime;
+import org.apache.james.jmap.mailet.VacationMailet;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailets.TemporaryJamesServer;
import org.apache.james.mailets.configuration.CommonProcessors;
import org.apache.james.mailets.configuration.MailetConfiguration;
import org.apache.james.mailets.configuration.MailetContainer;
import org.apache.james.mailets.configuration.ProcessorConfiguration;
-import org.apache.james.utils.SMTPMessageSender;
import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.probe.DataProbe;
+import org.apache.james.transport.mailets.LocalDelivery;
+import org.apache.james.transport.mailets.RecipientRewriteTable;
+import org.apache.james.transport.mailets.RemoteDelivery;
+import org.apache.james.transport.mailets.RemoveMimeHeader;
+import org.apache.james.transport.mailets.SMIMESign;
+import org.apache.james.transport.mailets.SetMimeHeader;
+import org.apache.james.transport.mailets.ToProcessor;
+import org.apache.james.transport.matchers.All;
+import org.apache.james.transport.matchers.HasMailAttribute;
+import org.apache.james.transport.matchers.RecipientIsLocal;
+import org.apache.james.transport.matchers.SMTPAuthSuccessful;
+import org.apache.james.transport.matchers.SenderIsLocal;
import org.apache.james.util.date.ZonedDateTimeProvider;
-import org.apache.james.utils.IMAPMessageReader;
import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.utils.SMTPMessageSender;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -74,45 +87,46 @@ public class SMIMESignIntegrationTest {
.state("transport")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("SMTPAuthSuccessful")
- .clazz("SetMimeHeader")
+ .matcher(SMTPAuthSuccessful.class)
+ .mailet(SetMimeHeader.class)
.addProperty("name", "X-UserIsAuth")
.addProperty("value", "true")
.build())
.addMailet(MailetConfiguration.builder()
- .match("HasMailAttribute=org.apache.james.SMIMECheckSignature")
- .clazz("SetMimeHeader")
+ .matcher(HasMailAttribute.class)
+ .matcherCondition("org.apache.james.SMIMECheckSignature")
+ .mailet(SetMimeHeader.class)
.addProperty("name", "X-WasSigned")
.addProperty("value", "true")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RemoveMimeHeader")
+ .matcher(All.class)
+ .mailet(RemoveMimeHeader.class)
.addProperty("name", "bcc")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RecipientRewriteTable")
+ .matcher(All.class)
+ .mailet(RecipientRewriteTable.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("org.apache.james.jmap.mailet.VacationMailet")
+ .matcher(RecipientIsLocal.class)
+ .mailet(VacationMailet.class)
.build())
.addMailet(MailetConfiguration.builder()
- .clazz("SMIMESign")
- .match("SenderIsLocal")
+ .mailet(SMIMESign.class)
+ .matcher(SenderIsLocal.class)
.addProperty("keyStoreFileName", temporaryFolder.getRoot().getAbsoluteFile().getAbsolutePath() + "/conf/smime.p12")
.addProperty("keyStorePassword", "secret")
.addProperty("keyStoreType", "PKCS12")
.addProperty("debug", "true")
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("LocalDelivery")
+ .matcher(RecipientIsLocal.class)
+ .mailet(LocalDelivery.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("SMTPAuthSuccessful")
- .clazz("RemoteDelivery")
+ .matcher(SMTPAuthSuccessful.class)
+ .mailet(RemoteDelivery.class)
.addProperty("outgoingQueue", "outgoing")
.addProperty("delayTime", "5000, 100000, 500000")
.addProperty("maxRetries", "25")
@@ -122,8 +136,8 @@ public class SMIMESignIntegrationTest {
.addProperty("bounceProcessor", "bounces")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ToProcessor")
+ .matcher(All.class)
+ .mailet(ToProcessor.class)
.addProperty("processor", "relay-denied")
.build())
.build())
http://git-wip-us.apache.org/repos/asf/james-project/blob/1fe32b91/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java
index db43632..fd13da2 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AmqpForwardAttachmentTest.java
@@ -23,12 +23,15 @@ import static org.assertj.core.api.Assertions.assertThat;
import javax.mail.internet.MimeMessage;
+import org.apache.james.jmap.mailet.VacationMailet;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailets.TemporaryJamesServer;
import org.apache.james.mailets.configuration.CommonProcessors;
import org.apache.james.mailets.configuration.MailetConfiguration;
import org.apache.james.mailets.configuration.MailetContainer;
import org.apache.james.mailets.configuration.ProcessorConfiguration;
+import org.apache.james.transport.matchers.All;
+import org.apache.james.transport.matchers.RecipientIsLocal;
import org.apache.james.utils.SMTPMessageSender;
import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.probe.DataProbe;
@@ -93,36 +96,36 @@ public class AmqpForwardAttachmentTest {
.state("transport")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RemoveMimeHeader")
+ .matcher(All.class)
+ .mailet(RemoveMimeHeader.class)
.addProperty("name", "bcc")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("StripAttachment")
- .addProperty("attribute", MAIL_ATTRIBUTE)
- .addProperty("pattern", ".*\\.txt")
+ .matcher(All.class)
+ .mailet(StripAttachment.class)
+ .addProperty(StripAttachment.ATTRIBUTE_PARAMETER_NAME, MAIL_ATTRIBUTE)
+ .addProperty(StripAttachment.PATTERN_PARAMETER_NAME, ".*\\.txt")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("MimeDecodingMailet")
- .addProperty("attribute", MAIL_ATTRIBUTE)
+ .matcher(All.class)
+ .mailet(MimeDecodingMailet.class)
+ .addProperty(MimeDecodingMailet.ATTRIBUTE_PARAMETER_NAME, MAIL_ATTRIBUTE)
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("AmqpForwardAttribute")
- .addProperty("uri", amqpRule.getAmqpUri())
- .addProperty("exchange", EXCHANGE_NAME)
- .addProperty("attribute", MAIL_ATTRIBUTE)
- .addProperty("routing_key", ROUTING_KEY)
+ .matcher(All.class)
+ .mailet(AmqpForwardAttribute.class)
+ .addProperty(AmqpForwardAttribute.URI_PARAMETER_NAME, amqpRule.getAmqpUri())
+ .addProperty(AmqpForwardAttribute.EXCHANGE_PARAMETER_NAME, EXCHANGE_NAME)
+ .addProperty(AmqpForwardAttribute.ATTRIBUTE_PARAMETER_NAME, MAIL_ATTRIBUTE)
+ .addProperty(AmqpForwardAttribute.ROUTING_KEY_PARAMETER_NAME, ROUTING_KEY)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("org.apache.james.jmap.mailet.VacationMailet")
+ .matcher(RecipientIsLocal.class)
+ .mailet(VacationMailet.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("LocalDelivery")
+ .matcher(RecipientIsLocal.class)
+ .mailet(LocalDelivery.class)
.build())
.build())
.build();
http://git-wip-us.apache.org/repos/asf/james-project/blob/1fe32b91/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
index cd2e86d..8e773ae 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java
@@ -31,6 +31,7 @@ import javax.mail.internet.MimeMessage;
import org.apache.james.core.MailAddress;
import org.apache.james.dnsservice.api.DNSService;
import org.apache.james.dnsservice.api.InMemoryDNSService;
+import org.apache.james.jmap.mailet.VacationMailet;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailets.TemporaryJamesServer;
import org.apache.james.mailets.configuration.CommonProcessors;
@@ -39,6 +40,10 @@ import org.apache.james.mailets.configuration.MailetContainer;
import org.apache.james.mailets.configuration.ProcessorConfiguration;
import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.probe.DataProbe;
+import org.apache.james.transport.matchers.All;
+import org.apache.james.transport.matchers.RecipientIsLocal;
+import org.apache.james.transport.matchers.RelayLimit;
+import org.apache.james.transport.matchers.SMTPAuthSuccessful;
import org.apache.james.util.streams.SwarmGenericContainer;
import org.apache.james.utils.DataProbeImpl;
import org.apache.james.utils.IMAPMessageReader;
@@ -105,21 +110,22 @@ public class GroupMappingTest {
.state("root")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("PostmasterAlias")
+ .matcher(All.class)
+ .mailet(PostmasterAlias.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RelayLimit=30")
- .clazz("Null")
+ .matcher(RelayLimit.class)
+ .matcherCondition("30")
+ .mailet(Null.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("SMTPAuthSuccessful")
- .clazz("ToProcessor")
+ .matcher(SMTPAuthSuccessful.class)
+ .mailet(ToProcessor.class)
.addProperty("processor", "transport")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ToProcessor")
+ .matcher(All.class)
+ .mailet(ToProcessor.class)
.addProperty("processor", "transport")
.build())
.build())
@@ -127,25 +133,25 @@ public class GroupMappingTest {
.addProcessor(ProcessorConfiguration.transport()
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RemoveMimeHeader")
+ .matcher(All.class)
+ .mailet(RemoveMimeHeader.class)
.addProperty("name", "bcc")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RecipientRewriteTable")
+ .matcher(All.class)
+ .mailet(RecipientRewriteTable.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("org.apache.james.jmap.mailet.VacationMailet")
+ .matcher(RecipientIsLocal.class)
+ .mailet(VacationMailet.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("LocalDelivery")
+ .matcher(RecipientIsLocal.class)
+ .mailet(LocalDelivery.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RemoteDelivery")
+ .matcher(All.class)
+ .mailet(RemoteDelivery.class)
.addProperty("outgoingQueue", "outgoing")
.addProperty("delayTime", "5000, 100000, 500000")
.addProperty("maxRetries", "25")
http://git-wip-us.apache.org/repos/asf/james-project/blob/1fe32b91/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
index 5c6e777..3a9f664 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
@@ -25,21 +25,25 @@ import java.util.Optional;
import javax.mail.internet.MimeMessage;
+import org.apache.james.core.MailAddress;
+import org.apache.james.jmap.mailet.TextCalendarBodyToAttachment;
+import org.apache.james.jmap.mailet.VacationMailet;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailets.TemporaryJamesServer;
import org.apache.james.mailets.configuration.CommonProcessors;
import org.apache.james.mailets.configuration.MailetConfiguration;
import org.apache.james.mailets.configuration.MailetContainer;
import org.apache.james.mailets.configuration.ProcessorConfiguration;
-import org.apache.james.utils.SMTPMessageSender;
import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.probe.DataProbe;
import org.apache.james.transport.mailets.amqp.AmqpRule;
+import org.apache.james.transport.matchers.All;
+import org.apache.james.transport.matchers.RecipientIsLocal;
import org.apache.james.util.streams.SwarmGenericContainer;
import org.apache.james.utils.DataProbeImpl;
import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.utils.SMTPMessageSender;
import org.apache.mailet.Mail;
-import org.apache.james.core.MailAddress;
import org.apache.mailet.base.test.FakeMail;
import org.apache.mailet.base.test.MimeMessageBuilder;
import org.junit.After;
@@ -457,58 +461,58 @@ public class ICSAttachmentWorkflowTest {
.state("transport")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RemoveMimeHeader")
+ .matcher(All.class)
+ .mailet(RemoveMimeHeader.class)
.addProperty("name", "bcc")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("StripAttachment")
+ .matcher(All.class)
+ .mailet(StripAttachment.class)
.addProperty("attribute", MAIL_ATTRIBUTE)
.addProperty("pattern", ".*")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("MimeDecodingMailet")
+ .matcher(All.class)
+ .mailet(MimeDecodingMailet.class)
.addProperty("attribute", MAIL_ATTRIBUTE)
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ICalendarParser")
+ .matcher(All.class)
+ .mailet(ICalendarParser.class)
.addProperty("sourceAttribute", MAIL_ATTRIBUTE)
.addProperty("destinationAttribute", PARSED_ICAL_MAIL_ATTRIBUTE)
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ICALToHeader")
+ .matcher(All.class)
+ .mailet(ICALToHeader.class)
.addProperty("attribute", PARSED_ICAL_MAIL_ATTRIBUTE)
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("ICALToJsonAttribute")
+ .matcher(All.class)
+ .mailet(ICALToJsonAttribute.class)
.addProperty("source", PARSED_ICAL_MAIL_ATTRIBUTE)
.addProperty("rawSource", MAIL_ATTRIBUTE)
.addProperty("destination", JSON_MAIL_ATTRIBUTE)
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("org.apache.james.jmap.mailet.TextCalendarBodyToAttachment")
- .build())
+ .matcher(All.class)
+ .mailet(TextCalendarBodyToAttachment.class)
+ .build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("AmqpForwardAttribute")
+ .matcher(All.class)
+ .mailet(AmqpForwardAttribute.class)
.addProperty("uri", amqpRule.getAmqpUri())
.addProperty("exchange", EXCHANGE_NAME)
.addProperty("attribute", JSON_MAIL_ATTRIBUTE)
.addProperty("routing_key", ROUTING_KEY)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("org.apache.james.jmap.mailet.VacationMailet")
+ .matcher(RecipientIsLocal.class)
+ .mailet(VacationMailet.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("LocalDelivery")
+ .matcher(RecipientIsLocal.class)
+ .mailet(LocalDelivery.class)
.build())
.build())
.build();
http://git-wip-us.apache.org/repos/asf/james-project/blob/1fe32b91/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
index 24a3ecb..132b661 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java
@@ -23,19 +23,22 @@ import static org.assertj.core.api.Assertions.assertThat;
import javax.mail.internet.MimeMessage;
+import org.apache.james.core.MailAddress;
+import org.apache.james.jmap.mailet.VacationMailet;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailets.TemporaryJamesServer;
import org.apache.james.mailets.configuration.CommonProcessors;
import org.apache.james.mailets.configuration.MailetConfiguration;
import org.apache.james.mailets.configuration.MailetContainer;
import org.apache.james.mailets.configuration.ProcessorConfiguration;
-import org.apache.james.utils.SMTPMessageSender;
import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.probe.DataProbe;
-import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.transport.matchers.All;
+import org.apache.james.transport.matchers.RecipientIsLocal;
import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.utils.SMTPMessageSender;
import org.apache.mailet.Mail;
-import org.apache.james.core.MailAddress;
import org.apache.mailet.base.test.FakeMail;
import org.apache.mailet.base.test.MimeMessageBuilder;
import org.junit.After;
@@ -77,33 +80,33 @@ public class StripAttachmentTest {
.state("transport")
.enableJmx(true)
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RemoveMimeHeader")
+ .matcher(All.class)
+ .mailet(RemoveMimeHeader.class)
.addProperty("name", "bcc")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("StripAttachment")
+ .matcher(All.class)
+ .mailet(StripAttachment.class)
.addProperty("attribute", "my.attribute")
.addProperty("remove", "all")
.addProperty("notpattern", ".*.tmp.*")
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("OnlyText")
+ .matcher(All.class)
+ .mailet(OnlyText.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("All")
- .clazz("RecoverAttachment")
+ .matcher(All.class)
+ .mailet(RecoverAttachment.class)
.addProperty("attribute", "my.attribute")
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("org.apache.james.jmap.mailet.VacationMailet")
+ .matcher(RecipientIsLocal.class)
+ .mailet(VacationMailet.class)
.build())
.addMailet(MailetConfiguration.builder()
- .match("RecipientIsLocal")
- .clazz("LocalDelivery")
+ .matcher(RecipientIsLocal.class)
+ .mailet(LocalDelivery.class)
.build())
.build())
.build();
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[5/9] james-project git commit: JAMES-2159 Fix multiple recipient
support in SMTPMessageSender
Posted by ma...@apache.org.
JAMES-2159 Fix multiple recipient support in SMTPMessageSender
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c5bf0716
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c5bf0716
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c5bf0716
Branch: refs/heads/master
Commit: c5bf07167e15015f6fdf1cf134db3658ede0bf4f
Parents: 0b286ab
Author: Matthieu Baechler <ma...@apache.org>
Authored: Tue Sep 12 18:17:23 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Sep 27 16:07:08 2017 +0200
----------------------------------------------------------------------
.../main/java/org/apache/james/utils/SMTPMessageSender.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c5bf0716/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
index 837fc29..ef61f24 100644
--- a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
+++ b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
@@ -34,6 +34,7 @@ import org.apache.commons.net.smtp.SMTPClient;
import org.apache.james.core.MailAddress;
import org.apache.mailet.Mail;
+import com.github.fge.lambdas.Throwing;
import com.google.common.base.Charsets;
import com.google.common.base.Throwables;
@@ -94,9 +95,9 @@ public class SMTPMessageSender implements Closeable {
String from = mail.getSender().asString();
smtpClient.helo(senderDomain);
smtpClient.setSender(from);
- for (MailAddress mailAddress : mail.getRecipients()) {
- smtpClient.addRecipient(mailAddress.asString());
- }
+ mail.getRecipients().stream()
+ .map(MailAddress::asString)
+ .forEach(Throwing.consumer(smtpClient::addRecipient));
smtpClient.sendShortMessageData(asString(mail.getMessage()));
} catch (IOException e) {
throw Throwables.propagate(e);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/9] james-project git commit: JAMES-2159 Fail fast when smtp auth
failed in tests
Posted by ma...@apache.org.
JAMES-2159 Fail fast when smtp auth failed in tests
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0b286ab2
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0b286ab2
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0b286ab2
Branch: refs/heads/master
Commit: 0b286ab2b44127077dd127186d4b647ac0e9043c
Parents: c803800
Author: Matthieu Baechler <ma...@apache.org>
Authored: Tue Sep 12 18:16:59 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Sep 27 16:07:08 2017 +0200
----------------------------------------------------------------------
.../src/main/java/org/apache/james/utils/SMTPMessageSender.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/0b286ab2/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
index b08c5d2..837fc29 100644
--- a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
+++ b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
@@ -49,7 +49,9 @@ public class SMTPMessageSender implements Closeable {
throws NoSuchAlgorithmException, IOException, InvalidKeySpecException, InvalidKeyException {
AuthenticatingSMTPClient smtpClient = new AuthenticatingSMTPClient();
smtpClient.connect(ip, port);
- smtpClient.auth(AuthenticatingSMTPClient.AUTH_METHOD.PLAIN, username, password);
+ if (smtpClient.auth(AuthenticatingSMTPClient.AUTH_METHOD.PLAIN, username, password) == false) {
+ throw new RuntimeException("auth failed");
+ }
return new SMTPMessageSender(smtpClient, senderDomain);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org