Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/index-storage.c @ 10:82b7de533f98 HEAD
s/user_data/context/ and some s/Data/Context/
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 22 Aug 2002 15:48:38 +0300 |
parents | 3b1985cbc908 |
children | bb294faf7379 |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "lib.h" | |
4 #include "mail-index.h" | |
5 #include "index-storage.h" | |
6 | |
7 IndexMailbox *index_storage_init(MailStorage *storage, Mailbox *box, | |
8 MailIndex *index, const char *name, | |
9 int readonly) | |
10 { | |
11 IndexMailbox *ibox; | |
12 FlagsFile *flagsfile; | |
13 const char *path, *error; | |
14 | |
15 i_assert(name != NULL); | |
16 | |
17 /* open the index first */ | |
18 if (!index->open_or_create(index, !readonly)) { | |
19 error = index->get_last_error(index); | |
20 if (error == NULL) | |
21 error = "(maildir_open)"; | |
22 mail_storage_set_error(storage, "%s", error); | |
23 | |
24 index->free(index); | |
25 return NULL; | |
26 } | |
27 | |
28 /* then flags file */ | |
29 path = t_strconcat(index->dir, "/", FLAGS_FILE_NAME, NULL); | |
30 flagsfile = flags_file_open_or_create(storage, path); | |
31 if (flagsfile == NULL) { | |
32 index->free(index); | |
33 return NULL; | |
34 } | |
35 | |
36 ibox = i_new(IndexMailbox, 1); | |
37 ibox->box = *box; | |
38 | |
39 ibox->box.storage = storage; | |
40 ibox->box.name = i_strdup(name); | |
41 ibox->box.readonly = readonly; | |
42 | |
43 ibox->index = index; | |
44 ibox->flagsfile = flagsfile; | |
45 ibox->cache = imap_msgcache_alloc(); | |
46 | |
47 return ibox; | |
48 } | |
49 | |
50 void index_storage_close(Mailbox *box) | |
51 { | |
52 IndexMailbox *ibox = (IndexMailbox *) box; | |
53 | |
54 flags_file_destroy(ibox->flagsfile); | |
55 imap_msgcache_free(ibox->cache); | |
56 ibox->index->free(ibox->index); | |
57 i_free(box->name); | |
58 i_free(box); | |
59 } | |
60 | |
61 int mail_storage_set_index_error(IndexMailbox *ibox) | |
62 { | |
63 const char *error; | |
64 | |
65 error = ibox->index->get_last_error(ibox->index); | |
66 if (error == NULL) | |
67 error = "(no error message)"; | |
68 | |
69 ibox->box.inconsistent = | |
70 ibox->index->is_inconsistency_error(ibox->index); | |
71 mail_storage_set_error(ibox->box.storage, "%s", error); | |
72 return FALSE; | |
73 } | |
74 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
75 static MailFlags get_used_flags(void *context) |
0 | 76 { |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
77 IndexMailbox *ibox = context; |
0 | 78 MailIndexRecord *rec; |
79 MailFlags used_flags; | |
80 | |
81 used_flags = 0; | |
82 | |
83 rec = ibox->index->lookup(ibox->index, 1); | |
84 while (rec != NULL) { | |
85 used_flags |= rec->msg_flags; | |
86 rec = ibox->index->next(ibox->index, rec); | |
87 } | |
88 | |
89 return used_flags; | |
90 } | |
91 | |
92 int index_mailbox_fix_custom_flags(IndexMailbox *ibox, MailFlags *flags, | |
93 const char *custom_flags[]) | |
94 { | |
95 return flags_file_fix_custom_flags(ibox->flagsfile, flags, | |
96 custom_flags, get_used_flags, ibox); | |
97 } |