JAMES-1900 header JSIEVE instruction should unfold and decode headers
authorbenwa <btellier@linagora.com>
Fri, 5 May 2017 03:59:00 +0000 (10:59 +0700)
committerbenwa <btellier@linagora.com>
Mon, 8 May 2017 02:32:20 +0000 (09:32 +0700)
core/pom.xml
core/src/main/java/org/apache/jsieve/tests/Header.java
core/src/test/java/org/apache/jsieve/HeaderTest.java
pom.xml

index cade211..829f292 100644 (file)
     </distributionManagement>
 
     <dependencies>
+
+        <dependency>
+            <groupId>org.apache.james</groupId>
+            <artifactId>apache-mime4j-core</artifactId>
+        </dependency>
         <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
index 014f2c7..95fce8a 100644 (file)
@@ -30,6 +30,9 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.codec.DecoderUtil;
+import org.apache.james.mime4j.util.MimeUtil;
 import org.apache.jsieve.Argument;
 import org.apache.jsieve.Arguments;
 import org.apache.jsieve.SieveContext;
@@ -199,10 +202,10 @@ public class Header extends AbstractTest {
             }
         // Iterate over the header values looking for a match
         boolean isMatched = false;
-        Iterator headerValuesIter = headerValues.iterator();
+        Iterator<String> headerValuesIter = headerValues.iterator();
         while (!isMatched && headerValuesIter.hasNext()) {
-            isMatched = match(comparator, matchType, (String) headerValuesIter
-                    .next(), keys, context);
+            String headerValue = MimeUtil.unscrambleHeaderValue(headerValuesIter.next());
+            isMatched = match(comparator, matchType, headerValue, keys, context);
         }
         return isMatched;
     }
index e15539e..67b1f59 100644 (file)
@@ -37,7 +37,7 @@ public class HeaderTest {
     /**
      * Test for Test 'header'
      */
-    @org.junit.Test
+    @Test
     public void testHeaderIsTrue() {
         boolean isTestPassed = false;
         String script = "if header :is \"X-Caffeine\" \"C8H10N4O2\" {throwTestException;}";
@@ -57,6 +57,21 @@ public class HeaderTest {
     /**
      * Test for Test 'header'
      */
+    @Test(expected = ThrowTestException.TestException.class)
+    public void testFoldedEncodedHeader() throws Exception {
+        String script = "if header :is \"To\" \"BenoĆ®t TELLIER <tellier@linagora.com>\" {throwTestException;}";
+
+
+        SieveMailAdapter mail = (SieveMailAdapter) JUnitUtils.createMail();
+        mail.getMessage().addHeader("To", "=?UTF-8?Q?Beno=c3=aet_TELLIER?=\r\n" +
+            " <tellier@linagora.com>");
+
+        JUnitUtils.interpret(mail, script);
+    }
+
+    /**
+     * Test for Test 'header'
+     */
     @Test
     public void testHeaderCaseInsensitivity() {
         boolean isTestPassed = false;
diff --git a/pom.xml b/pom.xml
index ba4dab6..6c380bf 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <mockito-core.version>1.9.0</mockito-core.version>
         <assertj.version>1.7.1</assertj.version>
         <guava.version>18.0</guava.version>
+        <mime4j.version>0.8.1-SNAPSHOT</mime4j.version>
     </properties>
 
     <dependencyManagement>
         <dependencies>
             <dependency>
                 <groupId>org.apache.james</groupId>
+                <artifactId>apache-mime4j-core</artifactId>
+                <version>${mime4j.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.james</groupId>
                 <artifactId>apache-jsieve</artifactId>
                 <version>${project.version}</version>
             </dependency>