JAMES-1900 header JSIEVE instruction should unfold and decode headers
diff --git a/core/pom.xml b/core/pom.xml
index cade211..829f292 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -46,6 +46,11 @@
     </distributionManagement>
 
     <dependencies>
+
+        <dependency>
+            <groupId>org.apache.james</groupId>
+            <artifactId>apache-mime4j-core</artifactId>
+        </dependency>
         <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
diff --git a/core/src/main/java/org/apache/jsieve/tests/Header.java b/core/src/main/java/org/apache/jsieve/tests/Header.java
index 014f2c7..95fce8a 100644
--- a/core/src/main/java/org/apache/jsieve/tests/Header.java
+++ b/core/src/main/java/org/apache/jsieve/tests/Header.java
@@ -30,6 +30,9 @@
 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 @@
             }
         // 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;
     }
diff --git a/core/src/test/java/org/apache/jsieve/HeaderTest.java b/core/src/test/java/org/apache/jsieve/HeaderTest.java
index e15539e..67b1f59 100644
--- a/core/src/test/java/org/apache/jsieve/HeaderTest.java
+++ b/core/src/test/java/org/apache/jsieve/HeaderTest.java
@@ -37,7 +37,7 @@
     /**
      * 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 @@
     /**
      * 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
--- a/pom.xml
+++ b/pom.xml
@@ -91,12 +91,18 @@
         <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>