james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [07/50] [abbrv] james-project git commit: JAMES-1877 Extract RemoteDelivery configuration to an other class
Date Tue, 10 Jan 2017 14:18:22 GMT
JAMES-1877 Extract RemoteDelivery configuration to an other class


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

Branch: refs/heads/master
Commit: 6fa52984020803b4d4c7de43d42e6dad3bfad6a6
Parents: 61c6309
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Nov 30 11:09:09 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Tue Jan 10 15:04:27 2017 +0700

----------------------------------------------------------------------
 mailet/base/pom.xml                             |   5 +
 .../org/apache/mailet/base/GenericMailet.java   |   2 +-
 .../java/org/apache/mailet/base/MailetUtil.java |  12 +-
 .../org/apache/mailet/base/MailetUtilTest.java  |   9 +-
 .../james/transport/mailets/RemoteDelivery.java | 281 +-----
 .../RemoteDeliveryConfiguration.java            | 288 ++++++
 .../mailets/remoteDelivery/Repeat.java          |   2 +-
 .../RemoteDeliveryConfigurationTest.java        | 911 +++++++++++++++++++
 .../mailets/remoteDelivery/RepeatTest.java      |   6 +-
 9 files changed, 1267 insertions(+), 249 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6fa52984/mailet/base/pom.xml
