Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/index-storage.c @ 106:5fe3e04ca8d9 HEAD
Added support for caching of MessagePart data. This is useful for fetching
body[part]s. Also BODY and BODYSTRUCTURE can be generated fast using it.
Also fixed index corruption in some situations when more cached data was
added to index.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 02 Sep 2002 05:31:18 +0300 |
parents | 306c20092a96 |
children | 0c3ffb677ad1 |
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
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
13 const char *path; |
0 | 14 |
15 i_assert(name != NULL); | |
16 | |
17 /* open the index first */ | |
18 if (!index->open_or_create(index, !readonly)) { | |
13
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
19 mail_storage_set_internal_error(storage); |
0 | 20 index->free(index); |
21 return NULL; | |
22 } | |
23 | |
24 /* then flags file */ | |
25 path = t_strconcat(index->dir, "/", FLAGS_FILE_NAME, NULL); | |
26 flagsfile = flags_file_open_or_create(storage, path); | |
27 if (flagsfile == NULL) { | |
28 index->free(index); | |
29 return NULL; | |
30 } | |
31 | |
32 ibox = i_new(IndexMailbox, 1); | |
33 ibox->box = *box; | |
34 | |
35 ibox->box.storage = storage; | |
36 ibox->box.name = i_strdup(name); | |
37 ibox->box.readonly = readonly; | |
38 | |
39 ibox->index = index; | |
40 ibox->flagsfile = flagsfile; | |
106
5fe3e04ca8d9
Added support for caching of MessagePart data. This is useful for fetching
Timo Sirainen <tss@iki.fi>
parents:
47
diff
changeset
|
41 ibox->cache = imap_msgcache_alloc(&index_msgcache_iface); |
0 | 42 |
43 return ibox; | |
44 } | |
45 | |
46 void index_storage_close(Mailbox *box) | |
47 { | |
48 IndexMailbox *ibox = (IndexMailbox *) box; | |
49 | |
50 flags_file_destroy(ibox->flagsfile); | |
51 imap_msgcache_free(ibox->cache); | |
52 ibox->index->free(ibox->index); | |
53 i_free(box->name); | |
54 i_free(box); | |
55 } | |
56 | |
57 int mail_storage_set_index_error(IndexMailbox *ibox) | |
58 { | |
59 ibox->box.inconsistent = | |
60 ibox->index->is_inconsistency_error(ibox->index); | |
13
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
61 mail_storage_set_internal_error(ibox->box.storage); |
0 | 62 return FALSE; |
63 } | |
64 | |
47
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
65 int index_messageset_foreach(IndexMailbox *ibox, |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
66 const char *messageset, int uidset, |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
67 MsgsetForeachFunc func, void *context) |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
68 { |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
69 const char *error; |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
70 int ret; |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
71 |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
72 if (uidset) { |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
73 ret = mail_index_uidset_foreach(ibox->index, messageset, |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
74 ibox->synced_messages_count, |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
75 func, context, &error); |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
76 } else { |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
77 ret = mail_index_messageset_foreach(ibox->index, messageset, |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
78 ibox->synced_messages_count, |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
79 func, context, &error); |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
80 } |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
81 |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
82 if (ret < 0) { |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
83 if (ret == -2) { |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
84 /* user error */ |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
85 mail_storage_set_error(ibox->box.storage, "%s", error); |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
86 } else { |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
87 mail_storage_set_index_error(ibox); |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
88 } |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
89 } |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
90 |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
91 return ret; |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
92 } |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
93 |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
13
diff
changeset
|
94 |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
95 static MailFlags get_used_flags(void *context) |
0 | 96 { |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
97 IndexMailbox *ibox = context; |
0 | 98 MailIndexRecord *rec; |
99 MailFlags used_flags; | |
100 | |
101 used_flags = 0; | |
102 | |
103 rec = ibox->index->lookup(ibox->index, 1); | |
104 while (rec != NULL) { | |
105 used_flags |= rec->msg_flags; | |
106 rec = ibox->index->next(ibox->index, rec); | |
107 } | |
108 | |
109 return used_flags; | |
110 } | |
111 | |
112 int index_mailbox_fix_custom_flags(IndexMailbox *ibox, MailFlags *flags, | |
113 const char *custom_flags[]) | |
114 { | |
115 return flags_file_fix_custom_flags(ibox->flagsfile, flags, | |
116 custom_flags, get_used_flags, ibox); | |
117 } |