Debian Codegraph @

Framework/Pantomime/CWMessage.h

raw symbols SCIP
1 /*
2 ** CWMessage.h
3 **
4 ** Copyright (c) 2001-2007 Ludovic Marcotte
5 ** Copyright (C) 2017 2018 Riccardo Mottola
6 **
7 ** Author: Ludovic Marcotte <[email protected]>
8 ** Riccardo Mottola
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_CWMessage
25 #define _Pantomime_H_CWMessage
26
27 #import <Pantomime/CWConstants.h>
28 #import <Pantomime/CWCacheManager.h>
29 #import <Pantomime/CWPart.h>
30
31 #import <Foundation/NSArray.h>
32 #import <Foundation/NSCalendarDate.h>
33 #import <Foundation/NSCoder.h>
34 #import <Foundation/NSData.h>
35 #import <Foundation/NSDictionary.h>
36 #import <Foundation/NSObject.h>
37
38 /*!
39 @const PantomimeMessageFetchCompleted
40 */
41 extern NSString* PantomimeMessageFetchCompleted;
42
43 /*!
44 @const PantomimeMessageFetchFailed
45 */
46 extern NSString* PantomimeMessageFetchFailed;
47
48 /*!
49 @const PantomimeMessagePrefetchCompleted
50 */
51 extern NSString* PantomimeMessagePrefetchCompleted;
52
53 /*!
54 @const PantomimeMessagePrefetchFailed
55 */
56 extern NSString* PantomimeMessagePrefetchFailed;
57
58 /*!
59 @const PantomimeMessageChanged
60 @discussion This notification is posted when message flags have changed
61 but the called didn't ask for flag changes.
62 */
63 extern NSString* PantomimeMessageChanged;
64
65 /*!
66 @const PantomimeMessageExpunged
67 @discussion This notification is posted when a message is expunged
68 but the called didn't expunge the mailbox.
69 */
70 extern NSString* PantomimeMessageExpunged;
71
72
73 @class CWFlags;
74 @class CWFolder;
75 @class CWInternetAddress;
76
77 /*!
78 @class CWMessage
79 @discussion This class is used to describe Internet messages. This class
80 extends the CWPart class and inherit all its methods.
81 */
82 @interface CWMessage : CWPart <NSCoding>
83 {
84 @protected
85 NSData *_rawSource;
86
87 @private
88 NSMutableDictionary *_properties;
89 NSMutableArray *_recipients;
90
91 NSArray *_references;
92 CWFolder *_folder;
93 CWFlags *_flags;
94
95 unsigned int _message_number;
96 BOOL _initialized;
97 }
98
99 /*!
100 @method initWithHeaders:
101 @discussion This method is used to initialize the receiver with
102 a predefined set of headers. The headers are specified
103 in a NSDictionary instance where the keys are the header
104 names (for example, "Content-Type") and the values are
105 the respective values of for each keys. This method class
106 -setHeaders:.
107 @param theHeaders The NSDictionary instance holding all headers / values.
108 @result A Message instance, nil on error.
109 */
110 - (id) initWithHeaders: (NSDictionary *) theHeaders;
111
112 /*!
113 @method initWithHeadersFromData:
114 @discussion This method is used to initialize the receiver with
115 a predefined set of headers in their raw representation.
116 This method calls -setHeadersFromData:.
117 @param theHeaders The headers in their raw represnetation.
118 @result A Message instance, nil on error.
119 */
120 - (id) initWithHeadersFromData: (NSData *) theHeaders;
121
122 /*!
123 @method from
124 @discussion This method is used to obtain the value of the
125 "From" header.
126 @result The value of the "From" header, as an CWInternetAddress instance.
127 */
128 - (CWInternetAddress *) from;
129
130 /*!
131 @method setFrom:
132 @discussion This method is used to set the value of the "From:" header.
133 @param theInternetAddress The CWInternetAddress instance.
134 */
135 - (void) setFrom: (CWInternetAddress *) theInternetAddress;
136
137 /*!
138 @method messageNumber
139 @discussion This method is used to obtain the message sequence number (MSN)
140 of the receiver. MSN have a special meaning for IMAP
141 messages (see 2.3.1.2. of RFC3501 for details).
142 @result The MSN, 0 if none was previously set.
143 */
144 - (unsigned int) messageNumber;
145
146 /*!
147 @method setMessageNumber:
148 @discussion This method is used to set the message number value
149 of the receiver.
150 @param theMessageNumber The value.
151 */
152 - (void) setMessageNumber: (unsigned int) theMessageNumber;
153
154 /*!
155 @method messageID
156 @discussion This method is used to obtain the value of
157 the "Message-ID" header.
158 @result The value of the "Message-ID" header.
159 */
160 - (NSString *) messageID;
161
162 /*!
163 @method setMessageID:
164 @discussion This method is used to set the value of
165 the "Message-ID" header.
166 @param theMessageID The value of the "Message-ID" header.
167 */
168 - (void) setMessageID: (NSString *) theMessageID;
169
170 /*!
171 @method inReplyTo
172 @discussion This method is used to obtain the value of
173 the "In-Reply-To" header.
174 @result The value of the "In-Reply-To" header.
175 */
176 - (NSString *) inReplyTo;
177
178 /*!
179 @method setInReplyTo:
180 @discussion This method is used to set the value of
181 the "In-Reply-To" header.
182 @param theInReplyTo The value of the "In-Reply-To" header.
183 */
184 - (void) setInReplyTo: (NSString *) theInReplyTo;
185
186 /*!
187 @method receivedDate
188 @discussion This method is used to obtain the value of
189 the "Date" header.
190 @result The value of the "Date" header, as a NSCalendarDate instance.
191 */
192 - (NSCalendarDate *) receivedDate;
193
194 /*!
195 @method setReceivedDate:
196 @discussion This method is used to set the value of
197 the "Date" header.
198 @param theDate The NSCalendarDate instance.
199 */
200 - (void) setReceivedDate: (NSCalendarDate *) theDate;
201
202 /*!
203 @method addRecipient:
204 @discussion This method is used to add a recipient to the
205 list of all recipients for the receiver. The
206 recipient type is determined by calling the
207 -type method on the CWInternetAddress's instance.
208 @param theAddress The CWInternetAddress instance holding the
209 recipient to add to the list.
210 */
211 - (void) addRecipient: (CWInternetAddress *) theAddress;
212
213 /*!
214 @method removeRecipient:
215 @discussion This method is used to remove the specified
216 recipient from the receiver's list of recipients.
217 @param theAddress The recipient to remove.
218 */
219 - (void) removeRecipient: (CWInternetAddress *) theAddress;
220
221 /*!
222 @method recipients
223 @discussion This method is used to obtain the list of recipients
224 of the receiver. All recipient types are returned.
225 @result The array of recipients which are all CWInternetAddress instances.
226 */
227 - (NSArray *) recipients;
228
229 /*!
230 @method setRecipients:
231 @discussion This method is used to add <i>theRecipients</i> to the
232 list of the receiver's recipients.
233 @param theRecipients The array of CWInternetAddress instances to add
234 to the receiver's list of recipients.
235 */
236 - (void) setRecipients: (NSArray *) theRecipients;
237
238 /*!
239 @method recipientsCount
240 @discussion This method is used to obtain the number of recipients
241 the receiver has.
242 @result The count.
243 */
244 - (NSUInteger) recipientsCount;
245
246 /*!
247 @method removeAllRecipients:
248 @discussion This method is used to remove all recipients from
249 the receiver.
250 */
251 - (void) removeAllRecipients;
252
253 /*!
254 @method replyTo
255 @discussion This method is used to obtain the value of the "Reply-To" header.
256 @result The value of the "Reply-To" header, as an array of CWInternetAddress instances.
257 If there are none, nil is returned.
258 */
259 - (NSArray *) replyTo;
260
261 /*!
262 @method setReplyTo:
263 @discussion This method is used to set the value of the "Reply-To:" header.
264 @param theAddressList An array of CWInternetAddress instances.
265 */
266 - (void) setReplyTo: (NSArray *) theAddressList;
267
268 /*!
269 @method subject
270 @discussion This method is used to obtain the value of the
271 "Subject" header.
272 @result The value of the "Subject" header.
273 */
274 - (NSString *) subject;
275
276 /*!
277 @method setSubject:
278 @discussion This method is used to set the value of the "Subject" header.
279 @param theSubject The value to set.
280 */
281 - (void) setSubject: (NSString *) theSubject;
282
283 /*!
284 @method baseSubject
285 @discussion This method is used to obtain the base subject. The base
286 subject is basically the value of the "Subject" header
287 but without the "re" or "fwd" (or whatever) prefix.
288 @result The base subject.
289 */
290 - (NSString *) baseSubject;
291
292 /*!
293 @method setBaseSubject:
294 @discussion This method is used to set the base subject of
295 the receiver.
296 @param theBaseSubject The base subject to set.
297 */
298 - (void) setBaseSubject: (NSString *) theBaseSubject;
299
300 /*!
301 @method isInitialized
302 @discussion This method is used to verify if a message has been
303 initialized or not. An inititalized message is a message
304 for which all parts have been initilized. A message
305 for which only the headers are set is not an
306 initialized message.
307 @result YES if the message is initialized, NO otherwise.
308 */
309 - (BOOL) isInitialized;
310
311 /*!
312 @method setInitialized:
313 @discussion This method is used to initialize the message or
314 free the resources taken by its content. Subclasses
315 of CWMessage sometimes overwrite this method.
316 @param theBOOL YES if we want to load the content of the message
317 and initialize the receiver with it. NO if we
318 want to free the resources taken by the decoded content.
319 */
320 - (void) setInitialized: (BOOL) theBOOL;
321
322 /*!
323 @method flags
324 @discussion This method is used to obtain the flags associated to
325 the receiver.
326 @result The CWFlags instance of the receiver.
327 */
328 - (CWFlags *) flags;
329
330 /*!
331 @method setFlags:
332 @discussion This method is used to set the flags of the receiver,
333 replacing any previous values set. Subclasses of
334 CWMessage sometimes overwrite this method.
335 @param theFlags The new flags for the receiver.
336 */
337 - (void) setFlags: (CWFlags *) theFlags;
338
339 /*!
340 @method MIMEVersion
341 @discussion This method is used to obtain the value of the
342 "MIME-Version" header.
343 @result The value of the header, nil if none was set.
344 */
345 - (NSString *) MIMEVersion;
346
347 /*!
348 @method setMIMEVersion:
349 @discussion This method is used to set the value of the
350 "MIME-Version" header, replacing any values
351 previously set.
352 @param theMIMEVersion The new value for the header.
353 */
354 - (void) setMIMEVersion: (NSString *) theMIMEVersion;
355
356 /*!
357 @method reply:
358 @discussion This method is used to contruct a new CWMessage
359 instance to be used when replying to a
360 message. The returned message will always
361 use the UTF-8 charset. The message will NOT have a
362 content other than the plain text one(s).
363 @param theMode The type of reply operation to do.
364 The default mode is PantomimeNormalReplyMode.
365 @result A CWMessage instance used for replying.
366 */
367 - (CWMessage *) reply: (PantomimeReplyMode) theMode;
368
369 /*!
370 @method forward
371 @discussion This method is used to contruct a new CWMessage
372 instance to be used when forward a message.
373 The returned message will always use
374 the UTF-8 charset.
375 @param theMode The type of forward operation to do.
376 @result A CWMessage instance used for forwarding.
377 */
378 - (CWMessage *) forward: (PantomimeForwardMode) theMode;
379
380 /*!
381 @method addHeader: withValue:
382 @discussion This method is used to add an extra header to the list of headers
383 of the message.
384 @param theName The header name, which should normally begin with an "X-".
385 @param theValue The header value.
386 */
387 - (void) addHeader: (NSString *) theName
388 withValue: (NSString *) theValue;
389
390 /*!
391 @method folder
392 @discussion This method is used to get the associated
393 receiver's folder.
394 @result The CWFolder instance in which the message is
395 stored, nil if no folder holds the receiver.
396 */
397 - (CWFolder *) folder;
398
399 /*!
400 @method setFolder:
401 @discussion This method is used to set the associated folder
402 to the message.
403 @param theFolder The folder which holds the receiver.
404 */
405 - (void) setFolder: (CWFolder *) theFolder;
406
407 /*!
408 @method rawSource
409 @discussion This method is used to obtain the raw
410 representation of the receiver. Subclasses
411 will overwrite this method so it's not
412 blocking (see the documentation of this
413 method for CWIMAPMessage, for example).
414 @result The raw representation, or nil if it has not
415 been loaded.
416 */
417 - (NSData *) rawSource;
418
419 /*!
420 @method setRawSource:
421 @discussion This method is used to set the raw representation
422 of the receiver. No specific actions are taken
423 when invoking this method.
424 @param theRawSource The raw source of the message.
425 */
426 - (void) setRawSource: (NSData *) theRawSource;
427
428 /*!
429 @method organization
430 @discussion This method is used to obtain the value of the
431 "Organization" header.
432 @result The value of the "Organization" header.
433 */
434 - (NSString *) organization;
435
436 /*!
437 @method setOrganization:
438 @discussion This method is used to set the value of the
439 "Organization" header.
440 @param theOrganization The new value of the header.
441 */
442 - (void) setOrganization: (NSString *) theOrganization;
443
444 /*!
445 @method propertyForKey:
446 @discussion This method is used to get an extra property for the
447 specified key.
448 @result The property for the specified key, nil if key isn't found.
449 */
450 - (id) propertyForKey: (id) theKey;
451
452 /*!
453 @method setProperty: forKey:
454 @discussion This method is used to set an extra property for the
455 specified key on this folder. If nil is passed for
456 theProperty parameter, the value will actually be
457 REMOVED for theKey.
458 @param theProperty The value of the property.
459 @param theKey The key of the property.
460 */
461 - (void) setProperty: (id) theProperty
462 forKey: (id) theKey;
463
464 /*!
465 @method resentDate
466 @discussion This method is used to obtain the value of the
467 "Resent-Date" header.
468 @result The value of the "Resent-Date" header.
469 */
470 - (NSCalendarDate *) resentDate;
471
472 /*!
473 @method setResentDate:
474 @discussion This method is used to set the value of the
475 "Resent-Date" header.
476 @param theResentDate The new value of the header.
477 */
478 - (void) setResentDate: (NSCalendarDate *) theResentDate;
479
480 /*!
481 @method resentFrom
482 @discussion This method is used to obtain the value of the
483 "Resent-From" header.
484 @result The value of the "Resent-From" header.
485 */
486 - (CWInternetAddress *) resentFrom;
487
488 /*!
489 @method setResentFrom:
490 @discussion This method is used to set the value of the
491 "Resent-From" header.
492 @param theInternetAddress The new value of the header.
493 */
494 - (void) setResentFrom: (CWInternetAddress *) theInternetAddress;
495
496 /*!
497 @method resentMessageID
498 @discussion This method is used to obtain the value of the
499 "Resent-Message-ID" header.
500 @result The value of the "Resent-Message-ID" header.
501 */
502 - (NSString *) resentMessageID;
503
504 /*!
505 @method setResentMessageID:
506 @discussion This method is used to set the value of the
507 "Resent-Message-ID" header.
508 @param theResentMessageID The new value of the header.
509 */
510 - (void) setResentMessageID: (NSString *) theResentMessageID;
511
512 /*!
513 @method resentSubject
514 @discussion This method is used to obtain the value of the
515 "Resent-Subject" header.
516 @result The value of the "Resent-Subject" header.
517 */
518 - (NSString *) resentSubject;
519
520 /*!
521 @method setResentSubject:
522 @discussion This method is used to set the value of the
523 "Resent-Subject" header.
524 @param theResentSubject The new value of the header.
525 */
526 - (void) setResentSubject: (NSString *) theResentSubject;
527
528 /*!
529 @method allReferences
530 @discussion This method is used to obtain the value of the
531 "References" header. The values are particularly
532 useful for message threading.
533 @result The value of the "References" header. This corresponds
534 to a NSArray of NSString instances. Each instance is normally
535 a Message-ID.
536 */
537 - (NSArray *) allReferences;
538
539 /*!
540 @method setReferences:
541 @discussion This method is used to the value of the "References"
542 header, replacing any previously defined value.
543 @param theReferences The array of references.
544 */
545 - (void) setReferences: (NSArray *) theReferences;
546
547 /*!
548 @method addHeadersFromData:record:
549 @discussion This method is used to add addionnal headers
550 from their raw representation. It will not erase the
551 currently defined headers. It also updates
552 the cache record <i>theRecord</i> with the decoded
553 information.
554 @param The additional headers, in their raw representation.
555 @param theRecord The cache_record to update.
556 */
557 - (void) addHeadersFromData: (NSData *) theHeaders record: (cache_record *) theRecord;
558
559 /*!
560 @method setHeadersFromData:record:
561 @discussion This method initalize all the headers of a message
562 from the raw data source. It replaces previously
563 defined values of headers found in <i>theHeaders</i>.
564 It also updates the cache record <i>theRecord</i> with
565 the decoded information.
566 @param theHeaders The bytes to use.
567 */
568 - (void) setHeadersFromData: (NSData *) theHeaders record: (cache_record *) theRecord;
569 @end
570
571
572 //
573 // Message's comparison category
574 //
575 @interface CWMessage (Comparing)
576
577 - (NSComparisonResult) compareAccordingToNumber: (CWMessage *) aMessage;
578 - (NSComparisonResult) reverseCompareAccordingToNumber: (CWMessage *) aMessage;
579 - (NSComparisonResult) compareAccordingToDate: (CWMessage *) aMessage;
580 - (NSComparisonResult) reverseCompareAccordingToDate: (CWMessage *) aMessage;
581 - (NSComparisonResult) compareAccordingToSender: (CWMessage *) aMessage;
582 - (NSComparisonResult) reverseCompareAccordingToSender: (CWMessage *) aMessage;
583 - (NSComparisonResult) compareAccordingToSize: (CWMessage *) aMessage;
584 - (NSComparisonResult) reverseCompareAccordingToSize: (CWMessage *) aMessage;
585
586 @end
587
588 #endif // _Pantomime_H_CWMessage
589
590
591