2
<title>GSMimeParser</title>
5
<a href ="GSMimeDocument.html">[Previous] </a>
6
<a href ="GSMime.html">[Up] </a>
10
<dt><a href ="http://www.gnustep.org/developers/whoiswho.html">Richard Frith-Macdonald</a>
13
<p>Version: $Revision: 1.15 $</p>
14
<p>Date: $Date: 2001/12/12 14:10:12 $</p>
15
<h2><a name ="cont-0">GSMimeParser</a></h2>
16
<h2><a name ="GSMimeParser">GSMimeParser</a></h2>
17
<p><b>Declared in: </b> Foundation/GSMime.h</p>
18
<p><b>Inherits from: </b> NSObject</p>
19
<p><b>Conforms to: </b> NSObject
25
This class provides support for parsing MIME messages
26
into GSMimeDocument objects. Each parser object maintains
27
an associated document into which data is stored.
32
You supply the document to be parsed as one or more data
33
items passed to the <code>Parse:</code> method, and (if
34
the method always returns <code>YES</code>, you give it
35
a final <code>nil</code> argument to mark the end of the
41
On completion of parsing a valid document, the
42
<code>document</code> method returns the resulting parsed document.
46
<h2>Instance Variables </h2>
51
<li ><a href ="GSMimeParser.html#method-0">+mimeParser</a>
52
<li ><a href ="GSMimeParser.html#method-1">-contextFor:</a>
53
<li ><a href ="GSMimeParser.html#method-2">-data</a>
54
<li ><a href ="GSMimeParser.html#method-3">-decodeData:fromRange:intoData:withContext:</a>
55
<li ><a href ="GSMimeParser.html#method-4">-document</a>
56
<li ><a href ="GSMimeParser.html#method-5">-isComplete</a>
57
<li ><a href ="GSMimeParser.html#method-6">-isInBody</a>
58
<li ><a href ="GSMimeParser.html#method-7">-isInHeaders</a>
59
<li ><a href ="GSMimeParser.html#method-8">-parse:</a>
60
<li ><a href ="GSMimeParser.html#method-9">-parseHeader:</a>
61
<li ><a href ="GSMimeParser.html#method-10">-parsingHeaders</a>
62
<li ><a href ="GSMimeParser.html#method-11">-scanHeader:named:inTo:</a>
63
<li ><a href ="GSMimeParser.html#method-12">-scanSpace:</a>
64
<li ><a href ="GSMimeParser.html#method-13">-scanSpecial:</a>
65
<li ><a href ="GSMimeParser.html#method-14">-scanToken:</a>
67
<hr><h2>Class Methods </h2>
68
<h3><a name ="method-0">mimeParser</a></h3>
69
+ (GSMimeParser*) <b>mimeParser</b>;<br>
74
<hr><h2>Instances Methods </h2>
75
<h3><a name ="method-1">contextFor:</a></h3>
76
- (GSMimeCodingContext*) <b>contextFor:</b> (NSDictionary*)headerInfo;<br>
78
Return a coding context object to be used for decoding data
79
according to the scheme specified in the header.
82
The default implementation supports the following transfer
83
encodings specified in either a <code>transfer-encoding</code>
84
of <code>content-transfer-encoding</code> header -
93
<li >chunked (for HTTP/1.1)
98
<h3><a name ="method-2">data</a></h3>
99
- (NSData*) <b>data</b>;<br>
101
Return the data accumulated in the parser. If the parser is
102
still parsing headers, this will be the header data read so far.
103
If the parse has parsed the body of the message, this will be
104
the data of the body, with any transfer encoding removed.
107
<h3><a name ="method-3">decodeData:fromRange:intoData:withContext:</a></h3>
108
- (BOOL) <b>decodeData:</b> (NSData*)sourceData <b>fromRange:</b> (NSRange)aRange <b>intoData:</b> (NSMutableData*)destinationData <b>withContext:</b> (GSMimeCodingContext*)ctxt;<br>
112
Decodes the raw data from the specified range in the source
113
data object and appends it to the destination data object.
114
The context object provides information about the content
115
encoding type in use, and the state of the decoding operation.
120
This method may be called repeatedly to incrementally decode
121
information as it arrives on some communications channel.
122
It should be called with a nil source data item (or with
123
the atEnd flag of the context set to YES) in order to flush
124
any information held in the context to the output data
130
You may override this method in order to implement
131
additional coding schemes.
136
<h3><a name ="method-4">document</a></h3>
137
- (GSMimeDocument*) <b>document</b>;<br>
139
Returns the object into which raw mime data is being parsed.
142
<h3><a name ="method-5">isComplete</a></h3>
143
- (BOOL) <b>isComplete</b>;<br>
145
Returns YES if the document parsing is known to be completed.
148
<h3><a name ="method-6">isInBody</a></h3>
149
- (BOOL) <b>isInBody</b>;<br>
151
Returns YES if all the document headers have been parsed but
152
the document body parsing may not yet be complete.
155
<h3><a name ="method-7">isInHeaders</a></h3>
156
- (BOOL) <b>isInHeaders</b>;<br>
158
Returns YES if parsing of the document headers has not yet
162
<h3><a name ="method-8">parse:</a></h3>
163
- (BOOL) <b>parse:</b> (NSData*)rawData;<br>
167
This method is called repeatedly to pass raw mime data into
168
the parser. It returns <code>YES</code> as long as it wants
169
more data to complete parsing of a document, and <code>NO</code>
170
if parsing is complete, either due to having reached the end of
171
a document or due to an error.
176
Since it is not always possible to determine if the end of a
177
MIME document has been reached from its content, the method
178
may need to be called with a nil argument after you have
179
passed all the data to it ... this tells it that the data
185
<h3><a name ="method-9">parseHeader:</a></h3>
186
- (BOOL) <b>parseHeader:</b> (NSString*)aRawHeader;<br>
190
This method is called to parse a header line <em>for the
191
current document</em>, split its contents into an info
192
dictionary, and add that information to the document.
197
The standard implementation of this method scans basic
198
information and then calls <code>scanHeaders:named:into:</code>
199
to complete the parsing of the header.
204
This method also performs consistency checks on headers scanned
205
so it is recommended that it is not overridden, but that
206
subclasses override <code>scanHeaders:named:into:</code> to
207
implement custom scanning.
212
As a special case, for HTTP support, this method also parses
213
lines in the format of HTTP responses as if they were headers
214
named <code>http</code>. The resulting header info dictionary
220
<dd>The first part of the version number
222
<dd>The second part of the version number
223
<dt>NSHTTPPropertyServerHTTPVersionKey
224
<dd>The full HTTP protocol version number
225
<dt>NSHTTPPropertyStatusCodeKey
226
<dd>The HTTP status code
227
<dt>NSHTTPPropertyStatusReasonKey
228
<dd>The text message (if any) after the status code
233
<h3><a name ="method-10">parsingHeaders</a></h3>
234
- (BOOL) <b>parsingHeaders</b>;<br>
236
Returns YES if the parser is expecting to read mime headers,
237
Returns NO is the parser has already been passed all the
238
data containing headers, and is now waiting for the body of
239
the mime message (or has been passed all data).
242
<h3><a name ="method-11">scanHeader:named:inTo:</a></h3>
243
- (BOOL) <b>scanHeader:</b> (NSScanner*)aScanner <b>named:</b> (NSString*)aName <b>inTo:</b> (NSMutableDictionary*)info;<br>
247
This method is called to parse a header line and split its
248
contents into an info dictionary.
253
On entry, the dictionary is already partially filled,
254
the name argument is a lowercase representation of the
255
header name, and the scanner is set to a scan location
256
immediately after the colon in the header string.
261
If the header is parsed successfully, the method should
262
return YES, otherwise NO.
267
You should not call this method directly yourself, but may
268
override it to support parsing of new headers.
273
You should be aware of the parsing that the standard
274
implementation performs, and that <em>needs</em> to be
275
done for certain headers in order to permit the parser to
280
<dt>content-disposition
285
A dictionary containing parameters as key-value pairs
290
The content disposition (excluding parameters) as a
301
A dictionary containing parameters as key-value pairs
305
<dd>The MIME subtype lowercase
307
<dd>The MIME type lowercase
309
<dd>The full MIME type (xxx/yyy) in lowercase
313
<dt>content-transfer-encoding
317
<dd>The transfer encoding type in lowercase
325
<dd>The HTTP protocol version number
327
<dd>The first component of the version number
329
<dd>The second component of the version number
331
<dd>The response status value (numeric code)
333
<dd>The text message (if any)
337
<dt>transfer-encoding
341
<dd>The transfer encoding type in lowercase
349
<h3><a name ="method-12">scanSpace:</a></h3>
350
- (BOOL) <b>scanSpace:</b> (NSScanner*)aScanner;<br>
352
A convenience method to scan past any whitespace in the scanner
353
in preparation for scanning something more interesting that
354
comes after it. Returns YES if any space was read, NO otherwise.
357
<h3><a name ="method-13">scanSpecial:</a></h3>
358
- (NSString*) <b>scanSpecial:</b> (NSScanner*)aScanner;<br>
360
A convenience method to use a scanner (that is set up to scan a
361
header line) to scan in a special character that terminated a
362
token previously scanned. If the token was terminated by
363
whitespace and no other special character, the string returned
364
will contain a single space character.
367
<h3><a name ="method-14">scanToken:</a></h3>
368
- (NSString*) <b>scanToken:</b> (NSScanner*)aScanner;<br>
370
A convenience method to use a scanner (that is set up to scan a
371
header line) to scan a header token - either a quoted string or
374
<li >Leading whitespace is ignored.
375
<li >Backslash escapes in quoted text are converted