james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [4/9] james-project git commit: JAMES-2263 Rely more on onMailetException for mailet error handling
Date Wed, 03 Jan 2018 03:20:38 GMT
JAMES-2263 Rely more on onMailetException for mailet error handling

This allows a way higher composability, thus we should avoid catching the exception. This
enables the user to write/use his/her own code and specify specific behaviour.

Reminder: By default, failed mail are processed by the error processor and stored for later
processing (that could rescheduled once the configuration is updated for instance).


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

Branch: refs/heads/master
Commit: d7134ddaf24124c34ab782403966a5fc3922f257
Parents: 410d92e
Author: benwa <btellier@linagora.com>
Authored: Fri Dec 29 10:11:29 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Jan 3 10:18:10 2018 +0700

----------------------------------------------------------------------
 .../destination/conf/mailetcontainer.xml        |  3 +++
 .../destination/conf/mailetcontainer.xml        |  3 +++
 .../jpa/destination/conf/mailetcontainer.xml    |  3 +++
 .../spring/destination/conf/mailetcontainer.xml |  3 +++
 .../transport/mailets/AddHabeasWarrantMark.java | 21 +++++----------
 .../james/transport/mailets/ClassifyBounce.java | 20 ++++++---------
 .../MailAttributesListToMimeHeaders.java        | 14 ++++------
 .../mailets/MailAttributesToMimeHeaders.java    | 23 ++++++-----------
 .../transport/mailets/RemoveMimeHeader.java     | 20 ++++-----------
 .../james/transport/mailets/SetMimeHeader.java  | 16 +++---------
 .../james/transport/matchers/FetchedFrom.java   | 12 +++++----
 .../transport/mailets/RemoveMimeHeaderTest.java |  6 +++--
 .../transport/mailets/SetMimeHeaderTest.java    |  7 +++--
 .../app/src/main/resources/mailetcontainer.xml  |  2 ++
 .../james/transport/mailets/SpamAssassin.java   | 27 ++++++++------------
 15 files changed, 77 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/dockerfiles/run/guice/cassandra-ldap/destination/conf/mailetcontainer.xml
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/cassandra-ldap/destination/conf/mailetcontainer.xml
index f1f7de4..9d56af4 100644
--- a/dockerfiles/run/guice/cassandra-ldap/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/cassandra-ldap/destination/conf/mailetcontainer.xml
@@ -52,13 +52,16 @@
             <mailet match="SMTPAuthSuccessful" class="SetMimeHeader">
                 <name>X-UserIsAuth</name>
                 <value>true</value>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="HasMailAttribute=org.apache.james.SMIMECheckSignature" class="SetMimeHeader">
                 <name>X-WasSigned</name>
                 <value>true</value>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="All" class="RemoveMimeHeader">
                 <name>bcc</name>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="All" class="RecipientRewriteTable" />
             <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.VacationMailet"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/dockerfiles/run/guice/cassandra/destination/conf/mailetcontainer.xml
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/cassandra/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/cassandra/destination/conf/mailetcontainer.xml
index f453b77..2a3d9b0 100644
--- a/dockerfiles/run/guice/cassandra/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/cassandra/destination/conf/mailetcontainer.xml
@@ -52,13 +52,16 @@
             <mailet match="SMTPAuthSuccessful" class="SetMimeHeader">
                 <name>X-UserIsAuth</name>
                 <value>true</value>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="HasMailAttribute=org.apache.james.SMIMECheckSignature" class="SetMimeHeader">
                 <name>X-WasSigned</name>
                 <value>true</value>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="All" class="RemoveMimeHeader">
                 <name>bcc</name>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="All" class="RecipientRewriteTable" />
             <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.VacationMailet"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/dockerfiles/run/guice/jpa/destination/conf/mailetcontainer.xml
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/jpa/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/jpa/destination/conf/mailetcontainer.xml
index 3872dd8..ef25e4e 100644
--- a/dockerfiles/run/guice/jpa/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/jpa/destination/conf/mailetcontainer.xml
@@ -52,13 +52,16 @@
             <mailet match="SMTPAuthSuccessful" class="SetMimeHeader">
                 <name>X-UserIsAuth</name>
                 <value>true</value>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="HasMailAttribute=org.apache.james.SMIMECheckSignature" class="SetMimeHeader">
                 <name>X-WasSigned</name>
                 <value>true</value>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="All" class="RemoveMimeHeader">
                 <name>bcc</name>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="All" class="RecipientRewriteTable" />
             <mailet match="RecipientIsLocal" class="Sieve"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/dockerfiles/run/spring/destination/conf/mailetcontainer.xml
