Debian Codegraph @

Framework/Pantomime/CWFolder.h

raw symbols SCIP
1 /*
2 ** CWFolder.h
3 **
4 ** Copyright (c) 2001-2006 Ludovic Marcotte
5 ** Copyright (C) 2013-2022 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_CWFolder
25 #define _Pantomime_H_CWFolder
26
27 #import <Foundation/NSArray.h>
28 #import <Foundation/NSData.h>
29 #import <Foundation/NSDictionary.h>
30 #import <Foundation/NSNotification.h>
31 #import <Foundation/NSObject.h>
32 #import <Foundation/NSString.h>
33
34 #import <Pantomime/CWConstants.h>
35
36 @class CWFlags;
37 @class CWMessage;
38 @class CWCacheManager;
39
40 /*!
41 @const PantomimeFolderAppendCompleted
42 */
43 extern NSString* PantomimeFolderAppendCompleted;
44
45 /*!
46 @const PantomimeFolderAppendFailed
47 */
48 extern NSString* PantomimeFolderAppendFailed;
49
50 /*!
51 @const PantomimeFolderCloseCompleted
52 */
53 extern NSString* PantomimeFolderCloseCompleted;
54
55 /*!
56 @const PantomimeFolderCloseFailed
57 */
58 extern NSString* PantomimeFolderCloseFailed;
59
60 /*!
61 @const PantomimeFolderExpungeCompleted
62 */
63 extern NSString* PantomimeFolderExpungeCompleted;
64
65 /*!
66 @const PantomimeFolderExpungeFailed
67 */
68 extern NSString* PantomimeFolderExpungeFailed;
69
70 /*!
71 @const PantomimeFolderListCompleted
72 */
73 extern NSString* PantomimeFolderListCompleted;
74
75 /*!
76 @const PantomimeFolderListFailed
77 */
78 extern NSString* PantomimeFolderListFailed;
79
80 /*!
81 @const PantomimeFolderListSubscribedCompleted
82 */
83 extern NSString* PantomimeFolderListSubscribedCompleted;
84
85 /*!
86 @const PantomimeFolderListSubscribedFailed
87 */
88 extern NSString* PantomimeFolderListSubscribedFailed;
89
90 /*!
91 @const PantomimeFolderOpenCompleted
92 */
93 extern NSString* PantomimeFolderOpenCompleted;
94
95 /*!
96 @const PantomimeFolderOpenFailed
97 */
98 extern NSString* PantomimeFolderOpenFailed;
99
100 /*!
101 @const PantomimeFolderPrefetchCompleted
102 */
103 extern NSString* PantomimeFolderPrefetchCompleted;
104
105 /*!
106 @const PantomimeFolderPrefetchFailed
107 */
108 extern NSString* PantomimeFolderPrefetchFailed;
109
110 /*!
111 @const PantomimeFolderSearchCompleted
112 */
113 extern NSString* PantomimeFolderSearchCompleted;
114
115 /*!
116 @const PantomimeFolderSearchFailed
117 */
118 extern NSString* PantomimeFolderSearchFailed;
119
120
121 /*!
122 @category NSObject (PantomimeFolderDelegate)
123 @discussion This informal protocol defines methods that can implemented in
124 CWFolder's delegate to control the behavior of the class
125 or to obtain status information.
126 */
127 @interface NSObject (PantomimeFolderDelegate)
128
129 /*!
130 @method folderAppendCompleted:
131 @discussion This method is automatically invoked on the store's
132 delegate in order to indicate that the last
133 message append operation was sucessful.
134 A PantomimeFolderAppendCompleted notification is
135 also posted.
136 @param theNotification The notification holding the information.
137 */
138 - (void) folderAppendCompleted: (NSNotification *) theNotification;
139
140 /*!
141 @method folderAppendFailed:
142 @discussion This method is automatically invoked on the store's
143 delegate in order to indicate that the last
144 message append operation failed.
145 A PantomimeFolderAppendCompleted notification is
146 also posted.
147 @param theNotification The notification holding the information.
148 */
149 - (void) folderAppendFailed: (NSNotification *) theNotification;
150
151 /*!
152 @method folderCloseCompleted
153 @discussion This method is automatically invoked on the store's
154 delegate in order to indicate that the close
155 operation completed.
156 @param theNotification The notification holding the information.
157 */
158 - (void) folderCloseCompleted: (NSNotification *) theNotification;
159
160 /*!
161 @method folderCloseFailed
162 @discussion This method is automatically invoked on the store's
163 delegate in order to indicate that the close
164 operation failed.
165 @param theNotification The notification holding the information.
166 */
167 - (void) folderCloseFailed: (NSNotification *) theNotification;
168
169 /*!
170 @method folderExpungeCompleted
171 @discussion This method is automatically invoked on the store's
172 delegate in order to indicate that the expunge
173 operation completed.
174 @param theNotification The notification holding the information.
175 */
176 - (void) folderExpungeCompleted: (NSNotification *) theNotification;
177
178 /*!
179 @method folderExpungeFailed
180 @discussion This method is automatically invoked on the store's
181 delegate in order to indicate that the expunge
182 operation failed.
183 @param theNotification The notification holding the information.
184 */
185 - (void) folderExpungeFailed: (NSNotification *) theNotification;
186
187 /*!
188 @method folderListCompleted
189 @discussion This method is automatically invoked on the store's
190 delegate in order to indicate that the mailbox listing
191 operation completed.
192 @param theNotification The notification holding the information.
193 */
194 - (void) folderListCompleted: (NSNotification *) theNotification;
195
196 /*!
197 @method folderListFailed
198 @discussion This method is automatically invoked on the store's
199 delegate in order to indicate that the mailbox listing
200 operation failed.
201 @param theNotification The notification holding the information.
202 */
203 - (void) folderListFailed: (NSNotification *) theNotification;
204
205 /*!
206 @method folderListSubscribedCompleted
207 @discussion This method is automatically invoked on the store's
208 delegate in order to indicate that the listing operation
209 of subscribed mailboxes completed.
210 @param theNotification The notification holding the information.
211 */
212 - (void) folderListSubscribedCompleted: (NSNotification *) theNotification;
213
214 /*!
215 @method folderListSuscribedFailed
216 @discussion This method is automatically invoked on the store's
217 delegate in order to indicate that the listing operation
218 of subscribed mailboxes failed.
219 @param theNotification The notification holding the information.
220 */
221 - (void) folderListSubscribedFailed: (NSNotification *) theNotification;
222
223 /*!
224 @method folderOpenCompleted
225 @discussion This method is automatically invoked on the store's
226 delegate in order to indicate that the open
227 operation completed.
228 @param theNotification The notification holding the information.
229 */
230 - (void) folderOpenCompleted: (NSNotification *) theNotification;
231
232 /*!
233 @method folderOpenFailed
234 @discussion This method is automatically invoked on the store's
235 delegate in order to indicate that the open
236 operation failed.
237 @param theNotification The notification holding the information.
238 */
239 - (void) folderOpenFailed: (NSNotification *) theNotification;
240
241 /*!
242 @method folderPrefetchCompleted
243 @discussion This method is automatically invoked on the store's
244 delegate in order to indicate that the prefetch
245 operation completed.
246 @param theNotification The notification holding the information.
247 */
248 - (void) folderPrefetchCompleted: (NSNotification *) theNotification;
249
250 /*!
251 @method folderPrefetchFailed
252 @discussion This method is automatically invoked on the store's
253 delegate in order to indicate that the prefetch
254 operation failed.
255 @param theNotification The notification holding the information.
256 */
257 - (void) folderPrefetchFailed: (NSNotification *) theNotification;
258
259 /*!
260 @method folderSearchCompleted
261 @discussion This method is automatically invoked on the store's
262 delegate in order to indicate that the search
263 operation completed.
264 @param theNotification The notification holding the information.
265 */
266 - (void) folderSearchCompleted: (NSNotification *) theNotification;
267
268 /*!
269 @method folderSearchFailed
270 @discussion This method is automatically invoked on the store's
271 delegate in order to indicate that the search
272 operation failed.
273 @param theNotification The notification holding the information.
274 */
275 - (void) folderSearchFailed: (NSNotification *) theNotification;
276
277 @end
278
279 /*!
280 @class CWFolder
281 @abstract A CWFolder object holds CWMessage instances.
282 @discussion This abstract class is used to represent a folder which holds messages.
283 A folder is a synonym for mailbox. Normally, you should never create
284 an instance of CWFolder directly but rather use the subclasses which
285 are CWIMAPFolder, CWLocalFolder and CWPOP3Folder. Futhermore, the corresponding
286 CWStore classes will instanciate the CWFolder subclasses for you.
287 */
288 @interface CWFolder : NSObject
289 {
290 @protected
291 NSMutableDictionary *_properties;
292 NSString *_name;
293
294 CWCacheManager *_cacheManager;
295 id _store;
296
297 NSMutableArray *_allMessages;
298 NSMutableArray *_allVisibleMessages;
299 NSMutableArray *_allContainers;
300
301 BOOL _show_deleted;
302 BOOL _show_read;
303
304 PantomimeFolderMode _mode;
305 }
306
307 /*!
308 @method initWithName:
309 @discussion This method initialize a folder with the
310 specified name. The name can contain folder
311 separators in order to create subfolders.
312 The separator can be obtained from a
313 class that implements the CWStore protocol.
314 @param theName The full path of the folder.
315 @result The folder, nil in case of an error.
316 */
317 - (id) initWithName: (NSString *) theName;
318
319 /*!
320 @method name
321 @discussion This method returns the name of the folder.
322 @result The full name of the folder.
323 */
324 - (NSString *) name;
325
326 /*!
327 @method setName:
328 @discussion Sets the name of a folder.
329 @param theName The name of the folder.
330 */
331 - (void) setName: (NSString *) theName;
332
333 /*!
334 @method appendMessage:
335 @discussion This method is used to add a message to
336 a CWFolder instance. This method will NOT add
337 the message to the underlying store. You MUST
338 use -appendMessageFromRawSource: flags: if you
339 want the message to be saved to the underlying
340 store. Generally, you should not use this
341 method directly. If the folder was threaded,
342 this method will NOT thread the appended message.
343 @param theMessage The message to append to the folder.
344 */
345 - (void) appendMessage: (CWMessage *) theMessage;
346
347
348 /*!
349 @method appendMessageFromRawSource:flags:
350 @discussion This method is used to append a message
351 from its raw source representation (RFC2822 compliant)
352 to the underlying store. This method will raise an
353 exception if it's invoked on an instance of CWFolder or
354 CWPOP3Folder instead of an instance of CWIMAPFolder and CWLocalFolder.
355 If the folder was threaded, this method will NOT thread the appended message.
356 Methods will be invoked on the delegate and notifications
357 will be posted. See the PantomimeFolderDelegate informal
358 protocol for more details.
359 @param theData The raw representation of the message to append.
360 @param theFlags The flags of the message, nil if no flags need to be kept.
361 */
362 - (void) appendMessageFromRawSource: (NSData *) theData
363 flags: (CWFlags *) theFlags;
364
365 /*!
366 @method messages
367 @discussion This method is used to obtain all messages
368 in the CWFolder instance. Note that the
369 messages MIGHT NOT been all completely initialized.
370 @result A mutable array of messages.
371 */
372 - (NSMutableArray *) messages;
373
374 /*!
375 @method setMessages:
376 @discussion This method is used to replace all messages in the
377 CWFolder instance by the ones specified in the array.
378 Normally, you shouldn't use this method directly.
379 @param theMessages The array of messages.
380 */
381 - (void) setMessages: (NSArray *) theMessages;
382
383 /*!
384 @method visibileMessages
385 @discussion This method is used to obtain all visible messages
386 in the CWFolder instance. It hides messages marked
387 as Deleted if -setShowDeleted: was invoked with
388 NO as the parameter and the the same for messages
389 marked as read (see -setShowRead:). Note that the
390 messages MIGHT NOT been all completely initialized.
391 @result An array of all visible messages.
392 */
393 - (NSArray *) visibleMessages;
394
395
396 /*!
397 @method messageAtIndex:
398 @discussion This method is used to obtain the message at the
399 specified index (which is zero-based). If the index
400 is out of bounds, nil is returned.
401 @param theIndex The index of the message.
402 @result The message at the specified index, nil otherwise.
403 */
404 - (CWMessage *) messageAtIndex: (NSUInteger) theIndex;
405
406 /*!
407 @method countVisible
408 @discussion This method is used to obtain the number of messages
409 present in the folder. Hidden messages will NOT
410 be part of the value returned. So, for example, if
411 a folder has 10 messages, 2 of them have the
412 PantomimeDeleted flag set and -setShowDeleted: NO was
413 invoked on the folder, this method will return
414 8 as the messages count.
415 @result The number of messages in the folder.
416 */
417 - (NSUInteger) countVisible;
418
419 /*!
420 @method close
421 @discussion This method is used to close the folder.
422 The subclasses of CWFolder MUST this method.
423 */
424 - (void) close;
425
426 /*!
427 @method expunge:
428 @discussion This method is used to permanently remove
429 messages marked as deleted in the folder.
430 */
431 - (void) expunge;
432
433 /*!
434 @method store
435 @discussion This method returns the associated store
436 to this folder. This will generally be an instance
437 of CWIMAPStore, CWLocalStore or CWPOP3Store.
438 @result The associated store.
439 */
440 - (id) store;
441
442 /*!
443 @method setStore:
444 @discussion This method is used to set the associated store
445 to this folder. The store will NOT be retained
446 since it is the store which holds and retains
447 the CWFolder instances.
448 @param theStore The associated store.
449 */
450 - (void) setStore: (id) theStore;
451
452 /*!
453 @method removeMessage:
454 @discussion This method removes permenantly a message from
455 the folder. It is used when transferring message
456 between folders in order to update the view or
457 when expunge deletes messages from a view. If the
458 folder is threaded, this method will rethread the
459 folder before returning.
460 @param theMessage The CWMessage instance to remove from the folder.
461 */
462 - (void) removeMessage: (CWMessage *) theMessage;
463
464 /*!
465 @method showDeleted
466 @discussion This method returns YES if messages marked as deleted
467 are shown in this folder, NO otherwise.
468 @result A BOOL corresponding to the value.
469 */
470 - (BOOL) showDeleted;
471
472 /*!
473 @method setShowDeleted:
474 @discussion This method is used to specify if we want to show or
475 hide messages marked as deleted in this folder.
476 @param theBOOL YES if we want to hide messages marked as deleted,
477 NO otherwise.
478 */
479 - (void) setShowDeleted: (BOOL) theBOOL;
480
481 /*!
482 @method showRead
483 @discussion This method returns YES if messages marked as read
484 are shown in this folder, NO otherwise.
485 @result A BOOL corresponding to the value.
486 */
487 - (BOOL) showRead;
488
489 /*!
490 @method setShowRead:
491 @discussion This method is used to specify if we want to show or
492 hide messages marked as read in this folder.
493 @param theBOOL YES if we want to hide messages marked as read,
494 NO otherwise.
495 */
496 - (void) setShowRead: (BOOL) theBOOL;
497
498 /*!
499 @method numberOfDeletedMessages
500 @discussion This method returns the number of messages in this
501 folder that have the PantomimeDeleted flag set.
502 @result The number of message marked has deleted, 0 if none.
503 */
504 - (NSUInteger) numberOfDeletedMessages;
505
506 /*!
507 @method numberOfUnreadMessages
508 @discussion This method returns the number of messages in this
509 folder that do not have the PantomimeSeen flag set.
510 @result The number of unread messages, 0 if none.
511 */
512 - (NSUInteger) numberOfUnreadMessages;
513
514 /*!
515 @method size
516 @discussion This method returns the size of the folder. That is,
517 it returns the sum of the size of all visible messages in
518 the folder.
519 @result The size of the folder.
520 */
521 - (unsigned long) size;
522
523 /*!
524 @method updateCache
525 @discussion This method is used to update our cache (_allVisibleMessages).
526 Applications can call this method if they set the PantomimeDeleted flags to
527 messages inside this folder. If not called, the cache won't be updated
528 the messages having the flag PantomimeDeleted will still be visible.
529 */
530 - (void) updateCache;
531
532 /*!
533 @method allContainers
534 @discussion This method returns the list of root containers when using
535 message threading.
536 @result Root containers if using message threading, nil otherwise.
537 */
538 - (NSArray *) allContainers;
539
540 /*!
541 @method thread
542 @discussion This method implements Jamie Zawinski's message threading algorithm.
543 The full algorithm is available here: http://www.jwz.org/doc/threading.html
544 After calling this method, -allContainers can be called to obtain the
545 root set of CWContainer instances.
546 */
547 - (void) thread;
548
549 /*!
550 @method unthread
551 @discussion This method is used to release all resources taken by the
552 message threading code. After calling this method,
553 -allContainers will return nil.
554 */
555 - (void) unthread;
556
557 /*!
558 @method search: mask: options:
559 @discussion This method is used to search this folder using a criteria,
560 mask and options. This method will post a PantomimeFolderSearchCompleted
561 (or invoked -folderSearchCompleted: on the delegate) once it has
562 completed its execution (or post PantomimeFolderSearchFailed or invoke
563 -folderSearchFailed on the delegate if it failed). This method will
564 do absolutely nothing on CWPOP3Folder instances as search operations
565 are not supported in POP3.
566 @param theString The string to search for. This can be a regex for LocalFolder instances.
567 @param theMask The mask to use. The values can be either one of the
568 PantomimeSearchMask enum. This parameter is ignored for IMAPFolder instances.
569 @param theOptions The search options. Can be either PantomimeRegularExpression
570 or PantomimeCaseInsensitiveSearch. This parameter is ignored for
571 CWIMAPFolder instances.
572 */
573 - (void) search: (NSString *) theString
574 mask: (PantomimeSearchMask) theMask
575 options: (PantomimeSearchOption) theOptions;
576
577 /*!
578 @method cacheManager
579 @discussion This method returns the associated cache manager for this folder.
580 For a CWIMAPFolder, a CWIMAPCacheManager instance will be returned.
581 For a CWLocalFolder, a CWLocalFolderCacheManager instance will be returned.
582 For a CWPOP3Folder, a CWPOP3CacheManager instance will be returned.
583 @result The associated cache manager instance, nil otherwise.
584 */
585 - (CWCacheManager *) cacheManager;
586
587 /*!
588 @method setCacheManager:
589 @discussion This method is used to set the respective cache manager instance
590 for this folder. Instance of CWIMAPCacheManager, CWLocalFolderCacheManager
591 or CWPOP3CacheManager will generally be used.
592 @param theCacheManager The cache manager instance for this folder.
593 */
594 - (void) setCacheManager: (id) theCacheManager;
595
596 /*!
597 @method mode
598 @discussion This method is used to get the mode of the folders. The returned
599 values can be either PantomimeUnknownMode, PantomimeReadOnlyMode
600 or PantomimeReadWriteMode. Calling this method on an instance
601 of Folder (ie., not a subclass) will raise an exception.
602 @result The mode of the folder.
603 */
604 - (PantomimeFolderMode) mode;
605
606 /*!
607 @method setMode:
608 @discussion This method is used to adjust the mode on the specified folder.
609 If has no impact on how the mailbox was open. For example,
610 if a mailbox was open as read-only, the mailbox will not
611 be re-opened as read-write after this method call.
612 @param theMode The new mode.
613 */
614 - (void) setMode: (PantomimeFolderMode) theMode;
615
616 /*!
617 @method setFlags: messages:
618 @discussion This method is used to set the same flags to a set of messages.
619 This can be useful, especially when dealing with CWIMAPFolder
620 instances in order to NOT send many IMAP commands to the server
621 but rather send just one.
622 @param theFlags The flags to set to all messages.
623 @param theMessages The array of messages to which flags will be applied.
624 */
625 - (void) setFlags: (CWFlags *) theFlags
626 messages: (NSArray *) theMessages;
627
628 /*!
629 @method propertyForKey:
630 @discussion This method is used to get an extra property for the
631 specified key.
632 @result The property for the specified key, nil if key isn't found.
633 */
634 - (id) propertyForKey: (id) theKey;
635
636 /*!
637 @method setProperty: forKey:
638 @discussion This method is used to set an extra property for the
639 specified key on this folder. If nil is passed for
640 theProperty parameter, the value will actually be
641 REMOVED for theKey.
642 @param theProperty The value of the property.
643 @param theKey The key of the property.
644 */
645 - (void) setProperty: (id) theProperty
646 forKey: (id) theKey;
647 @end
648
649 #endif // _Pantomime_H_CWFolder