Author: bago
Date: Fri Jan 1 14:29:54 2010
New Revision: 895016
URL: http://svn.apache.org/viewvc?rev=895016&view=rev
Log:
Remove static parse methods from Address beans. Created an AddressBuilder in
the address.parser package for that methods. Moved "Builder" to that package
too. (MIME4J-156)
Added:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java
(with props)
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java
(contents, props changed)
- copied, changed from r894746,
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Builder.java
Removed:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Builder.java
Modified:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Address.java
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/AddressList.java
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Group.java
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Mailbox.java
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
Modified:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Address.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Address.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Address.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Address.java
Fri Jan 1 14:29:54 2010
@@ -20,12 +20,8 @@
package org.apache.james.mime4j.field.address;
import java.io.Serializable;
-import java.io.StringReader;
import java.util.List;
-import org.apache.james.mime4j.field.address.parser.AddressListParser;
-import org.apache.james.mime4j.field.address.parser.ParseException;
-
/**
* The abstract base for classes that represent RFC2822 addresses. This
includes
* groups and mailboxes.
@@ -95,25 +91,6 @@
*/
public abstract String getEncodedString();
- /**
- * Parses the specified raw string into an address.
- *
- * @param rawAddressString
- * string to parse.
- * @return an <code>Address</code> object for the specified string.
- * @throws IllegalArgumentException
- * if the raw string does not represent a single address.
- */
- public static Address parse(String rawAddressString) {
- AddressListParser parser = new AddressListParser(new StringReader(
- rawAddressString));
- try {
- return Builder.getInstance().buildAddress(parser.parseAddress());
- } catch (ParseException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
@Override
public String toString() {
return getDisplayString(false);
Modified:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/AddressList.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/AddressList.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/AddressList.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/AddressList.java
Fri Jan 1 14:29:54 2010
@@ -19,11 +19,7 @@
package org.apache.james.mime4j.field.address;
-import org.apache.james.mime4j.field.address.parser.AddressListParser;
-import org.apache.james.mime4j.field.address.parser.ParseException;
-
import java.io.Serializable;
-import java.io.StringReader;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
@@ -109,40 +105,4 @@
}
}
- /**
- * Parse the address list string, such as the value of a From, To, Cc, Bcc,
- * Sender, or Reply-To header.
- *
- * The string MUST be unfolded already.
- */
- public static AddressList parse(String rawAddressList)
- throws ParseException {
- AddressListParser parser = new AddressListParser(new StringReader(
- rawAddressList));
- return
Builder.getInstance().buildAddressList(parser.parseAddressList());
- }
-
- /**
- * Test console.
- */
- public static void main(String[] args) throws Exception {
- java.io.BufferedReader reader = new java.io.BufferedReader(
- new java.io.InputStreamReader(System.in));
- while (true) {
- try {
- System.out.print("> ");
- String line = reader.readLine();
- if (line.length() == 0 || line.toLowerCase().equals("exit")
- || line.toLowerCase().equals("quit")) {
- System.out.println("Goodbye.");
- return;
- }
- AddressList list = parse(line);
- list.print();
- } catch (Exception e) {
- e.printStackTrace();
- Thread.sleep(300);
- }
- }
- }
}
Modified:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Group.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Group.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Group.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Group.java
Fri Jan 1 14:29:54 2010
@@ -73,23 +73,6 @@
}
/**
- * Parses the specified raw string into a group address.
- *
- * @param rawGroupString
- * string to parse.
- * @return a <code>Group</code> object for the specified string.
- * @throws IllegalArgumentException
- * if the raw string does not represent a single group address.
- */
- public static Group parse(String rawGroupString) {
- Address address = Address.parse(rawGroupString);
- if (!(address instanceof Group))
- throw new IllegalArgumentException("Not a group address");
-
- return (Group) address;
- }
-
- /**
* Returns the group name.
*/
public String getName() {
Modified:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Mailbox.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Mailbox.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Mailbox.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Mailbox.java
Fri Jan 1 14:29:54 2010
@@ -19,14 +19,11 @@
package org.apache.james.mime4j.field.address;
-import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.apache.james.mime4j.codec.EncoderUtil;
-import org.apache.james.mime4j.field.address.parser.AddressListParser;
-import org.apache.james.mime4j.field.address.parser.ParseException;
/**
* Represents a single e-mail address.
@@ -118,26 +115,6 @@
}
/**
- * Parses the specified raw string into a mailbox address.
- *
- * @param rawMailboxString
- * string to parse.
- * @return a <code>Mailbox</code> object for the specified string.
- * @throws IllegalArgumentException
- * if the raw string does not represent a single mailbox
- * address.
- */
- public static Mailbox parse(String rawMailboxString) {
- AddressListParser parser = new AddressListParser(new StringReader(
- rawMailboxString));
- try {
- return Builder.getInstance().buildMailbox(parser.parseMailbox());
- } catch (ParseException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- /**
* Returns the name of the mailbox or <code>null</code> if it does not
* have a name.
*/
Added:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java?rev=895016&view=auto
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java
(added)
+++
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java
Fri Jan 1 14:29:54 2010
@@ -0,0 +1,125 @@
+/****************************************************************
+ * 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.parser;
+
+import java.io.StringReader;
+
+import org.apache.james.mime4j.field.address.Address;
+import org.apache.james.mime4j.field.address.AddressList;
+import org.apache.james.mime4j.field.address.Group;
+import org.apache.james.mime4j.field.address.Mailbox;
+
+public class AddressBuilder {
+
+ /**
+ * Parses the specified raw string into an address.
+ *
+ * @param rawAddressString
+ * string to parse.
+ * @return an <code>Address</code> object for the specified string.
+ * @throws IllegalArgumentException
+ * if the raw string does not represent a single address.
+ */
+ public static Address parseAddress(String rawAddressString) {
+ AddressListParser parser = new AddressListParser(new StringReader(
+ rawAddressString));
+ try {
+ return Builder.getInstance().buildAddress(parser.parseAddress());
+ } catch (ParseException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ /**
+ * Parse the address list string, such as the value of a From, To, Cc, Bcc,
+ * Sender, or Reply-To header.
+ *
+ * The string MUST be unfolded already.
+ */
+ public static AddressList parseAddressList(String rawAddressList)
+ throws ParseException {
+ AddressListParser parser = new AddressListParser(new StringReader(
+ rawAddressList));
+ return
Builder.getInstance().buildAddressList(parser.parseAddressList());
+ }
+
+
+ /**
+ * Test console for AddressList
+ */
+ public static void main(String[] args) throws Exception {
+ java.io.BufferedReader reader = new java.io.BufferedReader(
+ new java.io.InputStreamReader(System.in));
+ while (true) {
+ try {
+ System.out.print("> ");
+ String line = reader.readLine();
+ if (line.length() == 0 || line.toLowerCase().equals("exit")
+ || line.toLowerCase().equals("quit")) {
+ System.out.println("Goodbye.");
+ return;
+ }
+ AddressList list = AddressBuilder.parseAddressList(line);
+ list.print();
+ } catch (Exception e) {
+ e.printStackTrace();
+ Thread.sleep(300);
+ }
+ }
+ }
+
+ /**
+ * Parses the specified raw string into a mailbox address.
+ *
+ * @param rawMailboxString
+ * string to parse.
+ * @return a <code>Mailbox</code> object for the specified string.
+ * @throws IllegalArgumentException
+ * if the raw string does not represent a single mailbox
+ * address.
+ */
+ public static Mailbox parseMailbox(String rawMailboxString) {
+ AddressListParser parser = new AddressListParser(new StringReader(
+ rawMailboxString));
+ try {
+ return Builder.getInstance().buildMailbox(parser.parseMailbox());
+ } catch (ParseException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ /**
+ * Parses the specified raw string into a group address.
+ *
+ * @param rawGroupString
+ * string to parse.
+ * @return a <code>Group</code> object for the specified string.
+ * @throws IllegalArgumentException
+ * if the raw string does not represent a single group address.
+ */
+ public static Group parseGroup(String rawGroupString) {
+ Address address = parseAddress(rawGroupString);
+ if (!(address instanceof Group))
+ throw new IllegalArgumentException("Not a group address");
+
+ return (Group) address;
+ }
+
+}
Propchange:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/AddressBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java
(from r894746,
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Builder.java)
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Builder.java&r1=894746&r2=895016&rev=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/Builder.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java
Fri Jan 1 14:29:54 2010
@@ -17,9 +17,15 @@
* under the License. *
****************************************************************/
-package org.apache.james.mime4j.field.address;
+package org.apache.james.mime4j.field.address.parser;
import org.apache.james.mime4j.codec.DecoderUtil;
+import org.apache.james.mime4j.field.address.Address;
+import org.apache.james.mime4j.field.address.AddressList;
+import org.apache.james.mime4j.field.address.DomainList;
+import org.apache.james.mime4j.field.address.Group;
+import org.apache.james.mime4j.field.address.Mailbox;
+import org.apache.james.mime4j.field.address.MailboxList;
import org.apache.james.mime4j.field.address.parser.ASTaddr_spec;
import org.apache.james.mime4j.field.address.parser.ASTaddress;
import org.apache.james.mime4j.field.address.parser.ASTaddress_list;
@@ -75,7 +81,9 @@
return new Group(name, buildGroupBody((ASTgroup_body) n2));
} else if (n2 instanceof ASTangle_addr) {
name = DecoderUtil.decodeEncodedWords(name);
- return new Mailbox(name, buildAngleAddr((ASTangle_addr) n2));
+ Mailbox mb = buildAngleAddr((ASTangle_addr) n2);
+ return new Mailbox(name, mb.getRoute(), mb.getLocalPart(),
+ mb.getDomain());
} else {
throw new IllegalStateException();
}
@@ -124,7 +132,9 @@
n = it.next();
if (n instanceof ASTangle_addr) {
name = DecoderUtil.decodeEncodedWords(name);
- return new Mailbox(name, buildAngleAddr((ASTangle_addr) n));
+ Mailbox mb = buildAngleAddr((ASTangle_addr) n);
+ return new Mailbox(name, mb.getRoute(), mb.getLocalPart(),
+ mb.getDomain());
} else {
throw new IllegalStateException();
}
Propchange:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/address/parser/Builder.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java
Fri Jan 1 14:29:54 2010
@@ -23,6 +23,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.james.mime4j.field.FieldParser;
import org.apache.james.mime4j.field.address.AddressList;
+import org.apache.james.mime4j.field.address.parser.AddressBuilder;
import org.apache.james.mime4j.field.address.parser.ParseException;
import org.apache.james.mime4j.util.ByteSequence;
@@ -66,7 +67,7 @@
String body = getBody();
try {
- addressList = AddressList.parse(body);
+ addressList = AddressBuilder.parseAddressList(body);
} catch (ParseException e) {
if (log.isDebugEnabled()) {
log.debug("Parsing value '" + body + "': " + e.getMessage());
Modified:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java
Fri Jan 1 14:29:54 2010
@@ -22,9 +22,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.james.mime4j.field.FieldParser;
-import org.apache.james.mime4j.field.address.AddressList;
import org.apache.james.mime4j.field.address.Mailbox;
import org.apache.james.mime4j.field.address.MailboxList;
+import org.apache.james.mime4j.field.address.parser.AddressBuilder;
import org.apache.james.mime4j.field.address.parser.ParseException;
import org.apache.james.mime4j.util.ByteSequence;
@@ -68,7 +68,7 @@
String body = getBody();
try {
- MailboxList mailboxList = AddressList.parse(body).flatten();
+ MailboxList mailboxList =
AddressBuilder.parseAddressList(body).flatten();
if (mailboxList.size() > 0) {
mailbox = mailboxList.get(0);
}
Modified:
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java
Fri Jan 1 14:29:54 2010
@@ -22,8 +22,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.james.mime4j.field.FieldParser;
-import org.apache.james.mime4j.field.address.AddressList;
import org.apache.james.mime4j.field.address.MailboxList;
+import org.apache.james.mime4j.field.address.parser.AddressBuilder;
import org.apache.james.mime4j.field.address.parser.ParseException;
import org.apache.james.mime4j.util.ByteSequence;
@@ -67,7 +67,7 @@
String body = getBody();
try {
- mailboxList = AddressList.parse(body).flatten();
+ mailboxList = AddressBuilder.parseAddressList(body).flatten();
} catch (ParseException e) {
if (log.isDebugEnabled()) {
log.debug("Parsing value '" + body + "': " + e.getMessage());
Modified:
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
Fri Jan 1 14:29:54 2010
@@ -29,6 +29,7 @@
import org.apache.james.mime4j.field.address.Group;
import org.apache.james.mime4j.field.address.Mailbox;
+import org.apache.james.mime4j.field.address.parser.AddressBuilder;
import org.apache.james.mime4j.field.impl.Fields;
import org.apache.james.mime4j.util.ByteSequence;
import org.apache.james.mime4j.util.ContentUtil;
@@ -231,14 +232,14 @@
}
public void testSender() throws Exception {
- MailboxField field = Fields.sender(Mailbox
- .parse("JD <[email protected]>"));
+ MailboxField field = Fields.sender(AddressBuilder
+ .parseMailbox("JD <[email protected]>"));
assertEquals("Sender: JD <[email protected]>", decode(field.getRaw()));
}
public void testFrom() throws Exception {
- Mailbox mailbox1 = Mailbox.parse("JD <[email protected]>");
- Mailbox mailbox2 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("JD
<[email protected]>");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
MailboxListField field = Fields.from(mailbox1);
assertEquals("From: JD <[email protected]>", decode(field.getRaw()));
@@ -253,9 +254,9 @@
}
public void testTo() throws Exception {
- Mailbox mailbox1 = Mailbox.parse("JD <[email protected]>");
- Mailbox mailbox2 = Mailbox.parse("[email protected]");
- Mailbox mailbox3 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("JD
<[email protected]>");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("[email protected]");
+ Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
Group group = new Group("The Does", mailbox1, mailbox2);
AddressListField field = Fields.to(group);
@@ -274,9 +275,9 @@
}
public void testCc() throws Exception {
- Mailbox mailbox1 = Mailbox.parse("JD <[email protected]>");
- Mailbox mailbox2 = Mailbox.parse("[email protected]");
- Mailbox mailbox3 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("JD
<[email protected]>");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("[email protected]");
+ Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
Group group = new Group("The Does", mailbox1, mailbox2);
AddressListField field = Fields.cc(group);
@@ -295,9 +296,9 @@
}
public void testBcc() throws Exception {
- Mailbox mailbox1 = Mailbox.parse("JD <[email protected]>");
- Mailbox mailbox2 = Mailbox.parse("[email protected]");
- Mailbox mailbox3 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("JD
<[email protected]>");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("[email protected]");
+ Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
Group group = new Group("The Does", mailbox1, mailbox2);
AddressListField field = Fields.bcc(group);
@@ -316,9 +317,9 @@
}
public void testReplyTo() throws Exception {
- Mailbox mailbox1 = Mailbox.parse("JD <[email protected]>");
- Mailbox mailbox2 = Mailbox.parse("[email protected]");
- Mailbox mailbox3 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("JD
<[email protected]>");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("[email protected]");
+ Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
Group group = new Group("The Does", mailbox1, mailbox2);
AddressListField field = Fields.replyTo(group);
@@ -337,15 +338,15 @@
}
public void testMailbox() throws Exception {
- MailboxField field = Fields.mailbox("Resent-Sender", Mailbox
- .parse("JD <[email protected]>"));
+ MailboxField field = Fields.mailbox("Resent-Sender", AddressBuilder
+ .parseMailbox("JD <[email protected]>"));
assertEquals("Resent-Sender: JD <[email protected]>", decode(field
.getRaw()));
}
public void testMailboxList() throws Exception {
- Mailbox mailbox1 = Mailbox.parse("JD <[email protected]>");
- Mailbox mailbox2 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("JD
<[email protected]>");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
MailboxListField field = Fields.mailboxList("Resent-From", Arrays
.asList(mailbox1, mailbox2));
@@ -354,9 +355,9 @@
}
public void testAddressList() throws Exception {
- Mailbox mailbox1 = Mailbox.parse("JD <[email protected]>");
- Mailbox mailbox2 = Mailbox.parse("[email protected]");
- Mailbox mailbox3 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("JD
<[email protected]>");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("[email protected]");
+ Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
Group group = new Group("The Does", mailbox1, mailbox2);
AddressListField field = Fields.addressList("Resent-To", Arrays.asList(
Modified:
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/address/AddressTest.java
Fri Jan 1 14:29:54 2010
@@ -20,6 +20,7 @@
package org.apache.james.mime4j.field.address;
import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.field.address.parser.AddressBuilder;
import org.apache.james.mime4j.field.address.parser.ParseException;
import java.io.BufferedReader;
@@ -43,7 +44,7 @@
}
public void testParse1() throws ParseException {
- AddressList addrList = AddressList.parse("John Doe
<j...@machine(comment). example>");
+ AddressList addrList = AddressBuilder.parseAddressList("John Doe
<j...@machine(comment). example>");
assertEquals(1, addrList.size());
Mailbox mailbox = (Mailbox)addrList.get(0);
assertEquals("John Doe", mailbox.getName());
@@ -52,7 +53,7 @@
}
public void testParse2() throws ParseException {
- AddressList addrList = AddressList.parse("Mary Smith \t \t\t
<[email protected]>");
+ AddressList addrList = AddressBuilder.parseAddressList("Mary Smith \t
\t\t <[email protected]>");
assertEquals(1, addrList.size());
Mailbox mailbox = (Mailbox)addrList.get(0);
assertEquals("Mary Smith", mailbox.getName());
@@ -61,7 +62,7 @@
}
public void testEmptyGroup() throws ParseException {
- AddressList addrList = AddressList.parse("undisclosed-recipients:;");
+ AddressList addrList =
AddressBuilder.parseAddressList("undisclosed-recipients:;");
assertEquals(1, addrList.size());
Group group = (Group)addrList.get(0);
assertEquals(0, group.getMailboxes().size());
@@ -69,7 +70,7 @@
}
public void testMessyGroupAndMailbox() throws ParseException {
- AddressList addrList = AddressList.parse("Marketing folks : Jane
Smith < jane @ example . net >, \" Jack \\\"Jackie\\\" Jones \" <
[email protected] > (comment(comment)); ,, (comment) , <@example .
net,@example(ignore\\)).com:(ignore)john@(ignore)example.net>");
+ AddressList addrList = AddressBuilder.parseAddressList("Marketing
folks : Jane Smith < jane @ example . net >, \" Jack \\\"Jackie\\\" Jones \" <
[email protected] > (comment(comment)); ,, (comment) , <@example .
net,@example(ignore\\)).com:(ignore)john@(ignore)example.net>");
assertEquals(2, addrList.size());
Group group = (Group)addrList.get(0);
@@ -96,12 +97,12 @@
}
public void testEmptyAddressList() throws ParseException {
- assertEquals(0, AddressList.parse(" \t \t ").size());
- assertEquals(0, AddressList.parse(" \t , , , ,,, , \t ").size());
+ assertEquals(0, AddressBuilder.parseAddressList(" \t \t ").size());
+ assertEquals(0, AddressBuilder.parseAddressList(" \t , , , ,,, , \t
").size());
}
public void testSimpleForm() throws ParseException {
- AddressList addrList = AddressList.parse("\"a b c d e f g\" (comment)
@example.net");
+ AddressList addrList = AddressBuilder.parseAddressList("\"a b c d e f
g\" (comment) @example.net");
assertEquals(1, addrList.size());
Mailbox mailbox = (Mailbox)addrList.get(0);
assertEquals("a b c d e f g", mailbox.getLocalPart());
@@ -109,7 +110,7 @@
}
public void testFlatten() throws ParseException {
- AddressList addrList = AddressList.parse("dev : [email protected],
[email protected]; , ,,, marketing:[email protected] ,[email protected];,
[email protected]");
+ AddressList addrList = AddressBuilder.parseAddressList("dev :
[email protected], [email protected]; , ,,, marketing:[email protected]
,[email protected];, [email protected]");
assertEquals(3, addrList.size());
assertEquals(5, addrList.flatten().size());
}
@@ -126,15 +127,15 @@
// there shouldn't be any aspect of the RFC that is tested here
// but not in the other unit tests.
- AddressList.parse("Alfred Neuman <neu...@bbn-tenexa>");
- AddressList.parse("neu...@bbn-tenexa");
- AddressList.parse("\"George, Ted\" <[email protected]>");
- AddressList.parse("Wilt . (the Stilt) [email protected]");
+ AddressBuilder.parseAddressList("Alfred Neuman <neu...@bbn-tenexa>");
+ AddressBuilder.parseAddressList("neu...@bbn-tenexa");
+ AddressBuilder.parseAddressList("\"George, Ted\"
<[email protected]>");
+ AddressBuilder.parseAddressList("Wilt . (the Stilt)
[email protected]");
// NOTE: In RFC822 8.1.5, the following example did not have
"Galloping Gourmet"
// in double-quotes. I can only assume this was a typo, since 6.2.4
specifically
// disallows spaces in unquoted local-part.
- AddressList.parse(" Gourmets: Pompous Person
<whoziwhat...@cordon-bleu>," +
+ AddressBuilder.parseAddressList(" Gourmets: Pompous Person
<whoziwhat...@cordon-bleu>," +
" [email protected], \"Galloping Gourmet\"@" +
" ANT.Down-Under (Australian National
Television)," +
" chea...@discount-liquors;," +
@@ -144,7 +145,7 @@
// NOTE: In RFC822 8.3.3, the following example ended with a lone ">"
after
// Tops-20-Host. I can only assume this was a typo, since 6.1 clearly
shows
// ">" requires a matching "<".
- AddressList.parse("Important folk:" +
+ AddressBuilder.parseAddressList("Important folk:" +
" Tom Softwood <[email protected]>," +
" \"Sam Irving\"@Other-Host;," +
" Standard Distribution:" +
@@ -153,16 +154,16 @@
// The following are from a Usenet post by Dan J. Bernstein:
//
http://groups.google.com/groups?selm=1996Aug1418.21.01.28081%40koobera.math.uic.edu
- AddressList.parse("\":sysmail\"@ Some-Group.\t Some-Org,
Muhammed.(I am the greatest) Ali @(the)Vegas.WBA");
- AddressList.parse("[email protected] (comment (nested (deeply\\))))");
- AddressList.parse("mailing list: [email protected], route two
<[email protected]>, [email protected] ;");
+ AddressBuilder.parseAddressList("\":sysmail\"@ Some-Group.\t
Some-Org, Muhammed.(I am the greatest) Ali @(the)Vegas.WBA");
+ AddressBuilder.parseAddressList("[email protected] (comment (nested
(deeply\\))))");
+ AddressBuilder.parseAddressList("mailing list: [email protected], route
two <[email protected]>, [email protected] ;");
}
public void testLexicalError() {
// ensure that TokenMgrError doesn't get thrown
try {
- AddressList.parse(")");
+ AddressBuilder.parseAddressList(")");
fail("Expected parsing error");
}
catch (ParseException e) {
@@ -189,7 +190,7 @@
public void testAddressList() throws ParseException {
- AddressList addlist = AddressList.parse("[email protected],
[email protected], [email protected]");
+ AddressList addlist =
AddressBuilder.parseAddressList("[email protected], [email protected],
[email protected]");
List<Address> al = new ArrayList<Address>();
al.add(addlist.get(0));
@@ -232,7 +233,7 @@
@Override
public void run() {
try {
- AddressList.main(null);
+ AddressBuilder.main(null);
} catch (Exception e) {
fail("Catched an exception in main: "+e);
}
@@ -367,7 +368,7 @@
* ParseException
*/
try {
- AddressList.parse("\"\"[email protected]");
+ AddressBuilder.parseAddressList("\"\"[email protected]");
fail("ParseException expected");
} catch (ParseException pe) {
}
@@ -405,12 +406,12 @@
}
public void testParseAddress() throws Exception {
- Address address = Address.parse("Mary Smith <[email protected]>");
+ Address address = AddressBuilder.parseAddress("Mary Smith
<[email protected]>");
assertTrue(address instanceof Mailbox);
assertEquals("Mary Smith", ((Mailbox) address).getName());
assertEquals("[email protected]", ((Mailbox) address).getAddress());
- address = Address.parse("group: Mary Smith <[email protected]>;");
+ address = AddressBuilder.parseAddress("group: Mary Smith
<[email protected]>;");
assertTrue(address instanceof Group);
assertEquals("group", ((Group) address).getName());
assertEquals("Mary Smith", ((Group) address).getMailboxes().get(0)
@@ -419,15 +420,15 @@
.get(0).getAddress());
try {
- Group.parse("[email protected], [email protected]");
+ AddressBuilder.parseGroup("[email protected], [email protected]");
fail();
} catch (IllegalArgumentException expected) {
}
}
public void testParseGroup() throws Exception {
- Group group = Group
- .parse("group: [email protected], Mary Smith
<[email protected]>;");
+ Group group = AddressBuilder
+ .parseGroup("group: [email protected], Mary Smith
<[email protected]>;");
assertEquals("group", group.getName());
MailboxList mailboxes = group.getMailboxes();
@@ -442,41 +443,41 @@
assertEquals("[email protected]", mailbox2.getAddress());
try {
- Group.parse("[email protected]");
+ AddressBuilder.parseGroup("[email protected]");
fail();
} catch (IllegalArgumentException expected) {
}
try {
- Group.parse("g1: [email protected];, g2: [email protected];");
+ AddressBuilder.parseGroup("g1: [email protected];, g2:
[email protected];");
fail();
} catch (IllegalArgumentException expected) {
}
}
public void testParseMailbox() throws Exception {
- Mailbox mailbox1 = Mailbox.parse("[email protected]");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("[email protected]");
assertNull(mailbox1.getName());
assertEquals("[email protected]", mailbox1.getAddress());
- Mailbox mailbox2 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
assertEquals("Mary Smith", mailbox2.getName());
assertEquals("[email protected]", mailbox2.getAddress());
// non-ascii should be allowed in quoted strings
- Mailbox mailbox3 = Mailbox
- .parse("\"Hans M\374ller\" <[email protected]>");
+ Mailbox mailbox3 = AddressBuilder
+ .parseMailbox("\"Hans M\374ller\" <[email protected]>");
assertEquals("Hans M\374ller", mailbox3.getName());
assertEquals("[email protected]", mailbox3.getAddress());
try {
- Mailbox.parse("g: Mary Smith <[email protected]>;");
+ AddressBuilder.parseMailbox("g: Mary Smith <[email protected]>;");
fail();
} catch (IllegalArgumentException expected) {
}
try {
- Mailbox.parse("Mary Smith <[email protected]>,
[email protected]");
+ AddressBuilder.parseMailbox("Mary Smith <[email protected]>,
[email protected]");
fail();
} catch (IllegalArgumentException expected) {
}
Modified:
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
(original)
+++
james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
Fri Jan 1 14:29:54 2010
@@ -35,6 +35,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.james.mime4j.field.address.Group;
import org.apache.james.mime4j.field.address.Mailbox;
+import org.apache.james.mime4j.field.address.parser.AddressBuilder;
import org.apache.james.mime4j.field.impl.DefaultFieldParser;
import org.apache.james.mime4j.message.impl.BodyPart;
import org.apache.james.mime4j.message.impl.MessageImpl;
@@ -247,7 +248,7 @@
public void testSetSender() throws Exception {
MessageImpl m = new MessageImpl();
- m.setSender(Mailbox.parse("[email protected]"));
+ m.setSender(AddressBuilder.parseMailbox("[email protected]"));
assertEquals("[email protected]", m.getHeader().getField("Sender")
.getBody());
@@ -269,8 +270,8 @@
public void testSetFrom() throws Exception {
MessageImpl m = new MessageImpl();
- Mailbox mailbox1 = Mailbox.parse("[email protected]");
- Mailbox mailbox2 = Mailbox.parse("[email protected]");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("[email protected]");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("[email protected]");
m.setFrom(mailbox1);
assertEquals("[email protected]", m.getHeader().getField("From")
@@ -303,10 +304,10 @@
public void testSetTo() throws Exception {
MessageImpl m = new MessageImpl();
- Mailbox mailbox1 = Mailbox.parse("[email protected]");
- Mailbox mailbox2 = Mailbox.parse("[email protected]");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("[email protected]");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("[email protected]");
Group group = new Group("Does", mailbox1, mailbox2);
- Mailbox mailbox3 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
m.setTo(group);
assertEquals("Does: [email protected], [email protected];", m
@@ -341,10 +342,10 @@
public void testSetCc() throws Exception {
MessageImpl m = new MessageImpl();
- Mailbox mailbox1 = Mailbox.parse("[email protected]");
- Mailbox mailbox2 = Mailbox.parse("[email protected]");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("[email protected]");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("[email protected]");
Group group = new Group("Does", mailbox1, mailbox2);
- Mailbox mailbox3 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
m.setCc(group);
assertEquals("Does: [email protected], [email protected];", m
@@ -379,10 +380,10 @@
public void testSetBcc() throws Exception {
MessageImpl m = new MessageImpl();
- Mailbox mailbox1 = Mailbox.parse("[email protected]");
- Mailbox mailbox2 = Mailbox.parse("[email protected]");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("[email protected]");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("[email protected]");
Group group = new Group("Does", mailbox1, mailbox2);
- Mailbox mailbox3 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
m.setBcc(group);
assertEquals("Does: [email protected], [email protected];", m
@@ -417,10 +418,10 @@
public void testSetReplyTo() throws Exception {
MessageImpl m = new MessageImpl();
- Mailbox mailbox1 = Mailbox.parse("[email protected]");
- Mailbox mailbox2 = Mailbox.parse("[email protected]");
+ Mailbox mailbox1 = AddressBuilder.parseMailbox("[email protected]");
+ Mailbox mailbox2 = AddressBuilder.parseMailbox("[email protected]");
Group group = new Group("Does", mailbox1, mailbox2);
- Mailbox mailbox3 = Mailbox.parse("Mary Smith <[email protected]>");
+ Mailbox mailbox3 = AddressBuilder.parseMailbox("Mary Smith
<[email protected]>");
m.setReplyTo(group);
assertEquals("Does: [email protected], [email protected];", m
Modified:
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
(original)
+++
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
Fri Jan 1 14:29:54 2010
@@ -29,7 +29,7 @@
import javax.imageio.ImageIO;
-import org.apache.james.mime4j.field.address.Mailbox;
+import org.apache.james.mime4j.field.address.parser.AddressBuilder;
import org.apache.james.mime4j.message.BinaryBody;
import org.apache.james.mime4j.message.Multipart;
import org.apache.james.mime4j.message.TextBody;
@@ -57,13 +57,13 @@
// Date and From are required fields
message.setDate(new Date());
- message.setFrom(Mailbox.parse("John Doe <[email protected]>"));
+ message.setFrom(AddressBuilder.parseMailbox("John Doe
<[email protected]>"));
// Message-ID should be present
message.createMessageId("machine.example");
// set some optional fields
- message.setTo(Mailbox.parse("Mary Smith <[email protected]>"));
+ message.setTo(AddressBuilder.parseMailbox("Mary Smith
<[email protected]>"));
message.setSubject("An image for you");
// 3) set a multipart body
Modified:
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
(original)
+++
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
Fri Jan 1 14:29:54 2010
@@ -22,7 +22,7 @@
import java.io.IOException;
import java.util.Date;
-import org.apache.james.mime4j.field.address.Mailbox;
+import org.apache.james.mime4j.field.address.parser.AddressBuilder;
import org.apache.james.mime4j.message.TextBody;
import org.apache.james.mime4j.message.impl.BodyFactory;
import org.apache.james.mime4j.message.impl.MessageImpl;
@@ -41,13 +41,13 @@
// Date and From are required fields
message.setDate(new Date());
- message.setFrom(Mailbox.parse("John Doe <[email protected]>"));
+ message.setFrom(AddressBuilder.parseMailbox("John Doe
<[email protected]>"));
// Message-ID should be present
message.createMessageId("machine.example");
// set some optional fields
- message.setTo(Mailbox.parse("Mary Smith <[email protected]>"));
+ message.setTo(AddressBuilder.parseMailbox("Mary Smith
<[email protected]>"));
message.setSubject("Saying Hello");
// 3) set a text body
Modified:
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
URL:
http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java?rev=895016&r1=895015&r2=895016&view=diff
==============================================================================
---
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
(original)
+++
james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
Fri Jan 1 14:29:54 2010
@@ -24,7 +24,7 @@
import java.util.Date;
import java.util.Random;
-import org.apache.james.mime4j.field.address.Mailbox;
+import org.apache.james.mime4j.field.address.parser.AddressBuilder;
import org.apache.james.mime4j.message.Body;
import org.apache.james.mime4j.message.Entity;
import org.apache.james.mime4j.message.Multipart;
@@ -114,7 +114,7 @@
message.createMessageId(HOSTNAME);
message.setSubject("Transformed message");
message.setDate(new Date());
- message.setFrom(Mailbox.parse("John Doe <[email protected]>"));
+ message.setFrom(AddressBuilder.parseMailbox("John Doe
<[email protected]>"));
return message;
}