james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/6] james-project git commit: JAMES-1900 HasHeader should support encoded folded values
Date Tue, 06 Jun 2017 02:04:24 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 173303649 -> 747e67154


JAMES-1900 HasHeader should support encoded folded values


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

Branch: refs/heads/master
Commit: 4254ac92b6743c252edc5b3aa4e7522b7d6e8aa6
Parents: 1733036
Author: benwa <btellier@linagora.com>
Authored: Fri May 5 10:10:38 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Mon Jun 5 20:23:28 2017 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/HasHeader.java     |  11 +-
 .../james/transport/matchers/HasHeaderTest.java |  29 ++++
 .../src/test/resources/mime/headerFolded.mime   | 154 +++++++++++++++++++
 3 files changed, 193 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4254ac92/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
b/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
index c8484d9..d982a61 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
@@ -20,6 +20,9 @@
 
 package org.apache.james.transport.matchers;
 
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.codec.DecoderUtil;
+import org.apache.james.mime4j.util.MimeUtil;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.GenericMatcher;
@@ -40,6 +43,12 @@ import java.util.StringTokenizer;
  */
 public class HasHeader extends GenericMatcher {
 
+    private static String sanitizeHeaderField(String headerName) {
+        return DecoderUtil.decodeEncodedWords(
+            MimeUtil.unfold(headerName),
+            DecodeMonitor.SILENT);
+    }
+
     private static final String CONDITION_SEPARATOR = "+";
     private static final String HEADER_VALUE_SEPARATOR = "=";
 
@@ -75,7 +84,7 @@ public class HasHeader extends GenericMatcher {
             String[] headerArray = mimeMessage.getHeader(headerName);
             if (headerArray != null && headerArray.length > 0) {
                 for (String value : headerArray) {
-                    if (headerValue.equals(value)) {
+                    if (headerValue.equals(sanitizeHeaderField(value))) {
                         return true;
                     }
                 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4254ac92/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
index 49dfc9b..c6e7af0 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
@@ -33,6 +33,7 @@ import org.apache.mailet.Matcher;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMatcherConfig;
 import org.apache.mailet.base.test.MailUtil;
+import org.apache.mailet.base.test.MimeMessageBuilder;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -131,6 +132,34 @@ public class HasHeaderTest {
     }
 
     @Test
+    public void matchShouldSupportFoldedHeaders() throws Exception {
+        matcher.init(FakeMatcherConfig.builder()
+            .matcherName("HasHeader")
+            .condition("From=aduprat <duprat@linagora.com>")
+            .build());
+
+        Mail mail = MailUtil.createMockMail2Recipients(
+            MimeMessageBuilder.mimeMessageFromStream(
+                ClassLoader.getSystemResourceAsStream("mime/headerFolded.mime")));
+
+        assertThat(matcher.match(mail)).containsAll(mail.getRecipients());
+    }
+
+    @Test
+    public void matchShouldSupportEncodedHeaders() throws Exception {
+        matcher.init(FakeMatcherConfig.builder()
+            .matcherName("HasHeader")
+            .condition("To=Benoît TELLIER <tellier@linagora.com>")
+            .build());
+
+        Mail mail = MailUtil.createMockMail2Recipients(
+            MimeMessageBuilder.mimeMessageFromStream(
+                ClassLoader.getSystemResourceAsStream("mime/gmail.mime")));
+
+        assertThat(matcher.match(mail)).containsAll(mail.getRecipients());
+    }
+
+    @Test
     public void matchShouldNotMatchMailsWithNoHeaderWhenValueNotSpecified() throws MessagingException
{
         matcher.init(FakeMatcherConfig.builder()
                 .matcherName("HasHeader")

http://git-wip-us.apache.org/repos/asf/james-project/blob/4254ac92/mailet/standard/src/test/resources/mime/headerFolded.mime
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/resources/mime/headerFolded.mime b/mailet/standard/src/test/resources/mime/headerFolded.mime
new file mode 100644
index 0000000..f8f44ce
--- /dev/null
+++ b/mailet/standard/src/test/resources/mime/headerFolded.mime
@@ -0,0 +1,154 @@
+Return-Path: <aduprat@linagora.com>
+Subject: Fwd: Invitation: (Aucun objet) - ven. 20 janv. 2017 14:00 - 15:00
+ (CET) (aduprat@linagora.com)
+To: =?UTF-8?Q?Beno=c3=aet_TELLIER?= <tellier@linagora.com>
+From: aduprat
+ <duprat@linagora.com>
+X-Forwarded-Message-Id: <001a114380a6a260d105467765ab@google.com>
+Message-ID: <f18fa52e-2e9d-1125-327d-2100b23f8a6b@linagora.com>
+Date: Thu, 19 Jan 2017 20:36:37 +0100
+MIME-Version: 1.0
+In-Reply-To: <001a114380a6a260d105467765ab@google.com>
+Content-Type: multipart/mixed;
+ boundary="------------17D96D411CBD55D8239A8C1F"
+
+This is a multi-part message in MIME format.
+--------------17D96D411CBD55D8239A8C1F
+Content-Type: multipart/alternative;
+ boundary="------------64D716A3DDAEC185D3E67448"
+
+
+--------------64D716A3DDAEC185D3E67448
+Content-Type: text/plain; charset=utf-8; format=flowed
+Content-Transfer-Encoding: 8bit
+
+
+
+
+-------- Message transéré --------
+Sujet : 	Invitation: (Aucun objet) - ven. 20 janv. 2017 14:00 - 15:00
+(CET) (duprat@linagora.com)
+Date : 	Thu, 19 Jan 2017 19:18:23 +0000
+De : 	Antoine Duprat <duprat@gmail.com>
+Répondre à : 	antduprat@gmail.com
+Pour : 	aduprat@linagora.com
+
+
+
+
+--------------64D716A3DDAEC185D3E67448
+Content-Type: text/html; charset=utf-8
+Content-Transfer-Encoding: 8bit
+
+<html>
+  <head>
+
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  </head>
+  <body bgcolor="#FFFFFF" text="#000000">
+    <p><br>
+    </p>
+    <div class="moz-forward-container"><br>
+      <br>
+      -------- Message transéré --------
+      <table class="moz-email-headers-table" border="0" cellpadding="0"
+        cellspacing="0">
+        <tbody>
+          <tr>
+            <th align="RIGHT" valign="BASELINE" nowrap="nowrap">Sujet :
+            </th>
+            <td>Invitation: (Aucun objet) - ven. 20 janv. 2017 14:00 -
+              15:00 (CET) (<a class="moz-txt-link-abbreviated" href="mailto:aduprat@linagora.com">aduprat@linagora.com</a>)</td>
+          </tr>
+          <tr>
+            <th align="RIGHT" valign="BASELINE" nowrap="nowrap">Date : </th>
+            <td>Thu, 19 Jan 2017 19:18:23 +0000</td>
+          </tr>
+          <tr>
+            <th align="RIGHT" valign="BASELINE" nowrap="nowrap">De : </th>
+            <td>Antoine Duprat <a class="moz-txt-link-rfc2396E" href="mailto:antduprat@gmail.com">&lt;antduprat@gmail.com&gt;</a></td>
+          </tr>
+          <tr>
+            <th align="RIGHT" valign="BASELINE" nowrap="nowrap">Répondre
+              Ã Â : </th>
+            <td><a class="moz-txt-link-abbreviated" href="mailto:antduprat@gmail.com">antduprat@gmail.com</a></td>
+          </tr>
+          <tr>
+            <th align="RIGHT" valign="BASELINE" nowrap="nowrap">Pour : </th>
+            <td><a class="moz-txt-link-abbreviated" href="mailto:aduprat@linagora.com">aduprat@linagora.com</a></td>
+          </tr>
+        </tbody>
+      </table>
+      <br>
+      <br>
+    </div>
+  </body>
+</html>
+
+--------------64D716A3DDAEC185D3E67448--
+
+--------------17D96D411CBD55D8239A8C1F
+Content-Type: text/calendar;
+ name="Portion de message joint"
+Content-Transfer-Encoding: 8bit
+Content-Disposition: attachment;
+ filename="Portion de message joint"
+
+BEGIN:VCALENDAR
+PRODID:-//Google Inc//Google Calendar 70.9054//EN
+VERSION:2.0
+CALSCALE:GREGORIAN
+METHOD:REQUEST
+BEGIN:VEVENT
+DTSTART:20170120T130000Z
+DTEND:20170120T140000Z
+DTSTAMP:20170119T191823Z
+ORGANIZER;CN=Antoine Duprat:mailto:duprat@gmail.com
+UID:ah86k5m342bmcrbe9khkkhln00@google.com
+ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
+ TRUE;CN=aduprat@linagora.com;X-NUM-GUESTS=0:mailto:duprat@linagora.com
+ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE
+ ;CN=Antoine Duprat;X-NUM-GUESTS=0:mailto:duprat@gmail.com
+CREATED:20170119T191823Z
+DESCRIPTION:Affichez votre evenement sur la page https://www.google.com/cal
+ endar/event?action=VIEW&eid=YWg4Nms1bTM0MmJtY3JiZTlraGtraGxuMDAgYWR1cHJhdEB
+ saW5hZ29yYS5jb20&tok=MTkjYW50ZHVwcmF0QGdtYWlsLmNvbTg1OTM5NWM4MGRlYmE1YTI4Nz
+ RjN2UyNjU0M2YyZmQ4NzRkNThhYTQ&ctz=Europe/Paris&hl=fr.
+LAST-MODIFIED:20170119T191823Z
+LOCATION:
+SEQUENCE:0
+STATUS:CONFIRMED
+SUMMARY:
+TRANSP:OPAQUE
+END:VEVENT
+END:VCALENDAR
+
+
+--------------17D96D411CBD55D8239A8C1F
+Content-Type: application/ics;
+ name="invite.ics"
+Content-Transfer-Encoding: base64
+Content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WTNKaVpUbHJh
+R3RyYUd4dU1EQWdZV1IxY0hKaGRFQg0KIHNhVzVoWjI5eVlTNWpiMjAmdG9rPU1Ua2pZVzUw
+WkhWd2NtRjBRR2R0WVdsc0xtTnZiVGcxT1RNNU5XTTRNR1JsWW1FMVlUSTROeg0KIFJqTjJV
+eU5qVTBNMll5Wm1RNE56UmtOVGhoWVRRJmN0ej1FdXJvcGUvUGFyaXMmaGw9ZnIuDQpMQVNU
+LU1PRElGSUVEOjIwMTcwMTE5VDE5MTgyM1oNCkxPQ0FUSU9OOg0KU0VRVUVOQ0U6MA0KU1RB
+VFVTOkNPTkZJUk1FRA0KU1VNTUFSWToNClRSQU5TUDpPUEFRVUUNCkVORDpWRVZFTlQNCkVO
+RDpWQ0FMRU5EQVINCg==
+--------------17D96D411CBD55D8239A8C1F--


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