james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1213393 - in /james/mime4j/trunk: ./ dom/src/main/java/org/apache/james/mime4j/field/address/ dom/src/test/java/org/apache/james/mime4j/field/address/
Date Mon, 12 Dec 2011 19:49:14 GMT
Author: olegk
Date: Mon Dec 12 19:49:14 2011
New Revision: 1213393

URL: http://svn.apache.org/viewvc?rev=1213393&view=rev
Log:
MIME4J-210: lenient address parser does not decode encoded display names

Added:
    james/mime4j/trunk/.gitignore
Modified:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/LenientAddressBuilder.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/DefaultAddressBuilderTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/LenientAddressBuilderTest.java

Added: james/mime4j/trunk/.gitignore
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/.gitignore?rev=1213393&view=auto
==============================================================================
--- james/mime4j/trunk/.gitignore (added)
+++ james/mime4j/trunk/.gitignore Mon Dec 12 19:49:14 2011
@@ -0,0 +1,5 @@
+.classpath
+.project
+.settings
+target
+maven-eclipse.xml

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/LenientAddressBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/LenientAddressBuilder.java?rev=1213393&r1=1213392&r2=1213393&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/LenientAddressBuilder.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/LenientAddressBuilder.java
Mon Dec 12 19:49:14 2011
@@ -24,6 +24,8 @@ import java.util.BitSet;
 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 @@ public class LenientAddressBuilder {
     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 @@ public class LenientAddressBuilder {
         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 @@ public class LenientAddressBuilder {
                 break;
             }
         }
-        return new Mailbox(openingText, domainList, localPart, domain);
+        return createMailbox(openingText, domainList, localPart, domain);
     }
 
     private Mailbox createMailbox(final String localPart) {

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/DefaultAddressBuilderTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/DefaultAddressBuilderTest.java?rev=1213393&r1=1213392&r2=1213393&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/DefaultAddressBuilderTest.java
(original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/DefaultAddressBuilderTest.java
Mon Dec 12 19:49:14 2011
@@ -68,6 +68,13 @@ public class DefaultAddressBuilderTest e
 
     }
 
+    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>");

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/LenientAddressBuilderTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/LenientAddressBuilderTest.java?rev=1213393&r1=1213392&r2=1213393&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/LenientAddressBuilderTest.java
(original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/LenientAddressBuilderTest.java
Mon Dec 12 19:49:14 2011
@@ -180,6 +180,13 @@ public class LenientAddressBuilderTest e
         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>");



Mime
View raw message