james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [23/24] james-project git commit: JAMES-2366 Simplify error handling in SMTPMessageSender
Date Fri, 20 Apr 2018 02:13:08 GMT
JAMES-2366 Simplify error handling in SMTPMessageSender


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

Branch: refs/heads/master
Commit: 00ea973a186f73691b7c3be5212736847d65a667
Parents: cf91dd4
Author: benwa <btellier@linagora.com>
Authored: Thu Apr 19 11:05:37 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Apr 20 09:12:09 2018 +0700

----------------------------------------------------------------------
 .../transport/mailets/ContactExtractorTest.java |  5 ++
 .../apache/james/utils/SMTPMessageSender.java   | 81 ++++++++------------
 2 files changed, 37 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/00ea973a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
index 050e177..800a5de 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java
@@ -104,6 +104,11 @@ public class ContactExtractorTest {
         probe.addDomain(DEFAULT_DOMAIN);
         probe.addUser(SENDER, PASSWORD);
         probe.addUser(TO, PASSWORD);
+        probe.addUser(TO2, PASSWORD);
+        probe.addUser(CC, PASSWORD);
+        probe.addUser(CC2, PASSWORD);
+        probe.addUser(BCC, PASSWORD);
+        probe.addUser(BCC2, PASSWORD);
     }
 
     @After

http://git-wip-us.apache.org/repos/asf/james-project/blob/00ea973a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
index 8d132a9..f3d1fb7 100644
--- a/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
+++ b/server/testing/src/main/java/org/apache/james/utils/SMTPMessageSender.java
@@ -37,7 +37,6 @@ import org.apache.mailet.base.test.FakeMail;
 import org.junit.rules.ExternalResource;
 
 import com.github.fge.lambdas.Throwing;
-import com.google.common.base.Throwables;
 
 public class SMTPMessageSender extends ExternalResource implements Closeable {
 
@@ -45,7 +44,7 @@ public class SMTPMessageSender extends ExternalResource implements Closeable
{
         try {
             return new AuthenticatingSMTPClient();
         } catch (NoSuchAlgorithmException e) {
-            throw Throwables.propagate(e);
+            throw new RuntimeException(e);
         }
     }
 
@@ -89,62 +88,46 @@ public class SMTPMessageSender extends ExternalResource implements Closeable
{
         return this;
     }
 
-    public SMTPMessageSender sendMessage(String from, String recipient) {
-        try {
-            doHelo();
-            doSetSender(from);
-            doRCPT("<" + recipient + ">");
-            doData("FROM: " + from + "\r\n" +
-                "subject: test\r\n" +
-                "\r\n" +
-                "content\r\n" +
-                ".\r\n");
-        } catch (IOException e) {
-            throw Throwables.propagate(e);
-        }
+    public SMTPMessageSender sendMessage(String from, String recipient) throws IOException
{
+        doHelo();
+        doSetSender(from);
+        doRCPT("<" + recipient + ">");
+        doData("FROM: " + from + "\r\n" +
+            "subject: test\r\n" +
+            "\r\n" +
+            "content\r\n" +
+            ".\r\n");
         return this;
     }
 
-    public SMTPMessageSender sendMessageNoBracket(String from, String recipient) {
-        try {
-            doHelo();
-            doSetSender(from);
-            doRCPT(recipient);
-            doData("FROM: " + from + "\r\n" +
-                "subject: test\r\n" +
-                "\r\n" +
-                "content\r\n" +
-                ".\r\n");
-        } catch (IOException e) {
-            throw Throwables.propagate(e);
-        }
+    public SMTPMessageSender sendMessageNoBracket(String from, String recipient) throws IOException
{
+        doHelo();
+        doSetSender(from);
+        doRCPT(recipient);
+        doData("FROM: " + from + "\r\n" +
+            "subject: test\r\n" +
+            "\r\n" +
+            "content\r\n" +
+            ".\r\n");
         return this;
     }
 
-    public SMTPMessageSender sendMessageWithHeaders(String from, String recipient, String
message) {
-        try {
-            doHelo();
-            doSetSender(from);
-            doRCPT("<" + recipient + ">");
-            doData(message);
-        } catch (IOException e) {
-            throw Throwables.propagate(e);
-        }
+    public SMTPMessageSender sendMessageWithHeaders(String from, String recipient, String
message) throws IOException {
+        doHelo();
+        doSetSender(from);
+        doRCPT("<" + recipient + ">");
+        doData(message);
         return this;
     }
 
-    public SMTPMessageSender sendMessage(Mail mail) throws MessagingException {
-        try {
-            String from = mail.getSender().asString();
-            doHelo();
-            doSetSender(from);
-            mail.getRecipients().stream()
-                .map(MailAddress::asString)
-                .forEach(Throwing.consumer(this::doAddRcpt));
-            doData(asString(mail.getMessage()));
-        } catch (IOException e) {
-            throw Throwables.propagate(e);
-        }
+    public SMTPMessageSender sendMessage(Mail mail) throws MessagingException, IOException
{
+        String from = mail.getSender().asString();
+        doHelo();
+        doSetSender(from);
+        mail.getRecipients().stream()
+            .map(MailAddress::asString)
+            .forEach(Throwing.consumer(this::doAddRcpt));
+        doData(asString(mail.getMessage()));
         return this;
     }
 


---------------------------------------------------------------------
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