[Up] [Next]

GSMimeDocument

Authors

Richard Frith-Macdonald

Version: 0.1

Date: 25 October, 2000

GSMimeDocument

GSMimeDocument

Declared in: Foundation/GSMime.h

Inherits from: NSObject

Conforms to: NSObject


This class is intended to provide a wrapper for MIME messages permitting easy access to the contents of a message and providing a basis for parsing an unparsing messages that have arrived via email or as a web document.

The class keeps track of all the document headers, and provides methods for modifying the headers that apply to a document and for looking at the header structures, by providing an info dictionary containing the various parts of a header.

The common dictionary keys used for elements provided for all headers are -

RawHeader
This is the unmodified text of the header
BaseName
This is the header name.
BaseValue
This is the text after the header name and colon.
Name
This is a lowercase representation of the header name.
Value
This is the value of the header (normally lower case).

Instance Variables

Methods


Class Methods

mimeDocument

+ (GSMimeDocument*) mimeDocument;
Create an empty MIME document.

Instances Methods

addHeader:

- (BOOL) addHeader: (NSString*)aHeader;
This method may be called to add a header to the document. The header must be a single line of text in the standard format (begining with a name and a colon). It will be added after all other headers in the document.

boundary

- (NSData*) boundary;
For a multipart document, return the raw data used to delimit the parts of the document. Otherwise, return nil.

content

- (id) content;
This returns the content data of the document in the appropriate format for the type of data -
text
an NSString object
binary
an NSData object
multipart
an NSArray object containing GSMimeDocument objects

deleteHeader:

- (void) deleteHeader: (NSString*)aHeader;
This method removes all occurrances of headers whose raw data exactly matches the supplied string.

deleteHeaderNamed:

- (void) deleteHeaderNamed: (NSString*)aName;
This method removes all occurrances of headers whose name matches the supplied string.

infoForAllHeaders

- (NSArray) infoForAllHeaders;
This method returns an array containing info dictionaries that represent all the headers of the document.

infoForHeaderNamed:

- (NSDictionary*) infoForHeaderNamed: (NSString*)aName;
This method returns the info dictionary for the first header whose name equals the supplied argument.

infoForHeadersNamed:

- (NSArray*) infoForHeadersNamed: (NSString*)aName;
This method returns an array of info dictionaries for all headers whose names equal the supplied argument.

parseHeader:named:inTo:

- (BOOL) parseHeader: (NSScanner*)aScanner named: (NSString*)aName inTo: (NSMutableDictionary*)info;
This method is called to parse a header line and split its contents into an info dictionary.

On entry, the dictionary is already partially filled, the name argument is a lowercase representation of the header name, and the scanner is set to a scan location immediately after the colon in the header string.

If the header is parsed successfully, the method should return YES, otherwise NO.

You should not call this method directly yourself, but may override it to support parsing of new headers.


scanSpecial:

- (NSString*) scanSpecial: (NSScanner*)aScanner;
A convenience method to use a scanner (that is set up to scan a header line) to scan in a special character that terminated a token previously scanned. If the token was terminated by whitespace and no other special character, the string returned will contain a single space character.

scanToken:

- (NSString*) scanToken: (NSScanner*)aScanner;
A convenience method to use a scanner (that is set up to scan a header line) to scan a header token - either a quoted string or a simple word.

setContent:

- (BOOL) setContent: (id)newContent;
Sets a new value for the content of the document.

setHeader:

- (BOOL) setHeader: (NSString*)aHeader;
This method may be called to set a header in the document. The header must be a single line of text in the standard format (begining with a name and a colon). It will be added after all other headers in the document. Any other headers with the same name will be removed from the document.