Resolve build warnings; part 2

Change-Id: I76c1a5a4f759071f92eef0574abb20a99bfb32b7
This commit is contained in:
Todd Kennedy 2011-02-02 11:47:06 -08:00
parent 44de127691
commit 8546e21e1e
21 changed files with 493 additions and 500 deletions

View File

@ -23,23 +23,23 @@ import java.util.HashMap;
import java.util.Map;
/**
* Encapsulates the values of the MIME-specific header fields
* (which starts with <code>Content-</code>).
* Encapsulates the values of the MIME-specific header fields
* (which starts with <code>Content-</code>).
*
*
*
* @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<String, String> parameters = new HashMap<String, String>();
private boolean contentTypeSet = false;
private boolean contentTransferEncSet = false;
/**
* Creates a new root <code>BodyDescriptor</code> instance.
*/
@ -49,7 +49,7 @@ public class BodyDescriptor {
/**
* Creates a new <code>BodyDescriptor</code> instance.
*
*
* @param parent the descriptor of the parent or <code>null</code> if this
* is the root descriptor.
*/
@ -60,31 +60,31 @@ public class BodyDescriptor {
mimeType = "text/plain";
}
}
/**
* Should be called for each <code>Content-</code> header field of
* Should be called for each <code>Content-</code> 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<String, String> 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<String, String> getHeaderParams(String headerValue) {
Map<String, String> result = new HashMap<String, String>();
// 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<String, String> 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;
}

View File

@ -32,7 +32,7 @@ import java.util.LinkedList;
/**
* <p>
* 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 <code>ContentHandler</code> instance.
* </p>
* <p>
@ -43,11 +43,11 @@ import java.util.LinkedList;
* parser.setContentHandler(handler);
* parser.parse(new BufferedInputStream(new FileInputStream("mime.msg")));
* </pre>
* <strong>NOTE:</strong> All lines must end with CRLF
* (<code>\r\n</code>). If you are unsure of the line endings in your stream
* <strong>NOTE:</strong> All lines must end with CRLF
* (<code>\r\n</code>). 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<BodyDescriptor> bodyDescriptors = new LinkedList<BodyDescriptor>();
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 <code>MimeStreamParser</code> 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 <code>true</code> if in raw mode, <code>false</code>
* 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 <code>true</code> enables raw mode, <code>false</code>
* 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 <code>BodyDescriptor</code> describing the body following
* @return a <code>BodyDescriptor</code> 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 <code>ContentHandler</code> to use when reporting
* Sets the <code>ContentHandler</code> to use when reporting
* parsing events.
*
*
* @param h the <code>ContentHandler</code>.
*/
public void setContentHandler(ContentHandler h) {

View File

@ -38,11 +38,11 @@ import org.apache.james.mime4j.field.contenttype.parser.TokenMgrError;
*
* <p>TODO: Remove dependency on Java 1.4 regexps</p>
*
*
*
* @version $Id: ContentTypeField.java,v 1.6 2005/01/27 14:16:31 ntherning Exp $
*/
public class ContentTypeField extends Field {
/**
* The prefix of all <code>multipart</code> MIME types.
*/
@ -67,12 +67,12 @@ public class ContentTypeField extends Field {
* The name of the <code>charset</code> parameter.
*/
public static final String PARAM_CHARSET = "charset";
private String mimeType = "";
private Map parameters = null;
private Map<String, String> 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<String, String> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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<String, String> getParameters() {
if (parameters != null) {
return Collections.unmodifiableMap(parameters);
}
return Collections.emptyMap();
}
/**
* Gets the value of the <code>boundary</code> parameter if set.
*
* @return the <code>boundary</code> parameter value or <code>null</code>
*
* @return the <code>boundary</code> parameter value or <code>null</code>
* if not set.
*/
public String getBoundary() {
return getParameter(PARAM_BOUNDARY);
}
/**
* Gets the value of the <code>charset</code> parameter if set.
*
* @return the <code>charset</code> parameter value or <code>null</code>
*
* @return the <code>charset</code> parameter value or <code>null</code>
* if not set.
*/
public String getCharset() {
return getParameter(PARAM_CHARSET);
}
/**
* Gets the value of the <code>charset</code> parameter if set for the
* given field. Returns the default <code>us-ascii</code> if not set or if
* <code>f</code> is <code>null</code>.
*
*
* @return the <code>charset</code> 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 <code>true</code> if the MIME type of this field matches,
* <code>false</code> otherwise.
* @return <code>true</code> if the MIME type of this field matches,
* <code>false</code> otherwise.
*/
public boolean isMimeType(String mimeType) {
return this.mimeType.equalsIgnoreCase(mimeType);
}
/**
* Determines if the MIME type of this field is <code>multipart/*</code>.
*
*
* @return <code>true</code> if this field is has a <code>multipart/*</code>
* MIME type, <code>false</code> otherwise.
* MIME type, <code>false</code> 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<String, String> 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<String> paramNames = parser.getParamNames();
ArrayList<String> 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<String, String>((int)(paramNames.size() * 1.3 + 1));
String paramName = paramNames.get(i).toLowerCase();
String paramValue = paramValues.get(i);
parameters.put(paramName, paramValue);
}
}

View File

@ -19,10 +19,10 @@ import java.util.HashMap;
import java.util.Map;
public class DelegatingFieldParser implements FieldParser {
private Map parsers = new HashMap();
private Map<String, FieldParser> parsers = new HashMap<String, FieldParser>();
private FieldParser defaultParser = new UnstructuredField.Parser();
/**
* Sets the parser used for the field named <code>name</code>.
* @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);

View File

@ -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<Address> 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<Address> results);
}

View File

@ -28,21 +28,21 @@ import java.util.ArrayList;
/**
* An immutable, random-access list of Address objects.
*
*
*
*/
public class AddressList {
private ArrayList addresses;
private ArrayList<Address> 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<Address> addresses, boolean dontCopy) {
if (addresses != null)
this.addresses = (dontCopy ? addresses : (ArrayList) addresses.clone());
this.addresses = (dontCopy ? addresses : new ArrayList<Address>(addresses));
else
this.addresses = new ArrayList(0);
this.addresses = new ArrayList<Address>(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<Address> results = new ArrayList<Address>();
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.
*/

View File

@ -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<Address> list = new ArrayList<Address>();
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<Address> results = new ArrayList<Address>();
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<String> results = new ArrayList<String>(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<Node> {
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++);
}
}
}

View File

@ -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<String> 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<String> domains, boolean dontCopy) {
if (domains != null)
this.domains = (dontCopy ? domains : (ArrayList) domains.clone());
this.domains = (dontCopy ? domains : new ArrayList<String>(domains));
else
this.domains = new ArrayList(0);
this.domains = new ArrayList<String>(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();

View File

@ -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<Address> results) {
for (int i = 0; i < mailboxList.size(); i++)
results.add(mailboxList.get(i));
}

View File

@ -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
*
*
* <Joe Cheng@joecheng.com>
*
*
* 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<Address> results) {
results.add(this);
}
@Override
public String toString() {
return getAddressString();
}

View File

@ -24,39 +24,39 @@ import java.util.ArrayList;
/**
* An immutable, random-access list of Mailbox objects.
*
*
*
*/
public class MailboxList {
private ArrayList mailboxes;
private ArrayList<Address> 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<Address> mailboxes, boolean dontCopy) {
if (mailboxes != null)
this.mailboxes = (dontCopy ? mailboxes : (ArrayList) mailboxes.clone());
this.mailboxes = (dontCopy ? mailboxes : new ArrayList<Address>(mailboxes));
else
this.mailboxes = new ArrayList(0);
this.mailboxes = new ArrayList<Address>(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.

View File

@ -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);
}

View File

@ -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<int[]> jj_expentries = new java.util.Vector<int[]>();
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<int[]> 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);
}

