annotate src/lib-storage/index/maildir/maildir-sync-index.c @ 6062:8341db7a1698 HEAD

Moved mailbox list index sync stamp checking and updating to storage-specific code.
author Timo Sirainen <tss@iki.fi>
date Wed, 18 Jul 2007 06:17:47 +0300
parents 8a9b077d503e
children d5d3adb86e12
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
30 uint32_t seq, uid;
5920
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
073dfd42d4e7 minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 5927
diff changeset
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
073dfd42d4e7 minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 5927
diff changeset
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,
6028
68be663e79ec Fixed reassigning new UIDs to more than one message.
Timo Sirainen <tss@iki.fi>
parents: 5983
diff changeset
130 MAILDIR_UIDLIST_SYNC_PARTIAL |
68be663e79ec Fixed reassigning new UIDs to more than one message.
Timo Sirainen <tss@iki.fi>
parents: 5983
diff changeset
131 MAILDIR_UIDLIST_SYNC_KEEP_STATE,
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
132 &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
133 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
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
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
136 uflags &= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR;
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
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;
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
157 enum mail_index_sync_flags sync_flags;
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
158
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
159 sync_flags = 0;
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
160 /* don't drop recent messages if we're saving messages */
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
161 if (!mbox->ibox.keep_recent && maildir_sync_ctx != NULL)
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
162 sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT;
5920
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 if (mail_index_sync_begin(mbox->ibox.index, &sync_ctx, &view, &trans,
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
165 (uint32_t)-1, (uoff_t)-1, sync_flags) <= 0) {
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 mail_storage_set_index_error(&mbox->ibox);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 return -1;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 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
171 ctx->mbox = mbox;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 ctx->maildir_sync_ctx = maildir_sync_ctx;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 ctx->sync_ctx = sync_ctx;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 ctx->view = view;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 ctx->trans = trans;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 ctx->keywords_sync_ctx =
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 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
178
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 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
180 ctx->view, ctx->trans,
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 mbox->ibox.readonly);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 *ctx_r = ctx;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 return 0;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 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
188 bool failed, bool cancel)
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 struct maildir_index_sync_context *ctx = *_ctx;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 struct maildir_mailbox *mbox = ctx->mbox;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
192 int ret = failed ? -1 : 0;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 *_ctx = NULL;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196 if (ret < 0 || cancel)
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197 mail_index_sync_rollback(&ctx->sync_ctx);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198 else {
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199 /* 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
200 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
201 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
202 start a second index sync and crash. */
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203 mbox->syncing_commit = TRUE;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
204 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
205 mail_storage_set_index_error(&mbox->ibox);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 ret = -1;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207 } else {
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
208 mbox->ibox.commit_log_file_seq = 0;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209 mbox->ibox.commit_log_file_offset = 0;
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 mbox->syncing_commit = FALSE;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
214 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
215 ctx->keywords_sync_ctx = NULL;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 index_sync_changes_deinit(&ctx->sync_changes);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 i_free(ctx);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219 return ret;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
221
5927
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
222 static void
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
223 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
224 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
225 {
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
226 const void *data;
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
227 size_t data_size;
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
228
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
229 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
230 &data, &data_size) < 0)
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
231 data_size = 0;
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
232
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
233 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
234 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
235 /* nothing changed */
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
236 } else {
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
237 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
238 &mbox->maildir_hdr,
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
239 sizeof(mbox->maildir_hdr));
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
240 }
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
241 }
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
242
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
243 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
244 bool partial)
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245 {
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246 struct maildir_mailbox *mbox = ctx->mbox;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
247 struct mail_index_view *view = ctx->view;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248 struct maildir_uidlist_iter_ctx *iter;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
249 struct mail_index_transaction *trans = ctx->trans;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 const struct mail_index_header *hdr;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251 struct mail_index_header empty_hdr;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252 const struct mail_index_record *rec;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 uint32_t seq, uid, prev_uid;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254 enum maildir_uidlist_rec_flag uflags;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255 const char *filename;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 ARRAY_TYPE(keyword_indexes) idx_keywords;
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
257 uint32_t uid_validity, next_uid, hdr_next_uid, last_nonrecent_uid;
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
258 unsigned int changes = 0;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259 int ret = 0;
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
260 bool recent, expunged, full_rescan = FALSE;
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262 i_assert(!mbox->syncing_commit);
5930
7cbeeb953b92 minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 5929
diff changeset
263 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
264
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 hdr = mail_index_get_header(view);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266 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
267 if (uid_validity != hdr->uid_validity &&
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
268 uid_validity != 0 && hdr->uid_validity != 0) {
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
269 /* uidvalidity changed and index isn't being synced for the
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
270 first time, reset the index so we can add all messages as
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
271 new */
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
272 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
273 mbox->path, hdr->uid_validity, uid_validity);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 mail_index_reset(trans);
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
275 maildir_uidlist_set_next_uid(mbox->uidlist, 1, TRUE);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 memset(&empty_hdr, 0, sizeof(empty_hdr));
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278 empty_hdr.next_uid = 1;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
279 hdr = &empty_hdr;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
280 }
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
281 hdr_next_uid = hdr->next_uid;
5920
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 mbox->syncing_commit = TRUE;
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
284 seq = prev_uid = last_nonrecent_uid = 0;
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
285 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
286 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
287 iter = maildir_uidlist_iter_init(mbox->uidlist);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288 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
289 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
290 &ctx->flags, &ctx->keywords);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292 i_assert(uid > prev_uid);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293 prev_uid = uid;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
294
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295 /* 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
296 at all even for newly seen mails */
6052
8a9b077d503e Moved private_flags_mask to struct mailbox.
Timo Sirainen <tss@iki.fi>
parents: 6038
diff changeset
297 ctx->flags &= ~mbox->ibox.box.private_flags_mask;
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
298
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299 __again:
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
300 ctx->seq = ++seq;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301 ctx->uid = uid;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
302
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
303 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RECENT) == 0 &&
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
304 (uflags & MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) == 0)
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
305 last_nonrecent_uid = uid;
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
306 recent = (uflags & MAILDIR_UIDLIST_REC_FLAG_RECENT) != 0 &&
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
307 uid >= hdr->first_recent_uid;
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
308
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309 if (seq > hdr->messages_count) {
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
310 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
311 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
312 filename, uid);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
313 seq--;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314 continue;
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
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
317 hdr_next_uid = uid + 1;
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
318 mail_index_append(trans, uid, &seq);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319 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
320 ctx->flags);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
321 if (array_count(&ctx->keywords) > 0) {
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
322 struct mail_keywords *kw;
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 kw = mail_index_keywords_create_from_indexes(
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325 trans, &ctx->keywords);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326 mail_index_update_keywords(trans, seq,
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
327 MODIFY_REPLACE, kw);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
328 mail_index_keywords_free(&kw);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329 }
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
330 if (recent)
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
331 index_mailbox_set_recent_uid(&mbox->ibox, uid);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
332 continue;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 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
336 mail_storage_set_index_error(&mbox->ibox);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337 ret = -1;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 break;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340
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
341 if (uid > rec->uid) {
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
342 /* expunged */
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
343 mail_index_expunge(trans, seq);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344 goto __again;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346
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
347 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
348 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
349 filename, uid);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350 seq--;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
351 continue;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
352 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354 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
355 &expunged) < 0) {
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
356 ret = -1;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
357 break;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
358 }
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 if (expunged) {
5930
7cbeeb953b92 minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 5929
diff changeset
361 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
362 maildir_expunge, ctx) >= 0) {
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
363 /* successful expunge */
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
364 mail_index_expunge(trans, seq);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
365 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
366 if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0)
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367 maildir_sync_notify(ctx->maildir_sync_ctx);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
368 continue;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
369 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
370
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
371 if (recent)
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
372 index_mailbox_set_recent_uid(&mbox->ibox, uid);
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
373
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374 /* the private flags are stored only in indexes, keep them */
6052
8a9b077d503e Moved private_flags_mask to struct mailbox.
Timo Sirainen <tss@iki.fi>
parents: 6038
diff changeset
375 ctx->flags |= rec->flags & mbox->ibox.box.private_flags_mask;
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377 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
378 /* partial syncing */
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
379 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_NEW_DIR) != 0) {
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380 /* 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
381 not there anymore. possibly expunged,
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382 make sure. */
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383 full_rescan = TRUE;
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 continue;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
386 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388 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
389 /* apply flag changes to maildir */
5930
7cbeeb953b92 minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 5929
diff changeset
390 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
391 maildir_sync_flags, ctx) < 0)
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
392 ctx->flags |= MAIL_INDEX_MAIL_FLAG_DIRTY;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
393 if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0)
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
394 maildir_sync_notify(ctx->maildir_sync_ctx);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
395 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 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
398 /* 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
399 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
400 continue;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
401 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
403 if (ctx->flags != (rec->flags & MAIL_FLAGS_NONRECENT)) {
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
404 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
405 ctx->flags);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
406 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
407
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
408 /* update keywords if they have changed */
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
409 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
410 mail_storage_set_index_error(&mbox->ibox);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411 ret = -1;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 break;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
413 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
414 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
415 struct mail_keywords *kw;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417 kw = mail_index_keywords_create_from_indexes(
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
418 trans, &ctx->keywords);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
419 mail_index_update_keywords(trans, seq,
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
420 MODIFY_REPLACE, kw);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
421 mail_index_keywords_free(&kw);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
422 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
423 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
424 maildir_uidlist_iter_deinit(iter);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
425 mbox->syncing_commit = FALSE;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
426
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
427 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
428 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
429 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
430 }
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
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 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
433 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
434
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 if (!partial) {
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 /* expunge the rest */
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 for (seq++; seq <= hdr->messages_count; seq++)
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 mail_index_expunge(trans, seq);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
439 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
441 if (ctx->changed)
5930
7cbeeb953b92 minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 5929
diff changeset
442 mbox->maildir_hdr.cur_mtime = time(NULL);
7cbeeb953b92 minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 5929
diff changeset
443 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
444
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
445 if (uid_validity == 0) {
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
446 uid_validity = hdr->uid_validity != 0 ?
5983
272796cfee66 compiler warning fixes
Timo Sirainen <tss@iki.fi>
parents: 5932
diff changeset
447 hdr->uid_validity : (uint32_t)ioloop_time;
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
448 maildir_uidlist_set_uid_validity(mbox->uidlist, uid_validity);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
449 }
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
450 maildir_uidlist_set_next_uid(mbox->uidlist, hdr_next_uid, FALSE);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
452 if (uid_validity != hdr->uid_validity) {
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
453 mail_index_update_header(trans,
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454 offsetof(struct mail_index_header, uid_validity),
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 &uid_validity, sizeof(uid_validity), TRUE);
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
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
458 next_uid = maildir_uidlist_get_next_uid(mbox->uidlist);
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
459 if (hdr_next_uid < next_uid) {
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
460 mail_index_update_header(trans,
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
461 offsetof(struct mail_index_header, next_uid),
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
462 &next_uid, sizeof(next_uid), FALSE);
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
463 }
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
464
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
465 if (ctx->mbox->ibox.keep_recent &&
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
466 hdr->first_recent_uid < last_nonrecent_uid + 1) {
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
467 uint32_t first_recent_uid = last_nonrecent_uid + 1;
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
468
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
469 mail_index_update_header(ctx->trans,
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
470 offsetof(struct mail_index_header, first_recent_uid),
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
471 &first_recent_uid, sizeof(first_recent_uid), FALSE);
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
472 }
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 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
474 }
6062
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
475
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
476 static unsigned int maildir_list_get_ext_id(struct maildir_storage *storage,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
477 struct mail_index_view *view)
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
478 {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
479 if (storage->maildir_list_ext_id == (uint32_t)-1) {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
480 storage->maildir_list_ext_id =
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
481 mail_index_ext_register(mail_index_view_get_index(view),
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
482 "maildir", 0,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
483 sizeof(struct maildir_list_index_record),
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
484 sizeof(uint32_t));
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
485 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
486 return storage->maildir_list_ext_id;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
487 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
488
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
489 int maildir_list_index_has_changed(struct mailbox *box,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
490 struct mail_index_view *list_view,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
491 uint32_t seq)
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
492 {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
493 struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
494 const struct maildir_list_index_record *rec;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
495 const void *data;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
496 const char *root_dir, *new_dir, *cur_dir;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
497 struct stat st;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
498 uint32_t ext_id;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
499
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
500 ext_id = maildir_list_get_ext_id(mbox->storage, list_view);
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
501 if (mail_index_lookup_ext(list_view, seq, ext_id, &data) <= 0)
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
502 return -1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
503 rec = data;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
504
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
505 if (rec == NULL || rec->new_mtime == 0 || rec->cur_mtime == 0) {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
506 /* doesn't exist, not synced or dirty-synced */
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
507 return 1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
508 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
509
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
510 root_dir = mailbox_list_get_path(mail_storage_get_list(box->storage),
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
511 box->name,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
512 MAILBOX_LIST_PATH_TYPE_MAILBOX);
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
513
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
514 /* check if new/ changed */
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
515 new_dir = t_strconcat(root_dir, "/new", NULL);
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
516 if (stat(new_dir, &st) < 0) {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
517 mail_storage_set_critical(box->storage,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
518 "stat(%s) failed: %m", new_dir);
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
519 return -1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
520 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
521 if (rec->new_mtime != st.st_mtime)
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
522 return 1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
523
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
524 /* check if cur/ changed */
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
525 cur_dir = t_strconcat(root_dir, "/cur", NULL);
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
526 if (stat(cur_dir, &st) < 0) {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
527 mail_storage_set_critical(box->storage,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
528 "stat(%s) failed: %m", cur_dir);
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
529 return -1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
530 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
531 if (rec->cur_mtime != st.st_mtime)
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
532 return 1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
533 return 0;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
534 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
535
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
536 int maildir_list_index_update_sync(struct mailbox *box,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
537 struct mail_index_transaction *trans,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
538 uint32_t seq)
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
539 {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
540 struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
541 struct mail_index_view *list_view;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
542 const struct maildir_index_header *mhdr = &mbox->maildir_hdr;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
543 const struct maildir_list_index_record *old_rec;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
544 struct maildir_list_index_record new_rec;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
545 const void *data;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
546 uint32_t ext_id;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
547
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
548 /* get the current record */
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
549 list_view = mail_index_transaction_get_view(trans);
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
550 ext_id = maildir_list_get_ext_id(mbox->storage, list_view);
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
551 if (mail_index_lookup_ext(list_view, seq, ext_id, &data) <= 0)
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
552 return -1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
553 old_rec = data;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
554
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
555 memset(&new_rec, 0, sizeof(new_rec));
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
556 if (mhdr->new_check_time <= mhdr->new_mtime + MAILDIR_SYNC_SECS ||
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
557 mhdr->cur_check_time <= mhdr->cur_mtime + MAILDIR_SYNC_SECS) {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
558 /* dirty, we need a refresh next time */
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
559 } else {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
560 new_rec.new_mtime = mhdr->new_mtime;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
561 new_rec.cur_mtime = mhdr->cur_mtime;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
562 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
563
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
564 if (old_rec == NULL ||
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
565 memcmp(old_rec, &new_rec, sizeof(old_rec)) != 0) {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
566 mail_index_update_ext(trans, seq,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
567 mbox->storage->maildir_list_ext_id,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
568 &new_rec, NULL);
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
569 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
570 return 0;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
571 }