james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [16/50] [abbrv] james-project git commit: MAILET-119 Don't count retry using errorMessage
Date Tue, 10 Jan 2017 14:18:31 GMT
MAILET-119 Don't count retry using errorMessage

Use Attribute for that


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

Branch: refs/heads/master
Commit: 2e60b2dcced3a90bbe408414f5a1f91df0d010c2
Parents: b563349
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Dec 2 13:37:30 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Tue Jan 10 15:12:49 2017 +0700

----------------------------------------------------------------------
 .../remoteDelivery/DeliveryRetriesHelper.java      | 17 ++++++++++++-----
 .../remoteDelivery/DeliveryRetryHelperTest.java    |  4 ++--
 2 files changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2e60b2dc/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/DeliveryRetriesHelper.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/DeliveryRetriesHelper.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/DeliveryRetriesHelper.java
index 485127e..81e5c8c 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/DeliveryRetriesHelper.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/DeliveryRetriesHelper.java
@@ -19,25 +19,32 @@
 
 package org.apache.james.transport.mailets.remoteDelivery;
 
+import java.io.Serializable;
+
 import org.apache.mailet.Mail;
 
 public class DeliveryRetriesHelper {
 
+    public static final String DELIVERY_RETRY_COUNT = "delivery_retry_count";
+
     public static int retrieveRetries(Mail mail) {
         try {
-            return Integer.parseInt(mail.getErrorMessage());
-        } catch (NumberFormatException e) {
-            // Something strange was happen with the errorMessage..
+            Serializable value = mail.getAttribute(DELIVERY_RETRY_COUNT);
+            if (value != null) {
+                return (Integer) value;
+            }
+            return 0;
+        } catch (ClassCastException e) {
             return 0;
         }
     }
 
     public static void initRetries(Mail mail) {
-        mail.setErrorMessage("0");
+        mail.setAttribute(DELIVERY_RETRY_COUNT, 0);
     }
 
     public static void incrementRetries(Mail mail) {
-        mail.setErrorMessage(String.valueOf(retrieveRetries(mail) + 1));
+        mail.setAttribute(DELIVERY_RETRY_COUNT, retrieveRetries(mail) + 1);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2e60b2dc/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/DeliveryRetryHelperTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/DeliveryRetryHelperTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/DeliveryRetryHelperTest.java
index 72ad294..406cd31 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/DeliveryRetryHelperTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/DeliveryRetryHelperTest.java
@@ -65,7 +65,7 @@ public class DeliveryRetryHelperTest {
 
     @Test
     public void retrieveRetriesShouldBeZeroOnInvalidValue() throws Exception {
-        FakeMail mail = FakeMail.builder().errorMessage("invalid").build();
+        FakeMail mail = FakeMail.builder().attribute(DeliveryRetriesHelper.DELIVERY_RETRY_COUNT,
"invalid").build();
 
         assertThat(DeliveryRetriesHelper.retrieveRetries(mail))
             .isEqualTo(0);
@@ -73,7 +73,7 @@ public class DeliveryRetryHelperTest {
 
     @Test
     public void incrementRetriesShouldWorkOnInvalidMails() throws Exception {
-        FakeMail mail = FakeMail.builder().errorMessage("invalid").build();
+        FakeMail mail = FakeMail.builder().attribute(DeliveryRetriesHelper.DELIVERY_RETRY_COUNT,
"invalid").build();
 
         DeliveryRetriesHelper.incrementRetries(mail);
 


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