View File

@ -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<Node> nodes;
private java.util.Stack<Integer> 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<Node>();
marks = new java.util.Stack<Integer>();
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;
}
}

View File

@ -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<String> paramNames = new ArrayList<String>();
private ArrayList<String> paramValues = new ArrayList<String>();
public String getType() { return type; }
public String getSubType() { return subtype; }
public ArrayList getParamNames() { return paramNames; }
public ArrayList getParamValues() { return paramValues; }
public ArrayList<String> getParamNames() { return paramNames; }
public ArrayList<String> 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<int[]> jj_expentries = new Vector<int[]>();
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);
}

View File

@ -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<int[]> jj_expentries = new Vector<int[]>();
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);
}

View File

@ -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<Field> fields = new LinkedList<Field>();
private HashMap<String, List<Field>> fieldMap = new HashMap<String, List<Field>>();
/**
* Creates a new empty <code>Header</code>.
*/
@ -55,15 +55,17 @@ public class Header {
/**
* Creates a new <code>Header</code> 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<Field> values = fieldMap.get(field.getName().toLowerCase());
if (values == null) {
values = new LinkedList();
values = new LinkedList<Field>();
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 <code>Field</code> objects.
*/
public List getFields() {
public List<Field> getFields() {
return Collections.unmodifiableList(fields);
}
/**
* Gets a <code>Field</code> 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 <code>null</code> if none found.
*/
public Field getField(String name) {
List l = (List) fieldMap.get(name.toLowerCase());
List<Field> l = fieldMap.get(name.toLowerCase());
if (l != null && !l.isEmpty()) {
return (Field) l.get(0);
return l.get(0);
}
return null;
}
/**
* Gets all <code>Field</code>s having the specified field name.
*
* Gets all <code>Field</code>s 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<Field> getFields(String name) {
List<Field> 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<Field> 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();

View File

@ -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
* <code>Message</code> object.
*
*
* <pre>
* Message msg = new Message(new BufferedInputStream(
* new FileInputStream("mime.msg")));
* </pre>
*
*
*
*
*
* @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 <code>Message</code>.
*/
public Message() {
}
/**
* Parses the specified MIME message stream into a <code>Message</code>
* 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 <code>Subject</code> field.
*
*
* @return the <code>Subject</code> field or <code>null</code> 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<Object> stack = new Stack<Object>();
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 {

View File

@ -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<BodyPart> bodyParts = new LinkedList<BodyPart>();
private Entity parent = null;
private String subType = "alternative";
@ -59,102 +59,102 @@ public class Multipart implements Body {
* Gets the multipart sub-type. E.g. <code>alternative</code> (the default)
* or <code>parallel</code>. 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. <code>alternative</code>
* or <code>parallel</code>. 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<BodyPart> 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 <code>BodyPart</code> objects.
*/
public List getBodyParts() {
public List<BodyPart> getBodyParts() {
return Collections.unmodifiableList(bodyParts);
}
/**
* Sets the list of body parts.
*
*
* @param bodyParts the new list of <code>BodyPart</code> objects.
*/
public void setBodyParts(List bodyParts) {
public void setBodyParts(List<BodyPart> bodyParts) {
this.bodyParts = bodyParts;
for (Iterator it = bodyParts.iterator(); it.hasNext();) {
((BodyPart) it.next()).setParent(parent);
for (Iterator<BodyPart> 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<BodyPart> 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();

View File

@ -786,68 +786,67 @@ import org.apache.james.mime4j.LogFactory;
* <td></td>
* </tr>
* </table>
*
*
*
*
* @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<Charset> {
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<String> 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<String> 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<String, Charset> charsetMap = null;
static {
decodingSupported = new TreeSet();
encodingSupported = new TreeSet();
decodingSupported = new TreeSet<String>();
encodingSupported = new TreeSet<String>();
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<String, Charset>();
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 <code>true</code> 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 <code>true</code> if the specified character is a whitespace
@ -1104,9 +1103,9 @@ public class CharsetUtil {
/**
* Returns <code>true</code> if the specified string consists entirely of
* whitespace characters.
*
*
* ANDROID: COPIED FROM A NEWER VERSION OF MIME4J
*
*
* @param s
* string to test.
* @return <code>true</code> 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 <code>true</code>.
* Use {@link #toJavaCharset(String)} to get the canonical Java character
* set name.
*
*
* @param charsetName the characters set name.
* @return <code>true</code> if encoding is supported, <code>false</code>
* 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 <code>true</code>.
* Use {@link #toJavaCharset(String)} to get the canonical Java character
* set name.
*
*
* @param charsetName the characters set name.
* @return <code>true</code> if decoding is supported, <code>false</code>
* 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 <code>null</code> if not known.
*
*
* @param charsetName the character set name to look for.
* @return the MIME preferred name or <code>null</code> 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 <code>null</code> 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 <code>null</code> 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(" * </table>\n");
return sb.toString();
}
public static void main(String[] args) {
System.out.println(dumpHtmlTable());
}*/

View File

@ -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<EmailProvider> {
Field contentType = header.getField("content-type");
assertTrue(contentType.getBody().contains("multipart/alternative"));
Multipart multipart = (Multipart)mimeMessage.getBody();
List<Body> partList = multipart.getBodyParts();
List<BodyPart> 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<EmailProvider> {
Field contentType = header.getField("content-type");
assertTrue(contentType.getBody().contains("multipart/mixed"));
Multipart multipart = (Multipart)mimeMessage.getBody();
List<Body> partList = multipart.getBodyParts();
List<BodyPart> 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"));