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 2018/01/04 02:24:48 UTC

[1/5] james-project git commit: JAMES-2253 addFooter mailet doesn't work for multipart mail

Repository: james-project
Updated Branches:
  refs/heads/master ab8ea00cd -> 7875cc08f


JAMES-2253 addFooter mailet doesn't work for multipart mail


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

Branch: refs/heads/master
Commit: 71284f56e30688df726aefc804176e357263052a
Parents: 214fc52
Author: apptaro <ap...@gmail.com>
Authored: Mon Dec 18 15:20:18 2017 +0900
Committer: benwa <bt...@linagora.com>
Committed: Thu Jan 4 09:21:13 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/transport/mailets/AddFooter.java   | 12 ++++++++++--
 .../apache/james/transport/mailets/AddFooterTest.java   |  2 --
 2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/71284f56/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddFooter.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddFooter.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddFooter.java
index 2161fbb..a1e20fa 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddFooter.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddFooter.java
@@ -93,11 +93,19 @@ public class AddFooter extends GenericMailet {
         if (part.isMimeType("multipart/mixed")
                 || part.isMimeType("multipart/related")) {
             MimeMultipart multipart = (MimeMultipart) part.getContent();
-            return attachFooterToFirstPart(multipart);
+            boolean added = attachFooterToFirstPart(multipart);
+            if (added) {
+            	part.setContent(multipart);
+            }
+            return added;
 
         } else if (part.isMimeType("multipart/alternative")) {
             MimeMultipart multipart = (MimeMultipart) part.getContent();
-            return attachFooterToAllSubparts(multipart);
+            boolean added = attachFooterToAllSubparts(multipart);
+            if (added) {
+            	part.setContent(multipart);
+            }
+            return added;
         }
         //Give up... we won't attach the footer to this MimePart
         return false;

http://git-wip-us.apache.org/repos/asf/james-project/blob/71284f56/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
index 9f8e512..5c43c22 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
@@ -42,7 +42,6 @@ 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.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -138,7 +137,6 @@ public class AddFooterTest {
         }
     }
 