----------------------------------------------------------------------
diff --git a/dockerfiles/run/spring/destination/conf/mailetcontainer.xml b/dockerfiles/run/spring/destination/conf/mailetcontainer.xml
index 4793203..063f559 100644
--- a/dockerfiles/run/spring/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/spring/destination/conf/mailetcontainer.xml
@@ -52,13 +52,16 @@
             <mailet match="SMTPAuthSuccessful" class="SetMimeHeader">
                 <name>X-UserIsAuth</name>
                 <value>true</value>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="HasMailAttribute=org.apache.james.SMIMECheckSignature" class="SetMimeHeader">
                 <name>X-WasSigned</name>
                 <value>true</value>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="All" class="RemoveMimeHeader">
                 <name>bcc</name>
+                <onMailetException>ignore</onMailetException>
             </mailet>
             <mailet match="All" class="RecipientRewriteTable" />
             <mailet match="RecipientIsLocal" class="Sieve"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddHabeasWarrantMark.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddHabeasWarrantMark.java
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddHabeasWarrantMark.java
index a51a6c6..a71fa8f 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddHabeasWarrantMark.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddHabeasWarrantMark.java
@@ -17,18 +17,15 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.transport.mailets;
 
 import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
 
 import org.apache.james.transport.matchers.HasHabeasWarrantMark;
 import org.apache.mailet.Experimental;
 import org.apache.mailet.Mail;
 import org.apache.mailet.base.GenericMailet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * <p>This matcher adds the Hebeas Warrant Mark to a message.
