This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9bb878bebcc2bf0451e834536f6c8dbff368071a
Author: Pablo Pita <[email protected]>
AuthorDate: Mon Mar 18 20:10:35 2019 +0100

    JAMES-2682 Sieve should just do nothing when handling Sieve errors
---
 .../transport/mailets/jsieve/delivery/SieveExecutor.java      | 11 ++++-------
 .../transport/mailets/delivery/SieveIntegrationTest.java      |  4 +++-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/delivery/SieveExecutor.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/delivery/SieveExecutor.java
index ebb78ce..3fed2ff 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/delivery/SieveExecutor.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/jsieve/delivery/SieveExecutor.java
@@ -39,6 +39,7 @@ import org.apache.jsieve.parser.generated.ParseException;
 import org.apache.jsieve.parser.generated.TokenMgrError;
 import org.apache.mailet.Attribute;
 import org.apache.mailet.AttributeName;
+import org.apache.mailet.AttributeUtils;
 import org.apache.mailet.AttributeValue;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailetContext;
@@ -119,14 +120,10 @@ public class SieveExecutor {
     public boolean execute(MailAddress recipient, Mail mail) throws 
MessagingException {
         Preconditions.checkNotNull(recipient, "Recipient for mail to be 
spooled cannot be null.");
         Preconditions.checkNotNull(mail.getMessage(), "Mail message to be 
spooled cannot be null.");
-        Optional<Attribute> oSieveNotification = 
mail.getAttribute(SIEVE_NOTIFICATION);
-        if (oSieveNotification.isPresent()) {
-            AttributeValue<Boolean> attrValue = (AttributeValue<Boolean>) 
oSieveNotification.get().getValue();
-            if (attrValue.value()) {
-                throw new MessagingException("Do not process Sieve error 
notification emails");
-            }
+        boolean isSieveNotification = 
AttributeUtils.getValueAndCastFromMail(mail, SIEVE_NOTIFICATION, 
Boolean.class).orElse(false);
+        if (isSieveNotification) {
+               return false;
         }
-        
         return sieveMessage(recipient, mail);
     }
 
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveIntegrationTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveIntegrationTest.java
index a287734..29876c8 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveIntegrationTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveIntegrationTest.java
@@ -939,13 +939,15 @@ public class SieveIntegrationTest {
         
assertThat(fakeMailContext.getSentMails()).containsExactly(expectedSentMail);
     }
     
-    @Test(expected = MessagingException.class)
+    @Test
     public void sieveErrorNotificationEmailsShouldNotBeProcessed() throws 
Exception {
         
prepareTestUsingScript("org/apache/james/transport/mailets/delivery/keep.script");
 
         FakeMail mail = createMail();
         mail.setAttribute(new Attribute(SieveExecutor.SIEVE_NOTIFICATION, 
AttributeValue.of(true)));
         testee.service(mail);
+        // check that the Sieve mailet performs normally, and nothing gets 
into ATTRIBUTE_NAME
+        assertThat(mail.getAttribute(ATTRIBUTE_NAME)).isEmpty();
     }
 
     private void prepareTestUsingScript(final String script) throws Exception {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to