Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MIME4J-210: lenient address parser does not decode encoded display names

git-svn-id: https://svn.apache.org/repos/asf/james/mime4j/trunk@1213393 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 28f70e83eee11063653ce86d5daa05662bb76922 1 parent 9024242
@ok2c ok2c authored
View
5 .gitignore
@@ -0,0 +1,5 @@
+.classpath
+.project
+.settings
+target
+maven-eclipse.xml
View
29 dom/src/main/java/org/apache/james/mime4j/field/address/LenientAddressBuilder.java
@@ -24,6 +24,8 @@
import java.util.Collections;
import java.util.List;
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.codec.DecoderUtil;
import org.apache.james.mime4j.dom.address.Address;
import org.apache.james.mime4j.dom.address.AddressList;
import org.apache.james.mime4j.dom.address.DomainList;
@@ -54,12 +56,14 @@
private static final BitSet COLON_ONLY = RawFieldParser.INIT_BITSET(COLON);
private static final BitSet SEMICOLON_ONLY = RawFieldParser.INIT_BITSET(SEMICOLON);
- public static final LenientAddressBuilder DEFAULT = new LenientAddressBuilder();
+ public static final LenientAddressBuilder DEFAULT = new LenientAddressBuilder(DecodeMonitor.SILENT);
+ private final DecodeMonitor monitor;
private final RawFieldParser parser;
- protected LenientAddressBuilder() {
+ protected LenientAddressBuilder(final DecodeMonitor monitor) {
super();
+ this.monitor = monitor;
this.parser = new RawFieldParser();
}
@@ -123,40 +127,47 @@ DomainList parseRoute(final ByteSequence buf, final ParserCursor cursor, final B
return domains != null ? new DomainList(domains, true) : null;
}
+ private Mailbox createMailbox(
+ final String name, final DomainList route, final String localPart, final String domain) {
+ return new Mailbox(
+ name != null ? DecoderUtil.decodeEncodedWords(name, this.monitor) : null,
+ route, localPart, domain);
+ }
+
Mailbox parseMailboxAddress(
final String openingText, final ByteSequence buf, final ParserCursor cursor) {
if (cursor.atEnd()) {
- return new Mailbox(null, null, openingText, null);
+ return createMailbox(null, null, openingText, null);
}
int pos = cursor.getPos();
char current = (char) (buf.byteAt(pos) & 0xff);
if (current == OPENING_BRACKET) {
cursor.updatePos(pos + 1);
} else {
- return new Mailbox(null, null, openingText, null);
+ return createMailbox(null, null, openingText, null);
}
DomainList domainList = parseRoute(buf, cursor, CLOSING_BRACKET_ONLY);
String localPart = this.parser.parseValue(buf, cursor, AT_AND_CLOSING_BRACKET);
if (cursor.atEnd()) {
- return new Mailbox(openingText, domainList, localPart, null);
+ return createMailbox(openingText, domainList, localPart, null);
}
pos = cursor.getPos();
current = (char) (buf.byteAt(pos) & 0xff);
if (current == AT) {
cursor.updatePos(pos + 1);
} else {
- return new Mailbox(openingText, domainList, localPart, null);
+ return createMailbox(openingText, domainList, localPart, null);
}
String domain = parseDomain(buf, cursor, CLOSING_BRACKET_ONLY);
if (cursor.atEnd()) {
- return new Mailbox(openingText, domainList, localPart, domain);
+ return createMailbox(openingText, domainList, localPart, domain);
}
pos = cursor.getPos();
current = (char) (buf.byteAt(pos) & 0xff);
if (current == CLOSING_BRACKET) {
cursor.updatePos(pos + 1);
} else {
- return new Mailbox(openingText, domainList, localPart, domain);
+ return createMailbox(openingText, domainList, localPart, domain);
}
while (!cursor.atEnd()) {
pos = cursor.getPos();
@@ -169,7 +180,7 @@ Mailbox parseMailboxAddress(
break;
}
}
- return new Mailbox(openingText, domainList, localPart, domain);
+ return createMailbox(openingText, domainList, localPart, domain);
}
private Mailbox createMailbox(final String localPart) {
View
7 dom/src/test/java/org/apache/james/mime4j/field/address/DefaultAddressBuilderTest.java
@@ -68,6 +68,13 @@ public void testParseMailbox() throws ParseException {
}
+ public void testParseMailboxEncoded() throws ParseException {
+ Mailbox mailbox1 = parser.parseMailbox("=?ISO-8859-1?B?c3R1ZmY=?= <stuff@localhost.localdomain>");
+ assertEquals("stuff", mailbox1.getName());
+ assertEquals("stuff", mailbox1.getLocalPart());
+ assertEquals("localhost.localdomain", mailbox1.getDomain());
+ }
+
public void testParseMailboxObsoleteSynatax() throws ParseException {
Mailbox mailbox1 = parser.parseMailbox("< (route)(obsolete) " +
"@host1.domain1 , @host2 . domain2: foo@bar.org>");
View
7 dom/src/test/java/org/apache/james/mime4j/field/address/LenientAddressBuilderTest.java
@@ -180,6 +180,13 @@ public void testParseMailbox() throws Exception {
assertEquals("hans.mueller@acme.org", mailbox5.getAddress());
}
+ public void testParseMailboxEncoded() throws ParseException {
+ Mailbox mailbox1 = parser.parseMailbox("=?ISO-8859-1?B?c3R1ZmY=?= <stuff@localhost.localdomain>");
+ assertEquals("stuff", mailbox1.getName());
+ assertEquals("stuff", mailbox1.getLocalPart());
+ assertEquals("localhost.localdomain", mailbox1.getDomain());
+ }
+
public void testParseMailboxNonASCII() throws Exception {
Mailbox mailbox1 = parser.parseMailbox(
"Hans M\374ller <hans.mueller@acme.org>");
Please sign in to comment.
Something went wrong with that request. Please try again.