You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mime4j-dev@james.apache.org by ol...@apache.org on 2011/01/12 16:31:34 UTC

svn commit: r1058191 - in /james/mime4j/branches/dom-api-refactoring/dom/src: main/java/org/apache/james/mime4j/dom/address/ main/java/org/apache/james/mime4j/field/ main/java/org/apache/james/mime4j/field/address/formatter/ main/java/org/apache/james/...

Author: olegk
Date: Wed Jan 12 15:31:33 2011
New Revision: 1058191

URL: http://svn.apache.org/viewvc?rev=1058191&view=rev
Log:
Factored out address formatting code to a separate utility class similar to AddressBuilder; there is no longer a need for MailboxImlp and GroupImpl

Added:
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/AddressFormatter.java   (with props)
Removed:
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/parser/GroupImpl.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/parser/MailboxImpl.java
Modified:
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Address.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Group.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/MailboxList.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/Fields.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java
    james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java
    james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
    james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Address.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Address.java?rev=1058191&r1=1058190&r2=1058191&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Address.java (original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Address.java Wed Jan 12 15:31:33 2011
@@ -45,55 +45,4 @@ public abstract class Address implements
      */
     protected abstract void doAddMailboxesTo(List<Mailbox> results);
 
-    /**
-     * Formats the address as a human readable string, not including the route.
-     * The resulting string is intended for display purposes only and cannot be
-     * used for transport purposes.
-     * 
-     * @return a string representation of this address intended to be displayed
-     * @see #getDisplayString(boolean)
-     */
-    public final String getDisplayString() {
-        return getDisplayString(false);
-    }
-
-    /**
-     * Formats the address as a human readable string, not including the route.
-     * The resulting string is intended for display purposes only and cannot be
-     * used for transport purposes.
-     * 
-     * For example, if the unparsed address was
-     * 
-     * <"Joe Cheng"@joecheng.com>
-     * 
-     * this method would return
-     * 
-     * <Joe Cheng@joecheng.com>
-     * 
-     * which is not valid for transport; the local part would need to be
-     * re-quoted.
-     * 
-     * @param includeRoute
-     *            <code>true</code> if the route should be included if it
-     *            exists, <code>false</code> otherwise.
-     * @return a string representation of this address intended to be displayed.
-     */
-    public abstract String getDisplayString(boolean includeRoute);
-
-    /**
-     * Returns a string representation of this address that can be used for
-     * transport purposes. The route is never included in this representation
-     * because routes are obsolete and RFC 5322 states that obsolete syntactic
-     * forms MUST NOT be generated.
-     * 
-     * @return a string representation of this address intended for transport
-     *         purposes.
-     */
-    public abstract String getEncodedString();
-
-    @Override
-    public String toString() {
-        return getDisplayString(false);
-    }
-
 }
