| 1 | /* |
| 2 | ** CWCacheManager.h |
| 3 | ** |
| 4 | ** Copyright (c) 2004-2007 Ludovic Marcotte |
| 5 | ** Copyright (C) 2013-2020 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_CWCacheManager |
| 25 | #define _Pantomime_H_CWCacheManager |
| 26 | |
| 27 | #import <Foundation/NSArray.h> |
| 28 | #import <Foundation/NSCoder.h> |
| 29 | #import <Foundation/NSString.h> |
| 30 | |
| 31 | #if defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4) |
| 32 | #ifndef NSUInteger |
| 33 | #define NSUInteger unsigned int |
| 34 | #define NSUIntegerMax UINT_MAX |
| 35 | #endif |
| 36 | #endif |
| 37 | |
| 38 | // |
| 39 | // |
| 40 | // |
| 41 | typedef struct { |
| 42 | unsigned int date; |
| 43 | unsigned int flags; |
| 44 | long position; // For mbox based cache files |
| 45 | unsigned int size; |
| 46 | unsigned int imap_uid; // For IMAP |
| 47 | char *filename; // For maildir base cache files |
| 48 | NSString *pop3_uid; // For POP3 |
| 49 | NSData *from; |
| 50 | NSData *in_reply_to; |
| 51 | NSData *message_id; |
| 52 | NSData *references; |
| 53 | NSData *subject; |
| 54 | NSData *to; |
| 55 | NSData *cc; |
| 56 | } cache_record; |
| 57 | |
| 58 | // |
| 59 | // Simple macro used to initialize a record to some |
| 60 | // default values. Faster than a memset(). |
| 61 | // |
| 62 | #define CLEAR_CACHE_RECORD(r) \ |
| 63 | r.date = 0; \ |
| 64 | r.flags = 0; \ |
| 65 | r.position = 0; \ |
| 66 | r.size = 0; \ |
| 67 | r.imap_uid = 0; \ |
| 68 | r.pop3_uid = nil;\ |
| 69 | r.from = nil; \ |
| 70 | r.in_reply_to = nil; \ |
| 71 | r.message_id = nil; \ |
| 72 | r.references = nil; \ |
| 73 | r.subject = nil; \ |
| 74 | r.to = nil; \ |
| 75 | r.cc = nil; |
| 76 | |
| 77 | /*! |
| 78 | @class CWCacheManager |
| 79 | @discussion This class is used to provide a generic superclass for |
| 80 | cache management with regard to various CWFolder sub-classes. |
| 81 | CWIMAPFolder, CWLocalFolder and CWPOP3Folder can make use of a |
| 82 | cache in order to speedup lots of operations. |
| 83 | */ |
| 84 | @interface CWCacheManager : NSObject |
| 85 | { |
| 86 | @protected |
| 87 | NSMutableArray *_cache; |
| 88 | NSString *_path; |
| 89 | NSUInteger _count; |
| 90 | int _fd; |
| 91 | } |
| 92 | |
| 93 | /*! |
| 94 | @method initWithPath: |
| 95 | @discussion This method is the designated initializer for the |
| 96 | CWCacheManager class. |
| 97 | @param thePath The complete path where the cache will be eventually |
| 98 | saved to. |
| 99 | @result A CWCacheManager subclass instance, nil on error. |
| 100 | */ |
| 101 | - (id) initWithPath: (NSString *) thePath; |
| 102 | |
| 103 | /*! |
| 104 | @method path |
| 105 | @discussion This method is used to obtain the path where the |
| 106 | cache has been loaded for or where it'll be saved to. |
| 107 | @result The path. |
| 108 | */ |
| 109 | - (NSString *) path; |
| 110 | |
| 111 | /*! |
| 112 | @method setPath: |
| 113 | @discussion This method is used to set the path where the |
| 114 | cache will be loaded from or where it'll be saved to. |
| 115 | @param thePath The complete path. |
| 116 | */ |
| 117 | - (void) setPath: (NSString *) thePath; |
| 118 | |
| 119 | /*! |
| 120 | @method invalidate |
| 121 | @discussion This method is used to invalide all cache entries. |
| 122 | */ |
| 123 | - (void) invalidate; |
| 124 | |
| 125 | /*! |
| 126 | @method synchronize |
| 127 | @discussion This method is used to save the cache on disk. |
| 128 | If the cache is empty, this method does not |
| 129 | write it on disk and returns YES. |
| 130 | @result YES on success, NO otherwise. |
| 131 | */ |
| 132 | - (BOOL) synchronize; |
| 133 | |
| 134 | /*! |
| 135 | @method expunge |
| 136 | @discussion This method is used to sync the cache on a folder expunge. |
| 137 | */ |
| 138 | - (void) expunge; |
| 139 | |
| 140 | /*! |
| 141 | @method count |
| 142 | @discussion This method returns the number of cache_record |
| 143 | entries present in the cache. |
| 144 | @result The count; |
| 145 | */ |
| 146 | - (NSUInteger) count; |
| 147 | |
| 148 | @end |
| 149 | |
| 150 | #endif // _Pantomime_H_CWCacheManager |