-    @Ignore("See JAMES-2253")
     @Test
     public void shouldAddFooterWhenMultipartMessage() throws Exception {
         MimeMessage message = MimeMessageBuilder.mimeMessageBuilder()


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


[3/5] james-project git commit: JAMES-2271 Added delay support in MailetContext.sendMail

Posted by bt...@apache.org.
JAMES-2271 Added delay support in MailetContext.sendMail


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

Branch: refs/heads/master
Commit: 4fd780eef11a56fa1fbfdfdb743dd29fa3069ca7
Parents: 71284f5
Author: apptaro <ap...@gmail.com>
Authored: Fri Dec 22 13:52:52 2017 +0900
Committer: benwa <bt...@linagora.com>
Committed: Thu Jan 4 09:22:36 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/mailet/MailetContext.java   | 36 +++++++++++++++
 .../mailet/base/test/FakeMailContext.java       | 13 ++++++
 .../impl/JamesMailetContext.java                | 13 ++++++
 .../impl/JamesMailetContextTest.java            | 46 ++++++++++++++++++++
 4 files changed, 108 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4fd780ee/mailet/api/src/main/java/org/apache/mailet/MailetContext.java
----------------------------------------------------------------------
diff --git a/mailet/api/src/main/java/org/apache/mailet/MailetContext.java b/mailet/api/src/main/java/org/apache/mailet/MailetContext.java
index e43b201..11d658c 100644
--- a/mailet/api/src/main/java/org/apache/mailet/MailetContext.java
+++ b/mailet/api/src/main/java/org/apache/mailet/MailetContext.java
@@ -23,6 +23,7 @@ package org.apache.mailet;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
@@ -338,6 +339,21 @@ public interface MailetContext {
     void sendMail(Mail mail)
             throws MessagingException;
 
+    /**
+     * Sends an outgoing message to the top of this mailet container's root queue.
+     * This is the equivalent of opening an SMTP session to localhost.
+     * The Mail object provides all envelope and content information
+     * 
+     * The given delay and unit are used to calculate the time when
+     * the Mail will be available for deQueue
+     *
+     * @param mail - the message that is to sent
+     * @param delay - the delay value for deQueue
+     * @param unit - the delay unit for deQueue
+     * @throws MessagingException if an error occurs accessing or sending the message
+     */
+    void sendMail(Mail mail, long delay, TimeUnit unit)
+            throws MessagingException;
 
 
     /**
@@ -354,6 +370,26 @@ public interface MailetContext {
      * @throws MessagingException if an error occurs accessing or sending the message
      */
     void sendMail(Mail mail, String state) throws MessagingException;
+    
+    /**
+     * Sends an outgoing message to the top of this mailet container's root queue,
+     * targeting a specific processing state.
+     *
+     * This functionally allows mail treatment done out of the MailetProcessor to be sent
+     * to a specific processor inside the MailetContainer. This is for instance useful for bouncing mail
+     * being remote delivered (asynchronously to original mail treatment)
+     * 
+     * The given delay and unit are used to calculate the time when
+     * the Mail will be available for deQueue
+     *
+     * @param message The message to send
+     * @param state   The state of the message, indicating the name of the processor for
+     *                which the message will be queued
+     * @param delay   The delay value for deQueue
+     * @param unit    The delay unit for deQueue
+     * @throws MessagingException if an error occurs accessing or sending the message
+     */
+    void sendMail(Mail mail, String state, long delay, TimeUnit unit) throws MessagingException;
 
     /**
      * Bounces the message using a standard format with the given message.

http://git-wip-us.apache.org/repos/asf/james-project/blob/4fd780ee/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
index 62d2c9d..3283d9b 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
@@ -27,6 +27,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.concurrent.TimeUnit;
 
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
@@ -404,16 +405,28 @@ public class FakeMailContext implements MailetContext {
             .build());
     }
 
+    @Override
     public void sendMail(Mail mail) throws MessagingException {
         sendMail(mail, Mail.DEFAULT);
     }
 
     @Override
+    public void sendMail(Mail mail, long delay, TimeUnit unit) throws MessagingException {
+        sendMail(mail, Mail.DEFAULT, delay, unit);
+    }
+
+    @Override
     public void sendMail(Mail mail, String state) throws MessagingException {
         mail.setState(state);
         sentMails.add(fromMail(mail));
     }
 
+    @Override
+    public void sendMail(Mail mail, String state, long delay, TimeUnit unit) throws MessagingException {
+        mail.setState(state);
+        sentMails.add(fromMail(mail)); // FIXME delay ignored here for now
+    }
+
     public void setAttribute(String name, Serializable object) {
         attributes.put(name,object);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4fd780ee/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
index 70f2411..c445af0 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
 
 import javax.inject.Inject;
 import javax.mail.Address;
@@ -400,11 +401,23 @@ public class JamesMailetContext implements MailetContext, Configurable {
     }
 
     @Override
+    public void sendMail(Mail mail, long delay, TimeUnit unit) throws MessagingException {
+        sendMail(mail, Mail.DEFAULT, delay, unit);
+    }
+
+    @Override
     public void sendMail(Mail mail, String state) throws MessagingException {
         mail.setAttribute(Mail.SENT_BY_MAILET, "true");
         mail.setState(state);
         rootMailQueue.enQueue(mail);
     }
+    
+    @Override
+    public void sendMail(Mail mail, String state, long delay, TimeUnit unit) throws MessagingException {
+        mail.setAttribute(Mail.SENT_BY_MAILET, "true");
+        mail.setState(state);
+        rootMailQueue.enQueue(mail, delay, unit);
+    }
 
     public void sendMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage message, String state) throws MessagingException {
         MailImpl mail = new MailImpl(MailImpl.getId(), sender, recipients, message);

http://git-wip-us.apache.org/repos/asf/james-project/blob/4fd780ee/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
index 61abeeb..5341325 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
@@ -27,6 +27,8 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
+import java.util.concurrent.TimeUnit;
+
 import javax.mail.internet.MimeMessage;
 
 import org.apache.commons.configuration.HierarchicalConfiguration;
@@ -40,7 +42,9 @@ import org.apache.james.server.core.MailImpl;
 import org.apache.james.user.memory.MemoryUsersRepository;
 import org.apache.mailet.Mail;
 import org.apache.mailet.base.test.MimeMessageBuilder;
+import org.assertj.core.api.JUnitSoftAssertions;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 
@@ -53,6 +57,9 @@ public class JamesMailetContextTest {
     public static final String PASSWORD = "password";
     public static final DNSService DNS_SERVICE = null;
 
+    @Rule
+    public final JUnitSoftAssertions softly = new JUnitSoftAssertions();
+    
     private MemoryDomainList domainList;
     private MemoryUsersRepository usersRepository;
     private JamesMailetContext testee;
@@ -215,6 +222,45 @@ public class JamesMailetContextTest {
     }
 
     @Test
+    public void sendMailShouldEnqueueEmailWithRootStateAndDelayWhenSpecified() throws Exception {
+        MailImpl mail = new MailImpl();
+        mail.setSender(mailAddress);
+        mail.setRecipients(ImmutableList.of(mailAddress));
+        mail.setMessage(MimeMessageBuilder.defaultMimeMessage());
+        testee.sendMail(mail, 5, TimeUnit.MINUTES);
+
+        ArgumentCaptor<Mail> mailArgumentCaptor = ArgumentCaptor.forClass(Mail.class);
+        ArgumentCaptor<Long> delayArgumentCaptor = ArgumentCaptor.forClass(Long.class);
+        ArgumentCaptor<TimeUnit> timeUnitArgumentCaptor = ArgumentCaptor.forClass(TimeUnit.class);
+        verify(spoolMailQueue).enQueue(mailArgumentCaptor.capture(), delayArgumentCaptor.capture(), timeUnitArgumentCaptor.capture());
+        verifyNoMoreInteractions(spoolMailQueue);
+
+        softly.assertThat(mailArgumentCaptor.getValue().getState()).isEqualTo(Mail.DEFAULT);
+        softly.assertThat(delayArgumentCaptor.getValue()).isEqualTo(5L);
+        softly.assertThat(timeUnitArgumentCaptor.getValue()).isEqualTo(TimeUnit.MINUTES);
+    }
+
+    @Test
+    public void sendMailShouldEnqueueEmailWithOtherStateAndDelayWhenSpecified() throws Exception {
+        MailImpl mail = new MailImpl();
+        mail.setSender(mailAddress);
+        mail.setRecipients(ImmutableList.of(mailAddress));
+        mail.setMessage(MimeMessageBuilder.defaultMimeMessage());
+        String other = "other";
+        testee.sendMail(mail, other, 5, TimeUnit.MINUTES);
+
+        ArgumentCaptor<Mail> mailArgumentCaptor = ArgumentCaptor.forClass(Mail.class);
+        ArgumentCaptor<Long> delayArgumentCaptor = ArgumentCaptor.forClass(Long.class);
+        ArgumentCaptor<TimeUnit> timeUnitArgumentCaptor = ArgumentCaptor.forClass(TimeUnit.class);
+        verify(spoolMailQueue).enQueue(mailArgumentCaptor.capture(), delayArgumentCaptor.capture(), timeUnitArgumentCaptor.capture());
+        verifyNoMoreInteractions(spoolMailQueue);
+
+        softly.assertThat(mailArgumentCaptor.getValue().getState()).isEqualTo(other);
+        softly.assertThat(delayArgumentCaptor.getValue()).isEqualTo(5L);
+        softly.assertThat(timeUnitArgumentCaptor.getValue()).isEqualTo(TimeUnit.MINUTES);
+    }
+
+    @Test
     public void sendMailForMessageShouldEnqueueEmailWithRootState() throws Exception {
         MimeMessage message = MimeMessageBuilder.mimeMessageBuilder()
             .addFrom(mailAddress.asString())


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


[2/5] james-project git commit: JAMES-2253 Integration test for AddFooter

Posted by bt...@apache.org.
JAMES-2253 Integration test for AddFooter


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

Branch: refs/heads/master
Commit: 214fc520b6d234a130d722dbd2e391c0146f5266
Parents: ab8ea00
Author: benwa <bt...@linagora.com>
Authored: Thu Dec 28 15:50:19 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jan 4 09:21:13 2018 +0700

----------------------------------------------------------------------
 .../james/transport/mailets/AddFooterTest.java  | 173 +++++++++++++++++++
 1 file changed, 173 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/214fc520/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
new file mode 100644
index 0000000..9f8e512
--- /dev/null
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/AddFooterTest.java
@@ -0,0 +1,173 @@
+/****************************************************************
+ * 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 org.assertj.core.api.Assertions.assertThat;
+
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.MemoryJamesServerMain;
+import org.apache.james.core.MailAddress;
+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.modules.server.ActiveMQQueueModule;
+import org.apache.james.probe.DataProbe;
+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.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.MimeMessageBuilder;
+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;
+
+import com.jayway.awaitility.Awaitility;
+import com.jayway.awaitility.Duration;
+import com.jayway.awaitility.core.ConditionFactory;
+
+public class AddFooterTest {
+
+    private static final String LOCALHOST_IP = "127.0.0.1";
+    private static final int IMAP_PORT = 1143;
+    private static final int SMTP_PORT = 1025;
+    private static final String PASSWORD = "secret";
+
+    private static final String JAMES_APACHE_ORG = "james.org";
+
+    private static final String FROM = "fromUser@" + JAMES_APACHE_ORG;
+    private static final String RECIPIENT = "touser@" + JAMES_APACHE_ORG;
+    public static final String MATCH_ME = "Match me";
+
+    @Rule
+    public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+    private TemporaryJamesServer jamesServer;
+    private ConditionFactory calmlyAwait;
+
+    @Before
+    public void setup() throws Exception {
+        MailetContainer mailetContainer = MailetContainer.builder()
+            .postmaster("postmaster@" + JAMES_APACHE_ORG)
+            .threads(5)
+            .addProcessor(CommonProcessors.root())
+            .addProcessor(CommonProcessors.error())
+            .addProcessor(ProcessorConfiguration.builder()
+                .state("transport")
+                .enableJmx(true)
+                .addMailet(MailetConfiguration.builder()
+                    .matcher(All.class)
+                    .mailet(RemoveMimeHeader.class)
+                    .addProperty("name", "bcc")
+                    .build())
+                .addMailet(MailetConfiguration.builder()
+                    .matcher(All.class)
+                    .mailet(AddFooter.class)
+                    .addProperty("text", MATCH_ME)
+                    .build())
+                .addMailet(MailetConfiguration.builder()
+                    .matcher(RecipientIsLocal.class)
+                    .mailet(LocalDelivery.class)
+                    .build())
+                .build())
+            .build();
+
+        jamesServer = TemporaryJamesServer.builder()
+            .withBase(MemoryJamesServerMain.SMTP_AND_IMAP_MODULE)
+            .withOverrides(new ActiveMQQueueModule())
+            .build(temporaryFolder, mailetContainer);
+        Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
+        calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await();
+
+        DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+        dataProbe.addDomain(JAMES_APACHE_ORG);
+        dataProbe.addUser(RECIPIENT, PASSWORD);
+    }
+
+    @After
+    public void tearDown() {
+        jamesServer.shutdown();
+    }
+
+    @Test
+    public void shouldAddFooterWhenSimpleMessage() throws Exception {
+        MimeMessage message = MimeMessageBuilder.mimeMessageBuilder()
+            .setText("Any content")
+            .setSubject("test")
+            .build();
+
+        Mail mail = FakeMail.builder()
+            .mimeMessage(message)
+            .sender(new MailAddress(FROM))
+            .recipient(new MailAddress(RECIPIENT))
+            .build();
+
+        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG);
+             IMAPMessageReader imapMessageReader = new IMAPMessageReader(LOCALHOST_IP, IMAP_PORT)) {
+            messageSender.sendMessage(mail);
+            calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent);
+
+            calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> imapMessageReader.userReceivedMessage(RECIPIENT, PASSWORD));
+            String processedMessage = imapMessageReader.readFirstMessageInInbox(RECIPIENT, PASSWORD);
+            assertThat(processedMessage).contains(MATCH_ME);
+        }
+    }
+
+    @Ignore("See JAMES-2253")
+    @Test
+    public void shouldAddFooterWhenMultipartMessage() throws Exception {
+        MimeMessage message = MimeMessageBuilder.mimeMessageBuilder()
+            .setMultipartWithBodyParts(
+                MimeMessageBuilder.bodyPartBuilder()
+                    .type("text/plain")
+                    .data("Text message")
+                    .build(),
+                MimeMessageBuilder.bodyPartBuilder()
+                    .data("IMAGE")
+                    .type("application/data")
+                    .build())
+            .setSubject("test")
+            .build();
+
+        Mail mail = FakeMail.builder()
+            .mimeMessage(message)
+            .sender(new MailAddress(FROM))
+            .recipient(new MailAddress(RECIPIENT))
+            .build();
+
+        try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG);
+             IMAPMessageReader imapMessageReader = new IMAPMessageReader(LOCALHOST_IP, IMAP_PORT)) {
+            messageSender.sendMessage(mail);
+            calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent);
+
+            calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> imapMessageReader.userReceivedMessage(RECIPIENT, PASSWORD));
+            String processedMessage = imapMessageReader.readFirstMessageInInbox(RECIPIENT, PASSWORD);
+            assertThat(processedMessage).contains(MATCH_ME);
+        }
+    }
+}


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


[5/5] james-project git commit: JAMES-2273 James should warn when the jwt token is invalid or empty

Posted by bt...@apache.org.
JAMES-2273 James should warn when the jwt token is invalid or empty


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

Branch: refs/heads/master
Commit: 7875cc08f2e3d9c7120f85d80a89b5dffa479f61
Parents: f2be591
Author: quynhn <qn...@linagora.com>
Authored: Wed Dec 27 17:26:35 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jan 4 09:23:59 2018 +0700

----------------------------------------------------------------------
 .../apache/james/jmap/JMAPConfiguration.java    |  2 +
 .../james/jmap/JMAPConfigurationTest.java       | 11 +++
 .../crypto/JamesSignatureHandlerProvider.java   | 11 +++
 .../org/apache/james/jwt/JwtConfiguration.java  | 10 +++
 .../apache/james/jwt/JwtConfigurationTest.java  | 72 ++++++++++++++++++++
 .../apache/james/jwt/PublicKeyProviderTest.java |  2 +-
 6 files changed, 107 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7875cc08/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPConfiguration.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPConfiguration.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPConfiguration.java
index e194e0f..3117929 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPConfiguration.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPConfiguration.java
@@ -82,8 +82,10 @@ public class JMAPConfiguration {
             Preconditions.checkState(enabled.isPresent(), "You should specify if JMAP server should be started");
             Preconditions.checkState(!enabled.get() || !Strings.isNullOrEmpty(keystore), "'keystore' is mandatory");
             Preconditions.checkState(!enabled.get() || !Strings.isNullOrEmpty(secret), "'secret' is mandatory");
+            Preconditions.checkState(!enabled.get() || jwtPublicKeyPem.isPresent(), "'publicKey' is mandatory");
             return new JMAPConfiguration(enabled.get(), keystore, secret, jwtPublicKeyPem, port);
         }
+
     }
 
     private final boolean enabled;

http://git-wip-us.apache.org/repos/asf/james-project/blob/7875cc08/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPConfigurationTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPConfigurationTest.java
index 4ffce68..8dbbda9 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPConfigurationTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPConfigurationTest.java
@@ -85,6 +85,17 @@ public class JMAPConfigurationTest {
     }
 
     @Test
+    public void buildShouldThrowWhenJwtPublicKeyPemIsEmpty() {
+        assertThatThrownBy(() -> JMAPConfiguration.builder()
+            .enable()
+            .keystore("keystore")
+            .secret("secret")
+            .jwtPublicKeyPem(Optional.empty())
+            .build())
+            .isInstanceOf(IllegalStateException.class);
+    }
+
+    @Test
     public void buildShouldWorkWhenRandomPort() {
         JMAPConfiguration expectedJMAPConfiguration = new JMAPConfiguration(ENABLED, "keystore", "secret", Optional.of("file://conf/jwt_publickey"), Optional.empty());
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/7875cc08/server/protocols/jmap/src/test/java/org/apache/james/jmap/crypto/JamesSignatureHandlerProvider.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/crypto/JamesSignatureHandlerProvider.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/crypto/JamesSignatureHandlerProvider.java
index f3d0656..b2b84bf 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/crypto/JamesSignatureHandlerProvider.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/crypto/JamesSignatureHandlerProvider.java
@@ -23,11 +23,21 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Optional;
 
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.jmap.JMAPConfiguration;
 
 public class JamesSignatureHandlerProvider {
+    private static final String JWT_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n" +
+        "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtlChO/nlVP27MpdkG0Bh\n" +
+        "16XrMRf6M4NeyGa7j5+1UKm42IKUf3lM28oe82MqIIRyvskPc11NuzSor8HmvH8H\n" +
+        "lhDs5DyJtx2qp35AT0zCqfwlaDnlDc/QDlZv1CoRZGpQk1Inyh6SbZwYpxxwh0fi\n" +
+        "+d/4RpE3LBVo8wgOaXPylOlHxsDizfkL8QwXItyakBfMO6jWQRrj7/9WDhGf4Hi+\n" +
+        "GQur1tPGZDl9mvCoRHjFrD5M/yypIPlfMGWFVEvV5jClNMLAQ9bYFuOc7H1fEWw6\n" +
+        "U1LZUUbJW9/CH45YXz82CYqkrfbnQxqRb2iVbVjs/sHopHd1NTiCfUtwvcYJiBVj\n" +
+        "kwIDAQAB\n" +
+        "-----END PUBLIC KEY-----";
 
     public JamesSignatureHandler provide() throws Exception {
         FileSystem fileSystem = new FileSystem() {
@@ -51,6 +61,7 @@ public class JamesSignatureHandlerProvider {
                     .enable()
                     .keystore("keystore")
                     .secret("james72laBalle")
+                    .jwtPublicKeyPem(Optional.of(JWT_PUBLIC_KEY))
                     .build());
         signatureHandler.init();
         return signatureHandler;

http://git-wip-us.apache.org/repos/asf/james-project/blob/7875cc08/server/protocols/jwt/src/main/java/org/apache/james/jwt/JwtConfiguration.java
----------------------------------------------------------------------
diff --git a/server/protocols/jwt/src/main/java/org/apache/james/jwt/JwtConfiguration.java b/server/protocols/jwt/src/main/java/org/apache/james/jwt/JwtConfiguration.java
index 3cfcfef..922ea00 100644
--- a/server/protocols/jwt/src/main/java/org/apache/james/jwt/JwtConfiguration.java
+++ b/server/protocols/jwt/src/main/java/org/apache/james/jwt/JwtConfiguration.java
@@ -21,13 +21,23 @@ package org.apache.james.jwt;
 
 import java.util.Optional;
 
+import com.google.common.base.Preconditions;
+
 public class JwtConfiguration {
+    private static final boolean DEFAULT_VALUE = true;
     private final Optional<String> jwtPublicKeyPem;
 
     public JwtConfiguration(Optional<String> jwtPublicKeyPem) {
+        Preconditions.checkState(validPublicKey(jwtPublicKeyPem), "The provided public key is not valid");
         this.jwtPublicKeyPem = jwtPublicKeyPem;
     }
 
+    private boolean validPublicKey(Optional<String> jwtPublicKeyPem) {
+        PublicKeyReader reader = new PublicKeyReader();
+        return jwtPublicKeyPem.map(value -> reader.fromPEM(Optional.of(value)).isPresent())
+            .orElse(DEFAULT_VALUE);
+    }
+
     public Optional<String> getJwtPublicKeyPem() {
         return jwtPublicKeyPem;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7875cc08/server/protocols/jwt/src/test/java/org/apache/james/jwt/JwtConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jwt/src/test/java/org/apache/james/jwt/JwtConfigurationTest.java b/server/protocols/jwt/src/test/java/org/apache/james/jwt/JwtConfigurationTest.java
new file mode 100644
index 0000000..34436a9
--- /dev/null
+++ b/server/protocols/jwt/src/test/java/org/apache/james/jwt/JwtConfigurationTest.java
@@ -0,0 +1,72 @@
+/****************************************************************
+ * 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.jwt;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.Optional;
+
+import org.junit.Test;
+
+public class JwtConfigurationTest {
+    private static final String INVALID_PUBLIC_KEY = "invalidPublicKey";
+    private static final String VALID_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n" +
+        "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtlChO/nlVP27MpdkG0Bh\n" +
+        "16XrMRf6M4NeyGa7j5+1UKm42IKUf3lM28oe82MqIIRyvskPc11NuzSor8HmvH8H\n" +
+        "lhDs5DyJtx2qp35AT0zCqfwlaDnlDc/QDlZv1CoRZGpQk1Inyh6SbZwYpxxwh0fi\n" +
+        "+d/4RpE3LBVo8wgOaXPylOlHxsDizfkL8QwXItyakBfMO6jWQRrj7/9WDhGf4Hi+\n" +
+        "GQur1tPGZDl9mvCoRHjFrD5M/yypIPlfMGWFVEvV5jClNMLAQ9bYFuOc7H1fEWw6\n" +
+        "U1LZUUbJW9/CH45YXz82CYqkrfbnQxqRb2iVbVjs/sHopHd1NTiCfUtwvcYJiBVj\n" +
+        "kwIDAQAB\n" +
+        "-----END PUBLIC KEY-----";
+
+    @Test
+    public void getJwtPublicKeyPemShouldReturnEmptyWhenEmptyPublicKey() throws Exception {
+        JwtConfiguration jwtConfiguration = new JwtConfiguration(Optional.empty());
+
+        assertThat(jwtConfiguration.getJwtPublicKeyPem()).isNotPresent();
+    }
+
+    @Test
+    public void constructorShouldThrowWhenNullPublicKey() throws Exception {
+        assertThatThrownBy(() -> new JwtConfiguration(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void constructorShouldThrowWhenNonePublicKey() throws Exception {
+        assertThatThrownBy(() -> new JwtConfiguration(Optional.of("")))
+            .isInstanceOf(IllegalStateException.class);
+    }
+
+    @Test
+    public void constructorShouldThrowWhenInvalidPublicKey() throws Exception {
+        assertThatThrownBy(() -> new JwtConfiguration(Optional.of(INVALID_PUBLIC_KEY)))
+            .isInstanceOf(IllegalStateException.class);
+    }
+
+    @Test
+    public void getJwtPublicKeyPemShouldReturnWhenValidPublicKey() throws Exception {
+        JwtConfiguration jwtConfiguration = new JwtConfiguration(Optional.of(VALID_PUBLIC_KEY));
+
+        assertThat(jwtConfiguration.getJwtPublicKeyPem()).isPresent();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/7875cc08/server/protocols/jwt/src/test/java/org/apache/james/jwt/PublicKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jwt/src/test/java/org/apache/james/jwt/PublicKeyProviderTest.java b/server/protocols/jwt/src/test/java/org/apache/james/jwt/PublicKeyProviderTest.java
index a48dc79..92dcf77 100644
--- a/server/protocols/jwt/src/test/java/org/apache/james/jwt/PublicKeyProviderTest.java
+++ b/server/protocols/jwt/src/test/java/org/apache/james/jwt/PublicKeyProviderTest.java
@@ -58,7 +58,7 @@ public class PublicKeyProviderTest {
 
     @Test
     public void getShouldThrowWhenPEMKeyNotProvided() {
-        JwtConfiguration configWithPEMKey = new JwtConfiguration(Optional.of(""));
+        JwtConfiguration configWithPEMKey = new JwtConfiguration(Optional.empty());
 
         PublicKeyProvider sut = new PublicKeyProvider(configWithPEMKey, new PublicKeyReader());
 


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


[4/5] james-project git commit: JAMES-2271 FakeMailContext should allow testing delayed sent emails

Posted by bt...@apache.org.
JAMES-2271 FakeMailContext should allow testing delayed sent emails


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

Branch: refs/heads/master
Commit: f2be591a298ae152738b746a79ff51a426ce811e
Parents: 4fd780e
Author: benwa <bt...@linagora.com>
Authored: Fri Dec 29 10:25:16 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jan 4 09:22:36 2018 +0700

----------------------------------------------------------------------
 .../mailet/base/test/FakeMailContext.java       | 87 ++++++++++++++++----
 1 file changed, 70 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f2be591a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
index 3283d9b..9489dbe 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
@@ -40,7 +41,6 @@ import org.apache.mailet.MailetContext;
 import org.slf4j.Logger;
 
 import com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -57,15 +57,14 @@ public class FakeMailContext implements MailetContext {
         return new SentMail.Builder();
     }
 
-    public static SentMail fromMail(Mail mail) throws MessagingException {
+    public static SentMail.Builder fromMail(Mail mail) throws MessagingException {
         return sentMailBuilder()
             .sender(mail.getSender())
             .recipients(mail.getRecipients())
             .message(mail.getMessage())
             .state(mail.getState())
             .attributes(buildAttributesMap(mail))
-            .fromMailet()
-            .build();
+            .fromMailet();
     }
 
     private static ImmutableMap<String, Serializable> buildAttributesMap(Mail mail) {
@@ -114,6 +113,7 @@ public class FakeMailContext implements MailetContext {
             private Map<String, Serializable> attributes = new HashMap<>();
             private Optional<String> state = Optional.empty();
             private Optional<Boolean> fromMailet = Optional.empty();
+            private Optional<Delay> delay = Optional.empty();
 
             public Builder sender(MailAddress sender) {
                 this.sender = sender;
@@ -160,12 +160,17 @@ public class FakeMailContext implements MailetContext {
                 return this;
             }
 
+            public Builder delay(Delay delay) {
+                this.delay = Optional.of(delay);
+                return this;
+            }
+
             public SentMail build() {
                 if (fromMailet.orElse(false)) {
                     this.attribute(Mail.SENT_BY_MAILET, "true");
                 }
                 return new SentMail(sender, recipients.orElse(ImmutableList.<MailAddress>of()), msg,
-                    ImmutableMap.copyOf(attributes), state.orElse(Mail.DEFAULT));
+                    ImmutableMap.copyOf(attributes), state.orElse(Mail.DEFAULT), delay);
             }
         }
 
@@ -175,14 +180,16 @@ public class FakeMailContext implements MailetContext {
         private final Optional<String> subject;
         private final Map<String, Serializable> attributes;
         private final String state;
+        private final Optional<Delay> delay;
 
-        private SentMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage msg, Map<String, Serializable> attributes, String state) {
+        private SentMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage msg, Map<String, Serializable> attributes, String state, Optional<Delay> delay) {
             this.sender = sender;
             this.recipients = ImmutableList.copyOf(recipients);
             this.msg = msg;
             this.subject = getSubject(msg);
             this.attributes = ImmutableMap.copyOf(attributes);
             this.state = state;
+            this.delay = delay;
         }
 
         private Optional<String> getSubject(MimeMessage msg) {
@@ -213,6 +220,11 @@ public class FakeMailContext implements MailetContext {
             return subject;
         }
 
+
+        public Optional<Delay> getDelay() {
+            return delay;
+        }
+
         @Override
         public boolean equals(Object o) {
             if (!(o instanceof SentMail)) {
@@ -221,15 +233,15 @@ public class FakeMailContext implements MailetContext {
 
             SentMail sentMail = (SentMail) o;
 
-            return Objects.equal(this.sender, sentMail.sender)
-                && Objects.equal(this.recipients, sentMail.recipients)
-                && Objects.equal(this.attributes, sentMail.attributes)
-                && Objects.equal(this.state, sentMail.state);
+            return Objects.equals(this.sender, sentMail.sender)
+                && Objects.equals(this.recipients, sentMail.recipients)
+                && Objects.equals(this.attributes, sentMail.attributes)
+                && Objects.equals(this.state, sentMail.state);
         }
 
         @Override
         public int hashCode() {
-            return Objects.hashCode(sender, recipients, attributes, state);
+            return Objects.hash(sender, recipients, attributes, state);
         }
 
         @Override
@@ -243,6 +255,40 @@ public class FakeMailContext implements MailetContext {
         }
     }
 
+    public static class Delay {
+        private final long duration;
+        private final TimeUnit timeUnit;
+
+        public Delay(long duration, TimeUnit timeUnit) {
+            this.duration = duration;
+            this.timeUnit = timeUnit;
+        }
+
+        public long getDuration() {
+            return duration;
+        }
+
+        public TimeUnit getTimeUnit() {
+            return timeUnit;
+        }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof Delay) {
+                Delay delay = (Delay) o;
+
+                return Objects.equals(this.duration, delay.duration)
+                    && Objects.equals(this.timeUnit, delay.timeUnit);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(duration, timeUnit);
+        }
+    }
+
     public static class BouncedMail {
         private final SentMail sentMail;
         private final String message;
@@ -254,6 +300,10 @@ public class FakeMailContext implements MailetContext {
             this.bouncer = bouncer;
         }
 
+        public BouncedMail(SentMail.Builder sentMail, String message, Optional<MailAddress> bouncer) {
+            this(sentMail.build(), message, bouncer);
+        }
+
         public SentMail getSentMail() {
             return sentMail;
         }
@@ -270,16 +320,16 @@ public class FakeMailContext implements MailetContext {
         public boolean equals(Object o) {
             if (o instanceof BouncedMail) {
                 BouncedMail that = (BouncedMail) o;
-                return Objects.equal(this.sentMail, that.sentMail)
-                    && Objects.equal(this.message, that.message)
-                    && Objects.equal(this.bouncer, that.bouncer);
+                return Objects.equals(this.sentMail, that.sentMail)
+                    && Objects.equals(this.message, that.message)
+                    && Objects.equals(this.bouncer, that.bouncer);
             }
             return false;
         }
 
         @Override
         public int hashCode() {
-            return Objects.hashCode(sentMail, message, bouncer);
+            return Objects.hash(sentMail, message, bouncer);
         }
 
         @Override
@@ -418,13 +468,16 @@ public class FakeMailContext implements MailetContext {
     @Override
     public void sendMail(Mail mail, String state) throws MessagingException {
         mail.setState(state);
-        sentMails.add(fromMail(mail));
+        sentMails.add(fromMail(mail).build());
     }
 
     @Override
     public void sendMail(Mail mail, String state, long delay, TimeUnit unit) throws MessagingException {
         mail.setState(state);
-        sentMails.add(fromMail(mail)); // FIXME delay ignored here for now
+        sentMails.add(
+            fromMail(mail)
+                .delay(new Delay(delay, unit))
+                .build());
     }
 
     public void setAttribute(String name, Serializable object) {


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