Debian Codegraph @

Framework/Pantomime/CWPart.h

raw symbols SCIP
1 /*
2 ** CWPart.h
3 **
4 ** Copyright (c) 2001-2007 Ludovic Marcotte
5 ** Copyright (C) 2017 Riccardo Mottola
6 **
7 ** Author: Ludovic Marcotte <[email protected]>
8 ** Riccardo Mottola <[email protected]>
9 **
10 ** This library is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU Lesser General Public
12 ** License as published by the Free Software Foundation; either
13 ** version 2.1 of the License, or (at your option) any later version.
14 **
15 ** This library is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** Lesser General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #ifndef _Pantomime_H_CWPart
25 #define _Pantomime_H_CWPart
26
27 #import <Foundation/NSCoder.h>
28 #import <Foundation/NSData.h>
29 #import <Foundation/NSDictionary.h>
30 #import <Foundation/NSObject.h>
31 #import <Foundation/NSString.h>
32
33 #include <Pantomime/CWConstants.h>
34
35 /*!
36 @class CWPart
37 @discussion This class defines what Internet messages are composed of.
38 An Internet message is composed of various parts which can
39 be text parts, images, PDF documents and so on. Even a message
40 is a part, with additional headers (like "From:", "Subject:"
41 and so on). CWMessage is a superclass of CWPart.
42 */
43 @interface CWPart : NSObject <NSCoding>
44 {
45 @protected
46 NSMutableDictionary *_parameters;
47 NSMutableDictionary *_headers;
48 NSString *_defaultCharset;
49 NSObject *_content;
50
51 NSUInteger _line_length;
52 unsigned long _size;
53 }
54
55 /*!
56 @method initWithData:
57 @discussion This method is used to initialize the CWPart instance
58 with the specified data. It splits the header
59 part with the content part and calls -setHeadersFromData:
60 with the header part and CWMIMEUtility: +setContentFromRawSource: inPart:
61 with the content part. This method will recursively go in
62 sub-parts (if needed) and initilize them also.
63 @param theData The bytes to use.
64 @result A CWPart instance, nil on error.
65 */
66 - (id) initWithData: (NSData *) theData;
67
68 /*!
69 @method initWithData: charset:
70 @discussion This method acts like -initWithData: but it uses
71 <i>theCharset</i> instead of the Part's charset
72 (found in theData).
73 @param theData The bytes to use.
74 @param theCharset The charset to force.
75 @result A CWPart instance, nil on error.
76 */
77 - (id) initWithData: (NSData *) theData
78 charset: (NSString *) theCharset;
79
80 /*!
81 @method setHeadersFromData:
82 @discussion This method initalize all the headers of a part
83 from the raw data source. It replaces previously
84 defined values of headers found in <i>theHeaders</i>.
85 @param theHeaders The bytes to use.
86 */
87 - (void) setHeadersFromData: (NSData *) theHeaders;
88
89 /*!
90 @method contentType
91 @discussion This method is used to get the value of the
92 receiver's "Content-Type" header. If none is
93 specified, nil will be returned. It's up to the
94 callee to use whatever charset it wants. Section
95 5.2 or RFC2045 recommends to use "text/plain" in
96 this case.
97 @result The value. If none was set, nil will
98 be returned.
99 */
100 - (NSString *) contentType;
101
102 /*!
103 @method setContentType:
104 @discussion This method is used to set the value of
105 the receiver's "Content-Type" header.
106 @param theContentType The "Content-Type" value.
107 */
108 - (void) setContentType: (NSString*) theContentType;
109
110 /*!
111 @method contentID
112 @discussion This method is used to get the value of the
113 receiver's "Content-ID" header.
114 @result The value. If none was set, nil will
115 be returned.
116 */
117 - (NSString *) contentID;
118
119 /*!
120 @method setContentID:
121 @discussion This method is used to set the value of
122 the receiver's "Content-ID" header.
123 @param theContentID The "Content-ID" value.
124 */
125 - (void) setContentID: (NSString *) theContentID;
126
127 /*!
128 @method contentDescription
129 @discussion This method is used to get the value of the
130 receiver's "Content-Description" header.
131 @result The value. If none was set, nil will
132 be returned.
133 */
134 - (NSString *) contentDescription;
135
136 /*!
137 @method setContentDescription:
138 @discussion This method is used to set the value of
139 the receiver's "Content-Description" header.
140 @param theContentDescription The "Content-Description" value.
141 */
142 - (void) setContentDescription: (NSString *) theContentDescription;
143
144 /*!
145 @method contentDisposition
146 @discussion This method is used to get the value of the
147 receiver's "Content-Disposition" header.
148 @result The value. If none was set, PantomimeInlineDisposition
149 will be returned.
150 */
151 - (PantomimeContentDisposition) contentDisposition;
152
153 /*!
154 @method setContentDisposition:
155 @discussion This method is used to set the value of
156 the receiver's "Content-Disposition" header.
157 @param theContentDisposition The "Content-Disposition" value.
158 */
159 - (void) setContentDisposition: (PantomimeContentDisposition) theContentDisposition;
160
161 /*!
162 @method contentTransferEncoding
163 @discussion This method is used to get the value of the
164 receiver's "Content-Transfer-Encoding" header.
165 @result The value. If none was set, PantomimeEncodingNone
166 will be returned.
167 */
168 - (PantomimeEncoding) contentTransferEncoding;
169
170 /*!
171 @method setContentTransferEndocing:
172 @discussion This method is used to set the value of
173 the receiver's "Content-Transfer-Encoding" header.
174 @param theEncoding The "Content-Transfer-Encoding" value. Accepted
175 values are part of the PantomimeEncoding enum.
176 */
177 - (void) setContentTransferEncoding: (PantomimeEncoding) theEncoding;
178
179 /*!
180 @method filename
181 @discussion This method is used to get the name of the receiver's
182 file, if any.
183 @result The name of the file, nil if none was specified.
184 */
185 - (NSString *) filename;
186
187 /*!
188 @method setFilename:
189 @discussion This method is used to set the name of the receiver's file.
190 @param theFilename The name of the file. If nil is passed or if
191 the length of the string is 0, "unknown" will
192 be set as the filename.
193 */
194 - (void) setFilename: (NSString *) theFilename;
195
196 /*!
197 @method format
198 @discussion This method is used to obtain the format of the receiver.
199 Possible values are part of the PantomimeMessageFormat.
200 See RFC 2646 for a detailed description of the "flowed" format.
201 @result The format, PantomimeFormatUnknown if no value was previously set.
202 */
203 - (PantomimeMessageFormat) format;
204
205 /*!
206 @method setFormat:
207 @discussion This method is used to set the format of the receiver.
208 Accepted values are part of the PantomimeMessageFormat enum.
209 @param theFormat The format to use.
210 */
211 - (void) setFormat: (PantomimeMessageFormat) theFormat;
212
213 /*!
214 @method lineLength
215 @discussion This method is used to return the maximum length that
216 a line can use in a text part.
217 @result The length, 0 if not defined.
218 */
219 - (NSUInteger) lineLength;
220
221 /*!
222 @method setLineLength:
223 @discussion This method is used to set the maximum length of a
224 line that can be used for a text part.
225 @param theLineLength The length.
226 */
227 - (void) setLineLength: (NSUInteger) theLineLength;
228
229 /*!
230 @method isMIMEType: subType:
231 @discussion This method is used to verify if the receiver matches
232 a specific MIME type. The "*" wildcard can be used
233 for the sub-type.
234 @param thePrimaryType The left part of the MIME type.
235 @param theSubType The right part of the MIME type.
236 @result YES if it matches, NO otherwise.
237 */
238 - (BOOL) isMIMEType: (NSString *) thePrimaryType
239 subType: (NSString *) theSubType;
240
241 /*!
242 @method content
243 @discussion This method is used to obtain the decoded content
244 of the receiver. The returned value can be a NSString
245 instance, a NSData instance, a CWMIMEMultipart instance
246 or a CWMessage instance.
247 @result The decoded content of the part.
248 */
249 - (NSObject *) content;
250
251 /*!
252 @method setContent:
253 @discussion This method is used to set the content of the receiver.
254 The content will later be correctly encoded before the
255 message is submitted or saved on disk (using -dataValue).
256 Accepted values are instances of NSData, CWMIMEMultipart
257 or CWMessage otherwise, a NSInvalidArgumentException
258 will be thrown.
259 @param theContent The content of the part.
260 */
261 - (void) setContent: (NSObject *) theContent;
262
263 /*!
264 @method size
265 @discussion This method is used to obtain the receiver's size
266 (total number of bytes of its raw representation).
267 @result The size of the receiver.
268 */
269 - (unsigned long) size;
270
271 /*!
272 @method setSize:
273 @discussion This method is used to set the receiver's size.
274 @param theSize The value of the size.
275 */
276 - (void) setSize: (unsigned long) theSize;
277
278 /*!
279 @method dataValue
280 @discussion This method is used to encoded the receiver's using
281 the MIME standard before it is ready for submisssion
282 (using a Transport method) or being saved on disk.
283 The CWMessage class overwrites this method in order
284 to add Message-specific headers such as "From",
285 "Subject" and so on.
286 @result The encoded CWPart instance, as a NSData instance.
287 */
288 - (NSData *) dataValue;
289
290 /*!
291 @method boundary
292 @discussion This method is used to get the boundary that separates
293 parts that compose a multipart composite part.
294 @result The boundary as a NSData instance, nil if none was set.
295 */
296 - (NSData *) boundary;
297
298 /*!
299 @method setBoundary:
300 @discussion This method is used to set the boundary used to separate
301 parts that compose a multipart composite part message.
302 @param theBoundary The value of the boundary.
303 */
304 - (void) setBoundary: (NSData *) theBoundary;
305
306 /*!
307 @method protocol
308 @discussion This method is used to obtain the value of the "protocol"
309 parameter found in some Content-Type headers. This parameter
310 is often present in PGP encoded messages.
311 @result The value of the "protocol" parameter, nil if none was set.
312 */
313 - (NSData *) protocol;
314
315 /*!
316 @method setProtocol:
317 @discussion This method is used to set the value of the "protocol"
318 parameter. This parameter will be added to the ones
319 found in the Content-Type header in -dataValue.
320 @param theProtocol The value of the "protocol" parameter.
321 */
322 - (void) setProtocol: (NSData *) theProtocol;
323
324 /*!
325 @method charset
326 @discussion This method is used to obtain the value of the "charset"
327 parameter found in the Content-Type header.
328 @result The value of the "charset" parameter, "us-ascii" if none was set.
329 */
330 - (NSString *) charset;
331
332 /*!
333 @method setCharset:
334 @discussion This method is used to set the value of the "charset" parameter
335 found in the Content-Type header.
336 @param theCharset The charset to use.
337 */
338 - (void) setCharset: (NSString *) theCharset;
339
340 /*!
341 @method defaultCharset
342 @discussion This method is used to get the charset that will be
343 enforced for usage when decoding the part.
344 @result The enforced charset.
345 */
346 - (NSString *) defaultCharset;
347
348 /*!
349 @method setDefaultCharset:
350 @discussion This method is used to set the charset that will be
351 enforced for usage when the part is being decoded.
352 @param theCharset The charset to force.
353 */
354 - (void) setDefaultCharset: (NSString *) theCharset;
355
356 /*!
357 @method parameterForKey:
358 @discussion This method is used to obtain a parameter value
359 based on its name. The name serves as the key.
360 Parameters are only part of the Content-Type
361 header field.They are NOT part of the
362 Content-Disposition header.
363 @param theKey The key for which the value will be returned.
364 @result The parameter value, nil if non-existent.
365 */
366 - (id) parameterForKey: (NSString *) theKey;
367
368 /*!
369 @method setPrameter:forKey:
370 @discussion This method is used to set a parameter value
371 based on its name. The name serves as the key.
372 Parameters are only part of the Content-Type
373 header field. They are NOT part of the
374 Content-Disposition header.
375 @param theParameter The value of the parameter. A nil value
376 will remove any existing defined value
377 for the specified key,
378 @param theKey The key for which the value will be set.
379 */
380 - (void) setParameter: (id) theParameter forKey: (NSString *) theKey;
381
382 /*!
383 @method allHeaders
384 @discussion This method is used to return all header names / values.
385 @result The NSDictionary holding everything.
386 */
387 - (NSDictionary *) allHeaders;
388
389 /*!
390 @method headerValueForName:
391 @discussion This method is used to obtain the value
392 of the header specified by <i>theName</i>. The search
393 is performed in a case-insensitive way.
394 @param theName The name of the header. For example, it could be "Date".
395 @result The value of the header.
396 */
397 - (id) headerValueForName: (NSString *) theName;
398
399 /*!
400 @method setHeaders:
401 @discussion This method is used to add the headers of
402 <i>theHeaders</i> to the list of headers
403 of the receiver.
404 @param theHeaders The headers to add.
405 */
406 - (void) setHeaders: (NSDictionary *) theHeaders;
407
408 @end
409
410 #endif // _Pantomime_H_CWPart