\ No newline at end of file

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Group.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Group.java?rev=1058191&r1=1058190&r2=1058191&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Group.java (original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Group.java Wed Jan 12 15:31:33 2011
@@ -19,12 +19,15 @@
 
 package org.apache.james.mime4j.dom.address;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 
 /**
  * A named group of zero or more mailboxes.
  */
-public abstract class Group extends Address {
+public class Group extends Address {
 
     private static final long serialVersionUID = 1L;
 
@@ -48,6 +51,26 @@ public abstract class Group extends Addr
     }
 
     /**
+     * @param name
+     *            The group name.
+     * @param mailboxes
+     *            The mailboxes in this group.
+     */
+    public Group(String name, Mailbox... mailboxes) {
+        this(name, new MailboxList(Arrays.asList(mailboxes), true));
+    }
+
+    /**
+     * @param name
+     *            The group name.
+     * @param mailboxes
+     *            The mailboxes in this group.
+     */
+    public Group(String name, Collection<Mailbox> mailboxes) {
+        this(name, new MailboxList(new ArrayList<Mailbox>(mailboxes), true));
+    }
+
+    /**
      * Returns the group name.
      */
     public String getName() {
@@ -62,12 +85,17 @@ public abstract class Group extends Addr
     }
 
     @Override
-    public String getDisplayString(boolean includeRoute) {
-        StringBuilder sb = new StringBuilder();
+    protected void doAddMailboxesTo(List<Mailbox> results) {
+        for (Mailbox mailbox : mailboxList) {
+            results.add(mailbox);
+        }
+    }
 
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
         sb.append(name);
         sb.append(':');
-
         boolean first = true;
         for (Mailbox mailbox : mailboxList) {
             if (first) {
@@ -75,21 +103,11 @@ public abstract class Group extends Addr
             } else {
                 sb.append(',');
             }
-
             sb.append(' ');
-            sb.append(mailbox.getDisplayString(includeRoute));
+            sb.append(mailbox);
         }
-
         sb.append(";");
-
         return sb.toString();
     }
-
-    @Override
-    protected void doAddMailboxesTo(List<Mailbox> results) {
-        for (Mailbox mailbox : mailboxList) {
-            results.add(mailbox);
-        }
-    }
-
+    
 }

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java?rev=1058191&r1=1058190&r2=1058191&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java (original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java Wed Jan 12 15:31:33 2011
@@ -26,7 +26,7 @@ import java.util.Locale;
 /**
  * Represents a single e-mail address.
  */
-public abstract class Mailbox extends Address {
+public class Mailbox extends Address {
 
     private static final long serialVersionUID = 1L;
 
@@ -72,6 +72,47 @@ public abstract class Mailbox extends Ad
     }
 
     /**
+     * Creates an unnamed mailbox without a route. Routes are obsolete.
+     * 
+     * @param localPart
+     *            The part of the e-mail address to the left of the "@".
+     * @param domain
+     *            The part of the e-mail address to the right of the "@".
+     */
+    public Mailbox(String localPart, String domain) {
+        this(null, null, localPart, domain);
+    }
+
+    /**
+     * Creates an unnamed mailbox with a route. Routes are obsolete.
+     * 
+     * @param route
+     *            The zero or more domains that make up the route. May be
+     *            <code>null</code>.
+     * @param localPart
+     *            The part of the e-mail address to the left of the "@".
+     * @param domain
+     *            The part of the e-mail address to the right of the "@".
+     */
+    public Mailbox(DomainList route, String localPart, String domain) {
+        this(null, route, localPart, domain);
+    }
+
+    /**
+     * Creates a named mailbox without a route. Routes are obsolete.
+     * 
+     * @param name
+     *            the name of the e-mail address. May be <code>null</code>.
+     * @param localPart
+     *            The part of the e-mail address to the left of the "@".
+     * @param domain
+     *            The part of the e-mail address to the right of the "@".
+     */
+    public Mailbox(String name, String localPart, String domain) {
+        this(name, null, localPart, domain);
+    }
+
+    /**
      * Returns the name of the mailbox or <code>null</code> if it does not
      * have a name.
      */
@@ -115,41 +156,6 @@ public abstract class Mailbox extends Ad
     }
 
     @Override
-    public String getDisplayString(boolean includeRoute) {
-        includeRoute &= route != null;
-        boolean includeAngleBrackets = name != null || includeRoute;
-
-        StringBuilder sb = new StringBuilder();
-
-        if (name != null) {
-            sb.append(name);
-            sb.append(' ');
-        }
-
-        if (includeAngleBrackets) {
-            sb.append('<');
-        }
-
-        if (includeRoute) {
-            sb.append(route.toRouteString());
-            sb.append(':');
-        }
-
-        sb.append(localPart);
-
-        if (domain != null) {
-            sb.append('@');
-            sb.append(domain);
-        }
-
-        if (includeAngleBrackets) {
-            sb.append('>');
-        }
-
-        return sb.toString();
-    }
-
-    @Override
     public int hashCode() {
         return getCanonicalizedAddress().hashCode();
     }
@@ -185,7 +191,7 @@ public abstract class Mailbox extends Ad
         results.add(this);
     }
 
-    private Object getCanonicalizedAddress() {
+    private String getCanonicalizedAddress() {
         if (domain == null) {
             return localPart;
         } else {
@@ -193,4 +199,9 @@ public abstract class Mailbox extends Ad
         }
     }
 
+    @Override
+    public String toString() {
+        return getCanonicalizedAddress();
+    }
+
 }

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/MailboxList.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/MailboxList.java?rev=1058191&r1=1058190&r2=1058191&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/MailboxList.java (original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/address/MailboxList.java Wed Jan 12 15:31:33 2011
@@ -65,15 +65,4 @@ public class MailboxList extends Abstrac
         return mailboxes.get(index);
     }
 
-    /**
-     * Dumps a representation of this mailbox list to stdout, for debugging
-     * purposes.
-     */
-    public void print() {
-        for (int i = 0; i < size(); i++) {
-            Mailbox mailbox = get(i);
-            System.out.println(mailbox.toString());
-        }
-    }
-
 }

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/Fields.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/Fields.java?rev=1058191&r1=1058190&r2=1058191&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/Fields.java (original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/Fields.java Wed Jan 12 15:31:33 2011
@@ -50,6 +50,7 @@ import org.apache.james.mime4j.field.Dat
 import org.apache.james.mime4j.field.MailboxFieldImpl;
 import org.apache.james.mime4j.field.MailboxListFieldImpl;
 import org.apache.james.mime4j.field.UnstructuredFieldImpl;
+import org.apache.james.mime4j.field.address.formatter.AddressFormatter;
 import org.apache.james.mime4j.stream.RawField;
 import org.apache.james.mime4j.util.MimeUtil;
 
@@ -634,9 +635,8 @@ public class Fields {
             if (sb.length() > 0) {
                 sb.append(", ");
             }
-            sb.append(address.getEncodedString());
+            AddressFormatter.encode(sb, address);
         }
-
         return sb.toString();
     }
 

