0
|
1 #ifndef __MAIL_STORAGE_H
|
|
2 #define __MAIL_STORAGE_H
|
|
3
|
|
4 #include "imap-util.h"
|
|
5 #include "imap-parser.h"
|
|
6
|
|
7 typedef enum {
|
|
8 MAILBOX_NOSELECT = 0x01,
|
|
9 MAILBOX_CHILDREN = 0x02,
|
|
10 MAILBOX_NOCHILDREN = 0x04,
|
|
11 MAILBOX_NOINFERIORS = 0x08,
|
|
12 MAILBOX_MARKED = 0x10,
|
|
13 MAILBOX_UNMARKED = 0x20,
|
|
14
|
|
15 MAILBOX_READONLY = 0x40
|
|
16 } MailboxFlags;
|
|
17
|
|
18 typedef enum {
|
|
19 STATUS_MESSAGES = 0x01,
|
|
20 STATUS_RECENT = 0x02,
|
|
21 STATUS_UIDNEXT = 0x04,
|
|
22 STATUS_UIDVALIDITY = 0x08,
|
|
23 STATUS_UNSEEN = 0x10,
|
|
24 STATUS_FIRST_UNSEEN_SEQ = 0x20
|
|
25 } MailboxStatusItems;
|
|
26
|
|
27 typedef enum {
|
|
28 MAILBOX_NAME_EXISTS,
|
|
29 MAILBOX_NAME_VALID,
|
|
30 MAILBOX_NAME_INVALID
|
|
31 } MailboxNameStatus;
|
|
32
|
|
33 typedef enum {
|
|
34 MODIFY_ADD,
|
|
35 MODIFY_REMOVE,
|
|
36 MODIFY_REPLACE
|
|
37 } ModifyType;
|
|
38
|
|
39 typedef struct _MailStorage MailStorage;
|
|
40 typedef struct _Mailbox Mailbox;
|
|
41 typedef struct _MailboxStatus MailboxStatus;
|
|
42 typedef struct _MailFetchData MailFetchData;
|
|
43 typedef struct _MailFetchBodyData MailFetchBodyData;
|
|
44 typedef struct _MailSearchArg MailSearchArg;
|
|
45
|
|
46 typedef void (*MailboxFunc)(MailStorage *storage, const char *name,
|
|
47 MailboxFlags flags, void *user_data);
|
|
48
|
|
49 typedef void (*MailExpungeFunc)(Mailbox *mailbox, unsigned int seq,
|
|
50 unsigned int uid, void *user_data);
|
|
51 typedef void (*MailFlagUpdateFunc)(Mailbox *mailbox, unsigned int seq,
|
|
52 unsigned int uid, MailFlags flags,
|
|
53 const char *custom_flags[],
|
|
54 void *user_data);
|
|
55
|
|
56 /* All methods returning int return either TRUE or FALSE. */
|
|
57 struct _MailStorage {
|
|
58 char *name;
|
|
59
|
|
60 char hierarchy_sep;
|
|
61
|
|
62 /* Create new instance */
|
|
63 MailStorage *(*create)(const char *data);
|
|
64
|
|
65 /* Free this instance */
|
|
66 void (*free)(MailStorage *storage);
|
|
67
|
|
68 /* Returns TRUE if this storage would accept the given data
|
|
69 as a valid parameter to create(). */
|
|
70 int (*autodetect)(const char *data);
|
|
71
|
|
72 /* Open a mailbox. If readonly is TRUE, mailbox must not be
|
|
73 modified in any way even when it's asked. */
|
|
74 Mailbox *(*open_mailbox)(MailStorage *storage, const char *name,
|
|
75 int readonly);
|
|
76
|
|
77 /* name is allowed to contain multiple new hierarchy levels */
|
|
78 int (*create_mailbox)(MailStorage *storage, const char *name);
|
|
79 int (*delete_mailbox)(MailStorage *storage, const char *name);
|
|
80 /* If the name has inferior hierarchical names, then the inferior
|
|
81 hierarchical names MUST also be renamed (ie. foo -> bar renames
|
|
82 also foo/bar -> bar/bar).
|
|
83
|
|
84 If oldname is case-insensitively "INBOX", the mails are moved
|
|
85 into new folder but the INBOX folder must not be deleted. */
|
|
86 int (*rename_mailbox)(MailStorage *storage, const char *oldname,
|
|
87 const char *newname);
|
|
88
|
|
89 /* Execute specified function for all mailboxes matching given
|
|
90 mask. The mask is in RFC2060 LIST format. */
|
|
91 int (*find_mailboxes)(MailStorage *storage, const char *mask,
|
|
92 MailboxFunc func, void *user_data);
|
|
93
|
|
94 /* Subscribe/unsubscribe mailbox. There should be no error when
|
|
95 subscribing to already subscribed mailbox. Subscribing to
|
|
96 unexisting mailboxes is optional. */
|
|
97 int (*set_subscribed)(MailStorage *storage, const char *name, int set);
|
|
98
|
|
99 /* Exactly like find_mailboxes(), but list only subscribed mailboxes. */
|
|
100 int (*find_subscribed)(MailStorage *storage, const char *mask,
|
|
101 MailboxFunc func, void *user_data);
|
|
102
|
|
103 /* Returns mailbox name status */
|
|
104 int (*get_mailbox_name_status)(MailStorage *storage, const char *name,
|
|
105 MailboxNameStatus *status);
|
|
106
|
|
107 /* Returns the error message of last occured error. */
|
|
108 const char *(*get_last_error)(MailStorage *storage);
|
|
109
|
|
110 /* private: */
|
|
111 char *dir; /* root directory */
|
|
112 char *error;
|
|
113 };
|
|
114
|
|
115 struct _Mailbox {
|
|
116 char *name;
|
|
117
|
|
118 MailStorage *storage;
|
|
119
|
|
120 /* Close the box */
|
|
121 void (*close)(Mailbox *box);
|
|
122
|
|
123 /* Gets the mailbox status information. */
|
|
124 int (*get_status)(Mailbox *box, MailboxStatusItems items,
|
|
125 MailboxStatus *status);
|
|
126
|
|
127 /* Synchronize the mailbox by reading all expunges and flag changes.
|
|
128 If new mail has been added to mailbox, messages contains the total
|
|
129 number of messages in mailbox, otherwise 0. functions may be NULL.
|
|
130
|
|
131 If expunge is TRUE, deleted mails are expunged as well. Difference
|
|
132 to expunge() function is that expunge_func is also called. */
|
|
133 int (*sync)(Mailbox *box, unsigned int *messages, int expunge,
|
|
134 MailExpungeFunc expunge_func, MailFlagUpdateFunc flag_func,
|
|
135 void *user_data);
|
|
136
|
|
137 /* Expunge all mails with \Deleted flag. */
|
|
138 int (*expunge)(Mailbox *box);
|
|
139
|
|
140 /* Update mail flags. func may be NULL. */
|
|
141 int (*update_flags)(Mailbox *box, const char *messageset, int uidset,
|
|
142 MailFlags flags, const char *custom_flags[],
|
|
143 ModifyType modify_type,
|
|
144 MailFlagUpdateFunc func, void *user_data,
|
|
145 int *all_found);
|
|
146
|
|
147 /* Copy mails to another mailbox */
|
|
148 int (*copy)(Mailbox *box, Mailbox *destbox,
|
|
149 const char *messageset, int uidset);
|
|
150
|
|
151 /* Fetch wanted mail data. The results are written into outbuf
|
|
152 in RFC2060 FETCH format. */
|
|
153 int (*fetch)(Mailbox *box, MailFetchData *fetch_data,
|
|
154 IOBuffer *outbuf, int *all_found);
|
|
155
|
|
156 /* Search wanted mail data. args contains the search criteria.
|
|
157 results are written into outbuf in RFC2060 SEARCH format. */
|
|
158 int (*search)(Mailbox *box, MailSearchArg *args,
|
|
159 IOBuffer *outbuf, int uid_result);
|
|
160
|
|
161 /* Save a new mail into mailbox. */
|
|
162 int (*save)(Mailbox *box, MailFlags flags, const char *custom_flags[],
|
|
163 time_t internal_date, IOBuffer *data, size_t data_size);
|
|
164
|
|
165 /* Returns TRUE if mailbox is now in inconsistent state, meaning that
|
|
166 the message IDs etc. may have changed - only way to recover this
|
|
167 would be to fully close the mailbox and reopen it. With IMAP
|
|
168 connection this would mean a forced disconnection since we can't
|
|
169 do forced CLOSE. */
|
|
170 int (*is_inconsistency_error)(Mailbox *box);
|
|
171
|
|
172 /* private: */
|
|
173 unsigned int readonly:1;
|
|
174 unsigned int inconsistent:1;
|
|
175 };
|
|
176
|
|
177 struct _MailboxStatus {
|
|
178 unsigned int messages;
|
|
179 unsigned int recent;
|
|
180 unsigned int unseen;
|
|
181
|
|
182 unsigned int uidvalidity;
|
|
183 unsigned int uidnext;
|
|
184
|
|
185 unsigned int first_unseen_seq;
|
|
186 };
|
|
187
|
|
188 struct _MailFetchData {
|
|
189 const char *messageset;
|
|
190 unsigned int uidset:1;
|
|
191
|
|
192 unsigned int body:1;
|
|
193 unsigned int bodystructure:1;
|
|
194 unsigned int envelope:1;
|
|
195 unsigned int flags:1;
|
|
196 unsigned int internaldate:1;
|
|
197 unsigned int rfc822:1;
|
|
198 unsigned int rfc822_header:1;
|
|
199 unsigned int rfc822_size:1;
|
|
200 unsigned int rfc822_text:1;
|
|
201 unsigned int uid:1;
|
|
202
|
|
203 MailFetchBodyData *body_sections;
|
|
204 };
|
|
205
|
|
206 struct _MailFetchBodyData {
|
|
207 MailFetchBodyData *next;
|
|
208
|
|
209 const char *section; /* NOTE: always uppercased */
|
|
210 off_t skip;
|
|
211 size_t max_size;
|
|
212 unsigned int skip_set:1;
|
|
213 unsigned int peek:1;
|
|
214 };
|
|
215
|
|
216 /* register all mail storages */
|
|
217 void mail_storage_register_all(void);
|
|
218
|
|
219 /* Register mail storage class with given name - all methods that are NULL
|
|
220 are set to default methods */
|
|
221 void mail_storage_class_register(MailStorage *storage_class);
|
|
222 void mail_storage_class_unregister(MailStorage *storage_class);
|
|
223
|
|
224 /* Create a new instance of registered mail storage class with given
|
|
225 storage-specific data. If data is NULL, it tries to use defaults.
|
|
226 May return NULL if anything fails. */
|
|
227 MailStorage *mail_storage_create(const char *name, const char *data);
|
|
228 void mail_storage_destroy(MailStorage *storage);
|
|
229
|
|
230 MailStorage *mail_storage_create_default(void);
|
|
231 MailStorage *mail_storage_create_with_data(const char *data);
|
|
232
|
|
233 /* Set error message in storage. Critical errors are logged with syslog() */
|
|
234 void mail_storage_clear_error(MailStorage *storage);
|
|
235 void mail_storage_set_error(MailStorage *storage, const char *fmt, ...)
|
|
236 __attr_format__(2, 3);
|
|
237 void mail_storage_set_critical(MailStorage *storage, const char *fmt, ...)
|
|
238 __attr_format__(2, 3);
|
|
239
|
|
240 const char *mail_storage_get_last_error(MailStorage *storage);
|
|
241 int mail_storage_is_inconsistency_error(Mailbox *box);
|
|
242
|
|
243 #endif
|