public class

ParameterList

extends Object
java.lang.Object
   ↳ com.google.code.javax.mail.internet.ParameterList

Class Overview

This class holds MIME parameters (attribute-value pairs). The mail.mime.encodeparameters and mail.mime.decodeparameters System properties control whether encoded parameters, as specified by RFC 2231, are supported. By default, such encoded parameters are not supported.

Also, in the current implementation, setting the System property mail.mime.decodeparameters.strict to "true" will cause a ParseException to be thrown for errors detected while decoding encoded parameters. By default, if any decoding errors occur, the original (undecoded) string is used.

The current implementation supports the System property mail.mime.parameters.strict, which if set to false when parsing a parameter list allows parameter values to contain whitespace and other special characters without being quoted; the parameter value ends at the next semicolon. If set to true (the default), parameter values are required to conform to the MIME specification and must be quoted if they contain whitespace or special characters.

Summary

Fields
private static final boolean applehack
private static final boolean decodeParameters
private static final boolean decodeParametersStrict
private static final boolean encodeParameters
private static final char[] hex
private String lastName MWB 3BView: The name of the last parameter added to the map.
private Map list The map of name, value pairs.
private Set multisegmentNames A set of names for multi-segment parameters that we haven't processed yet.
private static final boolean parametersStrict
private Map slist A map containing the segments for all not-yet-processed multi-segment parameters.
private static final boolean windowshack
Public Constructors
ParameterList()
No-arg Constructor.
ParameterList(String s)
Constructor that takes a parameter-list string.
Public Methods
String get(String name)
Returns the value of the specified parameter.
Enumeration getNames()
Return an enumeration of the names of all parameters in this list.
void remove(String name)
Removes the specified parameter from this ParameterList.
void set(String name, String value, String charset)
Set a parameter.
void set(String name, String value)
Set a parameter.
int size()
Return the number of parameters in this list.
String toString(int used)
Convert this ParameterList into a MIME String.
String toString()
Convert this ParameterList into a MIME String.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private static final boolean applehack

private static final boolean decodeParameters

private static final boolean decodeParametersStrict

private static final boolean encodeParameters

private static final char[] hex

private String lastName

MWB 3BView: The name of the last parameter added to the map. Used for the AppleMail hack.

private Map list

The map of name, value pairs. The value object is either a String, for unencoded values, or a Value object, for encoded values, or a MultiValue object, for multi-segment parameters. We use a LinkedHashMap so that parameters are (as much as possible) kept in the original order. Note however that multi-segment parameters (see below) will appear in the position of the first seen segment and orphan segments will all move to the end.

private Set multisegmentNames

A set of names for multi-segment parameters that we haven't processed yet. Normally such names are accumulated during the inital parse and processed at the end of the parse, but such names can also be set via the set method when the IMAP provider accumulates pre-parsed pieces of a parameter list. (A special call to the set method tells us when the IMAP provider is done setting parameters.) A multi-segment parameter is defined by RFC 2231. For example, "title*0=part1; title*1=part2", which represents a parameter named "title" with value "part1part2". Note also that each segment of the value might or might not be encoded, indicated by a trailing "*" on the parameter name. If any segment is encoded, the first segment must be encoded. Only the first segment contains the charset and language information needed to decode any encoded segments. RFC 2231 introduces many possible failure modes, which we try to handle as gracefully as possible. Generally, a failure to decode a parameter value causes the non-decoded parameter value to be used instead. Missing segments cause all later segments to be appear as independent parameters with names that include the segment number. For example, "title*0=part1; title*1=part2; title*3=part4" appears as two parameters named "title" and "title*3".

private static final boolean parametersStrict

private Map slist

A map containing the segments for all not-yet-processed multi-segment parameters. The map is indexed by "name*seg". The value object is either a String or a Value object. The Value object is not decoded during the initial parse because the segments may appear in any order and until the first segment appears we don't know what charset to use to decode any encoded segments. The segments are decoded in order in the combineMultisegmentNames method.

private static final boolean windowshack

Public Constructors

public ParameterList ()

No-arg Constructor.

public ParameterList (String s)

Constructor that takes a parameter-list string. The String is parsed and the parameters are collected and stored internally. A ParseException is thrown if the parse fails. Note that an empty parameter-list string is valid and will be parsed into an empty ParameterList.

Parameters
s The parameter-list string.
Throws
ParseException if the parse fails.

Public Methods

public String get (String name)

Returns the value of the specified parameter. Note that parameter names are case-insensitive.

Parameters
name Parameter name.
Returns
  • Value of the parameter. Returns null if the parameter is not present.

public Enumeration getNames ()

Return an enumeration of the names of all parameters in this list.

Returns
  • Enumeration of all parameter names in this list.

public void remove (String name)

Removes the specified parameter from this ParameterList. This method does nothing if the parameter is not present.

Parameters
name Name of the parameter.

public void set (String name, String value, String charset)

Set a parameter. If this parameter already exists, it is replaced by this new value. If the mail.mime.encodeparameters System property is true, and the parameter value is non-ASCII, it will be encoded with the specified charset, as specified by RFC 2231.

Parameters
name Name of the parameter.
value Value of the parameter.
charset Charset of the parameter value.

public void set (String name, String value)

Set a parameter. If this parameter already exists, it is replaced by this new value.

Parameters
name Name of the parameter.
value Value of the parameter.

public int size ()

Return the number of parameters in this list.

Returns
  • number of parameters.

public String toString (int used)

Convert this ParameterList into a MIME String. If this is an empty list, an empty string is returned. The 'used' parameter specifies the number of character positions already taken up in the field into which the resulting parameter list is to be inserted. It's used to determine where to fold the resulting parameter list.

Parameters
used Number of character positions already used, in the field into which the parameter list is to be inserted.
Returns
  • String

public String toString ()

Convert this ParameterList into a MIME String. If this is an empty list, an empty string is returned.

Returns
  • String