Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/index-update-flags.c @ 327:276b7a53c264 HEAD
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
numbers when some in the middle were externally deleted.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 29 Sep 2002 19:19:53 +0300 |
parents | 9be2c12d0983 |
children | 925d6eb5f8be |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "lib.h" | |
4 #include "index-storage.h" | |
171
4716cf66c2cc
Moved lib-index/mail-messageset.* to lib-storage/index/index-messageset.*.
Timo Sirainen <tss@iki.fi>
parents:
47
diff
changeset
|
5 #include "index-messageset.h" |
175
73bf05a1d862
Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents:
171
diff
changeset
|
6 #include "mail-custom-flags.h" |
0 | 7 |
8 typedef struct { | |
9 Mailbox *box; | |
175
73bf05a1d862
Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents:
171
diff
changeset
|
10 MailCustomFlags *custom_flags; |
0 | 11 MailFlags flags; |
12 ModifyType modify_type; | |
13 MailFlagUpdateFunc func; | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
14 void *context; |
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
15 } UpdateContext; |
0 | 16 |
17 static int update_func(MailIndex *index, MailIndexRecord *rec, | |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
273
diff
changeset
|
18 unsigned int client_seq, unsigned int idx_seq, |
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
273
diff
changeset
|
19 void *context) |
0 | 20 { |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
21 UpdateContext *ctx = context; |
0 | 22 MailFlags flags; |
23 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
24 switch (ctx->modify_type) { |
0 | 25 case MODIFY_ADD: |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
26 flags = rec->msg_flags | ctx->flags; |
0 | 27 break; |
28 case MODIFY_REMOVE: | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
29 flags = rec->msg_flags & ~ctx->flags; |
0 | 30 break; |
31 case MODIFY_REPLACE: | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
32 flags = ctx->flags; |
0 | 33 break; |
34 default: | |
35 flags = 0; | |
36 i_assert(0); | |
37 } | |
38 | |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
273
diff
changeset
|
39 if (!index->update_flags(index, rec, idx_seq, flags, FALSE)) |
268
7cb03d43a0ea
Don't save \Recent flag to index.
Timo Sirainen <tss@iki.fi>
parents:
175
diff
changeset
|
40 return FALSE; |
7cb03d43a0ea
Don't save \Recent flag to index.
Timo Sirainen <tss@iki.fi>
parents:
175
diff
changeset
|
41 |
0 | 42 if (rec->uid >= index->first_recent_uid) |
43 flags |= MAIL_RECENT; | |
44 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
45 if (ctx->func != NULL) { |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
273
diff
changeset
|
46 ctx->func(ctx->box, client_seq, rec->uid, flags, |
175
73bf05a1d862
Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents:
171
diff
changeset
|
47 mail_custom_flags_list_get(ctx->custom_flags), |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
48 ctx->context); |
175
73bf05a1d862
Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents:
171
diff
changeset
|
49 mail_custom_flags_list_unref(ctx->custom_flags); |
0 | 50 } |
51 return TRUE; | |
52 } | |
53 | |
54 int index_storage_update_flags(Mailbox *box, const char *messageset, int uidset, | |
55 MailFlags flags, const char *custom_flags[], | |
56 ModifyType modify_type, | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
57 MailFlagUpdateFunc func, void *context, |
0 | 58 int *all_found) |
59 { | |
60 IndexMailbox *ibox = (IndexMailbox *) box; | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
61 UpdateContext ctx; |
0 | 62 int ret; |
63 | |
64 if (box->readonly) { | |
65 mail_storage_set_error(box->storage, "Mailbox is read-only"); | |
66 return FALSE; | |
67 } | |
68 | |
273
9be2c12d0983
STORE needs to sync too, or maildir could see old filenames.
Timo Sirainen <tss@iki.fi>
parents:
268
diff
changeset
|
69 if (!index_storage_sync_if_possible(ibox)) |
9be2c12d0983
STORE needs to sync too, or maildir could see old filenames.
Timo Sirainen <tss@iki.fi>
parents:
268
diff
changeset
|
70 return FALSE; |
9be2c12d0983
STORE needs to sync too, or maildir could see old filenames.
Timo Sirainen <tss@iki.fi>
parents:
268
diff
changeset
|
71 |
0 | 72 if (!index_mailbox_fix_custom_flags(ibox, &flags, custom_flags)) |
175
73bf05a1d862
Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents:
171
diff
changeset
|
73 return FALSE; |
0 | 74 |
75 if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_EXCLUSIVE)) | |
76 return mail_storage_set_index_error(ibox); | |
77 | |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
78 ctx.box = box; |
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
79 ctx.flags = flags & ~MAIL_RECENT; /* \Recent can't be changed */ |
175
73bf05a1d862
Moved custom flags handling into lib-index.
Timo Sirainen <tss@iki.fi>
parents:
171
diff
changeset
|
80 ctx.custom_flags = ibox->index->custom_flags; |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
81 ctx.modify_type = modify_type; |
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
82 ctx.func = func; |
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
83 ctx.context = context; |
0 | 84 |
47
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
85 ret = index_messageset_foreach(ibox, messageset, uidset, |
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
86 update_func, &ctx); |
0 | 87 |
47
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
88 if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_UNLOCK)) |
0 | 89 return mail_storage_set_index_error(ibox); |
90 | |
91 if (all_found != NULL) | |
92 *all_found = ret == 1; | |
47
306c20092a96
Errors in user-specified messagesets are now properly reported back to user.
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
93 return ret >= 0; |
0 | 94 } |