@@ -88,7 +85,6 @@ import org.slf4j.LoggerFactory;
  */
 @Experimental
 public class AddHabeasWarrantMark extends GenericMailet {
-    private static final Logger LOGGER = LoggerFactory.getLogger(AddHabeasWarrantMark.class);
 
     /**
      * Called by the mailet container to allow the mailet to process to
@@ -103,18 +99,13 @@ public class AddHabeasWarrantMark extends GenericMailet {
      *      an exception that interferes with the mailet's normal operation
      */
     public void service(Mail mail) throws MessagingException {
-        try {
-            javax.mail.internet.MimeMessage message = mail.getMessage();
-
-            for(int i = 0 ; i < HasHabeasWarrantMark.warrantMark.length ; i++) {
-                message.setHeader(HasHabeasWarrantMark.warrantMark[i][0], HasHabeasWarrantMark.warrantMark[i][1]);
-            }
+        MimeMessage message = mail.getMessage();
 
-            message.saveChanges();
-        }
-        catch (MessagingException me) {
-            LOGGER.error("Error while adding habeas", me);
+        for(int i = 0 ; i < HasHabeasWarrantMark.warrantMark.length ; i++) {
+            message.setHeader(HasHabeasWarrantMark.warrantMark[i][0], HasHabeasWarrantMark.warrantMark[i][1]);
         }
+
+        message.saveChanges();
     }
 
     /*

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClassifyBounce.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClassifyBounce.java
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClassifyBounce.java
index e33af5a..e8a8c6c 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClassifyBounce.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClassifyBounce.java
@@ -73,18 +73,14 @@ public class ClassifyBounce extends GenericMailet {
      * @param mail the mail being processed
      * @throws MessagingException if an error arises during message processing
      */
-    public void service(Mail mail) {
-        try {
-            MimeMessage message = mail.getMessage();
-            Classifier classifier = new Classifier(message);
-            String classification = classifier.getClassification();
-            //if ( !classification.equals("Normal") ) {
-            message.setHeader(headerName, classification);
-            message.saveChanges();
-            //}
-        } catch (MessagingException me) {
-            LOGGER.error("Error classifying message: ", me);
-        }
+    public void service(Mail mail) throws MessagingException {
+        MimeMessage message = mail.getMessage();
+        Classifier classifier = new Classifier(message);
+        String classification = classifier.getClassification();
+        //if ( !classification.equals("Normal") ) {
+        message.setHeader(headerName, classification);
+        message.saveChanges();
+        //}
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesListToMimeHeaders.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesListToMimeHeaders.java
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesListToMimeHeaders.java
index 60d2208..2b26a71 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesListToMimeHeaders.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesListToMimeHeaders.java
@@ -64,15 +64,11 @@ public class MailAttributesListToMimeHeaders extends GenericMailet {
     }
 
     @Override
-    public void service(Mail mail) {
-        try {
-            MimeMessage message = mail.getMessage();
-            attributeNameToHeader.entrySet()
-                .forEach(entry -> addAttributeToHeader(mail, message, entry));
-            message.saveChanges();
-        } catch (MessagingException e) {
-            LOGGER.warn("Exception while adding headers", e);
-        }
+    public void service(Mail mail) throws MessagingException {
+        MimeMessage message = mail.getMessage();
+        attributeNameToHeader.entrySet()
+            .forEach(entry -> addAttributeToHeader(mail, message, entry));
+        message.saveChanges();
     }
 
     private void addAttributeToHeader(Mail mail, MimeMessage message, Entry<String, String>
entry) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesToMimeHeaders.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesToMimeHeaders.java
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesToMimeHeaders.java
index 03c882d..c1b37ee 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesToMimeHeaders.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesToMimeHeaders.java
@@ -27,8 +27,6 @@ import javax.mail.internet.MimeMessage;
 
 import org.apache.mailet.Mail;
 import org.apache.mailet.base.GenericMailet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Strings;
 
@@ -45,7 +43,6 @@ import com.google.common.base.Strings;
  * </code></pre>
  */
 public class MailAttributesToMimeHeaders extends GenericMailet {
-    private static final Logger LOGGER = LoggerFactory.getLogger(MailAttributesToMimeHeaders.class);
 
     private Map<String, String> mappings;
 
@@ -61,20 +58,16 @@ public class MailAttributesToMimeHeaders extends GenericMailet {
     }
 
     @Override
-    public void service(Mail mail) {
-        try {
-            MimeMessage message = mail.getMessage();
-            for (Entry<String, String> entry : mappings.entrySet()) {
-                String value = (String) mail.getAttribute(entry.getKey());
-                if (value != null) {
-                    String headerName = entry.getValue();
-                    message.addHeader(headerName, value);
-                }
+    public void service(Mail mail) throws MessagingException {
+        MimeMessage message = mail.getMessage();
+        for (Entry<String, String> entry : mappings.entrySet()) {
+            String value = (String) mail.getAttribute(entry.getKey());
+            if (value != null) {
+                String headerName = entry.getValue();
+                message.addHeader(headerName, value);
             }
-            message.saveChanges();
-        } catch (MessagingException e) {
-            LOGGER.error("Encountered exception", e);
         }
+        message.saveChanges();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveMimeHeader.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveMimeHeader.java
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveMimeHeader.java
index 43edd76..5f19e80 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveMimeHeader.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveMimeHeader.java
@@ -17,8 +17,6 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.transport.mailets;
 
 import java.util.List;
@@ -29,8 +27,6 @@ import javax.mail.internet.MimeMessage;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailetException;
 import org.apache.mailet.base.GenericMailet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableList;
@@ -48,8 +44,6 @@ import com.google.common.collect.ImmutableList;
  * 
  */
 public class RemoveMimeHeader extends GenericMailet {
-    private static final Logger LOGGER = LoggerFactory.getLogger(RemoveMimeHeader.class);
-    
     private List<String> headers;
 
     @Override
@@ -67,15 +61,11 @@ public class RemoveMimeHeader extends GenericMailet {
     }
 
     @Override
-    public void service(Mail mail) {
-        try {
-            MimeMessage  message = mail.getMessage();
-            for (String header : headers) {
-                message.removeHeader(header);
-            }
-            message.saveChanges();
-        } catch (MessagingException e) {
-            LOGGER.error("Unable to remove headers: ", e);
+    public void service(Mail mail) throws MessagingException {
+        MimeMessage  message = mail.getMessage();
+        for (String header : headers) {
+            message.removeHeader(header);
         }
+        message.saveChanges();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMimeHeader.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMimeHeader.java
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMimeHeader.java
index 70c7c19..9ba695e 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMimeHeader.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMimeHeader.java
@@ -26,8 +26,6 @@ import javax.mail.internet.MimeMessage;
 
 import org.apache.mailet.Mail;
 import org.apache.mailet.base.GenericMailet;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Strings;
 
@@ -46,8 +44,6 @@ import com.google.common.base.Strings;
  * @version 1.0.0, 2002-09-11
  */
 public class SetMimeHeader extends GenericMailet {
-    private static final Logger LOGGER = LoggerFactory.getLogger(SetMimeHeader.class);
-
     private String headerName;
     private String headerValue;
 
@@ -62,15 +58,11 @@ public class SetMimeHeader extends GenericMailet {
     }
 
     @Override
-    public void service(Mail mail) {
-        try {
-            MimeMessage message = mail.getMessage () ;
+    public void service(Mail mail) throws MessagingException {
+        MimeMessage message = mail.getMessage () ;
 
-            message.addHeader(headerName, headerValue);
-            message.saveChanges();
-        } catch (javax.mail.MessagingException me) {
-            LOGGER.error("Encountered exception", me);
-        }
+        message.addHeader(headerName, headerValue);
+        message.saveChanges();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/mailet/standard/src/main/java/org/apache/james/transport/matchers/FetchedFrom.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/FetchedFrom.java
b/mailet/standard/src/main/java/org/apache/james/transport/matchers/FetchedFrom.java
index a16baff..db28d4c 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/FetchedFrom.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/FetchedFrom.java
@@ -19,12 +19,14 @@
 
 package org.apache.james.transport.matchers;
 
-import org.apache.mailet.base.GenericMatcher;
-import org.apache.mailet.Mail;
-import org.apache.james.core.MailAddress;
+import java.util.Collection;
 
+import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
-import java.util.Collection;
+
+import org.apache.james.core.MailAddress;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMatcher;
 
 import com.google.common.base.Objects;
 
@@ -41,7 +43,7 @@ public class FetchedFrom extends GenericMatcher {
 
     public static final String X_FETCHED_FROM = "X-fetched-from";
 
-    public Collection<MailAddress> match(Mail mail) throws javax.mail.MessagingException
{
+    public Collection<MailAddress> match(Mail mail) throws MessagingException {
         MimeMessage message = mail.getMessage();
         String fetchHeaderValue = message.getHeader(X_FETCHED_FROM, null);
         if (Objects.equal(fetchHeaderValue, getCondition())) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java
index 3a04511..5482b52 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveMimeHeaderTest.java
@@ -21,6 +21,7 @@
 package org.apache.james.transport.mailets;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -145,7 +146,7 @@ public class RemoveMimeHeaderTest {
 
     @SuppressWarnings("unchecked")
     @Test
-    public void serviceShouldNotThrowWhenExceptionOccured() throws MessagingException {
+    public void serviceShouldThrowWhenExceptionOccured() throws MessagingException {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("Test")
                 .setProperty("name", "")
@@ -156,7 +157,8 @@ public class RemoveMimeHeaderTest {
         when(mail.getMessage())
             .thenThrow(MessagingException.class);
 
-        mailet.service(mail);
+        assertThatThrownBy(() -> mailet.service(mail))
+            .isInstanceOf(MessagingException.class);
     }
 
     private Mail createMail(MimeMessage message) throws MessagingException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
index a08ee21..8d122e4 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java
@@ -21,6 +21,7 @@
 package org.apache.james.transport.mailets;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -83,7 +84,7 @@ public class SetMimeHeaderTest {
     }
 
     @Test
-    public void shouldNotThrowOnMessagingException() throws MessagingException {
+    public void shouldThrowOnMessagingException() throws MessagingException {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("Test")
                 .setProperty("name", "header-name")
@@ -93,7 +94,9 @@ public class SetMimeHeaderTest {
         
         Mail mail = mock(Mail.class);
         when(mail.getMessage()).thenThrow(new MessagingException());
-        mailet.service(mail);
+
+        assertThatThrownBy(() -> mailet.service(mail))
+            .isInstanceOf(MessagingException.class);
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/server/app/src/main/resources/mailetcontainer.xml
----------------------------------------------------------------------
diff --git a/server/app/src/main/resources/mailetcontainer.xml b/server/app/src/main/resources/mailetcontainer.xml
index bce475e..ce0f2c2 100644
--- a/server/app/src/main/resources/mailetcontainer.xml
+++ b/server/app/src/main/resources/mailetcontainer.xml
@@ -207,11 +207,13 @@ Regards, Postmaster XXX.YYY
        <mailet match="SMTPAuthSuccessful" class="SetMimeHeader">
           <name>X-UserIsAuth</name>
           <value>true</value>
+          <onMailetException>ignore</onMailetException>
        </mailet>
     
        <mailet match="HasMailAttribute=org.apache.james.SMIMECheckSignature" class="SetMimeHeader">
           <name>X-WasSigned</name>
           <value>true</value>
+          <onMailetException>ignore</onMailetException>
        </mailet>
 
        <!-- Add a server-side signature -->

http://git-wip-us.apache.org/repos/asf/james-project/blob/d7134dda/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SpamAssassin.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SpamAssassin.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SpamAssassin.java
index c0221fa..fbcb3f6 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SpamAssassin.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/SpamAssassin.java
@@ -84,24 +84,19 @@ public class SpamAssassin extends GenericMailet {
     /**
      * @see org.apache.mailet.base.GenericMailet#service(Mail)
      */
-    public void service(Mail mail) {
-        try {
-            MimeMessage message = mail.getMessage();
-
-            // Invoke SpamAssassin connection and scan the message
-            SpamAssassinInvoker sa = new SpamAssassinInvoker(spamdHost, spamdPort);
-            sa.scanMail(message);
-
-            // Add headers as attribute to mail object
-            for (String key : sa.getHeadersAsAttribute().keySet()) {
-                mail.setAttribute(key, sa.getHeadersAsAttribute().get(key));
-            }
-
-            message.saveChanges();
-        } catch (MessagingException e) {
-            LOGGER.error("Encountered exception", e);
+    public void service(Mail mail) throws MessagingException {
+        MimeMessage message = mail.getMessage();
+
+        // Invoke SpamAssassin connection and scan the message
+        SpamAssassinInvoker sa = new SpamAssassinInvoker(spamdHost, spamdPort);
+        sa.scanMail(message);
+
+        // Add headers as attribute to mail object
+        for (String key : sa.getHeadersAsAttribute().keySet()) {
+            mail.setAttribute(key, sa.getHeadersAsAttribute().get(key));
         }
 
+        message.saveChanges();
     }
 
     /**


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