You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2016/11/23 13:50:17 UTC

[14/46] james-project git commit: JAMES-1854 Extract error message upon Sieve parsing failure

JAMES-1854 Extract error message upon Sieve parsing failure


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

Branch: refs/heads/master
Commit: 4362338373ee9d3b8b61ff57620d6f4e50527486
Parents: 6804799
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Oct 27 17:19:09 2016 +0200
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Nov 18 18:46:46 2016 +0700

----------------------------------------------------------------------
 .../delivery/SieveFailureMessageComposer.java   | 57 ++++++++++++++++++++
 .../transport/mailets/delivery/SieveMailet.java | 41 +-------------
 2 files changed, 59 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/43623383/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SieveFailureMessageComposer.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SieveFailureMessageComposer.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SieveFailureMessageComposer.java
new file mode 100644
index 0000000..241c714
--- /dev/null
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SieveFailureMessageComposer.java
@@ -0,0 +1,57 @@
+/****************************************************************
+ * 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.delivery;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import org.apache.mailet.Mail;
+
+public class SieveFailureMessageComposer {
+
+    public static MimeMessage composeMessage(Mail aMail, Exception ex, String user) throws MessagingException {
+        MimeMessage originalMessage = aMail.getMessage();
+        MimeMessage message = new MimeMessage(originalMessage);
+        MimeMultipart multipart = new MimeMultipart();
+
+        MimeBodyPart noticePart = new MimeBodyPart();
+        noticePart.setText("An error was encountered while processing this mail with the active sieve script for user \""
+            + user + "\". The error encountered was:\r\n" + ex.getLocalizedMessage() + "\r\n");
+        multipart.addBodyPart(noticePart);
+
+        MimeBodyPart originalPart = new MimeBodyPart();
+        originalPart.setContent(originalMessage, "message/rfc822");
+        if ((originalMessage.getSubject() != null) && (!originalMessage.getSubject().trim().isEmpty())) {
+            originalPart.setFileName(originalMessage.getSubject().trim());
+        } else {
+            originalPart.setFileName("No Subject");
+        }
+        originalPart.setDisposition(MimeBodyPart.INLINE);
+        multipart.addBodyPart(originalPart);
+
+        message.setContent(multipart);
+        message.setSubject("[SIEVE ERROR] " + originalMessage.getSubject());
+        message.setHeader("X-Priority", "1");
+        message.saveChanges();
+        return message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/43623383/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SieveMailet.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SieveMailet.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SieveMailet.java
index 69026f9..5a6ea59 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SieveMailet.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/SieveMailet.java
@@ -25,9 +25,7 @@ import java.util.List;
 import java.util.Vector;
 
 import javax.mail.MessagingException;
-import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
 
 import org.apache.commons.logging.Log;
 import org.apache.james.mailbox.MailboxManager;
@@ -309,44 +307,9 @@ public class SieveMailet  extends GenericMailet {
         return "//" + getUsername(m) + "/sieve";
     }
 
-    /**
-     * Deliver the original mail as an attachment with the main part being an error report.
-     *
-     * @param recipient
-     * @param aMail
-     * @param ex
-     * @throws MessagingException
-     * @throws IOException
-     */
-    protected void handleFailure(MailAddress recipient, Mail aMail, Exception ex)
-        throws MessagingException, IOException {
+    protected void handleFailure(MailAddress recipient, Mail aMail, Exception ex) throws MessagingException, IOException {
         String user = getUsername(recipient);
-
-        MimeMessage originalMessage = aMail.getMessage();
-        MimeMessage message = new MimeMessage(originalMessage);
-        MimeMultipart multipart = new MimeMultipart();
-
-        MimeBodyPart noticePart = new MimeBodyPart();
-        noticePart.setText("An error was encountered while processing this mail with the active sieve script for user \""
-            + user + "\". The error encountered was:\r\n" + ex.getLocalizedMessage() + "\r\n");
-        multipart.addBodyPart(noticePart);
-
-        MimeBodyPart originalPart = new MimeBodyPart();
-        originalPart.setContent(originalMessage, "message/rfc822");
-        if ((originalMessage.getSubject() != null) && (!originalMessage.getSubject().trim().isEmpty())) {
-            originalPart.setFileName(originalMessage.getSubject().trim());
-        } else {
-            originalPart.setFileName("No Subject");
-        }
-        originalPart.setDisposition(MimeBodyPart.INLINE);
-        multipart.addBodyPart(originalPart);
-
-        message.setContent(multipart);
-        message.setSubject("[SIEVE ERROR] " + originalMessage.getSubject());
-        message.setHeader("X-Priority", "1");
-        message.saveChanges();
-
-        storeMessageInbox(user, message);
+        storeMessageInbox(user, SieveFailureMessageComposer.composeMessage(aMail, ex, user));
     }
 
 }


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