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 22:03:54 UTC
svn commit: r1058315 - in /james/mime4j/trunk: ./
core/src/main/java/org/apache/james/mime4j/codec/
core/src/main/java/org/apache/james/mime4j/stream/
core/src/main/java/org/apache/james/mime4j/util/
core/src/test/java/org/apache/james/mime4j/io/ core/...
Author: olegk
Date: Wed Jan 12 21:03:53 2011
New Revision: 1058315
URL: http://svn.apache.org/viewvc?rev=1058315&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; slightly more efficient #equals and #hashCode implementations for Mailbox (merged from a refactoring branch)
Added:
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/LangUtils.java
- copied unchanged from r1058305, james/mime4j/branches/dom-api-refactoring/core/src/main/java/org/apache/james/mime4j/util/LangUtils.java
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/
- copied from r1058305, james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/AddressFormatter.java
- copied unchanged from r1058305, james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/field/address/formatter/AddressFormatter.java
Removed:
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/parser/GroupImpl.java
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/parser/MailboxImpl.java
Modified:
james/mime4j/trunk/ (props changed)
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/CodecUtil.java (props changed)
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java (props changed)
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java (props changed)
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/BaseTestForBodyDescriptors.java (props changed)
james/mime4j/trunk/dom/ (props changed)
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Address.java
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Group.java
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/MailboxList.java
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AbstractField.java (props changed)
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
Propchange: james/mime4j/trunk/
------------------------------------------------------------------------------
svn:mergeinfo = /james/mime4j/branches/dom-api-refactoring:1058070-1058305
Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/CodecUtil.java
('svn:mergeinfo' removed)
Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/RawField.java
('svn:mergeinfo' removed)
Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java
('svn:mergeinfo' removed)
Propchange: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/BaseTestForBodyDescriptors.java
('svn:mergeinfo' removed)
Propchange: james/mime4j/trunk/dom/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jan 12 21:03:53 2011
@@ -0,0 +1,3 @@
+.settings
+.classpath
+.project
Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Address.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Address.java?rev=1058315&r1=1058314&r2=1058315&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Address.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Address.java Wed Jan 12 21:03:53 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/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Group.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Group.java?rev=1058315&r1=1058314&r2=1058315&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Group.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Group.java Wed Jan 12 21:03:53 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/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java?rev=1058315&r1=1058314&r2=1058315&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/Mailbox.java Wed Jan 12 21:03:53 2011
@@ -23,10 +23,12 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
+import org.apache.james.mime4j.util.LangUtils;
+
/**
* 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 +74,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,43 +158,17 @@ 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();
+ protected final void doAddMailboxesTo(List<Mailbox> results) {
+ results.add(this);
}
@Override
public int hashCode() {
- return getCanonicalizedAddress().hashCode();
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.localPart);
+ hash = LangUtils.hashCode(hash, this.domain != null ?
+ this.domain.toLowerCase(Locale.US) : null);
+ return hash;
}
/**
@@ -174,23 +191,14 @@ public abstract class Mailbox extends Ad
return true;
if (!(obj instanceof Mailbox))
return false;
-
- Mailbox other = (Mailbox) obj;
- return getCanonicalizedAddress()
- .equals(other.getCanonicalizedAddress());
+ Mailbox that = (Mailbox) obj;
+ return LangUtils.equals(this.localPart, that.localPart) &&
+ LangUtils.equalsIgnoreCase(this.domain, that.domain);
}
@Override
- protected final void doAddMailboxesTo(List<Mailbox> results) {
- results.add(this);
- }
-
- private Object getCanonicalizedAddress() {
- if (domain == null) {
- return localPart;
- } else {
- return localPart + '@' + domain.toLowerCase(Locale.US);
- }
+ public String toString() {
+ return getAddress();
}
}
Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/MailboxList.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/MailboxList.java?rev=1058315&r1=1058314&r2=1058315&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/MailboxList.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/dom/address/MailboxList.java Wed Jan 12 21:03:53 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());
- }
- }
-
}
Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/AbstractField.java
('svn:mergeinfo' removed)
Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java?rev=1058315&r1=1058314&r2=1058315&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/Fields.java Wed Jan 12 21:03:53 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();
}
Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java?rev=1058315&r1=1058314&r2=1058315&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java Wed Jan 12 21:03:53 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/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java?rev=1058315&r1=1058314&r2=1058315&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java Wed Jan 12 21:03:53 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/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java?rev=1058315&r1=1058314&r2=1058315&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldsTest.java Wed Jan 12 21:03:53 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/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java?rev=1058315&r1=1058314&r2=1058315&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java Wed Jan 12 21:03:53 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 {
@@ -417,5 +415,28 @@ public class AddressTest extends TestCas
} catch (ParseException expected) {
}
}
+
+ public void testMailboxEquals() throws Exception {
+ Mailbox m1 = new Mailbox("john.doe", "acme.org");
+ Mailbox m2 = new Mailbox("john doe", "acme.org");
+ Mailbox m3 = new Mailbox("john.doe", "Acme.Org");
+ Mailbox m4 = new Mailbox("john.doe", null);
+ assertTrue(m1.equals(m1));
+ assertFalse(m1.equals(m2));
+ assertTrue(m1.equals(m3));
+ assertFalse(m1.equals(m4));
+ assertFalse(m1.equals(null));
+ }
+ public void testMailboxHashCode() throws Exception {
+ Mailbox m1 = new Mailbox("john.doe", "acme.org");
+ Mailbox m2 = new Mailbox("john doe", "acme.org");
+ Mailbox m3 = new Mailbox("john.doe", "Acme.Org");
+ Mailbox m4 = new Mailbox("john.doe", null);
+ assertTrue(m1.hashCode() == m1.hashCode());
+ assertFalse(m1.hashCode() == m2.hashCode());
+ assertTrue(m1.hashCode() == m3.hashCode());
+ assertFalse(m1.hashCode() == m4.hashCode());
+ }
+
}
Modified: james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java?rev=1058315&r1=1058314&r2=1058315&view=diff
==============================================================================
--- james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java (original)
+++ james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java Wed Jan 12 21:03:53 2011
@@ -53,6 +53,7 @@ import org.apache.james.mime4j.dom.field
import org.apache.james.mime4j.dom.field.DateTimeField;
import org.apache.james.mime4j.dom.field.Field;
import org.apache.james.mime4j.dom.field.UnstructuredField;
+import org.apache.james.mime4j.field.address.formatter.AddressFormatter;
import org.apache.james.mime4j.message.BodyPart;
import org.apache.james.mime4j.message.MessageImpl;
@@ -312,7 +313,7 @@ public class MessageTree extends JPanel
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
Mailbox mb = list.get(i);
- sb.append(mb.getDisplayString() + "\n");
+ sb.append(AddressFormatter.format(mb, false) + "\n");
}
textView.setText(sb.toString());