You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/11/03 08:08:29 UTC

[james-project] branch master updated (af69b0daee -> 415e1896e1)

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 af69b0daee JAMES-3775 Task should only count messages in the period (#1284)
     new 7f0eae001f JAMES-3843 VacationMailet should use null sender
     new 5fa6a93e6a JAMES-3843 Support nullSender in mockSMTP
     new f1d4ab6329 JAMES-3843 Drop extra parameters for VacationMailet
     new 05bba94dd0 JAMES-3843 Bump mock SMTP Image to 0.6
     new 415e1896e1 JAMES-3843 Rewrite VacationRelayIntegrationTest with Mock SMTP server

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:
 .../james/transport/mailets/VacationMailet.java    |  2 +-
 .../transport/mailets/VacationMailetTest.java      | 10 ++--
 server/mailet/mock-smtp-server/pom.xml             |  2 +-
 .../james/mock/smtp/server/MockMessageHandler.java |  3 ++
 .../apache/james/mock/smtp/server/model/Mail.java  | 15 ++++++
 .../mock/smtp/server/ConfigurationClientTest.java  | 31 +++++++++++++
 .../jmap-draft-integration-testing-common/pom.xml  |  4 ++
 .../org/apache/james/jmap/MockSmtpTestRule.java}   | 53 ++++------------------
 .../james/jmap/VacationRelayIntegrationTest.java   | 37 ++++++++++-----
 .../java/org/apache/james/util/docker/Images.java  |  2 +-
 10 files changed, 96 insertions(+), 63 deletions(-)
 copy server/{mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/testing/MockSmtpServerExtension.java => protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/MockSmtpTestRule.java} (61%)


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


[james-project] 01/05: JAMES-3843 VacationMailet should use null sender

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 7f0eae001fea6ffb990c35863808e75e762b1ccf
Author: Karsten Otto <ka...@akquinet.de>
AuthorDate: Thu Oct 27 14:39:08 2022 +0200

    JAMES-3843 VacationMailet should use null sender
