comparison src/lib-storage/index/index-storage.c @ 175:73bf05a1d862 HEAD

Moved custom flags handling into lib-index.
author Timo Sirainen <tss@iki.fi>
date Sun, 08 Sep 2002 02:31:56 +0300
parents 4716cf66c2cc
children 95d21ab87eeb
comparison
equal deleted inserted replaced
174:61b0bb62b42e 175:73bf05a1d862
1 /* Copyright (C) 2002 Timo Sirainen */ 1 /* Copyright (C) 2002 Timo Sirainen */
2 2
3 #include "lib.h" 3 #include "lib.h"
4 #include "mail-index.h" 4 #include "mail-index.h"
5 #include "mail-index-util.h" 5 #include "mail-index-util.h"
6 #include "mail-custom-flags.h"
6 #include "index-storage.h" 7 #include "index-storage.h"
7 8
8 IndexMailbox *index_storage_init(MailStorage *storage, Mailbox *box, 9 IndexMailbox *index_storage_init(MailStorage *storage, Mailbox *box,
9 MailIndex *index, const char *name, 10 MailIndex *index, const char *name,
10 int readonly) 11 int readonly)
11 { 12 {
12 IndexMailbox *ibox; 13 IndexMailbox *ibox;
13 FlagsFile *flagsfile;
14 const char *path;
15 14
16 i_assert(name != NULL); 15 i_assert(name != NULL);
17 16
18 /* open the index first */ 17 /* open the index first */
19 if (!index->open_or_create(index, !readonly)) { 18 if (!index->open_or_create(index, !readonly)) {
20 mail_storage_set_internal_error(storage); 19 mail_storage_set_internal_error(storage);
21 index->free(index);
22 return NULL;
23 }
24
25 /* then flags file */
26 path = t_strconcat(index->dir, "/", FLAGS_FILE_NAME, NULL);
27 flagsfile = flags_file_open_or_create(storage, path);
28 if (flagsfile == NULL) {
29 index->free(index); 20 index->free(index);
30 return NULL; 21 return NULL;
31 } 22 }
32 23
33 ibox = i_new(IndexMailbox, 1); 24 ibox = i_new(IndexMailbox, 1);
36 ibox->box.storage = storage; 27 ibox->box.storage = storage;
37 ibox->box.name = i_strdup(name); 28 ibox->box.name = i_strdup(name);
38 ibox->box.readonly = readonly; 29 ibox->box.readonly = readonly;
39 30
40 ibox->index = index; 31 ibox->index = index;
41 ibox->flagsfile = flagsfile;
42 ibox->cache = imap_msgcache_alloc(&index_msgcache_iface); 32 ibox->cache = imap_msgcache_alloc(&index_msgcache_iface);
43 33
44 return ibox; 34 return ibox;
45 } 35 }
46 36
47 void index_storage_close(Mailbox *box) 37 void index_storage_close(Mailbox *box)
48 { 38 {
49 IndexMailbox *ibox = (IndexMailbox *) box; 39 IndexMailbox *ibox = (IndexMailbox *) box;
50 40
51 flags_file_destroy(ibox->flagsfile);
52 imap_msgcache_free(ibox->cache); 41 imap_msgcache_free(ibox->cache);
53 ibox->index->free(ibox->index); 42 ibox->index->free(ibox->index);
54 i_free(box->name); 43 i_free(box->name);
55 i_free(box); 44 i_free(box);
56 } 45 }
62 mail_storage_set_internal_error(ibox->box.storage); 51 mail_storage_set_internal_error(ibox->box.storage);
63 index_reset_error(ibox->index); 52 index_reset_error(ibox->index);
64 return FALSE; 53 return FALSE;
65 } 54 }
66 55
67 static MailFlags get_used_flags(void *context) 56 int index_mailbox_fix_custom_flags(IndexMailbox *ibox, MailFlags *flags,
57 const char *custom_flags[])
68 { 58 {
69 IndexMailbox *ibox = context; 59 int ret;
70 MailIndexRecord *rec;
71 MailFlags used_flags;
72 60
73 used_flags = 0; 61 ret = mail_custom_flags_fix_list(ibox->index->custom_flags,
74 62 flags, custom_flags);
75 rec = ibox->index->lookup(ibox->index, 1); 63 switch (ret) {
76 while (rec != NULL) { 64 case 1:
77 used_flags |= rec->msg_flags; 65 return TRUE;
78 rec = ibox->index->next(ibox->index, rec); 66 case 0:
67 mail_storage_set_error(ibox->box.storage, "Maximum number of "
68 "different custom flags exceeded");
69 return FALSE;
70 default:
71 return mail_storage_set_index_error(ibox);
79 } 72 }
80
81 return used_flags;
82 } 73 }
83
84 int index_mailbox_fix_custom_flags(IndexMailbox *ibox, MailFlags *flags,
85 const char *custom_flags[])
86 {
87 return flags_file_fix_custom_flags(ibox->flagsfile, flags,
88 custom_flags, get_used_flags, ibox);
89 }