FileDocCategorySizeDatePackage
Field.javaAPI DocAndroid 1.5 API6572Wed May 06 22:42:46 BST 2009org.apache.james.mime4j.field

Field

public abstract class Field extends Object
The base class of all field classes.
version
$Id: Field.java,v 1.6 2004/10/25 07:26:46 ntherning Exp $

Fields Summary
public static final String
SENDER
public static final String
FROM
public static final String
TO
public static final String
CC
public static final String
BCC
public static final String
REPLY_TO
public static final String
RESENT_SENDER
public static final String
RESENT_FROM
public static final String
RESENT_TO
public static final String
RESENT_CC
public static final String
RESENT_BCC
public static final String
DATE
public static final String
RESENT_DATE
public static final String
SUBJECT
public static final String
CONTENT_TYPE
public static final String
CONTENT_TRANSFER_ENCODING
private static final String
FIELD_NAME_PATTERN
private static final Pattern
fieldNamePattern
private static final DefaultFieldParser
parser
private final String
name
private final String
body
private final String
raw
Constructors Summary
protected Field(String name, String body, String raw)

    
              
        this.name = name;
        this.body = body;
        this.raw = raw;
    
Methods Summary
public java.lang.StringgetBody()
Gets the unfolded, unparsed and possibly encoded (see RFC 2047) field body string.

return
the unfolded unparsed field body string.

        return body;
    
public java.lang.StringgetName()
Gets the name of the field (Subject, From, etc).

return
the field name.

        return name;
    
public static DefaultFieldParsergetParser()
Gets the default parser used to parse fields.

return
the default field parser

        return parser;
    
public java.lang.StringgetRaw()
Gets the original raw field string.

return
the original raw field string.

        return raw;
    
public booleanisContentType()
Determines if this is a Content-Type field.

return
true if this is a Content-Type field, false otherwise.

        return CONTENT_TYPE.equalsIgnoreCase(name);
    
public booleanisFrom()
Determines if this is a From field.

return
true if this is a From field, false otherwise.

        return FROM.equalsIgnoreCase(name);
    
public booleanisSubject()
Determines if this is a Subject field.

return
true if this is a Subject field, false otherwise.

        return SUBJECT.equalsIgnoreCase(name);
    
public booleanisTo()
Determines if this is a To field.

return
true if this is a To field, false otherwise.

        return TO.equalsIgnoreCase(name);
    
public static org.apache.james.mime4j.field.Fieldparse(java.lang.String raw)
Parses the given string and returns an instance of the Field class. The type of the class returned depends on the field name:
Field nameClass returned Content-Typeorg.apache.james.mime4j.field.ContentTypeField otherorg.apache.james.mime4j.field.UnstructuredField

param
s the string to parse.
return
a Field instance.
throws
IllegalArgumentException on parse errors.

        
        /*
         * Unfold the field.
         */
        final String unfolded = raw.replaceAll("\r|\n", "");
        
        /*
         * Split into name and value.
         */
        final Matcher fieldMatcher = fieldNamePattern.matcher(unfolded);
        if (!fieldMatcher.find()) {
            throw new IllegalArgumentException("Invalid field in string");
        }
        final String name = fieldMatcher.group(1);
        
        String body = unfolded.substring(fieldMatcher.end());
        if (body.length() > 0 && body.charAt(0) == ' ") {
            body = body.substring(1);
        }
        
        return parser.parse(name, body, raw);
    
public java.lang.StringtoString()

see
#getRaw()

        return raw;