----------------------------------------------------------------------
diff --git a/mailet/base/pom.xml b/mailet/base/pom.xml
index d40cc5d..0c47808 100644
--- a/mailet/base/pom.xml
+++ b/mailet/base/pom.xml
@@ -76,6 +76,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-guava</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/6fa52984/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java b/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
index c56a226..741f3f7 100644
--- a/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
+++ b/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
@@ -79,7 +79,7 @@ public abstract class GenericMailet implements Mailet, MailetConfig {
         if (config == null) {
             throw new NullPointerException("Mailet configuration must be set before getInitParameter is called.");
         }
-        return MailetUtil.getInitParameter(config, name, defaultValue);
+        return MailetUtil.getInitParameter(config, name).or(defaultValue);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/6fa52984/mailet/base/src/main/java/org/apache/mailet/base/MailetUtil.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/MailetUtil.java b/mailet/base/src/main/java/org/apache/mailet/base/MailetUtil.java
index 0155d5c..642f760 100644
--- a/mailet/base/src/main/java/org/apache/mailet/base/MailetUtil.java
+++ b/mailet/base/src/main/java/org/apache/mailet/base/MailetUtil.java
@@ -23,6 +23,8 @@ package org.apache.mailet.base;
 
 import org.apache.mailet.MailetConfig;
 
+import com.google.common.base.Optional;
+
 
 /**
  * Collects utility methods.
@@ -91,20 +93,18 @@ public class MailetUtil {
      * <p>Gets a boolean valued init parameter.</p>
      * @param config not null
      * @param name name of the init parameter to be queried
-     * @param defaultValue this value will be substituted when the named value
-     * cannot be parse or when the init parameter is absent
      * @return true when the init parameter is <code>true</code> (ignoring case);
      * false when the init parameter is <code>false</code> (ignoring case);
      * otherwise the default value
      */
-    public static boolean getInitParameter(MailetConfig config, String name, boolean defaultValue) {
+    public static Optional<Boolean> getInitParameter(MailetConfig config, String name) {
         String value = config.getInitParameter(name);
         if ("true".equalsIgnoreCase(value)) {
-            return true;
+            return Optional.of(true);
         }
         if ("false".equalsIgnoreCase(value)){
-            return false;
+            return Optional.of(false);
         }
-        return defaultValue;
+        return Optional.absent();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6fa52984/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java b/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
index db1f131..cb56b99 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
@@ -20,6 +20,7 @@
 package org.apache.mailet.base;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.guava.api.Assertions.assertThat;
 
 import org.apache.mailet.base.test.FakeMailetConfig;
 import org.junit.Test;
@@ -27,6 +28,7 @@ import org.junit.Test;
 public class MailetUtilTest {
 
     private static final String A_PARAMETER = "aParameter";
+    public static final String DEFAULT_VALUE = "default";
 
     @Test
     public void getInitParameterShouldReturnTrueWhenIsValueTrueLowerCase() {
@@ -77,17 +79,16 @@ public class MailetUtilTest {
     }
 
     @Test
-    public void getInitParameterShouldReturnDefaultValueWhenNull() {
+    public void getInitParameterShouldReturnAbsentWhenNull() {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .build();
-        assertThat(MailetUtil.getInitParameter(mailetConfig, A_PARAMETER, false)).isFalse();
-        assertThat(MailetUtil.getInitParameter(mailetConfig, A_PARAMETER, true)).isTrue();
+        assertThat(MailetUtil.getInitParameter(mailetConfig, A_PARAMETER)).isAbsent();
     }
 
     private boolean getParameterValued(String value, boolean defaultValue) {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
             .setProperty(A_PARAMETER, value)
             .build();
-        return MailetUtil.getInitParameter(mailetConfig, A_PARAMETER, defaultValue);
+        return MailetUtil.getInitParameter(mailetConfig, A_PARAMETER).or(defaultValue);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/6fa52984/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
index 88f8ea7..0067607 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
@@ -33,11 +33,9 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.Hashtable;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
-import java.util.StringTokenizer;
 import java.util.Vector;
 import java.util.concurrent.TimeUnit;
 
@@ -65,8 +63,7 @@ import org.apache.james.queue.api.MailQueue.MailQueueException;
 import org.apache.james.queue.api.MailQueue.MailQueueItem;
 import org.apache.james.queue.api.MailQueueFactory;
 import org.apache.james.transport.mailets.remoteDelivery.Delay;
-import org.apache.james.transport.mailets.remoteDelivery.DelaysAndMaxRetry;
-import org.apache.james.transport.mailets.remoteDelivery.HeloNameProvider;
+import org.apache.james.transport.mailets.remoteDelivery.RemoteDeliveryConfiguration;
 import org.apache.james.transport.mailets.remoteDelivery.RemoteDeliverySocketFactory;
 import org.apache.mailet.HostAddress;
 import org.apache.mailet.Mail;
@@ -156,101 +153,23 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
     private final DomainList domainList;
     private final MailQueueFactory queueFactory;
     private final Metric outgoingMailsMetric;
-    private final Properties defprops; // Default properties for the JavaMail Session
     private final Collection<Thread> workersThreads;
 
-    /**
-     * Flag to define verbose logging messages.
-     */
-    private boolean isDebug = false;
-
-    /**
-     * List of Delay Times. Controls frequency of retry attempts.
-     */
-    private List<Long> delayTimes;
-
-    /**
-     * Maximum no. of retries (Defaults to 5).
-     */
-    private int maxRetries;
-
-    /**
-     * Default number of ms to timeout on smtp delivery
-     */
-    private long smtpTimeout = 180000;
-
-    /**
-     * If false then ANY address errors will cause the transmission to fail
-     */
-    private boolean sendPartial = false;
-
-    /**
-     * The amount of time JavaMail will wait before giving up on a socket
-     * connect()
-     */
-    private int connectionTimeout = 60000;
-
-    /**
-     * No. of threads used to process messages that should be retried.
-     */
-    private int workersThreadCount = 1;
-
-    /**
-     * The server(s) to send all email to
-     */
-    private Collection<String> gatewayServer = null;
-
-    /**
-     * Auth for gateway server
-     */
-    private String authUser = null;
-
-    /**
-     * Password for gateway server
-     */
-    private String authPass = null;
-
-    /**
-     * True, if the bind configuration parameter is supplied,
-     * RemoteDeliverySocketFactory will be used in this case.
-     */
-    private boolean isBindUsed = false;
+    private MailQueue queue;
+    private Logger logger;
+    private RemoteDeliveryConfiguration configuration;
 
     /**
      * Flag used by 'run' method to end itself.
      */
     private volatile boolean destroyed = false;
 
-    /**
-     * the processor for creating Bounces
-     */
-    private String bounceProcessor = null;
-
-
-    /**
-     * The retry count dnsProblemErrors
-     */
-    private int dnsProblemRetry = 0;
-
-    private MailQueue queue;
-
-    private Logger logger;
-
-    private boolean usePriority;
-
-    private boolean startTLS = false;
-
-    private boolean isSSLEnable = false;
-
-    private HeloNameProvider heloNameProvider;
-
     @Inject
     public RemoteDelivery(DNSService dnsServer, DomainList domainList, MailQueueFactory queueFactory, MetricFactory metricFactory) {
         this.dnsServer = dnsServer;
         this.domainList = domainList;
         this.queueFactory = queueFactory;
         this.outgoingMailsMetric = metricFactory.generate(OUTGOING_MAILS);
-        this.defprops = new Properties();
         this.workersThreads = new Vector<Thread>();
     }
 
@@ -261,124 +180,20 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
      * @throws MessagingException on failure to initialize attributes.
      */
     public void init() throws MessagingException {
-        // Set isDebug flag.
-        isDebug = (getInitParameter("debug") == null) ? false : Boolean.valueOf(getInitParameter("debug"));
-
         logger = getMailetContext().getLogger();
-
-        try {
-            int intendedMaxRetries = Integer.parseInt(getInitParameter("maxRetries", "5"));
-            DelaysAndMaxRetry delaysAndMaxRetry = DelaysAndMaxRetry.from(intendedMaxRetries, getInitParameter("delayTime"));
-            maxRetries = delaysAndMaxRetry.getMaxRetries();
-            delayTimes = delaysAndMaxRetry.getExpendedDelays();
-        } catch (Exception e) {
-            log("Invalid maxRetries setting: " + getInitParameter("maxRetries"));
-        }
-        // Get the path for the 'Outgoing' repository. This is the place on the
-        // file system where Mail objects will be saved during the 'delivery'
-        // processing. This can be changed to a repository on a database (e.g.
-        // db://maildb/spool/retry).
-        String outgoing = getInitParameter("outgoing");
-        if (outgoing == null) {
-            outgoing = "outgoing";
-        }
-        queue = queueFactory.getQueue(outgoing);
-
-        try {
-            if (getInitParameter("timeout") != null) {
-                smtpTimeout = Integer.parseInt(getInitParameter("timeout"));
-            }
-        } catch (Exception e) {
-            log("Invalid timeout setting: " + getInitParameter("timeout"));
-        }
-
-        try {
-            if (getInitParameter("connectiontimeout") != null) {
-                connectionTimeout = Integer.parseInt(getInitParameter("connectiontimeout"));
-            }
-        } catch (Exception e) {
-            log("Invalid timeout setting: " + getInitParameter("timeout"));
-        }
-
-        sendPartial = (getInitParameter("sendpartial") == null) ? false : Boolean.valueOf(getInitParameter("sendpartial"));
-
-        bounceProcessor = getInitParameter("bounceProcessor");
-
-        String sTLS = getInitParameter("startTLS");
-        if (sTLS != null) {
-            startTLS = Boolean.valueOf(sTLS);
-        }
-
-        isSSLEnable = (getInitParameter("sslEnable") == null) ? false : Boolean.valueOf(getInitParameter("sslEnable"));
-
-        String gateway = getInitParameter("gateway");
-        String gatewayPort = getInitParameter("gatewayPort");
-
-        if (gateway != null) {
-            gatewayServer = new ArrayList<String>();
-            StringTokenizer st = new StringTokenizer(gateway, ",");
-            while (st.hasMoreTokens()) {
-                String server = st.nextToken().trim();
-                if (server.indexOf(':') < 0 && gatewayPort != null) {
-                    server += ":";
-                    server += gatewayPort;
-                }
-
-                if (isDebug)
-                    log("Adding SMTP gateway: " + server);
-                gatewayServer.add(server);
-            }
-            authUser = getInitParameter("gatewayUsername");
-            // backward compatibility with 2.3.x
-            if (authUser == null) {
-                authUser = getInitParameter("gatewayusername");
-            }
-            authPass = getInitParameter("gatewayPassword");
-        }
-
-        /*
-      JavaMail delivery socket binds to this local address. If null the
-      JavaMail default will be used.
-     */
-        String bindAddress = getInitParameter("bind");
-        isBindUsed = bindAddress != null;
+        configuration = new RemoteDeliveryConfiguration(getMailetConfig(), domainList);
+        queue = queueFactory.getQueue(configuration.getOutGoingQueueName());
+        initDeliveryThreads();
         try {
-            if (isBindUsed)
-                RemoteDeliverySocketFactory.setBindAdress(bindAddress);
+            if (configuration.isBindUsed())
+                RemoteDeliverySocketFactory.setBindAdress(configuration.getBindAddress());
         } catch (UnknownHostException e) {
-            log("Invalid bind setting (" + bindAddress + "): " + e.toString());
+            log("Invalid bind setting (" + configuration.getBindAddress() + "): " + e.toString());
         }
-
-
-        // deal with <mail.*> attributes, passing them to javamail
-        Iterator<String> i = getInitParameterNames();
-        while (i.hasNext()) {
-            String name = i.next();
-            if (name.startsWith("mail.")) {
-                defprops.put(name, getInitParameter(name));
-            }
-
-        }
-
-        String dnsRetry = getInitParameter("maxDnsProblemRetries");
-        if (dnsRetry != null && !dnsRetry.equals("")) {
-            dnsProblemRetry = Integer.parseInt(dnsRetry);
-        }
-
-        heloNameProvider = new HeloNameProvider(getInitParameter("heloName"), domainList);
-
-        String prio = getInitParameter("usePriority");
-        if (prio != null) {
-            usePriority = Boolean.valueOf(prio);
-        }
-
-        // Start Workers Threads.
-        workersThreadCount = Integer.parseInt(getInitParameter("deliveryThreads"));
-        initDeliveryThreads();
     }
 
     private void initDeliveryThreads() {
-        for (int a = 0; a < workersThreadCount; a++) {
+        for (int a = 0; a < configuration.getWorkersThreadCount(); a++) {
             String threadName = "Remote delivery thread (" + a + ")";
             Thread t = new Thread(this, threadName);
             t.start();
@@ -393,10 +208,10 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
      * @return the next delay time to use, given the retry count
      */
     private long getNextDelay(int retry_count) {
-        if (retry_count > delayTimes.size()) {
+        if (retry_count > configuration.getDelayTimes().size()) {
             return Delay.DEFAULT_DELAY_TIME;
         }
-        return delayTimes.get(retry_count - 1);
+        return configuration.getDelayTimes().get(retry_count - 1);
     }
 
     @Override
@@ -416,17 +231,17 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
     @Override
     public void service(Mail mail) throws MessagingException {
         // Do I want to give the internal key, or the message's Message ID
-        if (isDebug) {
+        if (configuration.isDebug()) {
             log("Remotely delivering mail " + mail.getName());
         }
         Collection<MailAddress> recipients = mail.getRecipients();
 
-        if (usePriority) {
+        if (configuration.isUsePriority()) {
 
             // Use highest prio for new emails. See JAMES-1311
             mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, MailPrioritySupport.HIGH_PRIORITY);
         }
-        if (gatewayServer == null) {
+        if (configuration.getGatewayServer() == null) {
             // Must first organize the recipients into distinct servers (name
             // made case insensitive)
             Hashtable<String, Collection<MailAddress>> targets = new Hashtable<String, Collection<MailAddress>>();
@@ -449,7 +264,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
             // outgoing mail repository
             String name = mail.getName();
             for (Map.Entry<String, Collection<MailAddress>> entry : targets.entrySet()) {
-                if (isDebug) {
+                if (configuration.isDebug()) {
                     String logMessageBuffer = "Sending mail to " + entry.getValue() + " on host " + entry.getKey();
                     log(logMessageBuffer);
                 }
@@ -464,8 +279,8 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
             }
         } else {
             // Store the mail unaltered for processing by the gateway server(s)
-            if (isDebug) {
-                String logMessageBuffer = "Sending mail to " + mail.getRecipients() + " via " + gatewayServer;
+            if (configuration.isDebug()) {
+                String logMessageBuffer = "Sending mail to " + mail.getRecipients() + " via " + configuration.getGatewayServer();
                 log(logMessageBuffer);
             }
 
@@ -521,20 +336,20 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
         // messages created by an inputstream.
         props.setProperty("mail.smtp.allow8bitmime", "true");
         // Sets timeout on going connections
-        props.put("mail.smtp.timeout", smtpTimeout + "");
+        props.put("mail.smtp.timeout", configuration.getSmtpTimeout() + "");
 
-        props.put("mail.smtp.connectiontimeout", connectionTimeout + "");
-        props.put("mail.smtp.sendpartial", String.valueOf(sendPartial));
+        props.put("mail.smtp.connectiontimeout", configuration.getConnectionTimeout() + "");
+        props.put("mail.smtp.sendpartial", String.valueOf(configuration.isSendPartial()));
 
-        props.put("mail.smtp.localhost", heloNameProvider.getHeloName());
+        props.put("mail.smtp.localhost", configuration.getHeloNameProvider().getHeloName());
 
         // handle starttls
-        props.put("mail.smtp.starttls.enable", String.valueOf(startTLS));
+        props.put("mail.smtp.starttls.enable", String.valueOf(configuration.isStartTLS()));
 
         // handle SSLEnable
-        props.put("mail.smtp.ssl.enable", String.valueOf(isSSLEnable));
+        props.put("mail.smtp.ssl.enable", String.valueOf(configuration.isSSLEnable()));
 
-        if (isBindUsed) {
+        if (configuration.isBindUsed()) {
             // undocumented JavaMail 1.2 feature, smtp transport will use
             // our socket factory, which will also set the local address
             props.put("mail.smtp.socketFactory.class", RemoteDeliverySocketFactory.class.getClass());
@@ -543,11 +358,11 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
             props.put("mail.smtp.socketFactory.fallback", "false");
         }
 
-        if (authUser != null) {
+        if (configuration.getAuthUser() != null) {
             props.put("mail.smtp.auth", "true");
         }
 
-        props.putAll(defprops);
+        props.putAll(configuration.getJavaxAdditionalProperties());
 
         final Session session = obtainSession(props);
         try {
@@ -567,7 +382,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
                     String key = mail.getName();
 
                     try {
-                        if (isDebug) {
+                        if (configuration.isDebug()) {
                             String message = Thread.currentThread().getName() + " will process mail " + key;
                             log(message);
                         }
@@ -593,7 +408,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
 
                             long delay = getNextDelay(retries);
 
-                            if (usePriority) {
+                            if (configuration.isUsePriority()) {
                                 // Use lowest priority for retries. See JAMES-1311
                                 mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, MailPrioritySupport.LOW_PRIORITY);
                             }
@@ -657,7 +472,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
      */
     private boolean deliver(Mail mail, Session session) {
         try {
-            if (isDebug) {
+            if (configuration.isDebug()) {
                 log("Attempting to deliver " + mail.getName());
             }
             MimeMessage message = mail.getMessage();
@@ -679,7 +494,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
             // Figure out which servers to try to send to. This collection
             // will hold all the possible target servers
             Iterator<HostAddress> targetServers;
-            if (gatewayServer == null) {
+            if (configuration.getGatewayServer() == null) {
                 MailAddress rcpt = recipients.iterator().next();
                 String host = rcpt.getDomain();
 
@@ -703,7 +518,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
                     } catch (NumberFormatException e) {
                         // Unable to parse retryCount
                     }
-                    if (retry == 0 || retry > dnsProblemRetry) {
+                    if (retry == 0 || retry > configuration.getDnsProblemRetry()) {
                         // The domain has no dns entry.. Return a permanent
                         // error
                         return failMessage(mail, new MessagingException(exceptionBuffer), true);
@@ -712,7 +527,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
                     }
                 }
             } else {
-                targetServers = getGatewaySMTPHostAddresses(gatewayServer);
+                targetServers = getGatewaySMTPHostAddresses(configuration.getGatewayServer());
             }
 
             MessagingException lastError = null;
@@ -745,10 +560,10 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
                     SMTPTransport transport = null;
                     try {
                         transport =  (SMTPTransport) session.getTransport(outgoingMailServer);
-                        transport.setLocalHost( props.getProperty("mail.smtp.localhost", heloNameProvider.getHeloName()) );
+                        transport.setLocalHost( props.getProperty("mail.smtp.localhost", configuration.getHeloNameProvider().getHeloName()) );
                         try {
-                            if (authUser != null) {
-                                transport.connect(outgoingMailServer.getHostName(), authUser, authPass);
+                            if (configuration.getAuthUser() != null) {
+                                transport.connect(outgoingMailServer.getHostName(), configuration.getAuthUser(), configuration.getAuthPass());
                             } else {
                                 transport.connect();
                             }
@@ -762,7 +577,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
                             // failing the message at the end of the loop.
 
                             // Also include the stacktrace if debug is enabled. See JAMES-1257
-                            if (isDebug) {
+                            if (configuration.isDebug()) {
                                 log(me.getMessage(), me.getCause());
                             } else {
                                 log(me.getMessage());
@@ -868,7 +683,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
                     }
 
                     if (sfe.getValidUnsentAddresses() != null && sfe.getValidUnsentAddresses().length > 0) {
-                        if (isDebug)
+                        if (configuration.isDebug())
                             log("Send failed, " + sfe.getValidUnsentAddresses().length + " valid addresses remain, continuing with any other servers");
                         lastError = sfe;
                     } else {
@@ -967,7 +782,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
             }
 
             // log the original set of intended recipients
-            if (isDebug)
+            if (configuration.isDebug())
                 log("Recipients: " + recipients);
 
             if (sfe.getInvalidAddresses() != null) {
@@ -987,7 +802,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
                     // Set the recipients for the mail
                     mail.setRecipients(recipients);
 
-                    if (isDebug)
+                    if (configuration.isDebug())
                         log("Invalid recipients: " + recipients);
                     deleteMessage = failMessage(mail, sfe, true);
                 }
@@ -1009,7 +824,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
                     }
                     // Set the recipients for the mail
                     mail.setRecipients(recipients);
-                    if (isDebug)
+                    if (configuration.isDebug())
                         log("Unsent recipients: " + recipients);
                     if (sfe.getClass().getName().endsWith(".SMTPSendFailedException")) {
                         int returnCode = (Integer) invokeGetter(sfe, "getReturnCode");
@@ -1141,7 +956,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
      * JavaMail 1.3.2.
      */
     private void logSendFailedException(SendFailedException sfe) {
-        if (isDebug) {
+        if (configuration.isDebug()) {
             MessagingException me = sfe;
             if (me.getClass().getName().endsWith(".SMTPSendFailedException")) {
                 try {
@@ -1247,7 +1062,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
 
         logBuffer.append(": ");
         out.print(logBuffer.toString());
-        if (isDebug)
+        if (configuration.isDebug())
             ex.printStackTrace(out);
         log(sout.toString());
         if (!permanent) {
@@ -1264,7 +1079,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
                 // Something strange was happen with the errorMessage..
             }
 
-            if (retries < maxRetries) {
+            if (retries < configuration.getMaxRetries()) {
                 logBuffer = new StringBuilder(128).append("Storing message ").append(mail.getName()).append(" into outgoing after ").append(retries).append(" retries");
                 log(logBuffer.toString());
                 ++retries;
@@ -1282,7 +1097,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
             return true;
         }
 
-        if (bounceProcessor != null) {
+        if (configuration.getBounceProcessor() != null) {
             // do the new DSN bounce
             // setting attributes for DSN mailet
             String cause;
@@ -1292,7 +1107,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
                 cause = ex.getMessage();
             }
             mail.setAttribute("delivery-error", cause);
-            mail.setState(bounceProcessor);
+            mail.setState(configuration.getBounceProcessor());
             // re-insert the mail into the spool for getting it passed to the
             // dsn-processor
             MailetContext mc = getMailetContext();
@@ -1330,7 +1145,7 @@ public class RemoteDelivery extends GenericMailet implements Runnable {
         PrintWriter out = new PrintWriter(sout, true);
         String machine;
         try {
-            machine = heloNameProvider.getHeloName();
+            machine = configuration.getHeloNameProvider().getHeloName();
 
         } catch (Exception e) {
             machine = "[address unknown]";

http://git-wip-us.apache.org/repos/asf/james-project/blob/6fa52984/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfiguration.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfiguration.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfiguration.java
new file mode 100644
index 0000000..621f3fe
--- /dev/null
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfiguration.java
@@ -0,0 +1,288 @@
+/****************************************************************
+ * 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.remoteDelivery;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.james.domainlist.api.DomainList;
+import org.apache.mailet.MailetConfig;
+import org.apache.mailet.base.MailetUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+
+public class RemoteDeliveryConfiguration {
+
+    private final static Logger LOGGER = LoggerFactory.getLogger(RemoteDeliveryConfiguration.class);
+
+    public static final String DELIVERY_THREADS = "deliveryThreads";
+    public static final String USE_PRIORITY = "usePriority";
+    public static final String MAX_DNS_PROBLEM_RETRIES = "maxDnsProblemRetries";
+    public static final String HELO_NAME = "heloName";
+    public static final String JAVAX_PREFIX = "mail.";
+    public static final String BIND = "bind";
+    public static final String GATEWAY_PASSWORD = "gatewayPassword";
+    public static final String GATEWAY_USERNAME_COMPATIBILITY = "gatewayusername";
+    public static final String GATEWAY_USERNAME = "gatewayUsername";
+    public static final String GATEWAY_PORT = "gatewayPort";
+    public static final String GATEWAY = "gateway";
+    public static final String SSL_ENABLE = "sslEnable";
+    public static final String START_TLS = "startTLS";
+    public static final String BOUNCE_PROCESSOR = "bounceProcessor";
+    public static final String SENDPARTIAL = "sendpartial";
+    public static final String TIMEOUT = "timeout";
+    public static final String CONNECTIONTIMEOUT = "connectiontimeout";
+    public static final String OUTGOING = "outgoing";
+    public static final String MAX_RETRIES = "maxRetries";
+    public static final String DELAY_TIME = "delayTime";
+    public static final String DEBUG = "debug";
+    public static final int DEFAULT_SMTP_TIMEOUT = 180000;
+    public static final String DEFAULT_OUTGOING_QUEUE_NAME = "outgoing";
+    public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
+    public static final int DEFAULT_DNS_RETRY_PROBLEM = 0;
+    public static final int DEFAULT_MAX_RETRY = 5;
+    public static final String ADDRESS_PORT_SEPARATOR = ":";
+
+    private final boolean isDebug;
+    private final boolean usePriority;
+    private final boolean startTLS;
+    private final boolean isSSLEnable;
+    private final boolean isBindUsed;
+    private final boolean sendPartial;
+    private final int maxRetries;
+    private final long smtpTimeout;
+    private final int dnsProblemRetry;
+    private final int connectionTimeout;
+    private final int workersThreadCount;
+    private final List<Long> delayTimes;
+    private final HeloNameProvider heloNameProvider;
+    private final String outGoingQueueName;
+    private final String bindAddress;
+    private final String bounceProcessor;
+    private final Collection<String> gatewayServer;
+    private final String authUser;
+    private final String authPass;
+    private final Properties javaxAdditionalProperties;
+
+    public RemoteDeliveryConfiguration(MailetConfig mailetConfig, DomainList domainList) {
+        isDebug = MailetUtil.getInitParameter(mailetConfig, DEBUG).or(false);
+        startTLS = MailetUtil.getInitParameter(mailetConfig, START_TLS).or(false);
+        isSSLEnable = MailetUtil.getInitParameter(mailetConfig, SSL_ENABLE).or(false);
+        usePriority = MailetUtil.getInitParameter(mailetConfig, USE_PRIORITY).or(false);
+        sendPartial = MailetUtil.getInitParameter(mailetConfig, SENDPARTIAL).or(false);
+        outGoingQueueName = Optional.fromNullable(mailetConfig.getInitParameter(OUTGOING)).or(DEFAULT_OUTGOING_QUEUE_NAME);
+        bounceProcessor = mailetConfig.getInitParameter(BOUNCE_PROCESSOR);
+        bindAddress = mailetConfig.getInitParameter(BIND);
+
+        DelaysAndMaxRetry delaysAndMaxRetry = computeDelaysAndMaxRetry(mailetConfig);
+        maxRetries = delaysAndMaxRetry.getMaxRetries();
+        delayTimes = delaysAndMaxRetry.getExpendedDelays();
+        smtpTimeout = computeSmtpTimeout(mailetConfig);
+        connectionTimeout = computeConnectionTimeout(mailetConfig);
+        dnsProblemRetry = computeDnsProblemRetry(mailetConfig);
+        heloNameProvider = new HeloNameProvider(mailetConfig.getInitParameter(HELO_NAME), domainList);
+        workersThreadCount = Integer.valueOf(mailetConfig.getInitParameter(DELIVERY_THREADS));
+
+        String gatewayPort = mailetConfig.getInitParameter(GATEWAY_PORT);
+        String gateway = mailetConfig.getInitParameter(GATEWAY);
+        gatewayServer = computeGatewayServers(gatewayPort, gateway);
+        if (gateway != null) {
+            authUser = computeGatewayUser(mailetConfig);
+            authPass = mailetConfig.getInitParameter(GATEWAY_PASSWORD);
+        } else {
+            authUser = null;
+            authPass = null;
+        }
+        isBindUsed = bindAddress != null;
+        javaxAdditionalProperties = computeJavaxProperties(mailetConfig);
+    }
+
+    private Properties computeJavaxProperties(MailetConfig mailetConfig) {
+        Properties result = new Properties();
+        // deal with <mail.*> attributes, passing them to javamail
+        for (String propertyName : ImmutableList.copyOf(mailetConfig.getInitParameterNames())) {
+            if (propertyName.startsWith(JAVAX_PREFIX)) {
+                result.put(propertyName, mailetConfig.getInitParameter(propertyName));
+            }
+        }
+        return result;
+    }
+
+    private int computeDnsProblemRetry(MailetConfig mailetConfig) {
+        String dnsRetry = mailetConfig.getInitParameter(MAX_DNS_PROBLEM_RETRIES);
+        if (!Strings.isNullOrEmpty(dnsRetry)) {
+            return Integer.valueOf(dnsRetry);
+        } else {
+            return DEFAULT_DNS_RETRY_PROBLEM;
+        }
+    }
+
+    private int computeConnectionTimeout(MailetConfig mailetConfig) {
+        try {
+            return Integer.valueOf(
+                Optional.fromNullable(mailetConfig.getInitParameter(CONNECTIONTIMEOUT))
+                    .or(String.valueOf(DEFAULT_CONNECTION_TIMEOUT)));
+        } catch (Exception e) {
+            LOGGER.warn("Invalid timeout setting: " + mailetConfig.getInitParameter(TIMEOUT));
+            return DEFAULT_CONNECTION_TIMEOUT;
+        }
+    }
+
+    private long computeSmtpTimeout(MailetConfig mailetConfig) {
+        try {
+            if (mailetConfig.getInitParameter(TIMEOUT) != null) {
+                return Integer.valueOf(mailetConfig.getInitParameter(TIMEOUT));
+            } else {
+                return DEFAULT_SMTP_TIMEOUT;
+            }
+        } catch (Exception e) {
+            LOGGER.warn("Invalid timeout setting: " + mailetConfig.getInitParameter(TIMEOUT));
+            return DEFAULT_SMTP_TIMEOUT;
+        }
+    }
+
+    private DelaysAndMaxRetry computeDelaysAndMaxRetry(MailetConfig mailetConfig) {
+        try {
+            int intendedMaxRetries = Integer.valueOf(
+                Optional.fromNullable(mailetConfig.getInitParameter(MAX_RETRIES))
+                    .or(String.valueOf(DEFAULT_MAX_RETRY)));
+            return DelaysAndMaxRetry.from(intendedMaxRetries, mailetConfig.getInitParameter(DELAY_TIME));
+        } catch (Exception e) {
+            LOGGER.warn("Invalid maxRetries setting: " + mailetConfig.getInitParameter(MAX_RETRIES));
+            return DelaysAndMaxRetry.defaults();
+        }
+    }
+
+    private String computeGatewayUser(MailetConfig mailetConfig) {
+        // backward compatibility with 2.3.x
+        String user = mailetConfig.getInitParameter(GATEWAY_USERNAME);
+        if (user == null) {
+            return mailetConfig.getInitParameter(GATEWAY_USERNAME_COMPATIBILITY);
+        }
+        return user;
+    }
+
+    private List<String> computeGatewayServers(String gatewayPort, String gateway) {
+        if (gateway != null) {
+            ImmutableList.Builder<String> builder = ImmutableList.builder();
+            Iterable<String> gatewayParts = Splitter.on(',').split(gateway);
+            for(String gatewayPart : gatewayParts) {
+                builder.add(parsePart(gatewayPort, gatewayPart));
+            }
+            return builder.build();
+        } else {
+            return ImmutableList.of();
+        }
+    }
+
+    private String parsePart(String gatewayPort, String gatewayPart) {
+        String address = gatewayPart.trim();
+        if (address.contains(ADDRESS_PORT_SEPARATOR) && gatewayPort != null) {
+            return address + ADDRESS_PORT_SEPARATOR + gatewayPort;
+        }
+        return address;
+    }
+
+    public boolean isDebug() {
+        return isDebug;
+    }
+
+    public List<Long> getDelayTimes() {
+        return delayTimes;
+    }
+
+    public int getMaxRetries() {
+        return maxRetries;
+    }
+
+    public long getSmtpTimeout() {
+        return smtpTimeout;
+    }
+
+    public boolean isSendPartial() {
+        return sendPartial;
+    }
+
+    public int getConnectionTimeout() {
+        return connectionTimeout;
+    }
+
+    public int getWorkersThreadCount() {
+        return workersThreadCount;
+    }
+
+    public Collection<String> getGatewayServer() {
+        return gatewayServer;
+    }
+
+    public String getAuthUser() {
+        return authUser;
+    }
+
+    public String getAuthPass() {
+        return authPass;
+    }
+
+    public boolean isBindUsed() {
+        return isBindUsed;
+    }
+
+    public String getBounceProcessor() {
+        return bounceProcessor;
+    }
+
+    public boolean isUsePriority() {
+        return usePriority;
+    }
+
+    public boolean isStartTLS() {
+        return startTLS;
+    }
+
+    public boolean isSSLEnable() {
+        return isSSLEnable;
+    }
+
+    public HeloNameProvider getHeloNameProvider() {
+        return heloNameProvider;
+    }
+
+    public String getOutGoingQueueName() {
+        return outGoingQueueName;
+    }
+
+    public Properties getJavaxAdditionalProperties() {
+        return javaxAdditionalProperties;
+    }
+
+    public int getDnsProblemRetry() {
+        return dnsProblemRetry;
+    }
+
+    public String getBindAddress() {
+        return bindAddress;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6fa52984/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/Repeat.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/Repeat.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/Repeat.java
index 0252214..19682b1 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/Repeat.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/Repeat.java
@@ -28,7 +28,7 @@ import com.google.common.collect.Iterables;
 public class Repeat {
 
     public static <T> List<T> repeat(T element, int times) {
-        Preconditions.checkArgument(times > 0, "Times argument should be strictly positive");
+        Preconditions.checkArgument(times >= 0, "Times argument should be strictly positive");
         return ImmutableList.copyOf(
             Iterables.limit(
                 Iterables.cycle(element), times));

http://git-wip-us.apache.org/repos/asf/james-project/blob/6fa52984/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfigurationTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfigurationTest.java
new file mode 100644
index 0000000..ec4e23f
--- /dev/null
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfigurationTest.java
@@ -0,0 +1,911 @@
+/****************************************************************
+ * 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.remoteDelivery;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Properties;
+
+import org.apache.james.domainlist.api.DomainList;
+import org.apache.mailet.base.test.FakeMailetConfig;
+import org.assertj.core.data.MapEntry;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class RemoteDeliveryConfigurationTest {
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    @Test
+    public void isDebugShouldBeFalseByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isDebug()).isFalse();
+    }
+
+    @Test
+    public void isDebugShouldBeTrueIfSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.DEBUG, "true")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isDebug()).isTrue();
+    }
+
+    @Test
+    public void isDebugShouldBeFalseIfSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.DEBUG, "false")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isDebug()).isFalse();
+    }
+
+    @Test
+    public void isDebugShouldBeFalseIfParsingException() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.DEBUG, "invalid")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isDebug()).isFalse();
+    }
+
+    @Test
+    public void getSmtpTimeoutShouldReturnDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getSmtpTimeout())
+            .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_SMTP_TIMEOUT);
+    }
+
+    @Test
+    public void getSmtpTimeoutShouldReturnProvidedValue() {
+        int value = 150000;
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.TIMEOUT, String.valueOf(value))
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getSmtpTimeout())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void getSmtpTimeoutShouldReturnDefaultIfParsingException() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.TIMEOUT, "invalid")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getSmtpTimeout())
+            .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_SMTP_TIMEOUT);
+    }
+
+    @Test
+    public void getSmtpTimeoutShouldReturnProvidedValueWhenZero() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.TIMEOUT, "0")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getSmtpTimeout())
+            .isEqualTo(0);
+    }
+
+    @Test
+    public void getSmtpTimeoutShouldReturnProvidedValueWhenNegativeNumber() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.TIMEOUT, "-1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getSmtpTimeout())
+            .isEqualTo(-1);
+    }
+
+    @Test
+    public void getOutGoingQueueNameShouldReturnDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getOutGoingQueueName())
+            .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_OUTGOING_QUEUE_NAME);
+    }
+
+    @Test
+    public void getOutGoingQueueNameShouldReturnProvidedValue() {
+        String value = "value";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.OUTGOING, value)
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getOutGoingQueueName())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void getConnectionTimeoutShouldReturnDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getConnectionTimeout())
+            .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_CONNECTION_TIMEOUT);
+    }
+
+    @Test
+    public void getConnectionTimeoutShouldReturnProvidedValue() {
+        int value = 150000;
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, String.valueOf(value))
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getConnectionTimeout())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void getConnectionTimeoutShouldReturnDefaultIfParsingException() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, "invalid")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getConnectionTimeout())
+            .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_CONNECTION_TIMEOUT);
+    }
+
+    @Test
+    public void getConnectionTimeoutShouldReturnProvidedValueWhenZero() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, "0")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getConnectionTimeout())
+            .isEqualTo(0);
+    }
+
+    @Test
+    public void getConnectionTimeoutShouldReturnProvidedValueWhenNegativeNumber() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, "-1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getConnectionTimeout())
+            .isEqualTo(-1);
+    }
+
+    @Test
+    public void isSendPartialShouldBeFalseByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSendPartial()).isFalse();
+    }
+
+    @Test
+    public void isSendPartialShouldBeTrueIfSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.SENDPARTIAL, "true")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSendPartial()).isTrue();
+    }
+
+    @Test
+    public void isSendPartialShouldBeFalseIfSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.SENDPARTIAL, "false")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSendPartial()).isFalse();
+    }
+
+    @Test
+    public void isSendPartialShouldBeFalseIfParsingException() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.SENDPARTIAL, "invalid")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSendPartial()).isFalse();
+    }
+
+    @Test
+    public void getBounceProcessorShouldReturnNullByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getBounceProcessor())
+            .isNull();
+    }
+
+    @Test
+    public void getBounceProcessorShouldReturnProvidedValue() {
+        String value = "value";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.BOUNCE_PROCESSOR, value)
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getBounceProcessor())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void isStartTLSShouldBeFalseByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isStartTLS()).isFalse();
+    }
+
+    @Test
+    public void isStartTLSShouldBeTrueIfSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.START_TLS, "true")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isStartTLS()).isTrue();
+    }
+
+    @Test
+    public void isStartTLSShouldBeFalseIfSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.START_TLS, "false")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isStartTLS()).isFalse();
+    }
+
+    @Test
+    public void isStartTLSShouldBeFalseIfParsingException() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.START_TLS, "invalid")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isStartTLS()).isFalse();
+    }
+
+    @Test
+    public void isSSLEnableShouldBeFalseByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSSLEnable()).isFalse();
+    }
+
+    @Test
+    public void isSSLEnableShouldBeTrueIfSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.SSL_ENABLE, "true")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSSLEnable()).isTrue();
+    }
+
+    @Test
+    public void isSSLEnableShouldBeFalseIfSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.SSL_ENABLE, "false")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSSLEnable()).isFalse();
+    }
+
+    @Test
+    public void isSSLEnableShouldBeFalseIfParsingException() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.SSL_ENABLE, "invalid")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSSLEnable()).isFalse();
+    }
+
+    @Test
+    public void isBindUsedShouldBeFalseByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.BIND, "127.0.0.1:25")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isBindUsed()).isTrue();
+    }
+
+    @Test
+    public void getBindAddressShouldBeNullByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getBindAddress()).isNull();
+    }
+
+    @Test
+    public void getBindAddressShouldReturnProvidedValue() {
+        String value = "127.0.0.1:25";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.BIND, value)
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getBindAddress()).isEqualTo(value);
+    }
+
+    @Test
+    public void getDnsProblemRetryShouldReturnDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDnsProblemRetry())
+            .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_DNS_RETRY_PROBLEM);
+    }
+
+    @Test
+    public void getDnsProblemRetryShouldReturnProvidedValue() {
+        int value = 4;
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.MAX_DNS_PROBLEM_RETRIES, String.valueOf(value))
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDnsProblemRetry())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void constructorShouldThrowOnInvalidDnsRetries() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.MAX_DNS_PROBLEM_RETRIES, "invalid")
+            .build();
+
+        expectedException.expect(NumberFormatException.class);
+
+        new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class));
+    }
+
+    @Test
+    public void getDnsProblemRetryShouldReturnProvidedValueWhenZero() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.MAX_DNS_PROBLEM_RETRIES, "0")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDnsProblemRetry())
+            .isEqualTo(0);
+    }
+
+    @Test
+    public void getDnsProblemRetryShouldReturnProvidedValueWhenEmpty() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.MAX_DNS_PROBLEM_RETRIES, "")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDnsProblemRetry())
+            .isEqualTo(0);
+    }
+
+    @Test
+    public void getDnsProblemRetryShouldReturnProvidedValueWhenNegativeNumber() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.MAX_DNS_PROBLEM_RETRIES, "-1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDnsProblemRetry())
+            .isEqualTo(-1);
+    }
+
+    @Test
+    public void constructorShouldThrowOnNonSpecifiedThreadCount() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .build();
+
+        expectedException.expect(NumberFormatException.class);
+
+        new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getWorkersThreadCount();
+    }
+
+    @Test
+    public void getWorkersThreadCountShouldReturnProvidedValue() {
+        int value = 36;
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, String.valueOf(value))
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getWorkersThreadCount())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void constructorShouldThrowOnInvalidThreadCount() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "invalid")
+            .build();
+
+        expectedException.expect(NumberFormatException.class);
+
+        new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getWorkersThreadCount();
+    }
+
+    @Test
+    public void isUsePriorityShouldBeFalseByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isUsePriority()).isFalse();
+    }
+
+    @Test
+    public void isUsePriorityShouldBeTrueIfSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.USE_PRIORITY, "true")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isUsePriority()).isTrue();
+    }
+
+    @Test
+    public void isUsePriorityShouldBeFalseIfSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.USE_PRIORITY, "false")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isUsePriority()).isFalse();
+    }
+
+    @Test
+    public void isUsePriorityShouldBeFalseIfParsingException() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.USE_PRIORITY, "invalid")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isUsePriority()).isFalse();
+    }
+
+    @Test
+    public void getHeloNameProviderShouldCallDomainListByDefault() throws Exception {
+        DomainList domainList = mock(DomainList.class);
+        String value = "value";
+        when(domainList.getDefaultDomain()).thenReturn(value);
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, domainList).getHeloNameProvider().getHeloName())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void getHeloNameProviderShouldTakeCareOfProvidedValue() {
+        String value = "value";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.HELO_NAME, value)
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getHeloNameProvider().getHeloName())
+            .isEqualTo(value);
+    }
+
+    @Test
+    public void getJavaxAdditionalPropertiesShouldBeEmptyByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getJavaxAdditionalProperties())
+            .isEmpty();
+    }
+
+    @Test
+    public void getJavaxAdditionalPropertiesShouldTakeOneEntryIntoAccount() {
+        String key1 = RemoteDeliveryConfiguration.JAVAX_PREFIX + "property1";
+        String value1 = "value1";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(key1, value1)
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getJavaxAdditionalProperties())
+            .containsOnly(MapEntry.entry(key1, value1));
+    }
+
+    @Test
+    public void getJavaxAdditionalPropertiesShouldTakeTwoEntriesIntoAccount() {
+        String key1 = RemoteDeliveryConfiguration.JAVAX_PREFIX + "property1";
+        String value1 = "value1";
+        String key2 = RemoteDeliveryConfiguration.JAVAX_PREFIX + "property2";
+        String value2 = "value2";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(key1, value1)
+            .setProperty(key2, value2)
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getJavaxAdditionalProperties())
+            .containsOnly(MapEntry.entry(key1, value1), MapEntry.entry(key2, value2));
+    }
+
+    @Test
+    public void constructorShouldThrowOnNullValueJavaxProperty() {
+        expectedException.expect(NullPointerException.class);
+
+        String key1 = RemoteDeliveryConfiguration.JAVAX_PREFIX + "property1";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(key1, null)
+            .build();
+
+        new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class));
+    }
+
+    @Test
+    public void getJavaxAdditionalPropertiesShouldTakeOneEmptyEntryIntoAccount() {
+        String key1 = RemoteDeliveryConfiguration.JAVAX_PREFIX + "property1";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(key1, "")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getJavaxAdditionalProperties())
+            .containsOnly(MapEntry.entry(key1, ""));
+    }
+
+    @Test
+    public void getGatewayServerShouldBeNullByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getGatewayServer()).isEmpty();
+    }
+
+    @Test
+    public void getGatewayServerShouldReturnProvidedValue() {
+        String value = "127.0.0.1";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY, value)
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getGatewayServer())
+            .containsOnly(value);
+    }
+
+    @Test
+    public void getGatewayServerShouldReturnProvidedValues() {
+        String value1 = "127.0.0.1";
+        String value2 = "domain";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY, value1 + ',' + value2)
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getGatewayServer())
+            .containsOnly(value1, value2);
+    }
+
+    @Test
+    public void getAuthUserShouldBeNullByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isNull();
+    }
+
+    @Test
+    public void getAuthUserShouldBeNullWhenGatewayIsNotSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME, "name")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isNull();
+    }
+
+    @Test
+    public void getAuthUserShouldReturnSpecifiedValueWhenGatewaySpecified() {
+        String value = "name";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME, value)
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isEqualTo(value);
+    }
+
+    @Test
+    public void getAuthUserShouldReturnSpecifiedEmptyValueWhenGatewaySpecified() {
+        String value = "";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME, value)
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isEqualTo(value);
+    }
+
+    @Test
+    public void getAuthUserShouldReturnSpecifiedCompatibilityValueWhenGatewaySpecified() {
+        String value = "name";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME_COMPATIBILITY, value)
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isEqualTo(value);
+    }
+
+    @Test
+    public void getAuthUserShouldReturnSpecifiedEmptyCompatibilityValueWhenGatewaySpecified() {
+        String value = "";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME_COMPATIBILITY, value)
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isEqualTo(value);
+    }
+
+    @Test
+    public void getAuthUserShouldReturnSpecifiedValueWhenValueAndCompatibilitySpecified() {
+        String value = "name";
+        String compatibilityValue = "compatibilityValue";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME, value)
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME_COMPATIBILITY, compatibilityValue)
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isEqualTo(value);
+    }
+
+    @Test
+    public void getAuthPassShouldBeNullByDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthPass()).isNull();
+    }
+
+    @Test
+    public void getAuthPassShouldBeNullWhenGatewayIsNotSpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_PASSWORD, "name")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthPass()).isNull();
+    }
+
+    @Test
+    public void getAuthPassShouldReturnSpecifiedValueWhenGatewaySpecified() {
+        String value = "name";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_PASSWORD, value)
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthPass()).isEqualTo(value);
+    }
+
+    @Test
+    public void getAuthPassShouldReturnSpecifiedEmptyValueWhenGatewaySpecified() {
+        String value = "";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_PASSWORD, value)
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthPass()).isEqualTo(value);
+    }
+
+    @Test
+    public void getMaxRetriesShouldReturnProvidedValue() {
+        int value = 36;
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.MAX_RETRIES, String.valueOf(value))
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getMaxRetries()).isEqualTo(value);
+    }
+
+    @Test
+    public void getMaxRetriesShouldReturnOneWhenZero() {
+        int value = 0;
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.MAX_RETRIES, String.valueOf(value))
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getMaxRetries()).isEqualTo(1);
+    }
+
+    @Test
+    public void getMaxRetriesShouldReturnOneWhenNegativeNumber() {
+        int value = -1;
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.MAX_RETRIES, String.valueOf(value))
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getMaxRetries()).isEqualTo(1);
+    }
+
+    @Test
+    public void getMaxRetriesShouldReturnDefaultWhenNoySpecified() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getMaxRetries())
+            .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_MAX_RETRY);
+    }
+
+    @Test
+    public void getDelayTimesShouldReturnDefault() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDelayTimes())
+            .containsOnly(Delay.DEFAULT_DELAY_TIME, Delay.DEFAULT_DELAY_TIME, Delay.DEFAULT_DELAY_TIME, Delay.DEFAULT_DELAY_TIME, Delay.DEFAULT_DELAY_TIME);
+    }
+
+    @Test
+    public void getDelayTimesShouldWorkWithDefaultConfiguration() {
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.DELAY_TIME, "5000, 100000, 500000")
+            .build();
+
+        assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDelayTimes())
+            .containsOnly(5000L, 100000L, 500000L);
+    }
+
+    @Test
+    public void createFinalJavaxPropertiesShouldProvidePropertiesWithMinimalConfiguration() {
+        String helo = "domain.com";
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.HELO_NAME, helo)
+            .build();
+
+        Properties properties = new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).createFinalJavaxProperties();
+
+
+        assertThat(properties)
+            .containsOnly(MapEntry.entry("mail.smtp.ssl.enable", "false"),
+                MapEntry.entry("mail.smtp.sendpartial", "false"),
+                MapEntry.entry("mail.smtp.allow8bitmime", "true"),
+                MapEntry.entry("mail.smtp.ehlo", "true"),
+                MapEntry.entry("mail.smtp.connectiontimeout", "60000"),
+                MapEntry.entry("mail.smtp.localhost", helo),
+                MapEntry.entry("mail.smtp.timeout", "180000"),
+                MapEntry.entry("mail.debug", "false"),
+                MapEntry.entry("mail.smtp.starttls.enable", "false"));
+    }
+
+    @Test
+    public void createFinalJavaxPropertiesShouldProvidePropertiesWithFullConfigurationWithoutGateway() {
+        String helo = "domain.com";
+        int connectionTimeout = 1856;
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.SSL_ENABLE, "true")
+            .setProperty(RemoteDeliveryConfiguration.SENDPARTIAL, "true")
+            .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, String.valueOf(connectionTimeout))
+            .setProperty(RemoteDeliveryConfiguration.START_TLS, "true")
+            .setProperty(RemoteDeliveryConfiguration.HELO_NAME, helo)
+            .build();
+
+        Properties properties = new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).createFinalJavaxProperties();
+
+
+        assertThat(properties)
+            .containsOnly(MapEntry.entry("mail.smtp.ssl.enable", "true"),
+                MapEntry.entry("mail.smtp.sendpartial", "true"),
+                MapEntry.entry("mail.smtp.allow8bitmime", "true"),
+                MapEntry.entry("mail.smtp.ehlo", "true"),
+                MapEntry.entry("mail.smtp.connectiontimeout", String.valueOf(connectionTimeout)),
+                MapEntry.entry("mail.smtp.localhost", helo),
+                MapEntry.entry("mail.smtp.timeout", "180000"),
+                MapEntry.entry("mail.debug", "false"),
+                MapEntry.entry("mail.smtp.starttls.enable", "true"));
+    }
+
+    @Test
+    public void createFinalJavaxPropertiesShouldProvidePropertiesWithFullConfigurationWithGateway() {
+        String helo = "domain.com";
+        int connectionTimeout = 1856;
+        FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
+            .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1")
+            .setProperty(RemoteDeliveryConfiguration.SSL_ENABLE, "true")
+            .setProperty(RemoteDeliveryConfiguration.SENDPARTIAL, "true")
+            .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, String.valueOf(connectionTimeout))
+            .setProperty(RemoteDeliveryConfiguration.START_TLS, "true")
+            .setProperty(RemoteDeliveryConfiguration.HELO_NAME, helo)
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY, "gateway.domain.com")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME, "user")
+            .setProperty(RemoteDeliveryConfiguration.GATEWAY_PASSWORD, "password")
+            .build();
+
+        Properties properties = new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).createFinalJavaxProperties();
+
+
+        assertThat(properties)
+            .containsOnly(MapEntry.entry("mail.smtp.ssl.enable", "true"),
+                MapEntry.entry("mail.smtp.sendpartial", "true"),
+                MapEntry.entry("mail.smtp.allow8bitmime", "true"),
+                MapEntry.entry("mail.smtp.ehlo", "true"),
+                MapEntry.entry("mail.smtp.connectiontimeout", String.valueOf(connectionTimeout)),
+                MapEntry.entry("mail.smtp.localhost", helo),
+                MapEntry.entry("mail.smtp.timeout", "180000"),
+                MapEntry.entry("mail.debug", "false"),
+                MapEntry.entry("mail.smtp.starttls.enable", "true"),
+                MapEntry.entry("mail.smtp.auth", "true"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6fa52984/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RepeatTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RepeatTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RepeatTest.java
index 13b9968..4ea1640 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RepeatTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RepeatTest.java
@@ -39,10 +39,8 @@ public class RepeatTest {
     }
 
     @Test
-    public void repeatShouldThrowOnZeroTimes() {
-        expectedException.expect(IllegalArgumentException.class);
-
-        Repeat.repeat(new Object(), 0);
+    public void repeatShouldReturnEmptyListOnZeroTimes() {
+        assertThat(Repeat.repeat(new Object(), 0)).isEmpty();
     }
 
     @Test


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


Mime
View raw message