annotate src/lib-storage/index/maildir/maildir-sync-index.c @ 6409:7f733ba453bf HEAD

Changed *_deinit() APIs to take ** pointer and set it to NULL.
author Timo Sirainen <tss@iki.fi>
date Sun, 16 Sep 2007 11:07:42 +0300
parents 8476d665530f
children 8ebc07d2eee9
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,
6332
aa4a78b3c626 Renamed mail_index_sync_begin() to mail_index_sync_begin_to() and added a
Timo Sirainen <tss@iki.fi>
parents: 6278
diff changeset
165 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
6409
7f733ba453bf Changed *_deinit() APIs to take ** pointer and set it to NULL.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
214 maildir_keywords_sync_deinit(&ctx->keywords_sync_ctx);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 index_sync_changes_deinit(&ctx->sync_changes);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 i_free(ctx);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 return ret;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219
6097
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
220 static bool
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
221 maildir_index_header_has_changed(const struct maildir_index_header *old_hdr,
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
222 const struct maildir_index_header *new_hdr)
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
223 {
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
224 #define DIR_DELAYED_REFRESH(hdr, name) \
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
225 ((hdr)->name ## _check_time <= \
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
226 (hdr)->name ## _mtime + MAILDIR_SYNC_SECS)
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
227
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
228 if (old_hdr->new_mtime != new_hdr->new_mtime ||
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
229 old_hdr->cur_mtime != new_hdr->cur_mtime ||
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
230 old_hdr->new_mtime_nsecs != new_hdr->new_mtime_nsecs ||
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
231 old_hdr->cur_mtime_nsecs != new_hdr->cur_mtime_nsecs)
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
232 return TRUE;
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
233
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
234 return DIR_DELAYED_REFRESH(old_hdr, new) !=
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
235 DIR_DELAYED_REFRESH(new_hdr, new) ||
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
236 DIR_DELAYED_REFRESH(old_hdr, cur) !=
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
237 DIR_DELAYED_REFRESH(new_hdr, cur);
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
238 }
d5d3adb86e12 Don't update maildir sync header if only sync time has changed, and that
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
239
5927
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
240 static void
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
241 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
242 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
243 {
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
244 const void *data;
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
245 size_t data_size;
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
246
6275
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 6205
diff changeset
247 mail_index_get_header_ext(mbox->ibox.view, mbox->maildir_ext_id,
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 6205
diff changeset
248 &data, &data_size);
6098
a9ad568ce598 Minor code cleanup
Timo Sirainen <tss@iki.fi>
parents: 6097
diff changeset
249 if (data_size != sizeof(mbox->maildir_hdr) ||
a9ad568ce598 Minor code cleanup
Timo Sirainen <tss@iki.fi>
parents: 6097
diff changeset
250 maildir_index_header_has_changed(data, &mbox->maildir_hdr)) {
5927
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
251 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
252 &mbox->maildir_hdr,
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
253 sizeof(mbox->maildir_hdr));
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
254 }
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
255 }
b9865213da42 Store syncing information to maildir extension header instead of kludging
Timo Sirainen <tss@iki.fi>
parents: 5924
diff changeset
256
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257 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
258 bool partial)
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259 {
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260 struct maildir_mailbox *mbox = ctx->mbox;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
261 struct mail_index_view *view = ctx->view;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
262 struct maildir_uidlist_iter_ctx *iter;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
263 struct mail_index_transaction *trans = ctx->trans;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
264 const struct mail_index_header *hdr;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 struct mail_index_header empty_hdr;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266 const struct mail_index_record *rec;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267 uint32_t seq, uid, prev_uid;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
268 enum maildir_uidlist_rec_flag uflags;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269 const char *filename;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270 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
271 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
272 unsigned int changes = 0;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273 int ret = 0;
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
274 bool recent, expunged, full_rescan = FALSE;
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
275
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 i_assert(!mbox->syncing_commit);
5930
7cbeeb953b92 minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 5929
diff changeset
277 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
278
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
279 hdr = mail_index_get_header(view);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
280 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
281 if (uid_validity != hdr->uid_validity &&
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282 uid_validity != 0 && hdr->uid_validity != 0) {
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
283 /* 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
284 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
285 new */
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286 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
287 mbox->path, hdr->uid_validity, uid_validity);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288 mail_index_reset(trans);
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
289 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
290
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 memset(&empty_hdr, 0, sizeof(empty_hdr));
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292 empty_hdr.next_uid = 1;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293 hdr = &empty_hdr;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
294 }
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
295 hdr_next_uid = hdr->next_uid;
5920
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 mbox->syncing_commit = TRUE;
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
298 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
299 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
300 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
301 iter = maildir_uidlist_iter_init(mbox->uidlist);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
302 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
303 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
304 &ctx->flags, &ctx->keywords);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
305
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
306 i_assert(uid > prev_uid);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
307 prev_uid = uid;
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 /* 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
310 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
311 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
312
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
313 __again:
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314 ctx->seq = ++seq;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315 ctx->uid = uid;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
317 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
318 (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
319 last_nonrecent_uid = uid;
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
320 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
321 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
322
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
323 if (seq > hdr->messages_count) {
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
324 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
325 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
326 filename, uid);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
327 seq--;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
328 continue;
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
5932
6ac8d6c93d34 Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents: 5931
diff changeset
331 hdr_next_uid = uid + 1;
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
332 mail_index_append(trans, uid, &seq);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333 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
334 ctx->flags);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 if (array_count(&ctx->keywords) > 0) {
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
336 struct mail_keywords *kw;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 kw = mail_index_keywords_create_from_indexes(
6354
8476d665530f Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents: 6332
diff changeset
339 mbox->ibox.index, &ctx->keywords);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340 mail_index_update_keywords(trans, seq,
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
341 MODIFY_REPLACE, kw);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
342 mail_index_keywords_free(&kw);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
343 }
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
344 if (recent)
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
345 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
346 continue;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
347 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
348
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
349 rec = mail_index_lookup(view, seq);
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
350 if (uid > rec->uid) {
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
351 /* expunged */
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
352 mail_index_expunge(trans, seq);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353 goto __again;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
355
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
356 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
357 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
358 filename, uid);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
359 seq--;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
360 continue;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
361 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
362
6278
ce83635191d4 mail_index_sync_next() can't fail anymore.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
363 index_sync_changes_read(ctx->sync_changes, rec->uid, &expunged);
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
364 if (expunged) {
5930
7cbeeb953b92 minor cleanups
Timo Sirainen <tss@iki.fi>
parents: 5929
diff changeset
365 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
366 maildir_expunge, ctx) >= 0) {
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367 /* successful expunge */
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
368 mail_index_expunge(trans, seq);
5920
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 if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0)
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 maildir_sync_notify(ctx->maildir_sync_ctx);
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372 continue;
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
6038
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
375 if (recent)
cadb5b7cd919 Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
376 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
377
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
378 /* 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
379 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
380
6205
65e12fa51d4d We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents: 6098
diff changeset
381 if (index_sync_changes_have(ctx->sync_changes)) {
65e12fa51d4d We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents: 6098
diff changeset
382 /* apply flag changes to maildir */
65e12fa51d4d We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents: 6098
diff changeset
383 if (maildir_file_do(mbox, ctx->uid,
65e12fa51d4d We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents: 6098
diff changeset
384 maildir_sync_flags, ctx) < 0)
65e12fa51d4d We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents: 6098
diff changeset
385 ctx->flags |= MAIL_INDEX_MAIL_FLAG_DIRTY;
65e12fa51d4d We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents: 6098
diff changeset
386 if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0)
65e12fa51d4d We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents: 6098
diff changeset
387 maildir_sync_notify(ctx->maildir_sync_ctx);
65e12fa51d4d We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents: 6098
diff changeset
388 }
65e12fa51d4d We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents: 6098
diff changeset
389
5920
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390 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
391 /* partial syncing */
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
392 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
393 /* 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
394 not there anymore. possibly expunged,
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
395 make sure. */
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396 full_rescan = TRUE;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 }
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 ((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
402 /* 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
403 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
404 continue;
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
405 }
00c5e3cbeaf0 Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
406
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6028
diff changeset
407 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
408 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
409 ctx->flags);
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 */
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
413 mail_index_lookup_keywords(view, seq, &idx_keywords);
5920
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(
6354
8476d665530f Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents: 6332
diff changeset
418 mbox->ibox.index, &ctx->keywords);
5920
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 }
6409
7f733ba453bf Changed *_deinit() APIs to take ** pointer and set it to NULL.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
424 maildir_uidlist_iter_deinit(&iter);
5920
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;
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
499 bool expunged;
6062
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
500
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
501 ext_id = maildir_list_get_ext_id(mbox->storage, list_view);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
502 mail_index_lookup_ext(list_view, seq, ext_id, &data, &expunged);
6062
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
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
505 if (rec == NULL || expunged ||
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
506 rec->new_mtime == 0 || rec->cur_mtime == 0) {
6062
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
507 /* 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
508 return 1;
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
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
511 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
512 box->name,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
513 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
514
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
515 /* check if new/ changed */
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
516 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
517 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
518 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
519 "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
520 return -1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
521 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
522 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
523 return 1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
524
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
525 /* check if cur/ changed */
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
526 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
527 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
528 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
529 "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
530 return -1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
531 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
532 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
533 return 1;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
534 return 0;
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
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
537 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
538 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
539 uint32_t seq)
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
540 {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
541 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
542 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
543 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
544 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
545 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
546 const void *data;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
547 uint32_t ext_id;
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
548 bool expunged;
6062
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
549
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
550 /* get the current record */
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
551 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
552 ext_id = maildir_list_get_ext_id(mbox->storage, list_view);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
553 mail_index_lookup_ext(list_view, seq, ext_id, &data, &expunged);
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
554 if (expunged)
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
555 return 0;
6062
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
556 old_rec = data;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
557
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
558 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
559 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
560 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
561 /* 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
562 } else {
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
563 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
564 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
565 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
566
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
567 if (old_rec == NULL ||
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
568 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
569 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
570 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
571 &new_rec, NULL);
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
572 }
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
573 return 0;
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6052
diff changeset
574 }