You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2016/08/26 07:41:51 UTC
[3/3] james-project git commit: MAILET-100 fix wrong header encoding
test case
MAILET-100 fix wrong header encoding test case
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/240bed00
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/240bed00
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/240bed00
Branch: refs/heads/master
Commit: 240bed003bf2b4acef685b5c88178711012b641b
Parents: 34dd34f
Author: Matthieu Baechler <ma...@linagora.com>
Authored: Thu Aug 25 12:10:24 2016 +0200
Committer: Matthieu Baechler <ma...@linagora.com>
Committed: Thu Aug 25 17:13:55 2016 +0200
----------------------------------------------------------------------
.../transport/mailets/AddSubjectPrefix.java | 69 +-------------------
.../transport/mailets/AddSubjectPrefixTest.java | 2 -
2 files changed, 1 insertion(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/240bed00/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddSubjectPrefix.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddSubjectPrefix.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddSubjectPrefix.java
index 1ef8579..d155801 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddSubjectPrefix.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/AddSubjectPrefix.java
@@ -22,7 +22,6 @@ package org.apache.james.transport.mailets;
import org.apache.mailet.Mail;
import org.apache.mailet.base.GenericMailet;
-import org.apache.mailet.base.RFC2822Headers;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
@@ -57,40 +56,8 @@ public class AddSubjectPrefix extends GenericMailet {
@Override
public void service(Mail mail) throws MessagingException {
MimeMessage m = mail.getMessage();
-
String newSubject = prefixSubject(m);
-
- /*
- * Get sure to use the right encoding when add the subjectPrefix..
- * otherwise we get problems with some special chars
- */
- String rawSubject = getFirstSubjectHeader(m);
- String mimeCharset = determineMailHeaderEncodingCharset(rawSubject);
- if (mimeCharset == null) { // most likely ASCII
- // it uses the system charset or the value of the
- // mail.mime.charset property if set
- m.setSubject(newSubject, Charsets.UTF_8.displayName());
- } else { // original charset determined
- String javaCharset = javax.mail.internet.MimeUtility
- .javaCharset(mimeCharset);
- try {
- m.setSubject(newSubject, javaCharset);
- } catch (MessagingException e) {
- // known, but unsupported encoding
- // this should be logged, the admin may setup a more i18n
- // capable JRE, but the log API cannot be accessed from here
- // if (charset != null) log(charset +
- // " charset unsupported by the JRE, email subject may be
- // damaged");
- m.setSubject(newSubject); // recover
- }
- m.saveChanges();
- }
- }
-
- private String getFirstSubjectHeader(MimeMessage m) throws MessagingException {
- String delimiter = null;
- return m.getHeader(RFC2822Headers.SUBJECT, delimiter);
+ m.setSubject(newSubject, Charsets.UTF_8.displayName());
}
private String prefixSubject(MimeMessage m) throws MessagingException {
@@ -107,39 +74,5 @@ public class AddSubjectPrefix extends GenericMailet {
return "AddSubjectPrefix Mailet";
}
- /**
- * It attempts to determine the charset used to encode an "unstructured" RFC
- * 822 header (like Subject). The encoding is specified in RFC 2047. If it
- * cannot determine or the the text is not encoded then it returns null.
- * <p/>
- * Here is an example raw text: Subject:
- * =?iso-8859-2?Q?leg=FAjabb_pr=F3ba_l=F5elemmel?=
- * <p/>
- * TODO: Should we include this in a util class ?
- *
- * @param rawText the raw (not decoded) value of the header. Null means that the
- * header was not present (in this case it always return null).
- * @return the MIME charset name or null if no encoding applied
- */
- static private String determineMailHeaderEncodingCharset(String rawText) {
- if (rawText == null)
- return null;
- int iEncodingPrefix = rawText.indexOf("=?");
- if (iEncodingPrefix == -1)
- return null;
- int iCharsetBegin = iEncodingPrefix + 2;
- int iSecondQuestionMark = rawText.indexOf('?', iCharsetBegin);
- if (iSecondQuestionMark == -1)
- return null;
- // safety checks
- if (iSecondQuestionMark == iCharsetBegin)
- return null; // empty charset? impossible
- int iThirdQuestionMark = rawText.indexOf('?', iSecondQuestionMark + 1);
- if (iThirdQuestionMark == -1)
- return null; // there must be one after encoding
- if (-1 == rawText.indexOf("?=", iThirdQuestionMark + 1))
- return null; // closing tag
- return rawText.substring(iCharsetBegin, iSecondQuestionMark);
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/240bed00/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
index d48fa95..8b80803 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
@@ -31,7 +31,6 @@ import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
import org.apache.mailet.base.test.MailUtil;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -63,7 +62,6 @@ public class AddSubjectPrefixTest {
}
- @Ignore
@Test
public void shouldAddPrefixToEncodedSubject() throws MessagingException {
mailetConfig.setProperty("subjectPrefix", "\u0420\u0443\u0441\u0441\u043a\u0438\u0439");
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org