james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [06/10] james-project git commit: MAILET-112 Improve FetchedFrom
Date Tue, 30 Aug 2016 18:01:41 GMT
MAILET-112 Improve FetchedFrom

 - Use Guava's equals
 - Use constant for header name


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

Branch: refs/heads/master
Commit: ef9f4a9e4c17a565926a02b2ff30dec8e31b0898
Parents: b10e5d0
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Aug 30 12:16:01 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Aug 31 00:59:27 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/FetchedFrom.java      | 17 +++++++----------
 .../james/transport/matchers/FetchedFromTest.java  | 13 ++++++-------
 2 files changed, 13 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ef9f4a9e/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 3ef395e..6b707f3 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
@@ -17,8 +17,6 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.transport.matchers;
 
 import org.apache.mailet.base.GenericMatcher;
@@ -28,6 +26,8 @@ import org.apache.mailet.MailAddress;
 import javax.mail.internet.MimeMessage;
 import java.util.Collection;
 
+import com.google.common.base.Objects;
+
 /**
  * Matches mail with a header set by Fetchpop X-fetched-from <br>
  * fetchpop sets X-fetched-by to the "name" of the fetchpop fetch task.<br>
@@ -38,17 +38,14 @@ import java.util.Collection;
  */
 
 public class FetchedFrom extends GenericMatcher {
-    
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.mailet.base.GenericMatcher#match(org.apache.mailet.Mail)
-     */
+    public static final String X_FETCHED_FROM = "X-fetched-from";
+
     public Collection<MailAddress> match(Mail mail) throws javax.mail.MessagingException
{
         MimeMessage message = mail.getMessage();
-        String fetch = message.getHeader("X-fetched-from", null);
-        if (fetch != null && fetch.equals(getCondition())) {
-            mail.getMessage().removeHeader("X-fetched-from");
+        String fetchHeaderValue = message.getHeader(X_FETCHED_FROM, null);
+        if (Objects.equal(fetchHeaderValue, getCondition())) {
+            mail.getMessage().removeHeader(X_FETCHED_FROM);
             return mail.getRecipients();
         }
         return null;

http://git-wip-us.apache.org/repos/asf/james-project/blob/ef9f4a9e/mailet/standard/src/test/java/org/apache/james/transport/matchers/FetchedFromTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/FetchedFromTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/FetchedFromTest.java
index 7a6fd47..faeb337 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/FetchedFromTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/FetchedFromTest.java
@@ -34,7 +34,6 @@ import org.junit.Before;
 import org.junit.Test;
 
 public class FetchedFromTest {
-    private static final String FETCH_FROM_HEADER = "X-fetched-from";
     private static final String EXPECTED_HEADER_VALUE = "james-user";
     private static final String WRONG_HEADER_VALUE = "defaultHeaderValue";
 
@@ -57,7 +56,7 @@ public class FetchedFromTest {
     public void matchShouldReturnMatchWhenFetchFromHeaderHoldsRightValue() throws MessagingException
{
         FakeMail fakeMail = FakeMail.builder()
             .recipients(mailAddress1, mailAddress2)
-            .mimeMessage(MailUtil.createMimeMessage(FETCH_FROM_HEADER, EXPECTED_HEADER_VALUE))
+            .mimeMessage(MailUtil.createMimeMessage(FetchedFrom.X_FETCHED_FROM, EXPECTED_HEADER_VALUE))
             .build();
 
         assertThat(matcher.match(fakeMail)).containsExactly(mailAddress1, mailAddress2);
@@ -68,7 +67,7 @@ public class FetchedFromTest {
     public void matchShouldReturnNotMatchWhenFetchFromHeaderHoldsWrongValue() throws MessagingException
{
         FakeMail fakeMail = FakeMail.builder()
             .recipients(mailAddress1, mailAddress2)
-            .mimeMessage(MailUtil.createMimeMessage(FETCH_FROM_HEADER, WRONG_HEADER_VALUE))
+            .mimeMessage(MailUtil.createMimeMessage(FetchedFrom.X_FETCHED_FROM, WRONG_HEADER_VALUE))
             .build();
 
         assertThat(matcher.match(fakeMail)).isNull();
@@ -79,23 +78,23 @@ public class FetchedFromTest {
     public void matchShouldRemoveMatchingHeaders() throws MessagingException {
         FakeMail fakeMail = FakeMail.builder()
             .recipients(mailAddress1, mailAddress2)
-            .mimeMessage(MailUtil.createMimeMessage(FETCH_FROM_HEADER, EXPECTED_HEADER_VALUE))
+            .mimeMessage(MailUtil.createMimeMessage(FetchedFrom.X_FETCHED_FROM, EXPECTED_HEADER_VALUE))
             .build();
 
         matcher.match(fakeMail);
 
-        assertThat(fakeMail.getMessage().getHeader(FETCH_FROM_HEADER)).isNull();
+        assertThat(fakeMail.getMessage().getHeader(FetchedFrom.X_FETCHED_FROM)).isNull();
     }
 
     @Test
     public void matchShouldNotRemoveNonMatchingHeaders() throws MessagingException {
         FakeMail fakeMail = FakeMail.builder()
             .recipients(mailAddress1, mailAddress2)
-            .mimeMessage(MailUtil.createMimeMessage(FETCH_FROM_HEADER, WRONG_HEADER_VALUE))
+            .mimeMessage(MailUtil.createMimeMessage(FetchedFrom.X_FETCHED_FROM, WRONG_HEADER_VALUE))
             .build();
 
         matcher.match(fakeMail);
 
-        assertThat(fakeMail.getMessage().getHeader(FETCH_FROM_HEADER)).containsExactly(WRONG_HEADER_VALUE);
+        assertThat(fakeMail.getMessage().getHeader(FetchedFrom.X_FETCHED_FROM)).containsExactly(WRONG_HEADER_VALUE);
     }
 }


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