---
 .../org/apache/james/transport/mailets/VacationMailet.java     |  6 +++++-
 .../org/apache/james/transport/mailets/VacationMailetTest.java | 10 +++++-----
 .../org/apache/james/jmap/VacationRelayIntegrationTest.java    |  3 +++
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationMailet.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationMailet.java
index 0884f3dbb6..1d8fc4485f 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationMailet.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationMailet.java
@@ -46,12 +46,15 @@ import reactor.core.publisher.Mono;
 
 public class VacationMailet extends GenericMailet {
 
+    public static final String EXPLICIT_SENDER_PROPERTY = "james.vacation.sender.explicit";
+
     private static final Logger LOGGER = LoggerFactory.getLogger(VacationMailet.class);
 
     private final VacationService vacationService;
     private final ZonedDateTimeProvider zonedDateTimeProvider;
     private final AutomaticallySentMailDetector automaticallySentMailDetector;
     private final MimeMessageBodyGenerator mimeMessageBodyGenerator;
+    private final boolean explicitSender;
 
     @Inject
     public VacationMailet(VacationService vacationService, ZonedDateTimeProvider zonedDateTimeProvider,
@@ -61,6 +64,7 @@ public class VacationMailet extends GenericMailet {
         this.zonedDateTimeProvider = zonedDateTimeProvider;
         this.automaticallySentMailDetector = automaticallySentMailDetector;
         this.mimeMessageBodyGenerator = mimeMessageBodyGenerator;
+        this.explicitSender = Boolean.parseBoolean(System.getProperty(EXPLICIT_SENDER_PROPERTY, "false"));
     }
 
     @Override
@@ -139,7 +143,7 @@ public class VacationMailet extends GenericMailet {
     }
 
     private void sendNotification(VacationReply vacationReply) throws MessagingException {
-        getMailetContext().sendMail(vacationReply.getSender(),
+        getMailetContext().sendMail(explicitSender ? vacationReply.getSender() : MailAddress.nullSender(),
             vacationReply.getRecipients(),
             vacationReply.getMimeMessage());
     }
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/VacationMailetTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/VacationMailetTest.java
index c91141d4b5..2bb5f783dc 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/VacationMailetTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/VacationMailetTest.java
@@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
@@ -122,7 +123,7 @@ public class VacationMailetTest {
 
         testee.service(mail);
 
-        verify(mailetContext).sendMail(eq(originalRecipient), eq(ImmutableList.of(originalSender)), any());
+        verify(mailetContext).sendMail(eq(MailAddress.nullSender()), eq(ImmutableList.of(originalSender)), any());
         verify(vacationService).retrieveVacation(AccountId.fromString(USERNAME));
         verify(vacationService).isNotificationRegistered(ACCOUNT_ID, recipientId);
         verify(vacationService).registerNotification(ACCOUNT_ID, recipientId, Optional.of(DATE_TIME_2018));
@@ -152,7 +153,7 @@ public class VacationMailetTest {
 
         testee.service(mail);
 
-        verify(mailetContext).sendMail(eq(originalRecipient), eq(ImmutableList.of(originalSender)), any());
+        verify(mailetContext).sendMail(eq(MailAddress.nullSender()), eq(ImmutableList.of(originalSender)), any());
         verifyNoMoreInteractions(mailetContext);
     }
 
@@ -206,8 +207,7 @@ public class VacationMailetTest {
 
         testee.service(mail);
 
-        verify(mailetContext).sendMail(eq(originalRecipient), eq(ImmutableList.of(originalSender)), any());
-        verify(mailetContext).sendMail(eq(secondRecipient), eq(ImmutableList.of(originalSender)), any());
+        verify(mailetContext, times(2)).sendMail(eq(MailAddress.nullSender()), eq(ImmutableList.of(originalSender)), any());
         verifyNoMoreInteractions(mailetContext);
     }
 
@@ -288,7 +288,7 @@ public class VacationMailetTest {
 
         testee.service(mail);
 
-        verify(mailetContext).sendMail(eq(originalRecipient), eq(ImmutableList.of(originalSender)), any());
+        verify(mailetContext).sendMail(eq(MailAddress.nullSender()), eq(ImmutableList.of(originalSender)), any());
         verifyNoMoreInteractions(mailetContext);
     }
 
diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
index 6f8004cacb..6e022bbed5 100644
--- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
+++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
@@ -31,6 +31,7 @@ import org.apache.commons.net.smtp.SMTPClient;
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.dnsservice.api.InMemoryDNSService;
 import org.apache.james.jmap.api.model.AccountId;
+import org.apache.james.transport.mailets.VacationMailet;
 import org.apache.james.vacation.api.VacationPatch;
 import org.apache.james.jmap.draft.JmapGuiceProbe;
 import org.apache.james.junit.categories.BasicFeature;
@@ -70,6 +71,7 @@ public abstract class VacationRelayIntegrationTest {
         getInMemoryDns()
             .registerMxRecord("yopmail.com", fakeSmtp.getContainer().getContainerIp());
 
+        System.setProperty(VacationMailet.EXPLICIT_SENDER_PROPERTY, "true");
         guiceJamesServer = getJmapServer();
         guiceJamesServer.start();
 
@@ -87,6 +89,7 @@ public abstract class VacationRelayIntegrationTest {
     public void teardown() {
         fakeSmtp.clean();
         guiceJamesServer.stop();
+        System.clearProperty(VacationMailet.EXPLICIT_SENDER_PROPERTY);
     }
 
     @Category(BasicFeature.class)


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


[james-project] 05/05: JAMES-3843 Rewrite VacationRelayIntegrationTest with Mock SMTP server

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 415e1896e1eb469a9617c8191a0b01084d692a6e
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Nov 1 22:52:14 2022 +0700

    JAMES-3843 Rewrite VacationRelayIntegrationTest with Mock SMTP server
---
 .../jmap-draft-integration-testing-common/pom.xml  |  4 ++
 .../org/apache/james/jmap/MockSmtpTestRule.java    | 74 ++++++++++++++++++++++
 .../james/jmap/VacationRelayIntegrationTest.java   | 40 ++++++++----
 3 files changed, 104 insertions(+), 14 deletions(-)

diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/pom.xml b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/pom.xml
index 96fcb9264d..62d10065b1 100644
--- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/pom.xml
+++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/pom.xml
@@ -101,6 +101,10 @@
             <artifactId>james-server-testing</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>mock-smtp-server</artifactId>
+        </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
             <artifactId>testing-base</artifactId>
diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/MockSmtpTestRule.java b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/MockSmtpTestRule.java
new file mode 100644
index 0000000000..c8e9d8c071
--- /dev/null
+++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/MockSmtpTestRule.java
@@ -0,0 +1,74 @@
+/****************************************************************
+ * 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.jmap;
+
+import java.util.UUID;
+
+import org.apache.james.mock.smtp.server.ConfigurationClient;
+import org.apache.james.util.Host;
+import org.apache.james.util.docker.DockerContainer;
+import org.apache.james.util.docker.Images;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+public class MockSmtpTestRule implements TestRule {
+    public static class DockerMockSmtp {
+        private static final Logger LOGGER = LoggerFactory.getLogger(DockerMockSmtp.class);
+
+        private final DockerContainer mockSmtpServer;
+
+        DockerMockSmtp() {
+            mockSmtpServer = DockerContainer.fromName(Images.MOCK_SMTP_SERVER)
+                .withLogConsumer(outputFrame -> LOGGER.debug("MockSMTP: " + outputFrame.getUtf8String()))
+                .withExposedPorts(25, 8000)
+                .waitingFor(Wait.forLogMessage(".*Mock SMTP server started.*", 1))
+                .withName("james-testing-mock-smtp-server-" + UUID.randomUUID());
+        }
+
+        public ConfigurationClient getConfigurationClient() {
+            return ConfigurationClient.from(Host.from(
+                mockSmtpServer.getHostIp(),
+                mockSmtpServer.getMappedPort(8000)));
+        }
+
+        public String getIPAddress() {
+            return mockSmtpServer.getContainerIp();
+        }
+    }
+
+    private final DockerMockSmtp dockerMockSmtp;
+
+    public MockSmtpTestRule() {
+        this.dockerMockSmtp = new DockerMockSmtp();
+    }
+
+    @Override
+    public Statement apply(Statement statement, Description description) {
+        return dockerMockSmtp.mockSmtpServer.apply(statement, description);
+    }
+
+    public DockerMockSmtp getDockerMockSmtp() {
+        return dockerMockSmtp;
+    }
+}
diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
index 6e022bbed5..96501f725e 100644
--- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
+++ b/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java
@@ -22,33 +22,37 @@ package org.apache.james.jmap;
 import static org.apache.james.jmap.JMAPTestingConstants.DOMAIN;
 import static org.apache.james.jmap.JMAPTestingConstants.LOCALHOST_IP;
 import static org.apache.james.jmap.JMAPTestingConstants.calmlyAwait;
-import static org.hamcrest.Matchers.equalTo;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.IOException;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.net.smtp.SMTPClient;
 import org.apache.james.GuiceJamesServer;
+import org.apache.james.core.MailAddress;
 import org.apache.james.dnsservice.api.InMemoryDNSService;
 import org.apache.james.jmap.api.model.AccountId;
-import org.apache.james.transport.mailets.VacationMailet;
-import org.apache.james.vacation.api.VacationPatch;
 import org.apache.james.jmap.draft.JmapGuiceProbe;
 import org.apache.james.junit.categories.BasicFeature;
 import org.apache.james.mailbox.DefaultMailboxes;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.probe.MailboxProbe;
+import org.apache.james.mock.smtp.server.model.Mail;
 import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.modules.protocols.SmtpGuiceProbe;
 import org.apache.james.probe.DataProbe;
 import org.apache.james.utils.DataProbeImpl;
-import org.apache.james.utils.FakeSmtp;
+import org.apache.james.vacation.api.VacationPatch;
+import org.assertj.core.api.SoftAssertions;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import com.github.fge.lambdas.Throwing;
+
 public abstract class VacationRelayIntegrationTest {
 
     private static final String USER = "benwa";
@@ -57,7 +61,7 @@ public abstract class VacationRelayIntegrationTest {
     private static final String REASON = "Message explaining my wonderful vacations";
 
     @ClassRule
-    public static FakeSmtp fakeSmtp = FakeSmtp.withDefaultPort();
+    public static MockSmtpTestRule fakeSmtp = new MockSmtpTestRule();
 
     private GuiceJamesServer guiceJamesServer;
     private JmapGuiceProbe jmapGuiceProbe;
@@ -69,9 +73,8 @@ public abstract class VacationRelayIntegrationTest {
     @Before
     public void setUp() throws Exception {
         getInMemoryDns()
-            .registerMxRecord("yopmail.com", fakeSmtp.getContainer().getContainerIp());
+            .registerMxRecord("yopmail.com", fakeSmtp.getDockerMockSmtp().getIPAddress());
 
-        System.setProperty(VacationMailet.EXPLICIT_SENDER_PROPERTY, "true");
         guiceJamesServer = getJmapServer();
         guiceJamesServer.start();
 
@@ -87,9 +90,9 @@ public abstract class VacationRelayIntegrationTest {
 
     @After
     public void teardown() {
-        fakeSmtp.clean();
+        fakeSmtp.getDockerMockSmtp().getConfigurationClient().clearMails();
+        fakeSmtp.getDockerMockSmtp().getConfigurationClient().clearBehaviors();
         guiceJamesServer.stop();
-        System.clearProperty(VacationMailet.EXPLICIT_SENDER_PROPERTY);
     }
 
     @Category(BasicFeature.class)
@@ -111,10 +114,19 @@ public abstract class VacationRelayIntegrationTest {
         smtpClient.sendShortMessageData("Reply-To: <" + externalMail + ">\r\n\r\ncontent");
 
         calmlyAwait.atMost(1, TimeUnit.MINUTES)
-            .untilAsserted(() ->
-                fakeSmtp.assertEmailReceived(response -> response
-                    .body("[0].from", equalTo(USER_WITH_DOMAIN))
-                    .body("[0].to[0]", equalTo(externalMail))
-                    .body("[0].text", equalTo(REASON))));
+            .untilAsserted(() -> {
+                List<Mail> mails = fakeSmtp.getDockerMockSmtp().getConfigurationClient()
+                    .listMails();
+
+                assertThat(mails).hasSize(1);
+                SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+                    softly.assertThat(mails.get(0).getEnvelope().getFrom()).isEqualTo(MailAddress.nullSender());
+                    softly.assertThat(mails.get(0).getEnvelope().getRecipients())
+                        .containsOnly(Mail.Recipient.builder()
+                            .address(new MailAddress(externalMail))
+                            .build());
+                    softly.assertThat(mails.get(0).getMessage()).contains(REASON);
+                }));
+            });
     }
 }


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


[james-project] 03/05: JAMES-3843 Drop extra parameters for VacationMailet

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 f1d4ab6329f5b991c967a8041a65585b4b73e157
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Nov 1 22:51:30 2022 +0700

    JAMES-3843 Drop extra parameters for VacationMailet
---
 .../java/org/apache/james/transport/mailets/VacationMailet.java     | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationMailet.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationMailet.java
index 1d8fc4485f..a2f0ef3850 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationMailet.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/VacationMailet.java
@@ -46,15 +46,12 @@ import reactor.core.publisher.Mono;
 
 public class VacationMailet extends GenericMailet {
 
-    public static final String EXPLICIT_SENDER_PROPERTY = "james.vacation.sender.explicit";
-
     private static final Logger LOGGER = LoggerFactory.getLogger(VacationMailet.class);
 
     private final VacationService vacationService;
     private final ZonedDateTimeProvider zonedDateTimeProvider;
     private final AutomaticallySentMailDetector automaticallySentMailDetector;
     private final MimeMessageBodyGenerator mimeMessageBodyGenerator;
-    private final boolean explicitSender;
 
     @Inject
     public VacationMailet(VacationService vacationService, ZonedDateTimeProvider zonedDateTimeProvider,
@@ -64,7 +61,6 @@ public class VacationMailet extends GenericMailet {
         this.zonedDateTimeProvider = zonedDateTimeProvider;
         this.automaticallySentMailDetector = automaticallySentMailDetector;
         this.mimeMessageBodyGenerator = mimeMessageBodyGenerator;
-        this.explicitSender = Boolean.parseBoolean(System.getProperty(EXPLICIT_SENDER_PROPERTY, "false"));
     }
 
     @Override
@@ -143,7 +139,7 @@ public class VacationMailet extends GenericMailet {
     }
 
     private void sendNotification(VacationReply vacationReply) throws MessagingException {
-        getMailetContext().sendMail(explicitSender ? vacationReply.getSender() : MailAddress.nullSender(),
+        getMailetContext().sendMail(MailAddress.nullSender(),
             vacationReply.getRecipients(),
             vacationReply.getMimeMessage());
     }


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


[james-project] 02/05: JAMES-3843 Support nullSender in mockSMTP

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 5fa6a93e6aaa71b51a7cafab4524f1075ede3e43
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Nov 1 22:50:59 2022 +0700

    JAMES-3843 Support nullSender in mockSMTP
---
 server/mailet/mock-smtp-server/pom.xml             |  2 +-
 .../james/mock/smtp/server/MockMessageHandler.java |  3 +++
 .../apache/james/mock/smtp/server/model/Mail.java  | 15 +++++++++++
 .../mock/smtp/server/ConfigurationClientTest.java  | 31 ++++++++++++++++++++++
 4 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/server/mailet/mock-smtp-server/pom.xml b/server/mailet/mock-smtp-server/pom.xml
index 707f7ff6e9..c9d3c10949 100644
--- a/server/mailet/mock-smtp-server/pom.xml
+++ b/server/mailet/mock-smtp-server/pom.xml
@@ -129,7 +129,7 @@
                     <to>
                         <image>linagora/mock-smtp-server</image>
                         <tags>
-                            <tag>0.5</tag>
+                            <tag>0.6</tag>
                         </tags>
                     </to>
                     <container>
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockMessageHandler.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockMessageHandler.java
index 1d50fc6bd3..1f975f15c9 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockMessageHandler.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockMessageHandler.java
@@ -187,6 +187,9 @@ public class MockMessageHandler implements MessageHandler {
     }
 
     private MailAddress parse(String mailAddress) {
+        if (mailAddress.isEmpty()) {
+            return MailAddress.nullSender();
+        }
         try {
             return new MailAddress(mailAddress);
         } catch (AddressException e) {
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mail.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mail.java
index c8e683f83c..9008a76b5b 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mail.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mail.java
@@ -26,6 +26,8 @@ import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Stream;
 
+import javax.mail.internet.AddressException;
+
 import org.apache.james.core.MailAddress;
 
 import com.fasterxml.jackson.annotation.JsonUnwrapped;
@@ -231,6 +233,19 @@ public class Mail {
                 return this;
             }
 
+            public Builder from(String from) {
+                if (from.equals("<>")) {
+                    this.from = MailAddress.nullSender();
+                } else {
+                    try {
+                        this.from = new MailAddress(from);
+                    } catch (AddressException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+                return this;
+            }
+
             public Builder addRecipientMailAddress(MailAddress mailAddress) {
                 this.recipients.add(Recipient.of(mailAddress));
                 return this;
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConfigurationClientTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConfigurationClientTest.java
index c85a80d6c7..3586940046 100644
--- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConfigurationClientTest.java
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConfigurationClientTest.java
@@ -22,7 +22,9 @@ package org.apache.james.mock.smtp.server;
 import static org.apache.james.mock.smtp.server.Fixture.BEHAVIOR_LIST;
 import static org.assertj.core.api.Assertions.assertThat;
 
+import org.apache.james.core.MailAddress;
 import org.apache.james.mock.smtp.server.Fixture.MailsFixutre;
+import org.apache.james.mock.smtp.server.model.Mail;
 import org.apache.james.mock.smtp.server.model.SMTPExtension;
 import org.apache.james.mock.smtp.server.model.SMTPExtensions;
 import org.junit.jupiter.api.AfterEach;
@@ -133,6 +135,35 @@ class ConfigurationClientTest {
             .containsExactly(MailsFixutre.MAIL_1, MailsFixutre.MAIL_2);
     }
 
+    @Test
+    void listMailsShouldReturnMailWithNullSender() throws Exception {
+        final Mail mail = new Mail(
+            Mail.Envelope.builder()
+                .from(MailAddress.nullSender())
+                .addRecipientMailAddress(new MailAddress(Fixture.ALICE))
+                .addRecipient(Mail.Recipient.builder()
+                    .address(new MailAddress(Fixture.JACK))
+                    .addParameter(Mail.Parameter.builder()
+                        .name("param1")
+                        .value("value1")
+                        .build())
+                    .addParameter(Mail.Parameter.builder()
+                        .name("param2")
+                        .value("value2")
+                        .build())
+                    .build())
+                .addMailParameter(Mail.Parameter.builder()
+                    .name("param3")
+                    .value("value3")
+                    .build())
+                .build(),
+            "bob to alice and jack");
+        mailRepository.store(mail);
+
+        assertThat(testee.listMails())
+            .containsExactly(mail);
+    }
+
     @Test
     void shouldReturnVersion() {
         mailRepository.store(MailsFixutre.MAIL_1);


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


[james-project] 04/05: JAMES-3843 Bump mock SMTP Image to 0.6

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 05bba94dd03d2e464792bea7ae5ee45e9dc2622d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Nov 1 22:51:53 2022 +0700

    JAMES-3843 Bump mock SMTP Image to 0.6
---
 server/testing/src/main/java/org/apache/james/util/docker/Images.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/testing/src/main/java/org/apache/james/util/docker/Images.java b/server/testing/src/main/java/org/apache/james/util/docker/Images.java
index 61074e7596..9b227cab8e 100644
--- a/server/testing/src/main/java/org/apache/james/util/docker/Images.java
+++ b/server/testing/src/main/java/org/apache/james/util/docker/Images.java
@@ -27,5 +27,5 @@ public interface Images {
     String ELASTICSEARCH_7 = "docker.elastic.co/elasticsearch/elasticsearch:7.10.2";
     String OPENSEARCH = "opensearchproject/opensearch:2.1.0";
     String TIKA = "apache/tika:1.28.2";
-    String MOCK_SMTP_SERVER = "linagora/mock-smtp-server:0.4";
+    String MOCK_SMTP_SERVER = "linagora/mock-smtp-server:0.6";
 }


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