Diffstat (limited to 'kmicromail/libetpan/generic/maildirdriver_cached_message.c') (more/less context) (show whitespace changes)
-rw-r--r-- | kmicromail/libetpan/generic/maildirdriver_cached_message.c | 88 |
1 files changed, 87 insertions, 1 deletions
diff --git a/kmicromail/libetpan/generic/maildirdriver_cached_message.c b/kmicromail/libetpan/generic/maildirdriver_cached_message.c index 51866aa..34de351 100644 --- a/kmicromail/libetpan/generic/maildirdriver_cached_message.c +++ b/kmicromail/libetpan/generic/maildirdriver_cached_message.c | |||
@@ -38,8 +38,10 @@ | |||
38 | #include "mailmessage_tools.h" | 38 | #include "mailmessage_tools.h" |
39 | #include "maildirdriver.h" | 39 | #include "maildirdriver.h" |
40 | #include "maildir.h" | 40 | #include "maildir.h" |
41 | #include "generic_cache.h" | 41 | #include "generic_cache.h" |
42 | #include "mail_cache_db.h" | ||
43 | #include "maildirdriver_tools.h" | ||
42 | 44 | ||
43 | #include <unistd.h> | 45 | #include <unistd.h> |
44 | #include <sys/mman.h> | 46 | #include <sys/mman.h> |
45 | #include <sys/types.h> | 47 | #include <sys/types.h> |
@@ -47,8 +49,11 @@ | |||
47 | #include <fcntl.h> | 49 | #include <fcntl.h> |
48 | #include <string.h> | 50 | #include <string.h> |
49 | #include <stdlib.h> | 51 | #include <stdlib.h> |
50 | 52 | ||
53 | static int get_flags(mailmessage * msg_info, | ||
54 | struct mail_flags ** result); | ||
55 | |||
51 | static int prefetch(mailmessage * msg_info); | 56 | static int prefetch(mailmessage * msg_info); |
52 | 57 | ||
53 | static void prefetch_free(struct generic_message_t * msg); | 58 | static void prefetch_free(struct generic_message_t * msg); |
54 | 59 | ||
@@ -77,9 +82,9 @@ static mailmessage_driver local_maildir_cached_message_driver = { | |||
77 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, | 82 | .msg_fetch_section_mime = mailmessage_generic_fetch_section_mime, |
78 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, | 83 | .msg_fetch_section_body = mailmessage_generic_fetch_section_body, |
79 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, | 84 | .msg_fetch_envelope = mailmessage_generic_fetch_envelope, |
80 | 85 | ||
81 | .msg_get_flags = NULL, | 86 | .msg_get_flags = get_flags, |
82 | }; | 87 | }; |
83 | 88 | ||
84 | mailmessage_driver * maildir_cached_message_driver = | 89 | mailmessage_driver * maildir_cached_message_driver = |
85 | &local_maildir_cached_message_driver; | 90 | &local_maildir_cached_message_driver; |
@@ -245,4 +250,85 @@ static void check(mailmessage * msg_info) | |||
245 | r = mail_flags_store_set(get_cached_session_data(msg_info)->md_flags_store, msg_info); | 250 | r = mail_flags_store_set(get_cached_session_data(msg_info)->md_flags_store, msg_info); |
246 | /* ignore errors */ | 251 | /* ignore errors */ |
247 | } | 252 | } |
248 | } | 253 | } |
254 | |||
255 | #define FLAGS_NAME "flags.db" | ||
256 | |||
257 | static int get_flags(mailmessage * msg_info, | ||
258 | struct mail_flags ** result) | ||
259 | { | ||
260 | struct mail_cache_db * cache_db_flags; | ||
261 | chashdatum key; | ||
262 | chashdatum value; | ||
263 | struct maildir * md; | ||
264 | struct mail_flags * flags; | ||
265 | struct maildir_cached_session_state_data * data; | ||
266 | struct maildir_msg * md_msg; | ||
267 | int r; | ||
268 | uint32_t driver_flags; | ||
269 | char filename_flags[PATH_MAX]; | ||
270 | char keyname[PATH_MAX]; | ||
271 | MMAPString * mmapstr; | ||
272 | |||
273 | if (msg_info->msg_flags != NULL) { | ||
274 | * result = msg_info->msg_flags; | ||
275 | return MAIL_NO_ERROR; | ||
276 | } | ||
277 | |||
278 | data = get_cached_session_data(msg_info); | ||
279 | flags = mail_flags_store_get(data->md_flags_store, | ||
280 | msg_info->msg_index); | ||
281 | if (flags != NULL) { | ||
282 | msg_info->msg_flags = flags; | ||
283 | * result = msg_info->msg_flags; | ||
284 | return MAIL_NO_ERROR; | ||
285 | } | ||
286 | |||
287 | snprintf(filename_flags, PATH_MAX, "%s%c%s%c%s", | ||
288 | data->md_flags_directory, MAIL_DIR_SEPARATOR, data->md_quoted_mb, | ||
289 | MAIL_DIR_SEPARATOR, FLAGS_NAME); | ||
290 | |||
291 | r = mail_cache_db_open_lock(filename_flags, &cache_db_flags); | ||
292 | if (r < 0) | ||
293 | return MAIL_ERROR_FILE; | ||
294 | |||
295 | snprintf(keyname, PATH_MAX, "%s-flags", msg_info->msg_uid); | ||
296 | |||
297 | mmapstr = mmap_string_new(""); | ||
298 | if (mmapstr == NULL) { | ||
299 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
300 | return MAIL_ERROR_MEMORY; | ||
301 | } | ||
302 | |||
303 | r = generic_cache_flags_read(cache_db_flags, mmapstr, keyname, &flags); | ||
304 | mmap_string_free(mmapstr); | ||
305 | |||
306 | mail_cache_db_close_unlock(filename_flags, cache_db_flags); | ||
307 | |||
308 | if (r != MAIL_NO_ERROR) { | ||
309 | flags = mail_flags_new_empty(); | ||
310 | if (flags == NULL) | ||
311 | return MAIL_ERROR_MEMORY; | ||
312 | } | ||
313 | |||
314 | md = get_maildir_session(msg_info); | ||
315 | if (md == NULL) | ||
316 | return MAIL_ERROR_BAD_STATE; | ||
317 | |||
318 | key.data = msg_info->msg_uid; | ||
319 | key.len = strlen(msg_info->msg_uid); | ||
320 | r = chash_get(md->mdir_msg_hash, &key, &value); | ||
321 | if (r < 0) | ||
322 | return MAIL_ERROR_MSG_NOT_FOUND; | ||
323 | |||
324 | md_msg = value.data; | ||
325 | |||
326 | driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags); | ||
327 | |||
328 | flags->fl_flags = driver_flags; | ||
329 | msg_info->msg_flags = flags; | ||
330 | |||
331 | * result = msg_info->msg_flags; | ||
332 | |||
333 | return MAIL_NO_ERROR; | ||
334 | } | ||