From 8546e21e1e127845071c595beda16fc23eb0f58e Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Wed, 2 Feb 2011 11:47:06 -0800 Subject: [PATCH] Resolve build warnings; part 2 Change-Id: I76c1a5a4f759071f92eef0574abb20a99bfb32b7 --- .../apache/james/mime4j/BodyDescriptor.java | 127 ++++++------- .../apache/james/mime4j/MimeStreamParser.java | 114 ++++++------ .../james/mime4j/field/ContentTypeField.java | 99 ++++++----- .../mime4j/field/DelegatingFieldParser.java | 12 +- .../james/mime4j/field/address/Address.java | 12 +- .../mime4j/field/address/AddressList.java | 38 ++-- .../james/mime4j/field/address/Builder.java | 49 +++-- .../mime4j/field/address/DomainList.java | 22 +-- .../james/mime4j/field/address/Group.java | 14 +- .../james/mime4j/field/address/Mailbox.java | 44 ++--- .../mime4j/field/address/MailboxList.java | 24 +-- .../mime4j/field/address/NamedMailbox.java | 15 +- .../address/parser/AddressListParser.java | 8 +- .../parser/JJTAddressListParserState.java | 24 +-- .../contenttype/parser/ContentTypeParser.java | 13 +- .../field/datetime/parser/DateTimeParser.java | 6 +- .../apache/james/mime4j/message/Header.java | 55 +++--- .../apache/james/mime4j/message/Message.java | 69 ++++---- .../james/mime4j/message/Multipart.java | 68 +++---- .../apache/james/mime4j/util/CharsetUtil.java | 167 +++++++++--------- .../mail/transport/Rfc822OutputTests.java | 13 +- 21 files changed, 493 insertions(+), 500 deletions(-) diff --git a/src/org/apache/james/mime4j/BodyDescriptor.java b/src/org/apache/james/mime4j/BodyDescriptor.java index 32dd52981..2fef0be04 100644 --- a/src/org/apache/james/mime4j/BodyDescriptor.java +++ b/src/org/apache/james/mime4j/BodyDescriptor.java @@ -23,23 +23,23 @@ import java.util.HashMap; import java.util.Map; /** - * Encapsulates the values of the MIME-specific header fields - * (which starts with Content-). + * Encapsulates the values of the MIME-specific header fields + * (which starts with Content-). + * * - * * @version $Id: BodyDescriptor.java,v 1.4 2005/02/11 10:08:37 ntherning Exp $ */ public class BodyDescriptor { private static Log log = LogFactory.getLog(BodyDescriptor.class); - + private String mimeType = "text/plain"; private String boundary = null; private String charset = "us-ascii"; private String transferEncoding = "7bit"; - private Map parameters = new HashMap(); + private Map parameters = new HashMap(); private boolean contentTypeSet = false; private boolean contentTransferEncSet = false; - + /** * Creates a new root BodyDescriptor instance. */ @@ -49,7 +49,7 @@ public class BodyDescriptor { /** * Creates a new BodyDescriptor instance. - * + * * @param parent the descriptor of the parent or null if this * is the root descriptor. */ @@ -60,31 +60,31 @@ public class BodyDescriptor { mimeType = "text/plain"; } } - + /** - * Should be called for each Content- header field of + * Should be called for each Content- header field of * a MIME message or part. - * + * * @param name the field name. * @param value the field value. */ public void addField(String name, String value) { - + name = name.trim().toLowerCase(); - + if (name.equals("content-transfer-encoding") && !contentTransferEncSet) { contentTransferEncSet = true; - + value = value.trim().toLowerCase(); if (value.length() > 0) { transferEncoding = value; } - + } else if (name.equals("content-type") && !contentTypeSet) { contentTypeSet = true; - + value = value.trim(); - + /* * Unfold Content-Type value */ @@ -96,10 +96,10 @@ public class BodyDescriptor { } sb.append(c); } - - Map params = getHeaderParams(sb.toString()); - - String main = (String) params.get(""); + + Map params = getHeaderParams(sb.toString()); + + String main = params.get(""); if (main != null) { main = main.toLowerCase().trim(); int index = main.indexOf('/'); @@ -112,32 +112,32 @@ public class BodyDescriptor { valid = true; } } - + if (!valid) { main = null; } } - String b = (String) params.get("boundary"); - - if (main != null - && ((main.startsWith("multipart/") && b != null) + String b = params.get("boundary"); + + if (main != null + && ((main.startsWith("multipart/") && b != null) || !main.startsWith("multipart/"))) { - + mimeType = main; } - + if (isMultipart()) { boundary = b; } - - String c = (String) params.get("charset"); + + String c = params.get("charset"); if (c != null) { c = c.trim(); if (c.length() > 0) { charset = c.toLowerCase(); } } - + /* * Add all other parameters to parameters. */ @@ -147,9 +147,9 @@ public class BodyDescriptor { parameters.remove("charset"); } } - - private Map getHeaderParams(String headerValue) { - Map result = new HashMap(); + + private Map getHeaderParams(String headerValue) { + Map result = new HashMap(); // split main value and parameters String main; @@ -198,7 +198,7 @@ public class BodyDescriptor { paramValue = new StringBuffer(); state = IN_NAME; - // fall-through + // $FALL-THROUGH$ case IN_NAME: if (c == '=') { @@ -232,7 +232,7 @@ public class BodyDescriptor { if (!fallThrough) break; - // fall-through + // $FALL-THROUGH$ case IN_VALUE: fallThrough = false; @@ -253,6 +253,8 @@ public class BodyDescriptor { if (!fallThrough) break; + // $FALL-THROUGH$ + case VALUE_DONE: switch (c) { case ';': @@ -268,7 +270,7 @@ public class BodyDescriptor { break; } break; - + case IN_QUOTED_VALUE: switch (c) { case '"': @@ -280,10 +282,10 @@ public class BodyDescriptor { state = VALUE_DONE; } else { escaped = false; - paramValue.append(c); + paramValue.append(c); } break; - + case '\\': if (escaped) { paramValue.append('\\'); @@ -314,93 +316,76 @@ public class BodyDescriptor { return result; } - + public boolean isMimeType(String mimeType) { return this.mimeType.equals(mimeType.toLowerCase()); } - + /** - * Return true if the BodyDescriptor belongs to a message - * - * @return + * Return true if the BodyDescriptor belongs to a message */ public boolean isMessage() { return mimeType.equals("message/rfc822"); } - + /** - * Retrun true if the BodyDescripotro belogns to a multipart - * - * @return + * Return true if the BodyDescripotro belongs to a multipart */ public boolean isMultipart() { return mimeType.startsWith("multipart/"); } - + /** - * Return the MimeType - * - * @return mimeType + * Return the MimeType */ public String getMimeType() { return mimeType; } - + /** * Return the boundary - * - * @return boundary */ public String getBoundary() { return boundary; } - + /** * Return the charset - * - * @return charset */ public String getCharset() { return charset; } - + /** * Return all parameters for the BodyDescriptor - * - * @return parameters */ - public Map getParameters() { + public Map getParameters() { return parameters; } - + /** * Return the TransferEncoding - * - * @return transferEncoding */ public String getTransferEncoding() { return transferEncoding; } - + /** * Return true if it's base64 encoded - * - * @return - * */ public boolean isBase64Encoded() { return "base64".equals(transferEncoding); } - + /** * Return true if it's quoted-printable - * @return */ public boolean isQuotedPrintableEncoded() { return "quoted-printable".equals(transferEncoding); } - + + @Override public String toString() { return mimeType; } diff --git a/src/org/apache/james/mime4j/MimeStreamParser.java b/src/org/apache/james/mime4j/MimeStreamParser.java index f55ca3139..fc4bb3557 100644 --- a/src/org/apache/james/mime4j/MimeStreamParser.java +++ b/src/org/apache/james/mime4j/MimeStreamParser.java @@ -32,7 +32,7 @@ import java.util.LinkedList; /** *

- * Parses MIME (or RFC822) message streams of bytes or characters and reports + * Parses MIME (or RFC822) message streams of bytes or characters and reports * parsing events to a ContentHandler instance. *

*

@@ -43,11 +43,11 @@ import java.util.LinkedList; * parser.setContentHandler(handler); * parser.parse(new BufferedInputStream(new FileInputStream("mime.msg"))); * - * NOTE: All lines must end with CRLF - * (\r\n). If you are unsure of the line endings in your stream + * NOTE: All lines must end with CRLF + * (\r\n). If you are unsure of the line endings in your stream * you should wrap it in a {@link org.apache.james.mime4j.EOLConvertingInputStream} instance. * - * + * * @version $Id: MimeStreamParser.java,v 1.8 2005/02/11 10:12:02 ntherning Exp $ */ public class MimeStreamParser { @@ -56,12 +56,12 @@ public class MimeStreamParser { private static final boolean DEBUG_LOG_MESSAGE = false; //DO NOT RELEASE AS 'TRUE' private static BitSet fieldChars = null; - + private RootInputStream rootStream = null; - private LinkedList bodyDescriptors = new LinkedList(); + private LinkedList bodyDescriptors = new LinkedList(); private ContentHandler handler = null; private boolean raw = false; - + static { fieldChars = new BitSet(); for (int i = 0x21; i <= 0x39; i++) { @@ -71,7 +71,7 @@ public class MimeStreamParser { fieldChars.set(i); } } - + /** * Creates a new MimeStreamParser instance. */ @@ -80,7 +80,7 @@ public class MimeStreamParser { /** * Parses a stream of bytes containing a MIME message. - * + * * @param is the stream to parse. * @throws IOException on I/O errors. */ @@ -91,10 +91,10 @@ public class MimeStreamParser { rootStream = new RootInputStream(is); parseMessage(rootStream); } - + /** * Determines if this parser is currently in raw mode. - * + * * @return true if in raw mode, false * otherwise. * @see #setRaw(boolean) @@ -102,29 +102,29 @@ public class MimeStreamParser { public boolean isRaw() { return raw; } - + /** - * Enables or disables raw mode. In raw mode all future entities + * Enables or disables raw mode. In raw mode all future entities * (messages or body parts) in the stream will be reported to the * {@link ContentHandler#raw(InputStream)} handler method only. - * The stream will contain the entire unparsed entity contents + * The stream will contain the entire unparsed entity contents * including header fields and whatever is in the body. - * + * * @param raw true enables raw mode, false * disables it. */ public void setRaw(boolean raw) { this.raw = raw; } - + /** * Finishes the parsing and stops reading lines. * NOTE: No more lines will be parsed but the parser - * will still call + * will still call * {@link ContentHandler#endMultipart()}, * {@link ContentHandler#endBodyPart()}, * {@link ContentHandler#endMessage()}, etc to match previous calls - * to + * to * {@link ContentHandler#startMultipart(BodyDescriptor)}, * {@link ContentHandler#startBodyPart()}, * {@link ContentHandler#startMessage()}, etc. @@ -132,23 +132,23 @@ public class MimeStreamParser { public void stop() { rootStream.truncate(); } - + /** * Parses an entity which consists of a header followed by a body containing * arbitrary data, body parts or an embedded message. - * + * * @param is the stream to parse. * @throws IOException on I/O errors. */ private void parseEntity(InputStream is) throws IOException { BodyDescriptor bd = parseHeader(is); - + if (bd.isMultipart()) { bodyDescriptors.addFirst(bd); - + handler.startMultipart(bd); - - MimeBoundaryInputStream tempIs = + + MimeBoundaryInputStream tempIs = new MimeBoundaryInputStream(is, bd.getBoundary()); handler.preamble(new CloseShieldInputStream(tempIs)); tempIs.consume(); @@ -159,7 +159,7 @@ public class MimeStreamParser { tempIs.consume(); if (tempIs.parentEOF()) { if (log.isWarnEnabled()) { - log.warn("Line " + rootStream.getLineNumber() + log.warn("Line " + rootStream.getLineNumber() + ": Body part ended prematurely. " + "Higher level boundary detected or " + "EOF reached."); @@ -167,13 +167,13 @@ public class MimeStreamParser { break; } } - + handler.epilogue(new CloseShieldInputStream(is)); - + handler.endMultipart(); - + bodyDescriptors.removeFirst(); - + } else if (bd.isMessage()) { if (bd.isBase64Encoded()) { log.warn("base64 encoded message/rfc822 detected"); @@ -190,14 +190,14 @@ public class MimeStreamParser { } else { handler.body(bd, new CloseShieldInputStream(is)); } - + /* * Make sure the stream has been consumed. */ while (is.read() != -1) { } } - + private void parseMessage(InputStream is) throws IOException { if (raw) { handler.raw(new CloseShieldInputStream(is)); @@ -207,7 +207,7 @@ public class MimeStreamParser { handler.endMessage(); } } - + private void parseBodyPart(InputStream is) throws IOException { if (raw) { handler.raw(new CloseShieldInputStream(is)); @@ -217,22 +217,22 @@ public class MimeStreamParser { handler.endBodyPart(); } } - + /** * Parses a header. - * + * * @param is the stream to parse. - * @return a BodyDescriptor describing the body following + * @return a BodyDescriptor describing the body following * the header. */ private BodyDescriptor parseHeader(InputStream is) throws IOException { - BodyDescriptor bd = new BodyDescriptor(bodyDescriptors.isEmpty() + BodyDescriptor bd = new BodyDescriptor(bodyDescriptors.isEmpty() ? null : (BodyDescriptor) bodyDescriptors.getFirst()); - + handler.startHeader(); - + int lineNumber = rootStream.getLineNumber(); - + StringBuffer sb = new StringBuffer(); int curr = 0; int prev = 0; @@ -247,9 +247,9 @@ public class MimeStreamParser { sb.append((char) curr); prev = curr == '\r' ? prev : curr; } - + if (curr == -1 && log.isWarnEnabled()) { - log.warn("Line " + rootStream.getLineNumber() + log.warn("Line " + rootStream.getLineNumber() + ": Unexpected end of headers detected. " + "Boundary detected in header or EOF reached."); } @@ -265,16 +265,16 @@ public class MimeStreamParser { pos++; continue; } - + if (pos >= sb.length() - 2 || fieldChars.get(sb.charAt(pos + 2))) { - + /* - * field should be the complete field data excluding the + * field should be the complete field data excluding the * trailing \r\n. */ String field = sb.substring(start, pos); start = pos + 2; - + /* * Check for a valid field. */ @@ -289,34 +289,34 @@ public class MimeStreamParser { break; } } - + if (valid) { handler.field(field); bd.addField(fieldName, field.substring(index + 1)); - } + } } - + if (!valid && log.isWarnEnabled()) { - log.warn("Line " + startLineNumber + log.warn("Line " + startLineNumber + ": Ignoring invalid field: '" + field.trim() + "'"); - } - + } + startLineNumber = lineNumber; } - + pos += 2; lineNumber++; } - + handler.endHeader(); - + return bd; } - + /** - * Sets the ContentHandler to use when reporting + * Sets the ContentHandler to use when reporting * parsing events. - * + * * @param h the ContentHandler. */ public void setContentHandler(ContentHandler h) { diff --git a/src/org/apache/james/mime4j/field/ContentTypeField.java b/src/org/apache/james/mime4j/field/ContentTypeField.java index 64086474d..646cf141a 100644 --- a/src/org/apache/james/mime4j/field/ContentTypeField.java +++ b/src/org/apache/james/mime4j/field/ContentTypeField.java @@ -38,11 +38,11 @@ import org.apache.james.mime4j.field.contenttype.parser.TokenMgrError; * *

TODO: Remove dependency on Java 1.4 regexps

* - * + * * @version $Id: ContentTypeField.java,v 1.6 2005/01/27 14:16:31 ntherning Exp $ */ public class ContentTypeField extends Field { - + /** * The prefix of all multipart MIME types. */ @@ -67,12 +67,12 @@ public class ContentTypeField extends Field { * The name of the charset parameter. */ public static final String PARAM_CHARSET = "charset"; - + private String mimeType = ""; - private Map parameters = null; + private Map parameters = null; private ParseException parseException; - protected ContentTypeField(String name, String body, String raw, String mimeType, Map parameters, ParseException parseException) { + protected ContentTypeField(String name, String body, String raw, String mimeType, Map parameters, ParseException parseException) { super(name, body, raw); this.mimeType = mimeType; this.parameters = parameters; @@ -89,89 +89,90 @@ public class ContentTypeField extends Field { /** * Gets the MIME type defined in this Content-Type field. - * + * * @return the MIME type or an empty string if not set. */ public String getMimeType() { return mimeType; } - + /** - * Gets the MIME type defined in the child's - * Content-Type field or derives a MIME type from the parent - * if child is null or hasn't got a MIME type value set. + * Gets the MIME type defined in the child's + * Content-Type field or derives a MIME type from the parent + * if child is null or hasn't got a MIME type value set. * If child's MIME type is multipart but no boundary * has been set the MIME type of child will be derived from * the parent. - * + * * @param child the child. * @param parent the parent. * @return the MIME type. */ - public static String getMimeType(ContentTypeField child, + public static String getMimeType(ContentTypeField child, ContentTypeField parent) { - - if (child == null || child.getMimeType().length() == 0 + + if (child == null || child.getMimeType().length() == 0 || child.isMultipart() && child.getBoundary() == null) { - + if (parent != null && parent.isMimeType(TYPE_MULTIPART_DIGEST)) { return TYPE_MESSAGE_RFC822; } else { return TYPE_TEXT_PLAIN; } } - + return child.getMimeType(); } - + /** * Gets the value of a parameter. Parameter names are case-insensitive. - * + * * @param name the name of the parameter to get. * @return the parameter value or null if not set. */ public String getParameter(String name) { - return parameters != null - ? (String) parameters.get(name.toLowerCase()) + return parameters != null + ? parameters.get(name.toLowerCase()) : null; } - + /** * Gets all parameters. - * + * * @return the parameters. */ - public Map getParameters() { - return parameters != null - ? Collections.unmodifiableMap(parameters) - : Collections.EMPTY_MAP; + public Map getParameters() { + if (parameters != null) { + return Collections.unmodifiableMap(parameters); + } + return Collections.emptyMap(); } - + /** * Gets the value of the boundary parameter if set. - * - * @return the boundary parameter value or null + * + * @return the boundary parameter value or null * if not set. */ public String getBoundary() { return getParameter(PARAM_BOUNDARY); } - + /** * Gets the value of the charset parameter if set. - * - * @return the charset parameter value or null + * + * @return the charset parameter value or null * if not set. */ public String getCharset() { return getParameter(PARAM_CHARSET); } - + /** * Gets the value of the charset parameter if set for the * given field. Returns the default us-ascii if not set or if * f is null. - * + * * @return the charset parameter value. */ public static String getCharset(ContentTypeField f) { @@ -182,35 +183,35 @@ public class ContentTypeField extends Field { } return "us-ascii"; } - + /** - * Determines if the MIME type of this field matches the given one. - * + * Determines if the MIME type of this field matches the given one. + * * @param mimeType the MIME type to match against. - * @return true if the MIME type of this field matches, - * false otherwise. + * @return true if the MIME type of this field matches, + * false otherwise. */ public boolean isMimeType(String mimeType) { return this.mimeType.equalsIgnoreCase(mimeType); } - + /** * Determines if the MIME type of this field is multipart/*. - * + * * @return true if this field is has a multipart/* - * MIME type, false otherwise. + * MIME type, false otherwise. */ public boolean isMultipart() { return mimeType.startsWith(TYPE_MULTIPART_PREFIX); } - + public static class Parser implements FieldParser { private static Log log = LogFactory.getLog(Parser.class); public Field parse(final String name, final String body, final String raw) { ParseException parseException = null; String mimeType = ""; - Map parameters = null; + Map parameters = null; ContentTypeParser parser = new ContentTypeParser(new StringReader(body)); try { @@ -236,15 +237,15 @@ public class ContentTypeField extends Field { if (type != null && subType != null) { mimeType = (type + "/" + parser.getSubType()).toLowerCase(); - ArrayList paramNames = parser.getParamNames(); - ArrayList paramValues = parser.getParamValues(); + ArrayList paramNames = parser.getParamNames(); + ArrayList paramValues = parser.getParamValues(); if (paramNames != null && paramValues != null) { for (int i = 0; i < paramNames.size() && i < paramValues.size(); i++) { if (parameters == null) - parameters = new HashMap((int)(paramNames.size() * 1.3 + 1)); - String paramName = ((String)paramNames.get(i)).toLowerCase(); - String paramValue = ((String)paramValues.get(i)); + parameters = new HashMap((int)(paramNames.size() * 1.3 + 1)); + String paramName = paramNames.get(i).toLowerCase(); + String paramValue = paramValues.get(i); parameters.put(paramName, paramValue); } } diff --git a/src/org/apache/james/mime4j/field/DelegatingFieldParser.java b/src/org/apache/james/mime4j/field/DelegatingFieldParser.java index e7787a336..2a2866f57 100644 --- a/src/org/apache/james/mime4j/field/DelegatingFieldParser.java +++ b/src/org/apache/james/mime4j/field/DelegatingFieldParser.java @@ -19,10 +19,10 @@ import java.util.HashMap; import java.util.Map; public class DelegatingFieldParser implements FieldParser { - - private Map parsers = new HashMap(); + + private Map parsers = new HashMap(); private FieldParser defaultParser = new UnstructuredField.Parser(); - + /** * Sets the parser used for the field named name. * @param name the name of the field @@ -31,15 +31,15 @@ public class DelegatingFieldParser implements FieldParser { public void setFieldParser(final String name, final FieldParser parser) { parsers.put(name.toLowerCase(), parser); } - + public FieldParser getParser(final String name) { - final FieldParser field = (FieldParser) parsers.get(name.toLowerCase()); + final FieldParser field = parsers.get(name.toLowerCase()); if(field==null) { return defaultParser; } return field; } - + public Field parse(final String name, final String body, final String raw) { final FieldParser parser = getParser(name); return parser.parse(name, body, raw); diff --git a/src/org/apache/james/mime4j/field/address/Address.java b/src/org/apache/james/mime4j/field/address/Address.java index 47cee0ba0..2a5d61e36 100644 --- a/src/org/apache/james/mime4j/field/address/Address.java +++ b/src/org/apache/james/mime4j/field/address/Address.java @@ -24,10 +24,10 @@ import java.util.ArrayList; /** * The abstract base for classes that represent RFC2822 addresses. * This includes groups and mailboxes. - * + * * Currently, no public methods are introduced on this class. - * - * + * + * */ public abstract class Address { @@ -38,15 +38,15 @@ public abstract class Address { * method is needed to allow the behavior to be * overridden by subclasses. */ - final void addMailboxesTo(ArrayList results) { + final void addMailboxesTo(ArrayList
results) { doAddMailboxesTo(results); } - + /** * Adds any mailboxes represented by this address * into the given ArrayList. Must be overridden by * concrete subclasses. */ - protected abstract void doAddMailboxesTo(ArrayList results); + protected abstract void doAddMailboxesTo(ArrayList
results); } diff --git a/src/org/apache/james/mime4j/field/address/AddressList.java b/src/org/apache/james/mime4j/field/address/AddressList.java index 75072bde4..fa4d02c23 100644 --- a/src/org/apache/james/mime4j/field/address/AddressList.java +++ b/src/org/apache/james/mime4j/field/address/AddressList.java @@ -28,21 +28,21 @@ import java.util.ArrayList; /** * An immutable, random-access list of Address objects. * - * + * */ public class AddressList { - - private ArrayList addresses; + + private ArrayList
addresses; /** - * @param addresses An ArrayList that contains only Address objects. + * @param addresses An ArrayList that contains only Address objects. * @param dontCopy true iff it is not possible for the addresses ArrayList to be modified by someone else. */ - public AddressList(ArrayList addresses, boolean dontCopy) { + public AddressList(ArrayList
addresses, boolean dontCopy) { if (addresses != null) - this.addresses = (dontCopy ? addresses : (ArrayList) addresses.clone()); + this.addresses = (dontCopy ? addresses : new ArrayList
(addresses)); else - this.addresses = new ArrayList(0); + this.addresses = new ArrayList
(0); } /** @@ -53,18 +53,18 @@ public class AddressList { } /** - * Gets an address. + * Gets an address. */ public Address get(int index) { if (0 > index || size() <= index) throw new IndexOutOfBoundsException(); - return (Address) addresses.get(index); + return addresses.get(index); } /** * Returns a flat list of all mailboxes represented * in this address list. Use this if you don't care - * about grouping. + * about grouping. */ public MailboxList flatten() { // in the common case, all addresses are mailboxes @@ -75,21 +75,21 @@ public class AddressList { break; } } - + if (!groupDetected) return new MailboxList(addresses, true); - - ArrayList results = new ArrayList(); + + ArrayList
results = new ArrayList
(); for (int i = 0; i < size(); i++) { Address addr = get(i); addr.addMailboxesTo(results); } - + // copy-on-construct this time, because subclasses // could have held onto a reference to the results return new MailboxList(results, false); } - + /** * Dumps a representation of this address list to * stdout, for debugging purposes. @@ -101,20 +101,18 @@ public class AddressList { } } - - /** - * Parse the address list string, such as the value + * 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.parse()); } - + /** * Test console. */ diff --git a/src/org/apache/james/mime4j/field/address/Builder.java b/src/org/apache/james/mime4j/field/address/Builder.java index 3699afed7..a2bd3f0c6 100644 --- a/src/org/apache/james/mime4j/field/address/Builder.java +++ b/src/org/apache/james/mime4j/field/address/Builder.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Iterator; import org.apache.james.mime4j.decoder.DecoderUtil; -import org.apache.james.mime4j.field.address.parser.*; 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; @@ -43,20 +42,20 @@ import org.apache.james.mime4j.field.address.parser.Token; * Transforms the JJTree-generated abstract syntax tree * into a graph of org.apache.james.mime4j.field.address objects. * - * + * */ class Builder { private static Builder singleton = new Builder(); - + public static Builder getInstance() { return singleton; } - - - + + + public AddressList buildAddressList(ASTaddress_list node) { - ArrayList list = new ArrayList(); + ArrayList
list = new ArrayList
(); for (int i = 0; i < node.jjtGetNumChildren(); i++) { ASTaddress childNode = (ASTaddress) node.jjtGetChild(i); Address address = buildAddress(childNode); @@ -92,11 +91,11 @@ class Builder { throw new IllegalStateException(); } } - - - + + + private MailboxList buildGroupBody(ASTgroup_body node) { - ArrayList results = new ArrayList(); + ArrayList
results = new ArrayList
(); ChildNodeIterator it = new ChildNodeIterator(node); while (it.hasNext()) { Node n = it.nextNode(); @@ -135,7 +134,7 @@ class Builder { else { throw new IllegalStateException(); } - + n = it.nextNode(); if (n instanceof ASTangle_addr) { name = DecoderUtil.decodeEncodedWords(name); @@ -145,7 +144,7 @@ class Builder { throw new IllegalStateException(); } } - + private Mailbox buildAngleAddr(ASTangle_addr node) { ChildNodeIterator it = new ChildNodeIterator(node); DomainList route = null; @@ -158,7 +157,7 @@ class Builder { ; // do nothing else throw new IllegalStateException(); - + if (n instanceof ASTaddr_spec) return buildAddrSpec(route, (ASTaddr_spec)n); else @@ -166,7 +165,7 @@ class Builder { } private DomainList buildRoute(ASTroute node) { - ArrayList results = new ArrayList(node.jjtGetNumChildren()); + ArrayList results = new ArrayList(node.jjtGetNumChildren()); ChildNodeIterator it = new ChildNodeIterator(node); while (it.hasNext()) { Node n = it.nextNode(); @@ -185,7 +184,7 @@ class Builder { ChildNodeIterator it = new ChildNodeIterator(node); String localPart = buildString((ASTlocal_part)it.nextNode(), true); String domain = buildString((ASTdomain)it.nextNode(), true); - return new Mailbox(route, localPart, domain); + return new Mailbox(route, localPart, domain); } @@ -193,15 +192,15 @@ class Builder { Token head = node.firstToken; Token tail = node.lastToken; StringBuffer out = new StringBuffer(); - + while (head != tail) { out.append(head.image); head = head.next; if (!stripSpaces) addSpecials(out, head.specialToken); } - out.append(tail.image); - + out.append(tail.image); + return out.toString(); } @@ -212,18 +211,18 @@ class Builder { } } - private static class ChildNodeIterator implements Iterator { + private static class ChildNodeIterator implements Iterator { private SimpleNode simpleNode; private int index; private int len; - + public ChildNodeIterator(SimpleNode simpleNode) { this.simpleNode = simpleNode; this.len = simpleNode.jjtGetNumChildren(); this.index = 0; } - + public void remove() { throw new UnsupportedOperationException(); } @@ -232,13 +231,13 @@ class Builder { return index < len; } - public Object next() { + public Node next() { return nextNode(); } - + public Node nextNode() { return simpleNode.jjtGetChild(index++); } - + } } diff --git a/src/org/apache/james/mime4j/field/address/DomainList.java b/src/org/apache/james/mime4j/field/address/DomainList.java index 23c377e9e..df5b4de27 100644 --- a/src/org/apache/james/mime4j/field/address/DomainList.java +++ b/src/org/apache/james/mime4j/field/address/DomainList.java @@ -22,25 +22,25 @@ package org.apache.james.mime4j.field.address; import java.util.ArrayList; /** - * An immutable, random-access list of Strings (that + * An immutable, random-access list of Strings (that * are supposedly domain names or domain literals). * - * + * */ public class DomainList { - private ArrayList domains; - + private ArrayList domains; + /** - * @param domains An ArrayList that contains only String objects. + * @param domains An ArrayList that contains only String objects. * @param dontCopy true iff it is not possible for the domains ArrayList to be modified by someone else. */ - public DomainList(ArrayList domains, boolean dontCopy) { + public DomainList(ArrayList domains, boolean dontCopy) { if (domains != null) - this.domains = (dontCopy ? domains : (ArrayList) domains.clone()); + this.domains = (dontCopy ? domains : new ArrayList(domains)); else - this.domains = new ArrayList(0); + this.domains = new ArrayList(0); } - + /** * The number of elements in this list. */ @@ -56,12 +56,12 @@ public class DomainList { public String get(int index) { if (0 > index || size() <= index) throw new IndexOutOfBoundsException(); - return (String) domains.get(index); + return domains.get(index); } /** * Returns the list of domains formatted as a route - * string (not including the trailing ':'). + * string (not including the trailing ':'). */ public String toRouteString() { StringBuffer out = new StringBuffer(); diff --git a/src/org/apache/james/mime4j/field/address/Group.java b/src/org/apache/james/mime4j/field/address/Group.java index eb4002708..cca2b40b5 100644 --- a/src/org/apache/james/mime4j/field/address/Group.java +++ b/src/org/apache/james/mime4j/field/address/Group.java @@ -22,14 +22,14 @@ package org.apache.james.mime4j.field.address; import java.util.ArrayList; /** - * A named group of zero or more mailboxes. + * A named group of zero or more mailboxes. + * * - * */ public class Group extends Address { private String name; private MailboxList mailboxList; - + /** * @param name The group name. * @param mailboxes The mailboxes in this group. @@ -45,14 +45,15 @@ public class Group extends Address { public String getName() { return name; } - + /** * Returns the mailboxes in this group. */ public MailboxList getMailboxes() { return mailboxList; } - + + @Override public String toString() { StringBuffer buf = new StringBuffer(); buf.append(name); @@ -66,7 +67,8 @@ public class Group extends Address { return buf.toString(); } - protected void doAddMailboxesTo(ArrayList results) { + @Override + protected void doAddMailboxesTo(ArrayList
results) { for (int i = 0; i < mailboxList.size(); i++) results.add(mailboxList.get(i)); } diff --git a/src/org/apache/james/mime4j/field/address/Mailbox.java b/src/org/apache/james/mime4j/field/address/Mailbox.java index 57668abfe..c05a57f8e 100644 --- a/src/org/apache/james/mime4j/field/address/Mailbox.java +++ b/src/org/apache/james/mime4j/field/address/Mailbox.java @@ -22,9 +22,9 @@ package org.apache.james.mime4j.field.address; import java.util.ArrayList; /** - * Represents a single e-mail address. + * Represents a single e-mail address. + * * - * */ public class Mailbox extends Address { private DomainList route; @@ -39,7 +39,7 @@ public class Mailbox extends Address { public Mailbox(String localPart, String domain) { this(null, localPart, domain); } - + /** * Creates a mailbox with a route. Routes are obsolete. * @param route The zero or more domains that make up the route. Can be null. @@ -60,15 +60,15 @@ public class Mailbox extends Address { } /** - * Returns the left part of the e-mail address + * Returns the left part of the e-mail address * (before "@"). */ public String getLocalPart() { return localPart; } - + /** - * Returns the right part of the e-mail address + * Returns the right part of the e-mail address * (after "@"). */ public String getDomain() { @@ -78,41 +78,43 @@ public class Mailbox extends Address { /** * Formats the address as a string, not including * the route. - * + * * @see #getAddressString(boolean) */ public String getAddressString() { return getAddressString(false); } - + /** * Note that this value may not be usable * for transport purposes, only display purposes. - * + * * For example, if the unparsed address was - * + * * <"Joe Cheng"@joecheng.com> - * + * * this method would return - * + * * - * + * * which is not valid for transport; the local part * would need to be re-quoted. - * - * @param includeRoute true if the route should be included if it exists. + * + * @param includeRoute true if the route should be included if it exists. */ public String getAddressString(boolean includeRoute) { - return "<" + (!includeRoute || route == null ? "" : route.toRouteString() + ":") + return "<" + (!includeRoute || route == null ? "" : route.toRouteString() + ":") + localPart - + (domain == null ? "" : "@") - + domain + ">"; + + (domain == null ? "" : "@") + + domain + ">"; } - - protected final void doAddMailboxesTo(ArrayList results) { + + @Override + protected final void doAddMailboxesTo(ArrayList
results) { results.add(this); } - + + @Override public String toString() { return getAddressString(); } diff --git a/src/org/apache/james/mime4j/field/address/MailboxList.java b/src/org/apache/james/mime4j/field/address/MailboxList.java index b25264da3..25337de9e 100644 --- a/src/org/apache/james/mime4j/field/address/MailboxList.java +++ b/src/org/apache/james/mime4j/field/address/MailboxList.java @@ -24,39 +24,39 @@ import java.util.ArrayList; /** * An immutable, random-access list of Mailbox objects. * - * + * */ public class MailboxList { - private ArrayList mailboxes; - + private ArrayList
mailboxes; + /** - * @param mailboxes An ArrayList that contains only Mailbox objects. + * @param mailboxes An ArrayList that contains only Mailbox objects. * @param dontCopy true iff it is not possible for the mailboxes ArrayList to be modified by someone else. */ - public MailboxList(ArrayList mailboxes, boolean dontCopy) { + public MailboxList(ArrayList
mailboxes, boolean dontCopy) { if (mailboxes != null) - this.mailboxes = (dontCopy ? mailboxes : (ArrayList) mailboxes.clone()); + this.mailboxes = (dontCopy ? mailboxes : new ArrayList
(mailboxes)); else - this.mailboxes = new ArrayList(0); + this.mailboxes = new ArrayList
(0); } - + /** * The number of elements in this list. */ public int size() { return mailboxes.size(); } - + /** - * Gets an address. + * Gets an address. */ public Mailbox get(int index) { if (0 > index || size() <= index) throw new IndexOutOfBoundsException(); - return (Mailbox) mailboxes.get(index); + return (Mailbox)mailboxes.get(index); } - + /** * Dumps a representation of this mailbox list to * stdout, for debugging purposes. diff --git a/src/org/apache/james/mime4j/field/address/NamedMailbox.java b/src/org/apache/james/mime4j/field/address/NamedMailbox.java index dea0d821c..a54bd1dad 100644 --- a/src/org/apache/james/mime4j/field/address/NamedMailbox.java +++ b/src/org/apache/james/mime4j/field/address/NamedMailbox.java @@ -22,7 +22,7 @@ package org.apache.james.mime4j.field.address; /** * A Mailbox that has a name/description. * - * + * */ public class NamedMailbox extends Mailbox { private String name; @@ -42,9 +42,9 @@ public class NamedMailbox extends Mailbox { super(route, localPart, domain); this.name = name; } - + /** - * Creates a named mailbox based on an unnamed mailbox. + * Creates a named mailbox based on an unnamed mailbox. */ public NamedMailbox(String name, Mailbox baseMailbox) { super(baseMailbox.getRoute(), baseMailbox.getLocalPart(), baseMailbox.getDomain()); @@ -52,18 +52,19 @@ public class NamedMailbox extends Mailbox { } /** - * Returns the name of the mailbox. + * Returns the name of the mailbox. */ public String getName() { return this.name; } - + /** * Same features (or problems) as Mailbox.getAddressString(boolean), * only more so. - * - * @see Mailbox#getAddressString(boolean) + * + * @see Mailbox#getAddressString(boolean) */ + @Override public String getAddressString(boolean includeRoute) { return (name == null ? "" : name + " ") + super.getAddressString(includeRoute); } diff --git a/src/org/apache/james/mime4j/field/address/parser/AddressListParser.java b/src/org/apache/james/mime4j/field/address/parser/AddressListParser.java index 6cf08ac1d..dde2a0892 100644 --- a/src/org/apache/james/mime4j/field/address/parser/AddressListParser.java +++ b/src/org/apache/james/mime4j/field/address/parser/AddressListParser.java @@ -859,7 +859,7 @@ public class AddressListParser/*@bgen(jjtree)*/implements AddressListParserTreeC return (jj_ntk = jj_nt.kind); } - private java.util.Vector jj_expentries = new java.util.Vector(); + private java.util.Vector jj_expentries = new java.util.Vector(); private int[] jj_expentry; private int jj_kind = -1; private int[] jj_lasttokens = new int[100]; @@ -875,8 +875,8 @@ public class AddressListParser/*@bgen(jjtree)*/implements AddressListParserTreeC jj_expentry[i] = jj_lasttokens[i]; } boolean exists = false; - for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) { - int[] oldentry = (int[])(e.nextElement()); + for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) { + int[] oldentry = e.nextElement(); if (oldentry.length == jj_expentry.length) { exists = true; for (int i = 0; i < jj_expentry.length; i++) { @@ -927,7 +927,7 @@ public class AddressListParser/*@bgen(jjtree)*/implements AddressListParserTreeC jj_add_error_token(0, 0); int[][] exptokseq = new int[jj_expentries.size()][]; for (int i = 0; i < jj_expentries.size(); i++) { - exptokseq[i] = (int[])jj_expentries.elementAt(i); + exptokseq[i] = jj_expentries.elementAt(i); } return new ParseException(token, exptokseq, tokenImage); } diff --git a/src/org/apache/james/mime4j/field/address/parser/JJTAddressListParserState.java b/src/org/apache/james/mime4j/field/address/parser/JJTAddressListParserState.java index cca539483..08b5c5bef 100644 --- a/src/org/apache/james/mime4j/field/address/parser/JJTAddressListParserState.java +++ b/src/org/apache/james/mime4j/field/address/parser/JJTAddressListParserState.java @@ -3,16 +3,16 @@ package org.apache.james.mime4j.field.address.parser; class JJTAddressListParserState { - private java.util.Stack nodes; - private java.util.Stack marks; + private java.util.Stack nodes; + private java.util.Stack marks; private int sp; // number of nodes on stack private int mk; // current mark private boolean node_created; JJTAddressListParserState() { - nodes = new java.util.Stack(); - marks = new java.util.Stack(); + nodes = new java.util.Stack(); + marks = new java.util.Stack(); sp = 0; mk = 0; } @@ -36,7 +36,7 @@ class JJTAddressListParserState { /* Returns the root node of the AST. It only makes sense to call this after a successful parse. */ Node rootNode() { - return (Node)nodes.elementAt(0); + return nodes.elementAt(0); } /* Pushes a node on to the stack. */ @@ -49,14 +49,14 @@ class JJTAddressListParserState { stack. */ Node popNode() { if (--sp < mk) { - mk = ((Integer)marks.pop()).intValue(); + mk = marks.pop().intValue(); } - return (Node)nodes.pop(); + return nodes.pop(); } /* Returns the node currently on the top of the stack. */ Node peekNode() { - return (Node)nodes.peek(); + return nodes.peek(); } /* Returns the number of children on the stack in the current node @@ -70,7 +70,7 @@ class JJTAddressListParserState { while (sp > mk) { popNode(); } - mk = ((Integer)marks.pop()).intValue(); + mk = marks.pop().intValue(); } @@ -86,7 +86,7 @@ class JJTAddressListParserState { made the children of the definite node. Then the definite node is pushed on to the stack. */ void closeNodeScope(Node n, int num) { - mk = ((Integer)marks.pop()).intValue(); + mk = marks.pop().intValue(); while (num-- > 0) { Node c = popNode(); c.jjtSetParent(n); @@ -106,7 +106,7 @@ class JJTAddressListParserState { void closeNodeScope(Node n, boolean condition) { if (condition) { int a = nodeArity(); - mk = ((Integer)marks.pop()).intValue(); + mk = marks.pop().intValue(); while (a-- > 0) { Node c = popNode(); c.jjtSetParent(n); @@ -116,7 +116,7 @@ class JJTAddressListParserState { pushNode(n); node_created = true; } else { - mk = ((Integer)marks.pop()).intValue(); + mk = marks.pop().intValue(); node_created = false; } } diff --git a/src/org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser.java b/src/org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser.java index 64e829a51..9d4a0f564 100644 --- a/src/org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser.java +++ b/src/org/apache/james/mime4j/field/contenttype/parser/ContentTypeParser.java @@ -17,18 +17,19 @@ package org.apache.james.mime4j.field.contenttype.parser; import java.util.ArrayList; +import java.util.Vector; public class ContentTypeParser implements ContentTypeParserConstants { private String type; private String subtype; - private ArrayList paramNames = new ArrayList(); - private ArrayList paramValues = new ArrayList(); + private ArrayList paramNames = new ArrayList(); + private ArrayList paramValues = new ArrayList(); public String getType() { return type; } public String getSubType() { return subtype; } - public ArrayList getParamNames() { return paramNames; } - public ArrayList getParamValues() { return paramValues; } + public ArrayList getParamNames() { return paramNames; } + public ArrayList getParamValues() { return paramValues; } public static void main(String args[]) throws ParseException { while (true) { @@ -221,7 +222,7 @@ public class ContentTypeParser implements ContentTypeParserConstants { return (jj_ntk = jj_nt.kind); } - private java.util.Vector jj_expentries = new java.util.Vector(); + private Vector jj_expentries = new Vector(); private int[] jj_expentry; private int jj_kind = -1; @@ -253,7 +254,7 @@ public class ContentTypeParser implements ContentTypeParserConstants { } int[][] exptokseq = new int[jj_expentries.size()][]; for (int i = 0; i < jj_expentries.size(); i++) { - exptokseq[i] = (int[])jj_expentries.elementAt(i); + exptokseq[i] = jj_expentries.elementAt(i); } return new ParseException(token, exptokseq, tokenImage); } diff --git a/src/org/apache/james/mime4j/field/datetime/parser/DateTimeParser.java b/src/org/apache/james/mime4j/field/datetime/parser/DateTimeParser.java index 94b517208..04cb9520b 100644 --- a/src/org/apache/james/mime4j/field/datetime/parser/DateTimeParser.java +++ b/src/org/apache/james/mime4j/field/datetime/parser/DateTimeParser.java @@ -18,7 +18,7 @@ package org.apache.james.mime4j.field.datetime.parser; import org.apache.james.mime4j.field.datetime.DateTime; -import java.util.Calendar; +import java.util.Vector; public class DateTimeParser implements DateTimeParserConstants { private static final boolean ignoreMilitaryZoneOffset = true; @@ -521,7 +521,7 @@ public class DateTimeParser implements DateTimeParserConstants { return (jj_ntk = jj_nt.kind); } - private java.util.Vector jj_expentries = new java.util.Vector(); + private Vector jj_expentries = new Vector(); private int[] jj_expentry; private int jj_kind = -1; @@ -556,7 +556,7 @@ public class DateTimeParser implements DateTimeParserConstants { } int[][] exptokseq = new int[jj_expentries.size()][]; for (int i = 0; i < jj_expentries.size(); i++) { - exptokseq[i] = (int[])jj_expentries.elementAt(i); + exptokseq[i] = jj_expentries.elementAt(i); } return new ParseException(token, exptokseq, tokenImage); } diff --git a/src/org/apache/james/mime4j/message/Header.java b/src/org/apache/james/mime4j/message/Header.java index 90a0ef480..e9216a821 100644 --- a/src/org/apache/james/mime4j/message/Header.java +++ b/src/org/apache/james/mime4j/message/Header.java @@ -40,13 +40,13 @@ import org.apache.james.mime4j.util.CharsetUtil; /** * The header of an entity (see RFC 2045). * - * + * * @version $Id: Header.java,v 1.3 2004/10/04 15:36:44 ntherning Exp $ */ public class Header { - private List fields = new LinkedList(); - private HashMap fieldMap = new HashMap(); - + private List fields = new LinkedList(); + private HashMap> fieldMap = new HashMap>(); + /** * Creates a new empty Header. */ @@ -55,15 +55,17 @@ public class Header { /** * Creates a new Header from the specified stream. - * + * * @param is the stream to read the header from. */ public Header(InputStream is) throws IOException { final MimeStreamParser parser = new MimeStreamParser(); parser.setContentHandler(new AbstractContentHandler() { + @Override public void endHeader() { parser.stop(); } + @Override public void field(String fieldData) { addField(Field.parse(fieldData)); } @@ -73,80 +75,81 @@ public class Header { /** * Adds a field to the end of the list of fields. - * + * * @param field the field to add. */ public void addField(Field field) { - List values = (List) fieldMap.get(field.getName().toLowerCase()); + List values = fieldMap.get(field.getName().toLowerCase()); if (values == null) { - values = new LinkedList(); + values = new LinkedList(); fieldMap.put(field.getName().toLowerCase(), values); } values.add(field); fields.add(field); } - + /** * Gets the fields of this header. The returned list will not be * modifiable. - * + * * @return the list of Field objects. */ - public List getFields() { + public List getFields() { return Collections.unmodifiableList(fields); } /** * Gets a Field given a field name. If there are multiple * such fields defined in this header the first one will be returned. - * + * * @param name the field name (e.g. From, Subject). * @return the field or null if none found. */ public Field getField(String name) { - List l = (List) fieldMap.get(name.toLowerCase()); + List l = fieldMap.get(name.toLowerCase()); if (l != null && !l.isEmpty()) { - return (Field) l.get(0); + return l.get(0); } return null; } - + /** - * Gets all Fields having the specified field name. - * + * Gets all Fields having the specified field name. + * * @param name the field name (e.g. From, Subject). * @return the list of fields. */ - public List getFields(String name) { - List l = (List) fieldMap.get(name.toLowerCase()); + public List getFields(String name) { + List l = fieldMap.get(name.toLowerCase()); return Collections.unmodifiableList(l); } - + /** * Return Header Object as String representation. Each headerline is * seperated by "\r\n" - * + * * @return headers */ + @Override public String toString() { StringBuffer str = new StringBuffer(); - for (Iterator it = fields.iterator(); it.hasNext();) { + for (Iterator it = fields.iterator(); it.hasNext();) { str.append(it.next().toString()); str.append("\r\n"); } return str.toString(); } - - + + /** * Write the Header to the given OutputStream - * + * * @param out the OutputStream to write to * @throws IOException */ public void writeTo(OutputStream out) throws IOException { String charString = ((ContentTypeField) getField(Field.CONTENT_TYPE)).getCharset(); - + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, CharsetUtil.getCharset(charString)),8192); writer.write(toString()+ "\r\n"); writer.flush(); diff --git a/src/org/apache/james/mime4j/message/Message.java b/src/org/apache/james/mime4j/message/Message.java index fc28c586a..514307185 100644 --- a/src/org/apache/james/mime4j/message/Message.java +++ b/src/org/apache/james/mime4j/message/Message.java @@ -34,30 +34,30 @@ import org.apache.james.mime4j.field.UnstructuredField; /** - * Represents a MIME message. The following code parses a stream into a + * Represents a MIME message. The following code parses a stream into a * Message object. - * + * *
  *      Message msg = new Message(new BufferedInputStream(
  *                                      new FileInputStream("mime.msg")));
  * 
- * * - * + * + * * @version $Id: Message.java,v 1.3 2004/10/02 12:41:11 ntherning Exp $ */ public class Message extends Entity implements Body { - + /** * Creates a new empty Message. */ public Message() { } - + /** * Parses the specified MIME message stream into a Message * instance. - * + * * @param is the stream to parse. * @throws IOException on I/O errors. */ @@ -67,10 +67,10 @@ public class Message extends Entity implements Body { parser.parse(is); } - + /** * Gets the Subject field. - * + * * @return the Subject field or null if it * doesn't exist. */ @@ -79,9 +79,10 @@ public class Message extends Entity implements Body { } /** - * + * * @see org.apache.james.mime4j.message.Entity#writeTo(java.io.OutputStream) */ + @Override public void writeTo(OutputStream out) throws IOException { getHeader().writeTo(out); @@ -93,14 +94,14 @@ public class Message extends Entity implements Body { body.writeTo(out); } } - - + + private class MessageBuilder implements ContentHandler { - private Stack stack = new Stack(); - + private Stack stack = new Stack(); + public MessageBuilder() { } - + private void expect(Class c) { if (!c.isInstance(stack.peek())) { throw new IllegalStateException("Internal stack error: " @@ -108,7 +109,7 @@ public class Message extends Entity implements Body { + stack.peek().getClass().getName() + "'"); } } - + /** * @see org.apache.james.mime4j.ContentHandler#startMessage() */ @@ -122,7 +123,7 @@ public class Message extends Entity implements Body { stack.push(m); } } - + /** * @see org.apache.james.mime4j.ContentHandler#endMessage() */ @@ -130,14 +131,14 @@ public class Message extends Entity implements Body { expect(Message.class); stack.pop(); } - + /** * @see org.apache.james.mime4j.ContentHandler#startHeader() */ public void startHeader() { stack.push(new Header()); } - + /** * @see org.apache.james.mime4j.ContentHandler#field(java.lang.String) */ @@ -145,7 +146,7 @@ public class Message extends Entity implements Body { expect(Header.class); ((Header) stack.peek()).addField(Field.parse(fieldData)); } - + /** * @see org.apache.james.mime4j.ContentHandler#endHeader() */ @@ -155,60 +156,60 @@ public class Message extends Entity implements Body { expect(Entity.class); ((Entity) stack.peek()).setHeader(h); } - + /** * @see org.apache.james.mime4j.ContentHandler#startMultipart(org.apache.james.mime4j.BodyDescriptor) */ public void startMultipart(BodyDescriptor bd) { expect(Entity.class); - + Entity e = (Entity) stack.peek(); Multipart multiPart = new Multipart(); e.setBody(multiPart); stack.push(multiPart); } - + /** * @see org.apache.james.mime4j.ContentHandler#body(org.apache.james.mime4j.BodyDescriptor, java.io.InputStream) */ public void body(BodyDescriptor bd, InputStream is) throws IOException { expect(Entity.class); - + String enc = bd.getTransferEncoding(); if ("base64".equals(enc)) { is = new Base64InputStream(is); } else if ("quoted-printable".equals(enc)) { is = new QuotedPrintableInputStream(is); } - + Body body = null; if (bd.getMimeType().startsWith("text/")) { body = new MemoryTextBody(is, bd.getCharset()); } else { body = new MemoryBinaryBody(is); } - + ((Entity) stack.peek()).setBody(body); } - + /** * @see org.apache.james.mime4j.ContentHandler#endMultipart() */ public void endMultipart() { stack.pop(); } - + /** * @see org.apache.james.mime4j.ContentHandler#startBodyPart() */ public void startBodyPart() { expect(Multipart.class); - + BodyPart bodyPart = new BodyPart(); ((Multipart) stack.peek()).addBodyPart(bodyPart); stack.push(bodyPart); } - + /** * @see org.apache.james.mime4j.ContentHandler#endBodyPart() */ @@ -216,7 +217,7 @@ public class Message extends Entity implements Body { expect(BodyPart.class); stack.pop(); } - + /** * @see org.apache.james.mime4j.ContentHandler#epilogue(java.io.InputStream) */ @@ -229,7 +230,7 @@ public class Message extends Entity implements Body { } ((Multipart) stack.peek()).setEpilogue(sb.toString()); } - + /** * @see org.apache.james.mime4j.ContentHandler#preamble(java.io.InputStream) */ @@ -242,10 +243,10 @@ public class Message extends Entity implements Body { } ((Multipart) stack.peek()).setPreamble(sb.toString()); } - + /** * TODO: Implement me - * + * * @see org.apache.james.mime4j.ContentHandler#raw(java.io.InputStream) */ public void raw(InputStream is) throws IOException { diff --git a/src/org/apache/james/mime4j/message/Multipart.java b/src/org/apache/james/mime4j/message/Multipart.java index 3c4b519c4..d83400097 100644 --- a/src/org/apache/james/mime4j/message/Multipart.java +++ b/src/org/apache/james/mime4j/message/Multipart.java @@ -33,19 +33,19 @@ import org.apache.james.mime4j.field.Field; import org.apache.james.mime4j.util.CharsetUtil; /** - * Represents a MIME multipart body (see RFC 2045).A multipart body has a + * Represents a MIME multipart body (see RFC 2045).A multipart body has a * ordered list of body parts. The multipart body also has a preamble and - * epilogue. The preamble consists of whatever characters appear before the + * epilogue. The preamble consists of whatever characters appear before the * first body part while the epilogue consists of whatever characters come * after the last body part. * - * + * * @version $Id: Multipart.java,v 1.3 2004/10/02 12:41:11 ntherning Exp $ */ public class Multipart implements Body { private String preamble = ""; private String epilogue = ""; - private List bodyParts = new LinkedList(); + private List bodyParts = new LinkedList(); private Entity parent = null; private String subType = "alternative"; @@ -59,102 +59,102 @@ public class Multipart implements Body { * Gets the multipart sub-type. E.g. alternative (the default) * or parallel. See RFC 2045 for common sub-types and their * meaning. - * + * * @return the multipart sub-type. */ public String getSubType() { return subType; } - + /** * Sets the multipart sub-type. E.g. alternative * or parallel. See RFC 2045 for common sub-types and their * meaning. - * + * * @param subType the sub-type. */ public void setSubType(String subType) { this.subType = subType; } - + /** * @see org.apache.james.mime4j.message.Body#getParent() */ public Entity getParent() { return parent; } - + /** * @see org.apache.james.mime4j.message.Body#setParent(org.apache.james.mime4j.message.Entity) */ public void setParent(Entity parent) { this.parent = parent; - for (Iterator it = bodyParts.iterator(); it.hasNext();) { - ((BodyPart) it.next()).setParent(parent); + for (Iterator it = bodyParts.iterator(); it.hasNext();) { + it.next().setParent(parent); } } /** * Gets the epilogue. - * + * * @return the epilogue. */ public String getEpilogue() { return epilogue; } - + /** * Sets the epilogue. - * + * * @param epilogue the epilogue. */ public void setEpilogue(String epilogue) { this.epilogue = epilogue; } - + /** * Gets the list of body parts. The list is immutable. - * + * * @return the list of BodyPart objects. */ - public List getBodyParts() { + public List getBodyParts() { return Collections.unmodifiableList(bodyParts); } - + /** * Sets the list of body parts. - * + * * @param bodyParts the new list of BodyPart objects. */ - public void setBodyParts(List bodyParts) { + public void setBodyParts(List bodyParts) { this.bodyParts = bodyParts; - for (Iterator it = bodyParts.iterator(); it.hasNext();) { - ((BodyPart) it.next()).setParent(parent); + for (Iterator it = bodyParts.iterator(); it.hasNext();) { + it.next().setParent(parent); } } - + /** * Adds a body part to the end of the list of body parts. - * + * * @param bodyPart the body part. */ public void addBodyPart(BodyPart bodyPart) { bodyParts.add(bodyPart); bodyPart.setParent(parent); } - + /** * Gets the preamble. - * + * * @return the preamble. */ public String getPreamble() { return preamble; } - + /** * Sets the preamble. - * + * * @param preamble the preamble. */ public void setPreamble(String preamble) { @@ -162,20 +162,20 @@ public class Multipart implements Body { } /** - * + * * @see org.apache.james.mime4j.message.Body#writeTo(java.io.OutputStream) */ public void writeTo(OutputStream out) throws IOException { String boundary = getBoundary(); - List bodyParts = getBodyParts(); + List bodyParts = getBodyParts(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, CharsetUtil.getCharset(getCharset())),8192); - + writer.write(getPreamble() + "\r\n"); for (int i = 0; i < bodyParts.size(); i++) { writer.write(boundary + "\r\n"); - ((BodyPart) bodyParts.get(i)).writeTo(out); + bodyParts.get(i).writeTo(out); } writer.write(getEpilogue() + "\r\n"); @@ -185,7 +185,7 @@ public class Multipart implements Body { /** * Return the boundory of the parent Entity - * + * * @return boundery */ private String getBoundary() { @@ -194,7 +194,7 @@ public class Multipart implements Body { Field.CONTENT_TYPE); return cField.getBoundary(); } - + private String getCharset() { Entity e = getParent(); String charString = ((ContentTypeField) e.getHeader().getField(Field.CONTENT_TYPE)).getCharset(); diff --git a/src/org/apache/james/mime4j/util/CharsetUtil.java b/src/org/apache/james/mime4j/util/CharsetUtil.java index d2074bb35..0fc267d3e 100644 --- a/src/org/apache/james/mime4j/util/CharsetUtil.java +++ b/src/org/apache/james/mime4j/util/CharsetUtil.java @@ -786,68 +786,67 @@ import org.apache.james.mime4j.LogFactory; * * * - * - * + * + * * @version $Id: CharsetUtil.java,v 1.1 2004/10/25 07:26:46 ntherning Exp $ */ public class CharsetUtil { private static Log log = LogFactory.getLog(CharsetUtil.class); - - private static class Charset implements Comparable { + + private static class Charset implements Comparable { private String canonical = null; private String mime = null; private String[] aliases = null; - + private Charset(String canonical, String mime, String[] aliases) { this.canonical = canonical; this.mime = mime; this.aliases = aliases; } - public int compareTo(Object o) { - Charset c = (Charset) o; + public int compareTo(Charset c) { return this.canonical.compareTo(c.canonical); } } - + private static Charset[] JAVA_CHARSETS = { - new Charset("ISO8859_1", "ISO-8859-1", - new String[] {"ISO_8859-1:1987", "iso-ir-100", "ISO_8859-1", - "latin1", "l1", "IBM819", "CP819", - "csISOLatin1", "8859_1", "819", "IBM-819", + new Charset("ISO8859_1", "ISO-8859-1", + new String[] {"ISO_8859-1:1987", "iso-ir-100", "ISO_8859-1", + "latin1", "l1", "IBM819", "CP819", + "csISOLatin1", "8859_1", "819", "IBM-819", "ISO8859-1", "ISO_8859_1"}), - new Charset("ISO8859_2", "ISO-8859-2", - new String[] {"ISO_8859-2:1987", "iso-ir-101", "ISO_8859-2", - "latin2", "l2", "csISOLatin2", "8859_2", + new Charset("ISO8859_2", "ISO-8859-2", + new String[] {"ISO_8859-2:1987", "iso-ir-101", "ISO_8859-2", + "latin2", "l2", "csISOLatin2", "8859_2", "iso8859_2"}), new Charset("ISO8859_3", "ISO-8859-3", new String[] {"ISO_8859-3:1988", "iso-ir-109", "ISO_8859-3", "latin3", "l3", "csISOLatin3", "8859_3"}), - new Charset("ISO8859_4", "ISO-8859-4", + new Charset("ISO8859_4", "ISO-8859-4", new String[] {"ISO_8859-4:1988", "iso-ir-110", "ISO_8859-4", "latin4", "l4", "csISOLatin4", "8859_4"}), - new Charset("ISO8859_5", "ISO-8859-5", - new String[] {"ISO_8859-5:1988", "iso-ir-144", "ISO_8859-5", + new Charset("ISO8859_5", "ISO-8859-5", + new String[] {"ISO_8859-5:1988", "iso-ir-144", "ISO_8859-5", "cyrillic", "csISOLatinCyrillic", "8859_5"}), new Charset("ISO8859_6", "ISO-8859-6", new String[] {"ISO_8859-6:1987", "iso-ir-127", "ISO_8859-6", "ECMA-114", "ASMO-708", "arabic", "csISOLatinArabic", "8859_6"}), - new Charset("ISO8859_7", "ISO-8859-7", - new String[] {"ISO_8859-7:1987", "iso-ir-126", "ISO_8859-7", - "ELOT_928", "ECMA-118", "greek", "greek8", + new Charset("ISO8859_7", "ISO-8859-7", + new String[] {"ISO_8859-7:1987", "iso-ir-126", "ISO_8859-7", + "ELOT_928", "ECMA-118", "greek", "greek8", "csISOLatinGreek", "8859_7", "sun_eu_greek"}), new Charset("ISO8859_8", "ISO-8859-8", new String[] {"ISO_8859-8:1988", "iso-ir-138", "ISO_8859-8", "hebrew", "csISOLatinHebrew", "8859_8"}), - new Charset("ISO8859_9", "ISO-8859-9", - new String[] {"ISO_8859-9:1989", "iso-ir-148", "ISO_8859-9", + new Charset("ISO8859_9", "ISO-8859-9", + new String[] {"ISO_8859-9:1989", "iso-ir-148", "ISO_8859-9", "latin5", "l5", "csISOLatin5", "8859_9"}), new Charset("ISO8859_13", "ISO-8859-13", new String[] {}), - new Charset("ISO8859_15", "ISO-8859-15", - new String[] {"ISO_8859-15", "Latin-9", "8859_15", + new Charset("ISO8859_15", "ISO-8859-15", + new String[] {"ISO_8859-15", "Latin-9", "8859_15", "csISOlatin9", "IBM923", "cp923", "923", "L9", - "IBM-923", "ISO8859-15", "LATIN9", "LATIN0", + "IBM-923", "ISO8859-15", "LATIN9", "LATIN0", "csISOlatin0", "ISO8859_15_FDIS"}), new Charset("KOI8_R", "KOI8-R", new String[] {"csKOI8R", "koi8"}), - new Charset("ASCII", "US-ASCII", - new String[] {"ANSI_X3.4-1968", "iso-ir-6", - "ANSI_X3.4-1986", "ISO_646.irv:1991", - "ISO646-US", "us", "IBM367", "cp367", + new Charset("ASCII", "US-ASCII", + new String[] {"ANSI_X3.4-1968", "iso-ir-6", + "ANSI_X3.4-1986", "ISO_646.irv:1991", + "ISO646-US", "us", "IBM367", "cp367", "csASCII", "ascii7", "646", "iso_646.irv:1983"}), new Charset("UTF8", "UTF-8", new String[] {}), new Charset("UTF-16", "UTF-16", new String[] {"UTF_16"}), @@ -855,13 +854,13 @@ public class CharsetUtil { new Charset("UnicodeLittleUnmarked", "UTF-16LE", new String[] {"UTF_16LE", "X-UTF-16LE"}), new Charset("Big5", "Big5", new String[] {"csBig5", "CN-Big5", "BIG-FIVE", "BIGFIVE"}), new Charset("Big5_HKSCS", "Big5-HKSCS", new String[] {"big5hkscs"}), - new Charset("EUC_JP", "EUC-JP", - new String[] {"csEUCPkdFmtJapanese", + new Charset("EUC_JP", "EUC-JP", + new String[] {"csEUCPkdFmtJapanese", "Extended_UNIX_Code_Packed_Format_for_Japanese", "eucjis", "x-eucjp", "eucjp", "x-euc-jp"}), - new Charset("EUC_KR", "EUC-KR", - new String[] {"csEUCKR", "ksc5601", "5601", "ksc5601_1987", - "ksc_5601", "ksc5601-1987", "ks_c_5601-1987", + new Charset("EUC_KR", "EUC-KR", + new String[] {"csEUCKR", "ksc5601", "5601", "ksc5601_1987", + "ksc_5601", "ksc5601-1987", "ks_c_5601-1987", "euckr"}), new Charset("GB18030", "GB18030", new String[] {"gb18030-2000"}), new Charset("EUC_CN", "GB2312", new String[] {"x-EUC-CN", "csGB2312", "euccn", "euc-cn", "gb2312-80", "gb2312-1980", "CN-GB", "CN-GB-ISOIR165"}), @@ -885,8 +884,8 @@ public class CharsetUtil { new Charset("Cp852", "IBM852", new String[] {"852", "csPCp852"}), new Charset("Cp855", "IBM855", new String[] {"855", "csIBM855"}), new Charset("Cp857", "IBM857", new String[] {"857", "csIBM857"}), - new Charset("Cp858", "IBM00858", - new String[] {"CCSID00858", "CP00858", + new Charset("Cp858", "IBM00858", + new String[] {"CCSID00858", "CP00858", "PC-Multilingual-850+euro"}), new Charset("Cp860", "IBM860", new String[] {"860", "csIBM860"}), new Charset("Cp861", "IBM861", new String[] {"861", "cp-is", "csIBM861"}), @@ -902,11 +901,11 @@ public class CharsetUtil { new Charset("Cp918", "IBM918", new String[] {"ebcdic-cp-ar2", "csIBM918"}), new Charset("Cp1026", "IBM1026", new String[] {"csIBM1026"}), new Charset("Cp1047", "IBM1047", new String[] {"IBM-1047"}), - new Charset("Cp1140", "IBM01140", - new String[] {"CCSID01140", "CP01140", + new Charset("Cp1140", "IBM01140", + new String[] {"CCSID01140", "CP01140", "ebcdic-us-37+euro"}), - new Charset("Cp1141", "IBM01141", - new String[] {"CCSID01141", "CP01141", + new Charset("Cp1141", "IBM01141", + new String[] {"CCSID01141", "CP01141", "ebcdic-de-273+euro"}), new Charset("Cp1142", "IBM01142", new String[] {"CCSID01142", "CP01142", "ebcdic-dk-277+euro", "ebcdic-no-277+euro"}), new Charset("Cp1143", "IBM01143", new String[] {"CCSID01143", "CP01143", "ebcdic-fi-278+euro", "ebcdic-se-278+euro"}), @@ -962,7 +961,7 @@ public class CharsetUtil { new Charset("Cp964", null, new String[] {}), new Charset("Cp970", null, new String[] {}), new Charset("Cp1006", null, new String[] {}), - new Charset("Cp1025", null, new String[] {}), + new Charset("Cp1025", null, new String[] {}), new Charset("Cp1046", null, new String[] {}), new Charset("Cp1097", null, new String[] {}), new Charset("Cp1098", null, new String[] {}), @@ -1000,26 +999,26 @@ public class CharsetUtil { }; /** - * Contains the canonical names of character sets which can be used to + * Contains the canonical names of character sets which can be used to * decode bytes into Java chars. */ - private static TreeSet decodingSupported = null; - + private static TreeSet decodingSupported = null; + /** - * Contains the canonical names of character sets which can be used to + * Contains the canonical names of character sets which can be used to * encode Java chars into bytes. */ - private static TreeSet encodingSupported = null; - + private static TreeSet encodingSupported = null; + /** * Maps character set names to Charset objects. All possible names of * a charset will be mapped to the Charset. */ - private static HashMap charsetMap = null; - + private static HashMap charsetMap = null; + static { - decodingSupported = new TreeSet(); - encodingSupported = new TreeSet(); + decodingSupported = new TreeSet(); + encodingSupported = new TreeSet(); byte[] dummy = new byte[] {'d', 'u', 'm', 'm', 'y'}; for (int i = 0; i < JAVA_CHARSETS.length; i++) { try { @@ -1035,8 +1034,8 @@ public class CharsetUtil { } catch (UnsupportedEncodingException e) { } } - - charsetMap = new HashMap(); + + charsetMap = new HashMap(); for (int i = 0; i < JAVA_CHARSETS.length; i++) { Charset c = JAVA_CHARSETS[i]; charsetMap.put(c.canonical.toLowerCase(), c); @@ -1049,19 +1048,19 @@ public class CharsetUtil { } } } - + if (log.isDebugEnabled()) { - log.debug("Character sets which support decoding: " + log.debug("Character sets which support decoding: " + decodingSupported); - log.debug("Character sets which support encoding: " + log.debug("Character sets which support encoding: " + encodingSupported); } } - + /** * ANDROID: THE FOLLOWING SET OF STATIC STRINGS ARE COPIED FROM A NEWER VERSION OF MIME4J */ - + /** carriage return - line feed sequence */ public static final String CRLF = "\r\n"; @@ -1076,7 +1075,7 @@ public class CharsetUtil { /** US-ASCII HT, horizontal-tab (9)*/ public static final int HT = '\t'; - + public static final java.nio.charset.Charset US_ASCII = java.nio.charset.Charset .forName("US-ASCII"); @@ -1089,9 +1088,9 @@ public class CharsetUtil { /** * Returns true if the specified character is a whitespace * character (CR, LF, SP or HT). - * + * * ANDROID: COPIED FROM A NEWER VERSION OF MIME4J - * + * * @param ch * character to test. * @return true if the specified character is a whitespace @@ -1104,9 +1103,9 @@ public class CharsetUtil { /** * Returns true if the specified string consists entirely of * whitespace characters. - * + * * ANDROID: COPIED FROM A NEWER VERSION OF MIME4J - * + * * @param s * string to test. * @return true if the specified string consists entirely of @@ -1126,12 +1125,12 @@ public class CharsetUtil { } /** - * Determines if the VM supports encoding (chars to bytes) the - * specified character set. NOTE: the given character set name may + * Determines if the VM supports encoding (chars to bytes) the + * specified character set. NOTE: the given character set name may * not be known to the VM even if this method returns true. * Use {@link #toJavaCharset(String)} to get the canonical Java character * set name. - * + * * @param charsetName the characters set name. * @return true if encoding is supported, false * otherwise. @@ -1139,14 +1138,14 @@ public class CharsetUtil { public static boolean isEncodingSupported(String charsetName) { return encodingSupported.contains(charsetName.toLowerCase()); } - + /** - * Determines if the VM supports decoding (bytes to chars) the - * specified character set. NOTE: the given character set name may + * Determines if the VM supports decoding (bytes to chars) the + * specified character set. NOTE: the given character set name may * not be known to the VM even if this method returns true. * Use {@link #toJavaCharset(String)} to get the canonical Java character * set name. - * + * * @param charsetName the characters set name. * @return true if decoding is supported, false * otherwise. @@ -1154,22 +1153,22 @@ public class CharsetUtil { public static boolean isDecodingSupported(String charsetName) { return decodingSupported.contains(charsetName.toLowerCase()); } - + /** * Gets the preferred MIME character set name for the specified * character set or null if not known. - * + * * @param charsetName the character set name to look for. * @return the MIME preferred name or null if not known. */ public static String toMimeCharset(String charsetName) { - Charset c = (Charset) charsetMap.get(charsetName.toLowerCase()); + Charset c = charsetMap.get(charsetName.toLowerCase()); if (c != null) { return c.mime; } return null; } - + /** * Gets the canonical Java character set name for the specified * character set or null if not known. This should be @@ -1177,12 +1176,12 @@ public class CharsetUtil { * you must use {@link #isEncodingSupported(String)} or * {@link #isDecodingSupported(String)} to make sure the returned * Java character set is supported by the current VM. - * + * * @param charsetName the character set name to look for. * @return the canonical Java name or null if not known. */ public static String toJavaCharset(String charsetName) { - Charset c = (Charset) charsetMap.get(charsetName.toLowerCase()); + Charset c = charsetMap.get(charsetName.toLowerCase()); if (c != null) { return c.canonical; } @@ -1191,28 +1190,28 @@ public class CharsetUtil { public static java.nio.charset.Charset getCharset(String charsetName) { String defaultCharset = "ISO-8859-1"; - + // Use the default chareset if given charset is null if(charsetName == null) charsetName = defaultCharset; - + try { return java.nio.charset.Charset.forName(charsetName); } catch (IllegalCharsetNameException e) { log.info("Illegal charset " + charsetName + ", fallback to " + defaultCharset + ": " + e); - // Use default charset on exception + // Use default charset on exception return java.nio.charset.Charset.forName(defaultCharset); } catch (UnsupportedCharsetException ex) { log.info("Unsupported charset " + charsetName + ", fallback to " + defaultCharset + ": " + ex); // Use default charset on exception return java.nio.charset.Charset.forName(defaultCharset); } - + } /* * Uncomment the code below and run the main method to regenerate the - * Javadoc table above when the known charsets change. + * Javadoc table above when the known charsets change. */ - + /* private static String dumpHtmlTable() { LinkedList l = new LinkedList(Arrays.asList(JAVA_CHARSETS)); @@ -1240,7 +1239,7 @@ public class CharsetUtil { sb.append(" * \n"); return sb.toString(); } - + public static void main(String[] args) { System.out.println(dumpHtmlTable()); }*/ diff --git a/tests/src/com/android/email/mail/transport/Rfc822OutputTests.java b/tests/src/com/android/email/mail/transport/Rfc822OutputTests.java index 9dba643a6..537bc4aad 100644 --- a/tests/src/com/android/email/mail/transport/Rfc822OutputTests.java +++ b/tests/src/com/android/email/mail/transport/Rfc822OutputTests.java @@ -24,6 +24,7 @@ import com.android.email.provider.EmailContent.Message; import org.apache.james.mime4j.field.Field; import org.apache.james.mime4j.message.Body; +import org.apache.james.mime4j.message.BodyPart; import org.apache.james.mime4j.message.Entity; import org.apache.james.mime4j.message.Header; import org.apache.james.mime4j.message.Multipart; @@ -210,11 +211,11 @@ public class Rfc822OutputTests extends ProviderTestCase2 { Field contentType = header.getField("content-type"); assertTrue(contentType.getBody().contains("multipart/alternative")); Multipart multipart = (Multipart)mimeMessage.getBody(); - List partList = multipart.getBodyParts(); + List partList = multipart.getBodyParts(); assertEquals(2, partList.size()); - Entity part = (Entity)partList.get(0); + Entity part = partList.get(0); assertEquals("text/plain", part.getMimeType()); - part = (Entity)partList.get(1); + part = partList.get(1); assertEquals("text/calendar", part.getMimeType()); header = part.getHeader(); assertNull(header.getField("content-disposition")); @@ -254,11 +255,11 @@ public class Rfc822OutputTests extends ProviderTestCase2 { Field contentType = header.getField("content-type"); assertTrue(contentType.getBody().contains("multipart/mixed")); Multipart multipart = (Multipart)mimeMessage.getBody(); - List partList = multipart.getBodyParts(); + List partList = multipart.getBodyParts(); assertEquals(2, partList.size()); - Entity part = (Entity)partList.get(0); + Entity part = partList.get(0); assertEquals("text/plain", part.getMimeType()); - part = (Entity)partList.get(1); + part = partList.get(1); assertEquals("text/html", part.getMimeType()); header = part.getHeader(); assertNotNull(header.getField("content-disposition"));