Added: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/AddressFormatter.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/AddressFormatter.java?rev=1058191&view=auto
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/AddressFormatter.java (added)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/AddressFormatter.java Wed Jan 12 15:31:33 2011
@@ -0,0 +1,209 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.field.address.formatter;
+
+import org.apache.james.mime4j.codec.EncoderUtil;
+import org.apache.james.mime4j.dom.address.Address;
+import org.apache.james.mime4j.dom.address.Group;
+import org.apache.james.mime4j.dom.address.Mailbox;
+
+public class AddressFormatter {
+
+    /**
+     * Formats the address as a human readable string, not including the route.
+     * The resulting string is intended for display purposes only and cannot be
+     * used for transport purposes.
+     * 
+     * For example, if the unparsed address was
+     * 
+     * <"Joe Cheng"@joecheng.com>
+     * 
+     * this method would return
+     * 
+     * <Joe Cheng@joecheng.com>
+     * 
+     * which is not valid for transport; the local part would need to be
+     * re-quoted.
+     * 
+     * @param includeRoute
+     *            <code>true</code> if the route should be included if it
+     *            exists, <code>false</code> otherwise.
+     * @return a string representation of this address intended to be displayed.
+     */
+    public static void format(final StringBuilder sb, final Address address, boolean includeRoute) {
+        if (address == null) {
+            return;
+        }
+        if (address instanceof Mailbox) {
+            format(sb, (Mailbox) address, includeRoute);
+        } else if (address instanceof Group) {
+            format(sb, (Group) address, includeRoute);
+        } else {
+            throw new IllegalArgumentException("Unsuppported Address class: " + address.getClass());
+        }
+    }
+
+    /**
+     * Returns a string representation of this address that can be used for
+     * transport purposes. The route is never included in this representation
+     * because routes are obsolete and RFC 5322 states that obsolete syntactic
+     * forms MUST NOT be generated.
+     * 
+     * @return a string representation of this address intended for transport
+     *         purposes.
+     */
+    public static void encode(final StringBuilder sb, final Address address) {
+        if (address == null) {
+            return;
+        }
+        if (address instanceof Mailbox) {
+            encode(sb, (Mailbox) address);
+        } else if (address instanceof Group) {
+            encode(sb, (Group) address);
+        } else {
+            throw new IllegalArgumentException("Unsuppported Address class: " + address.getClass());
+        }
+    }
+    
+    public static void format(final StringBuilder sb, final Mailbox mailbox, boolean includeRoute) {
+        if (sb == null) {
+            throw new IllegalArgumentException("StringBuilder may not be null");
+        }
+        if (mailbox == null) {
+            throw new IllegalArgumentException("Mailbox may not be null");
+        }
+        includeRoute &= mailbox.getRoute() != null;
+        boolean includeAngleBrackets = mailbox.getName() != null || includeRoute;
+        if (mailbox.getName() != null) {
+            sb.append(mailbox.getName());
+            sb.append(' ');
+        }
+        if (includeAngleBrackets) {
+            sb.append('<');
+        }
+        if (includeRoute) {
+            sb.append(mailbox.getRoute().toRouteString());
+            sb.append(':');
+        }
+        sb.append(mailbox.getLocalPart());
+        if (mailbox.getDomain() != null) {
+            sb.append('@');
+            sb.append(mailbox.getDomain());
+        }
+        if (includeAngleBrackets) {
+            sb.append('>');
+        }
+    }
+    
+    public static String format(final Mailbox mailbox, boolean includeRoute) {
+        StringBuilder sb = new StringBuilder();
+        format(sb, mailbox, includeRoute);
+        return sb.toString();
+    }
+    
+    public static void encode(final StringBuilder sb, final Mailbox mailbox) {
+        if (sb == null) {
+            throw new IllegalArgumentException("StringBuilder may not be null");
+        }
+        if (mailbox == null) {
+            throw new IllegalArgumentException("Mailbox may not be null");
+        }
+        if (mailbox.getName() != null) {
+            sb.append(EncoderUtil.encodeAddressDisplayName(mailbox.getName()));
+            sb.append(" <");
+        }
+        sb.append(EncoderUtil.encodeAddressLocalPart(mailbox.getLocalPart()));
+        // domain = dot-atom / domain-literal
+        // domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
+        // dtext = %d33-90 / %d94-126
+        if (mailbox.getDomain() != null) {
+            sb.append('@');
+            sb.append(mailbox.getDomain());
+        }
+        if (mailbox.getName() != null) {
+            sb.append('>');
+        }
+    }
+    
+    public static String encode(final Mailbox mailbox) {
+        StringBuilder sb = new StringBuilder();
+        encode(sb, mailbox);
+        return sb.toString();
+    }
+
+    public static void format(final StringBuilder sb, final Group group, boolean includeRoute) {
+        if (sb == null) {
+            throw new IllegalArgumentException("StringBuilder may not be null");
+        }
+        if (group == null) {
+            throw new IllegalArgumentException("Group may not be null");
+        }
+        sb.append(group.getName());
+        sb.append(':');
+
+        boolean first = true;
+        for (Mailbox mailbox : group.getMailboxes()) {
+            if (first) {
+                first = false;
+            } else {
+                sb.append(',');
+            }
+            sb.append(' ');
+            format(sb, mailbox, includeRoute);
+        }
+        sb.append(";");
+    }
+    
+    public static String format(final Group group, boolean includeRoute) {
+        StringBuilder sb = new StringBuilder();
+        format(sb, group, includeRoute);
+        return sb.toString();
+    }
+    
+    public static void encode(final StringBuilder sb, final Group group) {
+        if (sb == null) {
+            throw new IllegalArgumentException("StringBuilder may not be null");
+        }
+        if (group == null) {
+            throw new IllegalArgumentException("Group may not be null");
+        }
+        sb.append(EncoderUtil.encodeAddressDisplayName(group.getName()));
+        sb.append(':');
+        boolean first = true;
+        for (Mailbox mailbox : group.getMailboxes()) {
+            if (first) {
+                first = false;
+            } else {
+                sb.append(',');
+            }
+
+            sb.append(' ');
+            encode(sb, mailbox);
+        }
+        sb.append(';');
+    }
+
+    public static String encode(final Group group) {
+        StringBuilder sb = new StringBuilder();
+        encode(sb, group);
+        return sb.toString();
+    }
+
+}
\ No newline at end of file

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/AddressFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/AddressFormatter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/AddressFormatter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java?rev=1058191&r1=1058190&r2=1058191&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java (original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java Wed Jan 12 15:31:33 2011
@@ -28,6 +28,7 @@ import org.apache.james.mime4j.codec.Dec
 import org.apache.james.mime4j.dom.address.Address;
 import org.apache.james.mime4j.dom.address.AddressList;
 import org.apache.james.mime4j.dom.address.DomainList;
+import org.apache.james.mime4j.dom.address.Group;
 import org.apache.james.mime4j.dom.address.Mailbox;
 import org.apache.james.mime4j.dom.address.MailboxList;
 
@@ -64,7 +65,7 @@ class Builder {
             String name = buildString((ASTphrase) n, false);
             Node n2 = it.next();
             if (n2 instanceof ASTgroup_body) {
-                return new GroupImpl(name, buildGroupBody((ASTgroup_body) n2, monitor));
+                return new Group(name, buildGroupBody((ASTgroup_body) n2, monitor));
             } else if (n2 instanceof ASTangle_addr) {
                 try {
                     name = DecoderUtil.decodeEncodedWords(name, monitor);
@@ -72,7 +73,7 @@ class Builder {
                     throw new ParseException(e.getMessage());
                 }
                 Mailbox mb = buildAngleAddr((ASTangle_addr) n2);
-                return new MailboxImpl(name, mb.getRoute(), mb.getLocalPart(),
+                return new Mailbox(name, mb.getRoute(), mb.getLocalPart(),
                         mb.getDomain());
             } else {
                 throw new ParseException();
@@ -127,7 +128,7 @@ class Builder {
                 throw new ParseException(e.getMessage());
             }
             Mailbox mb = buildAngleAddr((ASTangle_addr) n);
-            return new MailboxImpl(name, mb.getRoute(), mb.getLocalPart(),
+            return new Mailbox(name, mb.getRoute(), mb.getLocalPart(),
                     mb.getDomain());
         } else {
             throw new ParseException();
@@ -174,7 +175,7 @@ class Builder {
         ChildNodeIterator it = new ChildNodeIterator(node);
         String localPart = buildString((ASTlocal_part) it.next(), true);
         String domain = buildString((ASTdomain) it.next(), true);
-        return new MailboxImpl(route, localPart, domain);
+        return new Mailbox(route, localPart, domain);
     }
 
     private String buildString(SimpleNode node, boolean stripSpaces) {

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java?rev=1058191&r1=1058190&r2=1058191&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java (original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java Wed Jan 12 15:31:33 2011
@@ -41,7 +41,6 @@ import org.apache.james.mime4j.dom.addre
 import org.apache.james.mime4j.dom.address.Mailbox;
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
-import org.apache.james.mime4j.field.address.parser.GroupImpl;
 import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.MessageImpl;
 import org.apache.james.mime4j.message.MultipartImpl;
@@ -311,7 +310,7 @@ public class MessageTest extends TestCas
 
         Mailbox mailbox1 = AddressBuilder.parseMailbox("john.doe@example.net");
         Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.net");
-        Group group = new GroupImpl("Does", mailbox1, mailbox2);
+        Group group = new Group("Does", mailbox1, mailbox2);
         Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <ma...@example.net>");
 
         m.setTo(group);
@@ -349,7 +348,7 @@ public class MessageTest extends TestCas
 
         Mailbox mailbox1 = AddressBuilder.parseMailbox("john.doe@example.net");
         Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.net");
-        Group group = new GroupImpl("Does", mailbox1, mailbox2);
+        Group group = new Group("Does", mailbox1, mailbox2);
         Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <ma...@example.net>");
 
         m.setCc(group);
@@ -387,7 +386,7 @@ public class MessageTest extends TestCas
 
         Mailbox mailbox1 = AddressBuilder.parseMailbox("john.doe@example.net");
         Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.net");
-        Group group = new GroupImpl("Does", mailbox1, mailbox2);
+        Group group = new Group("Does", mailbox1, mailbox2);
         Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <ma...@example.net>");
 
         m.setBcc(group);
@@ -425,7 +424,7 @@ public class MessageTest extends TestCas
 
         Mailbox mailbox1 = AddressBuilder.parseMailbox("john.doe@example.net");
         Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.net");
-        Group group = new GroupImpl("Does", mailbox1, mailbox2);
+        Group group = new Group("Does", mailbox1, mailbox2);
         Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <ma...@example.net>");
 
         m.setReplyTo(group);

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java?rev=1058191&r1=1058190&r2=1058191&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java (original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java Wed Jan 12 15:31:33 2011
@@ -41,7 +41,6 @@ import org.apache.james.mime4j.dom.field
 import org.apache.james.mime4j.dom.field.MailboxListField;
 import org.apache.james.mime4j.field.Fields;
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
-import org.apache.james.mime4j.field.address.parser.GroupImpl;
 import org.apache.james.mime4j.util.ByteArrayBuffer;
 import org.apache.james.mime4j.util.ContentUtil;
 import org.apache.james.mime4j.util.MimeUtil;
@@ -268,7 +267,7 @@ public class FieldsTest extends TestCase
         Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <jo...@acme.org>");
         Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.org");
         Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <ma...@example.net>");
-        Group group = new GroupImpl("The Does", mailbox1, mailbox2);
+        Group group = new Group("The Does", mailbox1, mailbox2);
 
         AddressListField field = Fields.to(group);
         assertEquals("To: The Does: JD <jo...@acme.org>, "
@@ -289,7 +288,7 @@ public class FieldsTest extends TestCase
         Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <jo...@acme.org>");
         Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.org");
         Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <ma...@example.net>");
-        Group group = new GroupImpl("The Does", mailbox1, mailbox2);
+        Group group = new Group("The Does", mailbox1, mailbox2);
 
         AddressListField field = Fields.cc(group);
         assertEquals("Cc: The Does: JD <jo...@acme.org>, "
@@ -310,7 +309,7 @@ public class FieldsTest extends TestCase
         Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <jo...@acme.org>");
         Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.org");
         Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <ma...@example.net>");
-        Group group = new GroupImpl("The Does", mailbox1, mailbox2);
+        Group group = new Group("The Does", mailbox1, mailbox2);
 
         AddressListField field = Fields.bcc(group);
         assertEquals("Bcc: The Does: JD <jo...@acme.org>, "
@@ -331,7 +330,7 @@ public class FieldsTest extends TestCase
         Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <jo...@acme.org>");
         Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.org");
         Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <ma...@example.net>");
-        Group group = new GroupImpl("The Does", mailbox1, mailbox2);
+        Group group = new Group("The Does", mailbox1, mailbox2);
 
         AddressListField field = Fields.replyTo(group);
         assertEquals("Reply-To: The Does: JD <jo...@acme.org>, "
@@ -369,7 +368,7 @@ public class FieldsTest extends TestCase
         Mailbox mailbox1 = AddressBuilder.parseMailbox("JD <jo...@acme.org>");
         Mailbox mailbox2 = AddressBuilder.parseMailbox("jane.doe@example.org");
         Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith <ma...@example.net>");
-        Group group = new GroupImpl("The Does", mailbox1, mailbox2);
+        Group group = new Group("The Does", mailbox1, mailbox2);
 
         AddressListField field = Fields.addressList("Resent-To", Arrays.asList(
                 group, mailbox3));

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java?rev=1058191&r1=1058190&r2=1058191&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java (original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java Wed Jan 12 15:31:33 2011
@@ -26,9 +26,8 @@ import org.apache.james.mime4j.dom.addre
 import org.apache.james.mime4j.dom.address.Group;
 import org.apache.james.mime4j.dom.address.Mailbox;
 import org.apache.james.mime4j.dom.address.MailboxList;
+import org.apache.james.mime4j.field.address.formatter.AddressFormatter;
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
-import org.apache.james.mime4j.field.address.parser.GroupImpl;
-import org.apache.james.mime4j.field.address.parser.MailboxImpl;
 import org.apache.james.mime4j.field.address.parser.ParseException;
 
 import java.util.ArrayList;
@@ -268,33 +267,32 @@ public class AddressTest extends TestCas
 
     public void testMailboxList() {
         List<Mailbox> al = new ArrayList<Mailbox>();
-        al.add(new MailboxImpl("local","example.com"));
+        al.add(new Mailbox("local","example.com"));
 
         // shared arraylist
         MailboxList ml = new MailboxList(al, true);
         assertEquals(1, ml.size());
-        al.add(new MailboxImpl("local2", "foo.example.com"));
+        al.add(new Mailbox("local2", "foo.example.com"));
         assertEquals(2, ml.size());
         
         // cloned arraylist
         MailboxList mlcopy = new MailboxList(al, false);
         assertEquals(2, mlcopy.size());
-        al.add(new MailboxImpl("local3", "bar.example.com"));
+        al.add(new Mailbox("local3", "bar.example.com"));
         assertEquals(2, mlcopy.size());
-        
-        mlcopy.print();
     }
     
     public void testGroupSerialization() {
         List<Mailbox> al = new ArrayList<Mailbox>();
-        al.add(new MailboxImpl("test", "example.com"));
-        al.add(new MailboxImpl("Foo!", "foo", "example.com"));
+        al.add(new Mailbox("test", "example.com"));
+        al.add(new Mailbox("Foo!", "foo", "example.com"));
         DomainList dl = new DomainList(new ArrayList<String>(Arrays.asList(new String[] {"foo.example.com"})), true);
-        Mailbox mailbox = new MailboxImpl("Foo Bar", dl, "foo2", "example.com");
+        Mailbox mailbox = new Mailbox("Foo Bar", dl, "foo2", "example.com");
         assertSame(dl, mailbox.getRoute());
         al.add(mailbox);
-        Group g = new GroupImpl("group", new MailboxList(al, false));
-        assertEquals("group: test@example.com, Foo! <fo...@example.com>, Foo Bar <fo...@example.com>;", g.getDisplayString());
+        Group g = new Group("group", new MailboxList(al, false));
+        String s = AddressFormatter.format(g, false);
+        assertEquals("group: test@example.com, Foo! <fo...@example.com>, Foo Bar <fo...@example.com>;", s);
     }
     
     public void testEmptyQuotedStringBeforeDotAtomInLocalPart() throws Exception {
@@ -310,34 +308,34 @@ public class AddressTest extends TestCas
     }
     
     public void testMailboxGetEncodedString() throws Exception {
-        assertEquals("john.doe@acme.org", new MailboxImpl("john.doe", "acme.org")
-                .getEncodedString());
-        assertEquals("\"john doe\"@acme.org", new MailboxImpl("john doe",
-                "acme.org").getEncodedString());
-        assertEquals("John Doe <jo...@acme.org>", new MailboxImpl("John Doe",
-                "john.doe", "acme.org").getEncodedString());
-        assertEquals("\"John Doe @Home\" <jo...@acme.org>", new MailboxImpl(
-                "John Doe @Home", "john.doe", "acme.org").getEncodedString());
+        Mailbox m1 = new Mailbox("john.doe", "acme.org");
+        assertEquals("john.doe@acme.org", AddressFormatter.encode(m1));
+        Mailbox m2 = new Mailbox("john doe", "acme.org");
+        assertEquals("\"john doe\"@acme.org", AddressFormatter.encode(m2));
+        Mailbox m3 = new Mailbox("John Doe", "john.doe", "acme.org");
+        assertEquals("John Doe <jo...@acme.org>", AddressFormatter.encode(m3));
+        Mailbox m4 = new Mailbox("John Doe @Home", "john.doe", "acme.org");
+        assertEquals("\"John Doe @Home\" <jo...@acme.org>", AddressFormatter.encode(m4));
+        Mailbox m5 = new Mailbox("Hans M\374ller", "hans.mueller", "acme.org");
         assertEquals("=?ISO-8859-1?Q?Hans_M=FCller?= <ha...@acme.org>",
-                new MailboxImpl("Hans M\374ller", "hans.mueller", "acme.org")
-                        .getEncodedString());
+                AddressFormatter.encode(m5));
     }
 
     public void testGroupGetEncodedString() throws Exception {
         List<Mailbox> al = new ArrayList<Mailbox>();
-        al.add(new MailboxImpl("test", "example.com"));
-        al.add(new MailboxImpl("Foo!", "foo", "example.com"));
-        al.add(new MailboxImpl("Hans M\374ller", "hans.mueller", "acme.org"));
-        Group g = new GroupImpl("group @work", new MailboxList(al, false));
+        al.add(new Mailbox("test", "example.com"));
+        al.add(new Mailbox("Foo!", "foo", "example.com"));
+        al.add(new Mailbox("Hans M\374ller", "hans.mueller", "acme.org"));
+        Group g = new Group("group @work", new MailboxList(al, false));
         assertEquals("\"group @work\": test@example.com, "
                 + "Foo! <fo...@example.com>, =?ISO-8859-1?Q?Hans_M=FCller?="
-                + " <ha...@acme.org>;", g.getEncodedString());
+                + " <ha...@acme.org>;", AddressFormatter.encode(g));
     }
 
     public void testEmptyGroupGetEncodedString() throws Exception {
         MailboxList emptyMailboxes = new MailboxList(null, true);
-        Group g = new GroupImpl("Undisclosed recipients", emptyMailboxes);
-        assertEquals("Undisclosed recipients:;", g.getEncodedString());
+        Group g = new Group("Undisclosed recipients", emptyMailboxes);
+        assertEquals("Undisclosed recipients:;", AddressFormatter.encode(g));
     }
 
     public void testParseAddress() throws Exception {