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 bt...@apache.org on 2019/06/25 01:52:42 UTC

[james-project] branch master updated (f5bd2b3 -> 3d39f3c)

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from f5bd2b3  Merge remote-tracking branch 'mbaechler/close-cluster-after-tests'
     new 0c645e0  JAMES-2294 Simple integration test for Mail Reprocessing
     new 156a6f2  JAMES-2994 Reprocessing to an unknown processor triggers an infinite loop as the mail is nack
     new 87e4135  JAMES-2294 Upon unknown processor, default to Mail.ERROR
     new 85e0b01  JAMES-2294 FactoriseSimple IMAP SMTP WebAdmin module
     new 3d39f3c  JAMES-2294 s/STATE_TRANSPORT/TRANSPORT_PROCESSOR

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/james/MemoryJamesServerMain.java    |  16 ++
 .../mailets/NetworkMatcherIntegrationTest.java     |  16 +-
 .../james/mailets/SmtpAuthIntegrationTest.java     |   2 +-
 .../apache/james/mailets/TemporaryJamesServer.java |   1 +
 .../mailets/configuration/MailetConfiguration.java |   2 +-
 .../configuration/ProcessorConfiguration.java      |   4 +-
 .../transport/mailets/DlpIntegrationTest.java      |  15 +-
 ...t.java => MailReprocessingIntegrationTest.java} | 197 ++++++++-------------
 .../james/transport/mailets/ToRepositoryTest.java  |   4 +-
 .../lib/AbstractStateCompositeProcessor.java       |  63 ++++---
 .../lib/AbstractStateCompositeProcessorTest.java   |   2 -
 11 files changed, 142 insertions(+), 180 deletions(-)
 copy server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/{DlpIntegrationTest.java => MailReprocessingIntegrationTest.java} (51%)


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


[james-project] 04/05: JAMES-2294 FactoriseSimple IMAP SMTP WebAdmin module

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 85e0b01db9d03964adb8339eac5c933567ffba7e
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jun 21 14:20:53 2019 +0700

    JAMES-2294 FactoriseSimple IMAP SMTP WebAdmin module
---
 .../java/org/apache/james/MemoryJamesServerMain.java    | 16 ++++++++++++++++
 .../org/apache/james/mailets/TemporaryJamesServer.java  |  1 +
 .../james/transport/mailets/DlpIntegrationTest.java     | 15 +--------------
 .../mailets/MailReprocessingIntegrationTest.java        | 17 ++---------------
 4 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
index 1e53751..18f4394 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
@@ -19,7 +19,10 @@
 
 package org.apache.james;
 
+import java.util.Optional;
+
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.james.jwt.JwtConfiguration;
 import org.apache.james.modules.BlobExportMechanismModule;
 import org.apache.james.modules.BlobMemoryModule;
 import org.apache.james.modules.MailboxModule;
@@ -50,6 +53,9 @@ import org.apache.james.modules.spamassassin.SpamAssassinListenerModule;
 import org.apache.james.modules.vault.DeletedMessageVaultModule;
 import org.apache.james.modules.vault.DeletedMessageVaultRoutesModule;
 import org.apache.james.server.core.configuration.Configuration;
+import org.apache.james.webadmin.WebAdminConfiguration;
+import org.apache.james.webadmin.authentication.AuthenticationFilter;
+import org.apache.james.webadmin.authentication.NoAuthenticationFilter;
 
 import com.google.inject.Module;
 import com.google.inject.util.Modules;
@@ -67,6 +73,16 @@ public class MemoryJamesServerMain {
         new DLPRoutesModule(),
         new SieveRoutesModule());
 
