james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1204855 - in /james/mime4j/trunk/dom/src: main/java/org/apache/james/mime4j/field/address/LenientAddressBuilder.java test/java/org/apache/james/mime4j/field/address/LenientAddressBuilderTest.java
Date Tue, 22 Nov 2011 08:29:30 GMT
Author: olegk
Date: Tue Nov 22 08:29:29 2011
New Revision: 1204855

URL: http://svn.apache.org/viewvc?rev=1204855&view=rev
Log:
MIME4J-207: IndexOutOfBoundsException while parsing email address with a leading 'at' character

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/LenientAddressBuilderTest.java

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=1204855&r1=1204854&r2=1204855&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
Tue Nov 22 08:29:29 2011
@@ -50,7 +50,6 @@ public class LenientAddressBuilder {
 
     private static final BitSet AT_AND_CLOSING_BRACKET = RawFieldParser.INIT_BITSET(AT, CLOSING_BRACKET);
     private static final BitSet CLOSING_BRACKET_ONLY   = RawFieldParser.INIT_BITSET(CLOSING_BRACKET);
-    private static final BitSet COMMA_AND_COLON        = RawFieldParser.INIT_BITSET(COMMA,
COLON);
     private static final BitSet COMMA_ONLY             = RawFieldParser.INIT_BITSET(COMMA);
     private static final BitSet COLON_ONLY             = RawFieldParser.INIT_BITSET(COLON);
     private static final BitSet SEMICOLON_ONLY         = RawFieldParser.INIT_BITSET(SEMICOLON);
@@ -81,10 +80,17 @@ public class LenientAddressBuilder {
         return dst.toString();
     }
 
-    DomainList parseRoute(final ByteSequence buf, final ParserCursor cursor) {
+    DomainList parseRoute(final ByteSequence buf, final ParserCursor cursor, final BitSet
delimiters) {
+        BitSet bitset = RawFieldParser.INIT_BITSET(COMMA, COLON);
+        if (delimiters != null) {
+            bitset.or(delimiters);
+        }
         List<String> domains = null;
-        while (!cursor.atEnd()) {
+        for (;;) {
             this.parser.skipAllWhiteSpace(buf, cursor);
+            if (cursor.atEnd()) {
+                break;
+            }
             int pos = cursor.getPos();
             int current = (char) (buf.byteAt(pos) & 0xff);
             if (current == AT) {
@@ -92,13 +98,16 @@ public class LenientAddressBuilder {
             } else {
                 break;
             }
-            String s = parseDomain(buf, cursor, COMMA_AND_COLON);
+            String s = parseDomain(buf, cursor, bitset);
             if (s != null && s.length() > 0) {
                 if (domains == null) {
                     domains = new ArrayList<String>();
                 }
                 domains.add(s);
             }
+            if (cursor.atEnd()) {
+                break;
+            }
             pos = cursor.getPos();
             current = (char) (buf.byteAt(pos) & 0xff);
             if (current == COMMA) {
@@ -126,7 +135,7 @@ public class LenientAddressBuilder {
         } else {
             return new Mailbox(null, null, openingText, null);
         }
-        DomainList domainList = parseRoute(buf, cursor);
+        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);

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=1204855&r1=1204854&r2=1204855&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
Tue Nov 22 08:29:29 2011
@@ -122,7 +122,7 @@ public class LenientAddressBuilderTest e
         ByteSequence raw = ContentUtil.encode(s);
         ParserCursor cursor = new ParserCursor(0, s.length());
 
-        DomainList route = parser.parseRoute(raw, cursor);
+        DomainList route = parser.parseRoute(raw, cursor, null);
         assertNotNull(route);
         assertEquals(3, route.size());
         assertEquals("a", route.get(0));
@@ -131,12 +131,26 @@ public class LenientAddressBuilderTest e
         assertEquals('m', raw.byteAt(cursor.getPos()));
     }
 
+    public void testParseAddressStartingWithAt() throws Exception {
+        String s = "<@somehost.com@somehost.com>";
+        ByteSequence raw = ContentUtil.encode(s);
+        ParserCursor cursor = new ParserCursor(0, s.length());
+
+        Mailbox mailbox = parser.parseMailboxAddress(null, raw, cursor);
+        assertEquals("", mailbox.getLocalPart());
+        assertEquals(null, mailbox.getDomain());
+        DomainList route = mailbox.getRoute();
+        assertNotNull(route);
+        assertEquals(1, route.size());
+        assertEquals("somehost.com@somehost.com", route.get(0));
+    }
+    
     public void testParseNoRoute() throws Exception {
         String s = "stuff";
         ByteSequence raw = ContentUtil.encode(s);
         ParserCursor cursor = new ParserCursor(0, s.length());
 
-        DomainList route = parser.parseRoute(raw, cursor);
+        DomainList route = parser.parseRoute(raw, cursor, null);
         assertNull(route);
     }
 



Mime
View raw message