Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/maildir/maildir-sync-index.c @ 5931:6371b2a7178f HEAD
Removed outdated FIXME comment
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 09 Jul 2007 04:31:46 +0300 |
parents | 7cbeeb953b92 |
children | 6ac8d6c93d34 |
rev | line source |
---|---|
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (C) 2007 Timo Sirainen */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "ioloop.h" |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "array.h" |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "maildir-storage.h" |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "index-sync-changes.h" |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "maildir-uidlist.h" |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "maildir-keywords.h" |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "maildir-filename.h" |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "maildir-sync.h" |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include <stdio.h> |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include <unistd.h> |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 struct maildir_index_sync_context { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 struct maildir_mailbox *mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 struct maildir_sync_context *maildir_sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 struct mail_index_view *view; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 struct mail_index_sync_ctx *sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 struct maildir_keywords_sync_ctx *keywords_sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 struct mail_index_transaction *trans; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 |
5924
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
25 struct maildir_uidlist_sync_ctx *uidlist_sync_ctx; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 struct index_sync_changes_context *sync_changes; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 enum mail_flags flags; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 ARRAY_TYPE(keyword_indexes) keywords; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 uint32_t seq, uid; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 bool changed; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 }; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 struct maildir_keywords_sync_ctx * |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 maildir_sync_get_keywords_sync_ctx(struct maildir_index_sync_context *ctx) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 return ctx->keywords_sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 static int maildir_expunge(struct maildir_mailbox *mbox, const char *path, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 struct maildir_index_sync_context *ctx) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 struct mailbox *box = &mbox->ibox.box; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 if (unlink(path) == 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 if (box->v.sync_notify != NULL) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 box->v.sync_notify(box, ctx->uid, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 MAILBOX_SYNC_TYPE_EXPUNGE); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 mail_index_expunge(ctx->trans, ctx->seq); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 ctx->changed = TRUE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 return 1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 if (errno == ENOENT) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 return 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 mail_storage_set_critical(&mbox->storage->storage, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 "unlink(%s) failed: %m", path); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 return -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 static int maildir_sync_flags(struct maildir_mailbox *mbox, const char *path, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 struct maildir_index_sync_context *ctx) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 struct mailbox *box = &mbox->ibox.box; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 const char *dir, *fname, *newfname, *newpath; |
5929 | 68 enum mailbox_sync_type sync_type; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 uint8_t flags8; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 fname = strrchr(path, '/'); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 i_assert(fname != NULL); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 fname++; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 dir = t_strdup_until(path, fname); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 /* get the current flags and keywords */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 maildir_filename_get_flags(ctx->keywords_sync_ctx, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 fname, &ctx->flags, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 /* apply changes */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 flags8 = ctx->flags; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 index_sync_changes_apply(ctx->sync_changes, NULL, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 &flags8, &ctx->keywords, &sync_type); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 ctx->flags = flags8; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 /* and try renaming with the new name */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 newfname = maildir_filename_set_flags(ctx->keywords_sync_ctx, fname, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 ctx->flags, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 newpath = t_strconcat(dir, newfname, NULL); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 if (rename(path, newpath) == 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 if (box->v.sync_notify != NULL) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 box->v.sync_notify(box, ctx->uid, sync_type); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 ctx->changed = TRUE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 return 1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 if (errno == ENOENT) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 return 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 if (!ENOSPACE(errno) && errno != EACCES) { |
5929 | 100 mail_storage_set_critical(box->storage, |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 "rename(%s, %s) failed: %m", path, newpath); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 return -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 |
5924
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
106 static void maildir_handle_uid_insertion(struct maildir_index_sync_context *ctx, |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
107 enum maildir_uidlist_rec_flag uflags, |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
108 const char *filename, uint32_t uid) |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
109 { |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
110 int ret; |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
111 |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
112 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
113 /* partial syncing */ |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
114 return; |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
115 } |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
116 |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
117 /* most likely a race condition: we read the maildir, then someone else |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
118 expunged messages and committed changes to index. so, this message |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
119 shouldn't actually exist. */ |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
120 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RACING) == 0) { |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
121 /* mark it racy and check in next sync */ |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
122 ctx->mbox->maildir_hdr.cur_check_time = 0; |
5924
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
123 maildir_uidlist_add_flags(ctx->mbox->uidlist, filename, |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
124 MAILDIR_UIDLIST_REC_FLAG_RACING); |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
125 return; |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
126 } |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
127 |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
128 if (ctx->uidlist_sync_ctx == NULL) { |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
129 ret = maildir_uidlist_sync_init(ctx->mbox->uidlist, |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
130 MAILDIR_UIDLIST_SYNC_PARTIAL, |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
131 &ctx->uidlist_sync_ctx); |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
132 i_assert(ret > 0); |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
133 } |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
134 |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
135 uflags &= (MAILDIR_UIDLIST_REC_FLAG_NEW_DIR | |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
136 MAILDIR_UIDLIST_REC_FLAG_RECENT); |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
137 maildir_uidlist_sync_remove(ctx->uidlist_sync_ctx, filename); |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
138 ret = maildir_uidlist_sync_next(ctx->uidlist_sync_ctx, |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
139 filename, uflags); |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
140 i_assert(ret > 0); |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
141 |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
142 /* give the new UID to it immediately */ |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
143 maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx); |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
144 |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
145 i_warning("Maildir %s: Expunged message reappeared, giving a new UID " |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
146 "(old uid=%u, file=%s)", ctx->mbox->path, uid, filename); |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
147 } |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
148 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 int maildir_sync_index_begin(struct maildir_mailbox *mbox, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 struct maildir_sync_context *maildir_sync_ctx, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 struct maildir_index_sync_context **ctx_r) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 struct maildir_index_sync_context *ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 struct mail_index_sync_ctx *sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 struct mail_index_view *view; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 struct mail_index_transaction *trans; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 if (mail_index_sync_begin(mbox->ibox.index, &sync_ctx, &view, &trans, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 (uint32_t)-1, (uoff_t)-1, 0) <= 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 mail_storage_set_index_error(&mbox->ibox); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 return -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 ctx = i_new(struct maildir_index_sync_context, 1); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 ctx->mbox = mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 ctx->maildir_sync_ctx = maildir_sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 ctx->sync_ctx = sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 ctx->view = view; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 ctx->trans = trans; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 ctx->keywords_sync_ctx = |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 maildir_keywords_sync_init(mbox->keywords, mbox->ibox.index); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 ctx->sync_changes = index_sync_changes_init(&mbox->ibox, ctx->sync_ctx, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 ctx->view, ctx->trans, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 mbox->ibox.readonly); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 *ctx_r = ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 return 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 int maildir_sync_index_finish(struct maildir_index_sync_context **_ctx, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
182 bool failed, bool cancel) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 struct maildir_index_sync_context *ctx = *_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 struct maildir_mailbox *mbox = ctx->mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 int ret = failed ? -1 : 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 *_ctx = NULL; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 if (ret < 0 || cancel) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 mail_index_sync_rollback(&ctx->sync_ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 else { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 /* Set syncing_commit=TRUE so that if any sync callbacks try |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 to access mails which got lost (eg. expunge callback trying |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 to open the file which was just unlinked) we don't try to |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 start a second index sync and crash. */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 mbox->syncing_commit = TRUE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 if (mail_index_sync_commit(&ctx->sync_ctx) < 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 mail_storage_set_index_error(&mbox->ibox); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 ret = -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 } else { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 mbox->ibox.commit_log_file_seq = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 mbox->ibox.commit_log_file_offset = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 mbox->syncing_commit = FALSE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 maildir_keywords_sync_deinit(ctx->keywords_sync_ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 ctx->keywords_sync_ctx = NULL; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 index_sync_changes_deinit(&ctx->sync_changes); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 i_free(ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 return ret; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 |
5927
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
216 static void |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
217 maildir_index_update_ext_header(struct maildir_mailbox *mbox, |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
218 struct mail_index_transaction *trans) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
219 { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
220 const void *data; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
221 size_t data_size; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
222 |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
223 if (mail_index_get_header_ext(mbox->ibox.view, mbox->maildir_ext_id, |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
224 &data, &data_size) < 0) |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
225 data_size = 0; |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
226 |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
227 if (data_size == sizeof(mbox->maildir_hdr) && |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
228 memcmp(data, &mbox->maildir_hdr, data_size) == 0) { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
229 /* nothing changed */ |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
230 } else { |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
231 mail_index_update_header_ext(trans, mbox->maildir_ext_id, 0, |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
232 &mbox->maildir_hdr, |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
233 sizeof(mbox->maildir_hdr)); |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
234 } |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
235 } |
b9865213da42
Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents:
5924
diff
changeset
|
236 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 int maildir_sync_index(struct maildir_index_sync_context *ctx, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 bool partial) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 struct maildir_mailbox *mbox = ctx->mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 struct mail_index_view *view = ctx->view; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 struct maildir_uidlist_iter_ctx *iter; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 struct mail_index_transaction *trans = ctx->trans; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 const struct mail_index_header *hdr; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 struct mail_index_header empty_hdr; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 const struct mail_index_record *rec; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 uint32_t seq, uid, prev_uid; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 enum maildir_uidlist_rec_flag uflags; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 const char *filename; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 ARRAY_TYPE(keyword_indexes) idx_keywords; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 uint32_t uid_validity, next_uid; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 unsigned int changes = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 int ret = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 bool expunged, full_rescan = FALSE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 i_assert(!mbox->syncing_commit); |
5930 | 257 i_assert(maildir_uidlist_is_locked(mbox->uidlist)); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 hdr = mail_index_get_header(view); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 uid_validity = maildir_uidlist_get_uid_validity(mbox->uidlist); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 if (uid_validity != hdr->uid_validity && |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 uid_validity != 0 && hdr->uid_validity != 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 /* uidvalidity changed and mailbox isn't being initialized, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 reset mailbox so we can add all messages as new */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 i_warning("Maildir %s: UIDVALIDITY changed (%u -> %u)", |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 mbox->path, hdr->uid_validity, uid_validity); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 mail_index_reset(trans); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 memset(&empty_hdr, 0, sizeof(empty_hdr)); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 empty_hdr.next_uid = 1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 hdr = &empty_hdr; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 mbox->syncing_commit = TRUE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 seq = prev_uid = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 t_array_init(&ctx->keywords, MAILDIR_MAX_KEYWORDS); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 t_array_init(&idx_keywords, MAILDIR_MAX_KEYWORDS); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 iter = maildir_uidlist_iter_init(mbox->uidlist); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 while (maildir_uidlist_iter_next(iter, &uid, &uflags, &filename)) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 maildir_filename_get_flags(ctx->keywords_sync_ctx, filename, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 &ctx->flags, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 i_assert(uid > prev_uid); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 prev_uid = uid; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 /* the private flags are kept only in indexes. don't use them |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 at all even for newly seen mails */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 ctx->flags &= ~mbox->private_flags_mask; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RECENT) != 0 && |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 (uflags & MAILDIR_UIDLIST_REC_FLAG_NEW_DIR) != 0 && |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 (uflags & MAILDIR_UIDLIST_REC_FLAG_MOVED) == 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 /* mail is recent for next session as well */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
294 ctx->flags |= MAIL_RECENT; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
295 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
296 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 __again: |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 ctx->seq = ++seq; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 ctx->uid = uid; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
300 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 if (seq > hdr->messages_count) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 if (uid < hdr->next_uid) { |
5924
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
303 maildir_handle_uid_insertion(ctx, uflags, |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
304 filename, uid); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 seq--; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 mail_index_append(trans, uid, &seq); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 mail_index_update_flags(trans, seq, MODIFY_REPLACE, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 ctx->flags); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 if (array_count(&ctx->keywords) > 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 struct mail_keywords *kw; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 kw = mail_index_keywords_create_from_indexes( |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 trans, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 mail_index_update_keywords(trans, seq, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 MODIFY_REPLACE, kw); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 mail_index_keywords_free(&kw); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 if (mail_index_lookup(view, seq, &rec) < 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 mail_storage_set_index_error(&mbox->ibox); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
327 ret = -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 break; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
329 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
330 |
5924
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
331 if (uid > rec->uid) { |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 /* expunged */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 mail_index_expunge(trans, seq); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 goto __again; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
335 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 |
5924
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
337 if (uid < rec->uid) { |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
338 maildir_handle_uid_insertion(ctx, uflags, |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
339 filename, uid); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
340 seq--; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
341 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
343 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
344 if (index_sync_changes_read(ctx->sync_changes, rec->uid, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
345 &expunged) < 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
346 ret = -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
347 break; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
348 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
349 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
350 if (expunged) { |
5930 | 351 if (maildir_file_do(mbox, ctx->uid, |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
352 maildir_expunge, ctx) >= 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
353 /* successful expunge */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
354 mail_index_expunge(trans, ctx->seq); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
355 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
356 if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 maildir_sync_notify(ctx->maildir_sync_ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
358 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
359 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
361 /* the private flags are stored only in indexes, keep them */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
362 ctx->flags |= rec->flags & mbox->private_flags_mask; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
363 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
364 if ((rec->flags & MAIL_RECENT) != 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
365 index_mailbox_set_recent(&mbox->ibox, seq); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
366 if (mbox->ibox.keep_recent) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 ctx->flags |= MAIL_RECENT; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 } else { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
369 mail_index_update_flags(trans, seq, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
370 MODIFY_REMOVE, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
371 MAIL_RECENT); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
372 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
376 /* partial syncing */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
377 if ((ctx->flags & MAIL_RECENT) != 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
378 /* we last saw this mail in new/, but it's |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
379 not there anymore. possibly expunged, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 make sure. */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
381 full_rescan = TRUE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
385 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
386 if (index_sync_changes_have(ctx->sync_changes)) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 /* apply flag changes to maildir */ |
5930 | 388 if (maildir_file_do(mbox, ctx->uid, |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 maildir_sync_flags, ctx) < 0) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 ctx->flags |= MAIL_INDEX_MAIL_FLAG_DIRTY; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 maildir_sync_notify(ctx->maildir_sync_ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
393 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
394 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
395 if ((rec->flags & MAIL_INDEX_MAIL_FLAG_DIRTY) != 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
396 /* we haven't been able to update maildir with this |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 record's flag changes. don't sync them. */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
398 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
399 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
400 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
401 if ((ctx->flags & ~MAIL_RECENT) != |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
402 (rec->flags & (MAIL_FLAGS_MASK^MAIL_RECENT))) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
403 mail_index_update_flags(trans, seq, MODIFY_REPLACE, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
404 ctx->flags); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 } else if ((ctx->flags & MAIL_RECENT) == 0 && |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
406 (rec->flags & MAIL_RECENT) != 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
407 /* just remove recent flag */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
408 mail_index_update_flags(trans, seq, MODIFY_REMOVE, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
409 MAIL_RECENT); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
410 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 /* update keywords if they have changed */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
413 if (mail_index_lookup_keywords(view, seq, &idx_keywords) < 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
414 mail_storage_set_index_error(&mbox->ibox); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
415 ret = -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
416 break; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
417 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
418 if (!index_keyword_array_cmp(&ctx->keywords, &idx_keywords)) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
419 struct mail_keywords *kw; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
420 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
421 kw = mail_index_keywords_create_from_indexes( |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
422 trans, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
423 mail_index_update_keywords(trans, seq, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
424 MODIFY_REPLACE, kw); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
425 mail_index_keywords_free(&kw); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
426 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
427 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
428 maildir_uidlist_iter_deinit(iter); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
429 mbox->syncing_commit = FALSE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 |
5924
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
431 if (ctx->uidlist_sync_ctx != NULL) { |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
432 if (maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx) < 0) |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
433 ret = -1; |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
434 } |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
435 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
436 if (mbox->ibox.box.v.sync_notify != NULL) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 mbox->ibox.box.v.sync_notify(&mbox->ibox.box, 0, 0); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 if (!partial) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 /* expunge the rest */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
441 for (seq++; seq <= hdr->messages_count; seq++) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 mail_index_expunge(trans, seq); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
444 /* next_uid must be updated only in non-partial syncs since |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 partial syncs don't add the new mails to index. also we'll |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
446 have to do it here before syncing index records, since after |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
447 that the uidlist's next_uid value may have changed. */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 next_uid = maildir_uidlist_get_next_uid(mbox->uidlist); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
449 i_assert(next_uid > prev_uid); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
450 if (hdr->next_uid < next_uid) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 mail_index_update_header(trans, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 offsetof(struct mail_index_header, next_uid), |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 &next_uid, sizeof(next_uid), FALSE); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
454 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
456 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
457 if (ctx->changed) |
5930 | 458 mbox->maildir_hdr.cur_mtime = time(NULL); |
459 maildir_index_update_ext_header(mbox, trans); | |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
460 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
461 if (hdr->uid_validity == 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 /* get the initial uidvalidity */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 uid_validity = maildir_uidlist_get_uid_validity(mbox->uidlist); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 if (uid_validity == 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
465 uid_validity = ioloop_time; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
466 maildir_uidlist_set_uid_validity(mbox->uidlist, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 uid_validity, 0); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 } else if (uid_validity == 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
470 maildir_uidlist_set_uid_validity(mbox->uidlist, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 hdr->uid_validity, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 hdr->next_uid); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
474 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
475 if (uid_validity != hdr->uid_validity && uid_validity != 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 mail_index_update_header(trans, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 offsetof(struct mail_index_header, uid_validity), |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 &uid_validity, sizeof(uid_validity), TRUE); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
481 return ret < 0 ? -1 : (full_rescan ? 0 : 1); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
482 } |