+
+    public static final JwtConfiguration NO_JWT_CONFIGURATION = new JwtConfiguration(Optional.empty());
+
+    public static final Module WEBADMIN_NO_AUTH_MODULE = Modules.combine(binder -> binder.bind(JwtConfiguration.class).toInstance(NO_JWT_CONFIGURATION),
+        binder -> binder.bind(AuthenticationFilter.class).to(NoAuthenticationFilter.class),
+        binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION));
+
+    public static final Module WEBADMIN_TESTING = Modules.override(WEBADMIN)
+        .with(WEBADMIN_NO_AUTH_MODULE);
+
     public static final Module PROTOCOLS = Modules.combine(
         new IMAPServerModule(),
         new LMTPServerModule(),
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
index a1a7905..f940a29 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
@@ -61,6 +61,7 @@ public class TemporaryJamesServer {
         .putProcessor(CommonProcessors.error())
         .putProcessor(CommonProcessors.transport());
 
+
     public static class Builder {
         private ImmutableList.Builder<Module> overrideModules;
         private Optional<Module> module;
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/DlpIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/DlpIntegrationTest.java
index 581d964..5b8575b 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/DlpIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/DlpIntegrationTest.java
@@ -28,11 +28,8 @@ import static org.apache.james.mailets.configuration.Constants.RECIPIENT;
 import static org.apache.james.mailets.configuration.Constants.RECIPIENT2;
 import static org.apache.james.mailets.configuration.Constants.awaitAtMostOneMinute;
 
-import java.util.Optional;
-
 import org.apache.james.MemoryJamesServerMain;
 import org.apache.james.core.builder.MimeMessageBuilder;
-import org.apache.james.jwt.JwtConfiguration;
 import org.apache.james.mailets.TemporaryJamesServer;
 import org.apache.james.mailets.configuration.MailetConfiguration;
 import org.apache.james.mailets.configuration.MailetContainer;
@@ -45,10 +42,7 @@ import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.IMAPMessageReader;
 import org.apache.james.utils.SMTPMessageSender;
 import org.apache.james.utils.WebAdminGuiceProbe;
-import org.apache.james.webadmin.WebAdminConfiguration;
 import org.apache.james.webadmin.WebAdminUtils;
-import org.apache.james.webadmin.authentication.AuthenticationFilter;
-import org.apache.james.webadmin.authentication.NoAuthenticationFilter;
 import org.apache.mailet.base.test.FakeMail;
 import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
@@ -62,7 +56,6 @@ import io.restassured.specification.RequestSpecification;
 
 public class DlpIntegrationTest {
     public static final String REPOSITORY_PREFIX = "file://var/mail/dlp/quarantine/";
-    public static final JwtConfiguration NO_JWT_CONFIGURATION = new JwtConfiguration(Optional.empty());
 
     @Rule
     public TemporaryFolder folder = new TemporaryFolder();
@@ -86,13 +79,7 @@ public class DlpIntegrationTest {
                         .mailet(Null.class)));
 
         jamesServer = TemporaryJamesServer.builder()
-            .withBase(Modules.override(
-                    MemoryJamesServerMain.SMTP_AND_IMAP_MODULE,
-                    MemoryJamesServerMain.WEBADMIN)
-                .with(
-                    binder -> binder.bind(JwtConfiguration.class).toInstance(NO_JWT_CONFIGURATION),
-                    binder -> binder.bind(AuthenticationFilter.class).to(NoAuthenticationFilter.class),
-                    binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION)))
+            .withBase(Modules.combine(MemoryJamesServerMain.SMTP_AND_IMAP_MODULE, MemoryJamesServerMain.WEBADMIN_TESTING))
             .withMailetContainer(mailets)
             .build(folder);
 
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
index 002f458..d77a618 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
@@ -31,11 +31,8 @@ import static org.apache.james.mailets.configuration.Constants.awaitAtMostOneMin
 import static org.apache.james.mailets.configuration.ProcessorConfiguration.STATE_TRANSPORT;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.util.Optional;
-
 import org.apache.james.MemoryJamesServerMain;
 import org.apache.james.core.builder.MimeMessageBuilder;
-import org.apache.james.jwt.JwtConfiguration;
 import org.apache.james.mailets.TemporaryJamesServer;
 import org.apache.james.mailets.configuration.MailetConfiguration;
 import org.apache.james.mailets.configuration.MailetContainer;
@@ -47,10 +44,7 @@ import org.apache.james.transport.matchers.All;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.SMTPMessageSender;
 import org.apache.james.utils.WebAdminGuiceProbe;
-import org.apache.james.webadmin.WebAdminConfiguration;
 import org.apache.james.webadmin.WebAdminUtils;
-import org.apache.james.webadmin.authentication.AuthenticationFilter;
-import org.apache.james.webadmin.authentication.NoAuthenticationFilter;
 import org.apache.mailet.base.test.FakeMail;
 import org.junit.After;
 import org.junit.Before;
@@ -65,7 +59,6 @@ import io.restassured.specification.RequestSpecification;
 public class MailReprocessingIntegrationTest {
     private static final MailRepositoryUrl REPOSITORY_A = MailRepositoryUrl.from("file://var/mail/a");
     private static final MailRepositoryUrl REPOSITORY_B = MailRepositoryUrl.from("file://var/mail/b");
-    private static final JwtConfiguration NO_JWT_CONFIGURATION = new JwtConfiguration(Optional.empty());
 
     @Rule
     public TemporaryFolder folder = new TemporaryFolder();
@@ -92,13 +85,7 @@ public class MailReprocessingIntegrationTest {
                         .addProperty("repositoryPath", REPOSITORY_B.asString())));
 
         jamesServer = TemporaryJamesServer.builder()
-            .withBase(Modules.override(
-                    MemoryJamesServerMain.SMTP_AND_IMAP_MODULE,
-                    MemoryJamesServerMain.WEBADMIN)
-                .with(
-                    binder -> binder.bind(JwtConfiguration.class).toInstance(NO_JWT_CONFIGURATION),
-                    binder -> binder.bind(AuthenticationFilter.class).to(NoAuthenticationFilter.class),
-                    binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION)))
+            .withBase(Modules.combine(MemoryJamesServerMain.SMTP_AND_IMAP_MODULE, MemoryJamesServerMain.WEBADMIN_TESTING))
             .withMailetContainer(mailets)
             .build(folder);
 
@@ -210,7 +197,7 @@ public class MailReprocessingIntegrationTest {
             .param("action", "reprocess")
             .param("queue", MailQueueFactory.SPOOL)
             .param("processor", "unknown")
-            .patch("/mailRepositories/" + REPOSITORY_B.getPath().urlEncoded() + "/mails").prettyPeek();
+            .patch("/mailRepositories/" + REPOSITORY_B.getPath().urlEncoded() + "/mails");
 
         // Then I can move it to repository A
         awaitAtMostOneMinute.until(() -> containsExactlyOneMail(ERROR_REPOSITORY));


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


[james-project] 02/05: JAMES-2994 Reprocessing to an unknown processor triggers an infinite loop as the mail is nack

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 156a6f269165f0c8061115c0c6a055bee0ab99ad
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jun 21 10:58:17 2019 +0700

    JAMES-2994 Reprocessing to an unknown processor triggers an infinite loop as the mail is nack
---
 .../mailets/MailReprocessingIntegrationTest.java   | 31 ++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
index 19c63a8..f8de0d5 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.transport.mailets;
 
 import static io.restassured.RestAssured.given;
+import static org.apache.james.mailets.configuration.CommonProcessors.ERROR_REPOSITORY;
 import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
 import static org.apache.james.mailets.configuration.Constants.FROM;
 import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
@@ -53,6 +54,7 @@ import org.apache.james.webadmin.authentication.NoAuthenticationFilter;
 import org.apache.mailet.base.test.FakeMail;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -188,6 +190,35 @@ public class MailReprocessingIntegrationTest {
         assertThat(containsExactlyOneMail(REPOSITORY_A)).isTrue();
     }
 
+    @Ignore("JAMES-2994 Reprocessing to an unknown processor triggers an infinite loop as the mail is nack")
+    @Test
+    public void reprocessingShouldProcessAsErrorWhenUnknownMailProcessor() throws Exception {
+        // Given an incoming email
+        messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .sendMessage(FakeMail.builder()
+                .name("name")
+                .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                    .addToRecipient(RECIPIENT)
+                    .setSender(FROM)
+                    .setText("match me"))
+                .sender(FROM)
+                .recipient(RECIPIENT));
+        // Being stored in MailRepository B
+        awaitAtMostOneMinute.until(() -> containsExactlyOneMail(REPOSITORY_B));
+
+        // When I reprocess it
+        given()
+            .spec(specification)
+            .param("action", "reprocess")
+            .param("queue", MailQueueFactory.SPOOL)
+            .param("processor", "unknown")
+            .patch("/mailRepositories/" + REPOSITORY_B.getPath().urlEncoded() + "/mails").prettyPeek();
+
+        // Then I can move it to repository A
+        awaitAtMostOneMinute.until(() -> containsExactlyOneMail(ERROR_REPOSITORY));
+        assertThat(containsExactlyOneMail(ERROR_REPOSITORY)).isTrue();
+    }
+
     private boolean containsExactlyOneMail(MailRepositoryUrl repositoryUrl) {
         try {
             return given()


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


[james-project] 05/05: JAMES-2294 s/STATE_TRANSPORT/TRANSPORT_PROCESSOR

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 3d39f3cfdfba889d80576b45f5a825b54deb2a35
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jun 21 14:22:08 2019 +0700

    JAMES-2294 s/STATE_TRANSPORT/TRANSPORT_PROCESSOR
---
 .../james/mailets/NetworkMatcherIntegrationTest.java     | 16 ++++++++--------
 .../apache/james/mailets/SmtpAuthIntegrationTest.java    |  2 +-
 .../james/mailets/configuration/MailetConfiguration.java |  2 +-
 .../mailets/configuration/ProcessorConfiguration.java    |  4 ++--
 .../mailets/MailReprocessingIntegrationTest.java         |  6 +++---
 .../apache/james/transport/mailets/ToRepositoryTest.java |  4 ++--
 6 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java
index f355a69..776d0ee 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java
@@ -93,7 +93,7 @@ public class NetworkMatcherIntegrationTest {
                 .matcher(RemoteAddrInNetwork.class)
                 .matcherCondition("127.0.0.0/8")
                 .mailet(ToProcessor.class)
-                .addProperty("processor", ProcessorConfiguration.STATE_TRANSPORT))
+                .addProperty("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR))
             .addMailet(toRepository()));
 
         messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -113,7 +113,7 @@ public class NetworkMatcherIntegrationTest {
                 .matcher(RemoteAddrNotInNetwork.class)
                 .matcherCondition("172.0.0.0/8")
                 .mailet(ToProcessor.class)
-                .addProperty("processor", ProcessorConfiguration.STATE_TRANSPORT))
+                .addProperty("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR))
             .addMailet(toRepository()));
 
         messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -133,7 +133,7 @@ public class NetworkMatcherIntegrationTest {
                 .matcher(RemoteAddrInNetwork.class)
                 .matcherCondition("127.0.0.0/2")
                 .mailet(ToProcessor.class)
-                .addProperty("processor", ProcessorConfiguration.STATE_TRANSPORT))
+                .addProperty("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR))
             .addMailet(toRepository()));
 
         messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -153,7 +153,7 @@ public class NetworkMatcherIntegrationTest {
                 .matcher(RemoteAddrInNetwork.class)
                 .matcherCondition("127.0.4.108/8")
                 .mailet(ToProcessor.class)
-                .addProperty("processor", ProcessorConfiguration.STATE_TRANSPORT))
+                .addProperty("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR))
             .addMailet(toRepository()));
 
         messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -173,7 +173,7 @@ public class NetworkMatcherIntegrationTest {
                 .matcher(RemoteAddrInNetwork.class)
                 .matcherCondition("127.255.255.255/8")
                 .mailet(ToProcessor.class)
-                .addProperty("processor", ProcessorConfiguration.STATE_TRANSPORT))
+                .addProperty("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR))
             .addMailet(toRepository()));
 
         messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -193,7 +193,7 @@ public class NetworkMatcherIntegrationTest {
                 .matcher(RemoteAddrInNetwork.class)
                 .matcherCondition("126.0.0.0/4")
                 .mailet(ToProcessor.class)
-                .addProperty("processor", ProcessorConfiguration.STATE_TRANSPORT))
+                .addProperty("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR))
             .addMailet(toRepository()));
 
         messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -213,7 +213,7 @@ public class NetworkMatcherIntegrationTest {
                 .matcher(RemoteAddrInNetwork.class)
                 .matcherCondition("172.0.0.0/8")
                 .mailet(ToProcessor.class)
-                .addProperty("processor", ProcessorConfiguration.STATE_TRANSPORT))
+                .addProperty("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR))
             .addMailet(toRepository()));
 
         messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -237,7 +237,7 @@ public class NetworkMatcherIntegrationTest {
                 .matcher(RemoteAddrNotInNetwork.class)
                 .matcherCondition("127.0.0.0/8")
                 .mailet(ToProcessor.class)
-                .addProperty("processor", ProcessorConfiguration.STATE_TRANSPORT))
+                .addProperty("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR))
             .addMailet(toRepository()));
 
         messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java
index c048d65..72a3c9b 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java
@@ -68,7 +68,7 @@ public class SmtpAuthIntegrationTest {
             .addMailet(MailetConfiguration.builder()
                 .matcher(SMTPAuthSuccessful.class)
                 .mailet(ToProcessor.class)
-                .addProperty("processor", ProcessorConfiguration.STATE_TRANSPORT))
+                .addProperty("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR))
             .addMailet(MailetConfiguration.TO_BOUNCE);
 
         MailetContainer.Builder mailetContainer = TemporaryJamesServer.DEFAULT_MAILET_CONTAINER_CONFIGURATION
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 cdba77d..8896bdf 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
@@ -95,7 +95,7 @@ public class MailetConfiguration implements SerializableAsXml {
     public static final MailetConfiguration TO_TRANSPORT = MailetConfiguration.builder()
         .matcher(All.class)
         .mailet(ToProcessor.class)
-        .addProperty("processor", ProcessorConfiguration.STATE_TRANSPORT)
+        .addProperty("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR)
         .build();
 
     public static final MailetConfiguration TO_BOUNCE = MailetConfiguration.builder()
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/ProcessorConfiguration.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/ProcessorConfiguration.java
index 08a0a17..c36fb00 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/ProcessorConfiguration.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/ProcessorConfiguration.java
@@ -28,7 +28,7 @@ import com.google.common.collect.ImmutableList;
 
 public class ProcessorConfiguration implements SerializableAsXml {
 
-    public static final String STATE_TRANSPORT = "transport";
+    public static final String TRANSPORT_PROCESSOR = "transport";
     public static final String STATE_ROOT = "root";
     public static final String STATE_BOUNCES = "bounces";
     public static final String STATE_ERROR = "error";
@@ -39,7 +39,7 @@ public class ProcessorConfiguration implements SerializableAsXml {
     }
 
     public static Builder transport() {
-        return builder().state(STATE_TRANSPORT);
+        return builder().state(TRANSPORT_PROCESSOR);
     }
 
     public static Builder root() {
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
index d77a618..429f777 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
@@ -28,7 +28,7 @@ import static org.apache.james.mailets.configuration.Constants.PASSWORD;
 import static org.apache.james.mailets.configuration.Constants.RECIPIENT;
 import static org.apache.james.mailets.configuration.Constants.RECIPIENT2;
 import static org.apache.james.mailets.configuration.Constants.awaitAtMostOneMinute;
-import static org.apache.james.mailets.configuration.ProcessorConfiguration.STATE_TRANSPORT;
+import static org.apache.james.mailets.configuration.ProcessorConfiguration.TRANSPORT_PROCESSOR;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.james.MemoryJamesServerMain;
@@ -124,7 +124,7 @@ public class MailReprocessingIntegrationTest {
             .spec(specification)
             .param("action", "reprocess")
             .param("queue", MailQueueFactory.SPOOL)
-            .param("processor", STATE_TRANSPORT)
+            .param("processor", TRANSPORT_PROCESSOR)
         .patch("/mailRepositories/" + REPOSITORY_B.getPath().urlEncoded() + "/mails");
 
         // Then I can move it to repository A
@@ -152,7 +152,7 @@ public class MailReprocessingIntegrationTest {
             .spec(specification)
             .param("action", "reprocess")
             .param("queue", MailQueueFactory.SPOOL)
-            .param("processor", STATE_TRANSPORT)
+            .param("processor", TRANSPORT_PROCESSOR)
         .patch("/mailRepositories/" + REPOSITORY_B.getPath().urlEncoded() + "/mails");
 
         // I can move it to repository A
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
index 6cfd351..238711d 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
@@ -114,7 +114,7 @@ public class ToRepositoryTest {
 
         String taskId = with()
             .spec(webAdminAPI)
-            .queryParam("processor", ProcessorConfiguration.STATE_TRANSPORT)
+            .queryParam("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR)
             .queryParam("action", "reprocess")
         .patch(MailRepositoriesRoutes.MAIL_REPOSITORIES
                 + "/" + CUSTOM_REPOSITORY.getPath().urlEncoded()
@@ -145,7 +145,7 @@ public class ToRepositoryTest {
 
         with()
             .spec(webAdminAPI)
-            .queryParam("processor", ProcessorConfiguration.STATE_TRANSPORT)
+            .queryParam("processor", ProcessorConfiguration.TRANSPORT_PROCESSOR)
             .queryParam("action", "reprocess")
             .patch(MailRepositoriesRoutes.MAIL_REPOSITORIES
                 + "/" + CUSTOM_REPOSITORY.getPath().urlEncoded()


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


[james-project] 03/05: JAMES-2294 Upon unknown processor, default to Mail.ERROR

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 87e41356b548d429faf67185998c9bff4093abbd
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jun 21 11:01:04 2019 +0700

    JAMES-2294 Upon unknown processor, default to Mail.ERROR
    
    This allows the admin to be aware of the issue and in-fine fix it. Note
    that the state of the mail needs to be overwritten...
    
    This behaviour prevents an infinite loop that is otherwise triggered upon
    reprocessing to an unknown processor - a typo/missconfiguration that could
    easily happen!
---
 .../mailets/MailReprocessingIntegrationTest.java   |  2 -
 .../lib/AbstractStateCompositeProcessor.java       | 63 ++++++++++++----------
 .../lib/AbstractStateCompositeProcessorTest.java   |  2 -
 3 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
index f8de0d5..002f458 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
@@ -54,7 +54,6 @@ import org.apache.james.webadmin.authentication.NoAuthenticationFilter;
 import org.apache.mailet.base.test.FakeMail;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -190,7 +189,6 @@ public class MailReprocessingIntegrationTest {
         assertThat(containsExactlyOneMail(REPOSITORY_A)).isTrue();
     }
 
-    @Ignore("JAMES-2994 Reprocessing to an unknown processor triggers an infinite loop as the mail is nack")
     @Test
     public void reprocessingShouldProcessAsErrorWhenUnknownMailProcessor() throws Exception {
         // Given an incoming email
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessor.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessor.java
index 8c28422..0985721 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessor.java
@@ -23,6 +23,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
@@ -66,7 +67,7 @@ public abstract class AbstractStateCompositeProcessor implements MailProcessor,
     }
 
     @Override
-    public void configure(HierarchicalConfiguration config) throws ConfigurationException {
+    public void configure(HierarchicalConfiguration config) {
         this.config = config;
         this.enableJmx = config.getBoolean("[@enableJmx]", true);
 
@@ -74,34 +75,42 @@ public abstract class AbstractStateCompositeProcessor implements MailProcessor,
 
     @Override
     public void service(Mail mail) throws MessagingException {
-        long start = System.currentTimeMillis();
+        handleWithProcessor(mail, getProcessorOrFallBackToError(mail));
+    }
+
+    private MailProcessor getProcessorOrFallBackToError(Mail mail) {
+        return Optional.ofNullable(getProcessor(mail.getState()))
+            .orElseGet(() -> {
+                mail.setErrorMessage("MailProcessor '" + mail.getState() + "' could not be found. Processing to 'error' instead");
+                LOGGER.error("MailProcessor '{}' could not be found. Processing {} to 'error' instead", mail.getState(), mail.getName());
+                mail.setState(Mail.ERROR);
+                return getProcessor(Mail.ERROR);
+            });
+    }
+
+    private void handleWithProcessor(Mail mail, MailProcessor processor) throws MessagingException {
         MessagingException ex = null;
-        MailProcessor processor = getProcessor(mail.getState());
-
-        if (processor != null) {
-            LOGGER.debug("Call MailProcessor {}", mail.getState());
-            try {
-                processor.service(mail);
-
-                if (Mail.GHOST.equals(mail.getState())) {
-                    LifecycleUtil.dispose(mail);
-                }
-                /*
-                 * // check the mail needs further processing if
-                 * (Mail.GHOST.equalsIgnoreCase(mail.getState()) == false) {
-                 * service(mail); } else { LifecycleUtil.dispose(mail); }
-                 */
-            } catch (MessagingException e) {
-                ex = e;
-                throw e;
-            } finally {
-                long end = System.currentTimeMillis() - start;
-                for (CompositeProcessorListener listener : listeners) {
-                    listener.afterProcessor(processor, mail.getName(), end, ex);
-                }
+        long start = System.currentTimeMillis();
+        LOGGER.debug("Call MailProcessor {}", mail.getState());
+        try {
+            processor.service(mail);
+
+            if (Mail.GHOST.equals(mail.getState())) {
+                LifecycleUtil.dispose(mail);
+            }
+            /*
+             * // check the mail needs further processing if
+             * (Mail.GHOST.equalsIgnoreCase(mail.getState()) == false) {
+             * service(mail); } else { LifecycleUtil.dispose(mail); }
+             */
+        } catch (MessagingException e) {
+            ex = e;
+            throw e;
+        } finally {
+            long end = System.currentTimeMillis() - start;
+            for (CompositeProcessorListener listener : listeners) {
+                listener.afterProcessor(processor, mail.getName(), end, ex);
             }
-        } else {
-            throw new MessagingException("No processor found for mail " + mail.getName() + " with state " + mail.getState());
         }
     }
 
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java
index 781d84b..8b585fd 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java
@@ -74,8 +74,6 @@ public abstract class AbstractStateCompositeProcessorTest {
             processor.service(mail2);
             processor.service(mail3);
 
-            expectedException.expect(MessagingException.class);
-
             processor.service(mail4);
         } finally {
             processor.dispose();


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


[james-project] 01/05: JAMES-2294 Simple integration test for Mail Reprocessing

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 0c645e0127f70a2ff272330da3acbc09b1d2acbf
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jun 21 10:57:04 2019 +0700

    JAMES-2294 Simple integration test for Mail Reprocessing
---
 .../mailets/MailReprocessingIntegrationTest.java   | 203 +++++++++++++++++++++
 1 file changed, 203 insertions(+)

diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
new file mode 100644
index 0000000..19c63a8
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/MailReprocessingIntegrationTest.java
@@ -0,0 +1,203 @@
+/****************************************************************
+ * 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 io.restassured.RestAssured.given;
+import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
+import static org.apache.james.mailets.configuration.Constants.FROM;
+import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
+import static org.apache.james.mailets.configuration.Constants.PASSWORD;
+import static org.apache.james.mailets.configuration.Constants.RECIPIENT;
+import static org.apache.james.mailets.configuration.Constants.RECIPIENT2;
+import static org.apache.james.mailets.configuration.Constants.awaitAtMostOneMinute;
+import static org.apache.james.mailets.configuration.ProcessorConfiguration.STATE_TRANSPORT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.apache.james.MemoryJamesServerMain;
+import org.apache.james.core.builder.MimeMessageBuilder;
+import org.apache.james.jwt.JwtConfiguration;
+import org.apache.james.mailets.TemporaryJamesServer;
+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.mailrepository.api.MailRepositoryUrl;
+import org.apache.james.modules.protocols.SmtpGuiceProbe;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.transport.matchers.All;
+import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.SMTPMessageSender;
+import org.apache.james.utils.WebAdminGuiceProbe;
+import org.apache.james.webadmin.WebAdminConfiguration;
+import org.apache.james.webadmin.WebAdminUtils;
+import org.apache.james.webadmin.authentication.AuthenticationFilter;
+import org.apache.james.webadmin.authentication.NoAuthenticationFilter;
+import org.apache.mailet.base.test.FakeMail;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import com.google.inject.util.Modules;
+
+import io.restassured.specification.RequestSpecification;
+
+public class MailReprocessingIntegrationTest {
+    private static final MailRepositoryUrl REPOSITORY_A = MailRepositoryUrl.from("file://var/mail/a");
+    private static final MailRepositoryUrl REPOSITORY_B = MailRepositoryUrl.from("file://var/mail/b");
+    private static final JwtConfiguration NO_JWT_CONFIGURATION = new JwtConfiguration(Optional.empty());
+
+    @Rule
+    public TemporaryFolder folder = new TemporaryFolder();
+
+    @Rule
+    public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
+
+    private TemporaryJamesServer jamesServer;
+    private RequestSpecification specification;
+
+    @Before
+    public void createJamesServer() throws Exception {
+        MailetContainer.Builder mailets = TemporaryJamesServer.DEFAULT_MAILET_CONTAINER_CONFIGURATION
+            .putProcessor(ProcessorConfiguration.transport()
+                    .addMailet(MailetConfiguration.BCC_STRIPPER)
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(ToRepository.class)
+                        .addProperty("repositoryPath", REPOSITORY_A.asString())))
+            .putProcessor(ProcessorConfiguration.root()
+                    .addMailet(MailetConfiguration.builder()
+                        .matcher(All.class)
+                        .mailet(ToRepository.class)
+                        .addProperty("repositoryPath", REPOSITORY_B.asString())));
+
+        jamesServer = TemporaryJamesServer.builder()
+            .withBase(Modules.override(
+                    MemoryJamesServerMain.SMTP_AND_IMAP_MODULE,
+                    MemoryJamesServerMain.WEBADMIN)
+                .with(
+                    binder -> binder.bind(JwtConfiguration.class).toInstance(NO_JWT_CONFIGURATION),
+                    binder -> binder.bind(AuthenticationFilter.class).to(NoAuthenticationFilter.class),
+                    binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION)))
+            .withMailetContainer(mailets)
+            .build(folder);
+
+        jamesServer.getProbe(DataProbeImpl.class)
+            .fluent()
+            .addDomain(DEFAULT_DOMAIN)
+            .addUser(FROM, PASSWORD)
+            .addUser(RECIPIENT, PASSWORD)
+            .addUser(RECIPIENT2, PASSWORD);
+
+        specification = WebAdminUtils.spec(jamesServer.getProbe(WebAdminGuiceProbe.class).getWebAdminPort());
+    }
+
+    @After
+    public void tearDown() {
+        jamesServer.shutdown();
+    }
+
+    @Test
+    public void reprocessingShouldAllowToTargetASpecificProcessor() throws Exception {
+        // Given an incoming email
+        messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .sendMessage(FakeMail.builder()
+                .name("name")
+                .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                    .addToRecipient(RECIPIENT)
+                    .setSender(FROM)
+                    .setText("match me"))
+                .sender(FROM)
+                .recipient(RECIPIENT));
+        // Being stored in MailRepository B
+        awaitAtMostOneMinute.until(() -> containsExactlyOneMail(REPOSITORY_B));
+
+        // When I reprocess it
+        given()
+            .spec(specification)
+            .param("action", "reprocess")
+            .param("queue", MailQueueFactory.SPOOL)
+            .param("processor", STATE_TRANSPORT)
+        .patch("/mailRepositories/" + REPOSITORY_B.getPath().urlEncoded() + "/mails");
+
+        // Then I can move it to repository A
+        awaitAtMostOneMinute.until(() -> containsExactlyOneMail(REPOSITORY_A));
+        assertThat(containsExactlyOneMail(REPOSITORY_A)).isTrue();
+    }
+
+    @Test
+    public void reprocessingShouldPreserveStateWhenProcessorIsNotSpecified() throws Exception {
+        // Given an incoming email
+        messageSender.connect(LOCALHOST_IP, jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
+            .sendMessage(FakeMail.builder()
+                .name("name")
+                .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                    .addToRecipient(RECIPIENT)
+                    .setSender(FROM)
+                    .setText("match me"))
+                .sender(FROM)
+                .recipient(RECIPIENT));
+        // Being stored in MailRepository B
+        awaitAtMostOneMinute.until(() -> containsExactlyOneMail(REPOSITORY_B));
+
+        // I reprocess it
+        given()
+            .spec(specification)
+            .param("action", "reprocess")
+            .param("queue", MailQueueFactory.SPOOL)
+            .param("processor", STATE_TRANSPORT)
+        .patch("/mailRepositories/" + REPOSITORY_B.getPath().urlEncoded() + "/mails");
+
+        // I can move it to repository A
+        awaitAtMostOneMinute.until(() -> containsExactlyOneMail(REPOSITORY_A));
+
+        // When I reprocess it without target processor
+        String taskId = given()
+            .spec(specification)
+            .param("action", "reprocess")
+            .param("queue", MailQueueFactory.SPOOL)
+        .patch("/mailRepositories/" + REPOSITORY_A.getPath().urlEncoded() + "/mails")
+            .jsonPath()
+            .get("taskId");
+
+        given()
+            .spec(specification)
+            .get("/tasks/" + taskId + "/await");
+
+        // It then is processed by the transport processor again
+        awaitAtMostOneMinute.until(() -> containsExactlyOneMail(REPOSITORY_A));
+        assertThat(containsExactlyOneMail(REPOSITORY_A)).isTrue();
+    }
+
+    private boolean containsExactlyOneMail(MailRepositoryUrl repositoryUrl) {
+        try {
+            return given()
+                .spec(specification)
+            .get("/mailRepositories/" + repositoryUrl.getPath().urlEncoded() + "/mails")
+                .jsonPath()
+                .getList(".")
+                .size() == 1;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+}


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