Skip to content
Permalink
Browse files
JAMES-1900 header JSIEVE instruction should unfold and decode headers
  • Loading branch information
chibenwa committed May 8, 2017
1 parent ef01c32 commit ffeccf9af8978140ce3c840cbea1cbbcee2863a5
Showing 4 changed files with 33 additions and 4 deletions.
@@ -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>
@@ -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 @@ protected boolean match(String comparator, String matchType,
}
// 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;
}
@@ -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;}";
@@ -54,6 +54,21 @@ public void testHeaderIsTrue() {
Assert.assertTrue(isTestPassed);
}

/**
* 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'
*/
@@ -91,10 +91,16 @@
<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>

0 comments on commit ffeccf9

Please sign in to comment.