Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/maildir/maildir-sync-index.c @ 8590:b9faf4db2a9f HEAD
Updated copyright notices to include year 2009.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 06 Jan 2009 09:25:38 -0500 |
parents | d077e608a2d6 |
children | de27a19a8721 |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8576
diff
changeset
|
1 /* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */ |
5920
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; |
8576
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
67 struct stat st; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 const char *dir, *fname, *newfname, *newpath; |
7128
98788fdcc3a6
When syncing a mailbox, sync the view internally first completely and just
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
69 enum mail_index_sync_type sync_type; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 uint8_t flags8; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 fname = strrchr(path, '/'); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 i_assert(fname != NULL); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 fname++; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 dir = t_strdup_until(path, fname); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 /* get the current flags and keywords */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 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
|
79 fname, &ctx->flags, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 /* apply changes */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 flags8 = ctx->flags; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 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
|
84 &flags8, &ctx->keywords, &sync_type); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 ctx->flags = flags8; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 /* and try renaming with the new name */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 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
|
89 ctx->flags, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 newpath = t_strconcat(dir, newfname, NULL); |
8576
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
91 if (strcmp(path, newpath) == 0) { |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
92 /* just make sure that the file still exists. avoid rename() |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
93 here because it's slow on HFS. */ |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
94 if (stat(path, &st) < 0) { |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
95 if (errno == ENOENT) |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
96 return 0; |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
97 mail_storage_set_critical(box->storage, |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
98 "stat(%s) failed: %m", path); |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
99 return -1; |
7128
98788fdcc3a6
When syncing a mailbox, sync the view internally first completely and just
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
100 } |
8576
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
101 } else { |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
102 if (rename(path, newpath) < 0) { |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
103 if (errno == ENOENT) |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
104 return 0; |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
105 if (!ENOSPACE(errno) && errno != EACCES) { |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
106 mail_storage_set_critical(box->storage, |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
107 "rename(%s, %s) failed: %m", |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
108 path, newpath); |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
109 } |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
110 return -1; |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
111 } |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 } |
8576
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
113 if (box->v.sync_notify != NULL) { |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
114 box->v.sync_notify(box, ctx->uid, |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
115 index_sync_type_convert(sync_type)); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
116 } |
8576
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
117 ctx->changed = TRUE; |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
118 return 1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 |
8554
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
121 static int maildir_handle_uid_insertion(struct maildir_index_sync_context *ctx, |
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
122 enum maildir_uidlist_rec_flag uflags, |
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
123 const char *filename, uint32_t 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
|
124 { |
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 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
|
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 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
|
128 /* partial syncing */ |
8554
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
129 return 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
|
130 } |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
131 |
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 /* 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
|
133 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
|
134 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
|
135 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
|
136 /* 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
|
137 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
|
138 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
|
139 MAILDIR_UIDLIST_REC_FLAG_RACING); |
8554
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
140 return 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
|
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 |
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 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
|
144 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
|
145 MAILDIR_UIDLIST_SYNC_PARTIAL | |
68be663e79ec
Fixed reassigning new UIDs to more than one message.
Timo Sirainen <tss@iki.fi>
parents:
5983
diff
changeset
|
146 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
|
147 &ctx->uidlist_sync_ctx); |
8554
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
148 if (ret <= 0) |
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
149 return -1; |
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
|
150 } |
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
|
151 |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 |
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
|
158 /* 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
|
159 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
|
160 |
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
|
161 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
|
162 "(old uid=%u, file=%s)", ctx->mbox->path, uid, filename); |
8554
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
163 return 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
|
164 } |
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
|
165 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 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
|
167 struct maildir_sync_context *maildir_sync_ctx, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 struct maildir_index_sync_context **ctx_r) |
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 struct maildir_index_sync_context *ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 struct mail_index_sync_ctx *sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 struct mail_index_view *view; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 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
|
174 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
|
175 |
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
176 sync_flags = 0; |
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
177 /* 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
|
178 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
|
179 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
|
180 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 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
|
182 sync_flags) < 0) { |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 mail_storage_set_index_error(&mbox->ibox); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 return -1; |
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 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
|
188 ctx->mbox = mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 ctx->maildir_sync_ctx = maildir_sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 ctx->sync_ctx = sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 ctx->view = view; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 ctx->trans = trans; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 ctx->keywords_sync_ctx = |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 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
|
195 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 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
|
197 ctx->view, ctx->trans, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 mbox->ibox.readonly); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 *ctx_r = ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 return 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 |
7515
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
204 static bool |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
205 maildir_index_header_has_changed(const struct maildir_index_header *old_hdr, |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
206 const struct maildir_index_header *new_hdr) |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
207 { |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
208 #define DIR_DELAYED_REFRESH(hdr, name) \ |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
209 ((hdr)->name ## _check_time <= \ |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
210 (hdr)->name ## _mtime + MAILDIR_SYNC_SECS) |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
211 |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
212 if (old_hdr->new_mtime != new_hdr->new_mtime || |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
213 old_hdr->new_mtime_nsecs != new_hdr->new_mtime_nsecs || |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
214 old_hdr->cur_mtime != new_hdr->cur_mtime || |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
215 old_hdr->cur_mtime_nsecs != new_hdr->cur_mtime_nsecs || |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
216 old_hdr->uidlist_mtime != new_hdr->uidlist_mtime || |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
217 old_hdr->uidlist_mtime_nsecs != new_hdr->uidlist_mtime_nsecs || |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
218 old_hdr->uidlist_size != new_hdr->uidlist_size) |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
219 return TRUE; |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
220 |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
221 return DIR_DELAYED_REFRESH(old_hdr, new) != |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
222 DIR_DELAYED_REFRESH(new_hdr, new) || |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
223 DIR_DELAYED_REFRESH(old_hdr, cur) != |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
224 DIR_DELAYED_REFRESH(new_hdr, cur); |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
225 } |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
226 |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
227 static void |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
228 maildir_sync_index_update_ext_header(struct maildir_index_sync_context *ctx) |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
229 { |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
230 struct maildir_mailbox *mbox = ctx->mbox; |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
231 const void *data; |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
232 size_t data_size; |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
233 |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
234 mail_index_get_header_ext(mbox->ibox.view, mbox->maildir_ext_id, |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
235 &data, &data_size); |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
236 if (data_size != sizeof(mbox->maildir_hdr) || |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
237 maildir_index_header_has_changed(data, &mbox->maildir_hdr)) { |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
238 mail_index_update_header_ext(ctx->trans, mbox->maildir_ext_id, |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
239 0, &mbox->maildir_hdr, |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
240 sizeof(mbox->maildir_hdr)); |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
241 } |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
242 } |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
243 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 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
|
245 bool failed, bool cancel) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 struct maildir_index_sync_context *ctx = *_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 struct maildir_mailbox *mbox = ctx->mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 int ret = failed ? -1 : 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 *_ctx = NULL; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 if (ret < 0 || cancel) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 mail_index_sync_rollback(&ctx->sync_ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 else { |
7515
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
256 maildir_sync_index_update_ext_header(ctx); |
c14a2b0a3126
Keep track of dovecot-uidlist mtime+size in index file. If it's up-to-date
Timo Sirainen <tss@iki.fi>
parents:
7464
diff
changeset
|
257 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 /* 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
|
259 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
|
260 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
|
261 start a second index sync and crash. */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 mbox->syncing_commit = TRUE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 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
|
264 mail_storage_set_index_error(&mbox->ibox); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 ret = -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 } else { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 mbox->ibox.commit_log_file_seq = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 mbox->ibox.commit_log_file_offset = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 mbox->syncing_commit = FALSE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 |
6409
7f733ba453bf
Changed *_deinit() APIs to take ** pointer and set it to NULL.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
273 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
|
274 index_sync_changes_deinit(&ctx->sync_changes); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 i_free(ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 return ret; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 } |
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 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
|
280 bool partial) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 struct maildir_mailbox *mbox = ctx->mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 struct mail_index_view *view = ctx->view; |
7067 | 284 struct mail_index_view *view2; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 struct maildir_uidlist_iter_ctx *iter; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 struct mail_index_transaction *trans = ctx->trans; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 const struct mail_index_header *hdr; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 struct mail_index_header empty_hdr; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 const struct mail_index_record *rec; |
7067 | 290 uint32_t seq, seq2, uid, prev_uid; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 enum maildir_uidlist_rec_flag uflags; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 const char *filename; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 ARRAY_TYPE(keyword_indexes) idx_keywords; |
7067 | 294 uint32_t uid_validity, next_uid, hdr_next_uid, first_recent_uid; |
7464
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
295 uint32_t first_uid; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
296 unsigned int changes = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 int ret = 0; |
7067 | 298 bool expunged, full_rescan = FALSE; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
300 i_assert(!mbox->syncing_commit); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 |
7464
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
302 first_uid = 1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 hdr = mail_index_get_header(view); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
304 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
|
305 if (uid_validity != hdr->uid_validity && |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 uid_validity != 0 && hdr->uid_validity != 0) { |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
307 /* 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
|
308 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
|
309 new */ |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 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
|
311 mbox->path, hdr->uid_validity, uid_validity); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 mail_index_reset(trans); |
7463
d1bd08d468d0
Reset cached \Recent flags if UIDVALIDITY changes, because we were using
Timo Sirainen <tss@iki.fi>
parents:
7231
diff
changeset
|
313 index_mailbox_reset_uidvalidity(&mbox->ibox); |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
314 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
|
315 |
7464
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
316 first_uid = hdr->messages_count + 1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 memset(&empty_hdr, 0, sizeof(empty_hdr)); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 empty_hdr.next_uid = 1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 hdr = &empty_hdr; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 } |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
321 hdr_next_uid = hdr->next_uid; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 mbox->syncing_commit = TRUE; |
7231
0706d404a8fb
Handle first_recent_uid=0 without crashing, even though it shouldn't happen..
Timo Sirainen <tss@iki.fi>
parents:
7128
diff
changeset
|
324 seq = prev_uid = 0; first_recent_uid = I_MAX(hdr->first_recent_uid, 1); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 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
|
326 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
|
327 iter = maildir_uidlist_iter_init(mbox->uidlist); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 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
|
329 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
|
330 &ctx->flags, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 i_assert(uid > prev_uid); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 prev_uid = uid; |
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 /* 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
|
336 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
|
337 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
|
338 |
6412 | 339 again: |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
340 ctx->seq = ++seq; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
341 ctx->uid = uid; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
343 if (seq > hdr->messages_count) { |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
344 if (uid < hdr_next_uid) { |
8554
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
345 if (maildir_handle_uid_insertion(ctx, uflags, |
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
346 filename, |
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
347 uid) < 0) |
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
348 ret = -1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
349 seq--; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
350 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
352 |
7067 | 353 /* Trust uidlist recent flags only for newly added |
354 messages. When saving/copying messages with flags | |
355 they're stored to cur/ and uidlist treats them | |
356 as non-recent. */ | |
7961
820cc75d6ccc
Maildir: \Recent flags weren't set correctly if mail was saved externally.
Timo Sirainen <tss@iki.fi>
parents:
7515
diff
changeset
|
357 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RECENT) == 0) { |
7067 | 358 if (uid >= first_recent_uid) |
359 first_recent_uid = uid + 1; | |
360 } | |
361 | |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
362 hdr_next_uid = uid + 1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
363 mail_index_append(trans, uid, &seq); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
364 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
|
365 ctx->flags); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
366 if (array_count(&ctx->keywords) > 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 struct mail_keywords *kw; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
369 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
|
370 mbox->ibox.index, &ctx->keywords); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
371 mail_index_update_keywords(trans, seq, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
372 MODIFY_REPLACE, kw); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 mail_index_keywords_free(&kw); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 continue; |
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 |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
378 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
|
379 if (uid > rec->uid) { |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 /* expunged */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
381 mail_index_expunge(trans, seq); |
6412 | 382 goto again; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 |
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
|
385 if (uid < rec->uid) { |
8554
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
386 if (maildir_handle_uid_insertion(ctx, uflags, |
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
387 filename, uid) < 0) |
c438437b709a
maildir: Allow opening mailbox and expunging messages when uidlist couldn't be locked (e.g. out of quota).
Timo Sirainen <tss@iki.fi>
parents:
8260
diff
changeset
|
388 ret = -1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 seq--; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 |
6278
ce83635191d4
mail_index_sync_next() can't fail anymore.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
393 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
|
394 if (expunged) { |
5930 | 395 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
|
396 maildir_expunge, ctx) >= 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 /* successful expunge */ |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
398 mail_index_expunge(trans, seq); |
5920
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 if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
401 maildir_sync_notify(ctx->maildir_sync_ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
402 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
403 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
404 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 /* 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
|
406 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
|
407 |
6205
65e12fa51d4d
We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents:
6098
diff
changeset
|
408 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
|
409 /* 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 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
|
415 } |
65e12fa51d4d
We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents:
6098
diff
changeset
|
416 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
417 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
|
418 /* partial syncing */ |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
419 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
|
420 /* 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
|
421 not there anymore. possibly expunged, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
422 make sure. */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
423 full_rescan = TRUE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
424 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
425 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
426 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
427 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
428 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
|
429 /* 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
|
430 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
|
431 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
432 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
434 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
|
435 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
|
436 ctx->flags); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 /* 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
|
440 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
|
441 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
|
442 struct mail_keywords *kw; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
444 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
|
445 mbox->ibox.index, &ctx->keywords); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
446 mail_index_update_keywords(trans, seq, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
447 MODIFY_REPLACE, kw); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 mail_index_keywords_free(&kw); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
449 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
450 } |
6409
7f733ba453bf
Changed *_deinit() APIs to take ** pointer and set it to NULL.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
451 maildir_uidlist_iter_deinit(&iter); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 mbox->syncing_commit = FALSE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 |
7067 | 454 if (!partial) { |
455 /* expunge the rest */ | |
456 for (seq++; seq <= hdr->messages_count; seq++) | |
457 mail_index_expunge(trans, seq); | |
458 } | |
459 | |
460 /* add \Recent flags. use updated view so it contains newly | |
461 appended messages. */ | |
462 view2 = mail_index_transaction_open_updated_view(trans); | |
463 if (mail_index_lookup_seq_range(view2, first_recent_uid, (uint32_t)-1, | |
7464
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
464 &seq, &seq2) && seq2 >= first_uid) { |
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
465 if (seq < first_uid) { |
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
466 /* UIDVALIDITY changed, skip over the old messages */ |
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
467 seq = first_uid; |
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
468 } |
7067 | 469 index_mailbox_set_recent_seq(&mbox->ibox, view2, seq, seq2); |
7464
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
470 } |
7067 | 471 mail_index_view_close(&view2); |
472 | |
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
|
473 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
|
474 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
|
475 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
|
476 } |
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
|
477 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 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
|
479 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
|
480 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
481 if (ctx->changed) |
5930 | 482 mbox->maildir_hdr.cur_mtime = time(NULL); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
484 if (uid_validity == 0) { |
8260
110afc84fbb1
Maildir/dbox: Try harder to assign unique UIDVALIDITY values to mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
7961
diff
changeset
|
485 uid_validity = hdr->uid_validity != 0 ? hdr->uid_validity : |
110afc84fbb1
Maildir/dbox: Try harder to assign unique UIDVALIDITY values to mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
7961
diff
changeset
|
486 maildir_get_uidvalidity_next(mbox->ibox.box.storage); |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
487 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
|
488 } |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
489 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
|
490 |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
491 if (uid_validity != hdr->uid_validity) { |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
492 mail_index_update_header(trans, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
493 offsetof(struct mail_index_header, uid_validity), |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
494 &uid_validity, sizeof(uid_validity), TRUE); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
495 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
496 |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
497 next_uid = maildir_uidlist_get_next_uid(mbox->uidlist); |
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
498 if (hdr_next_uid < next_uid) { |
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
499 mail_index_update_header(trans, |
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
500 offsetof(struct mail_index_header, next_uid), |
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
501 &next_uid, sizeof(next_uid), FALSE); |
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
502 } |
6038
cadb5b7cd919
Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
503 |
7067 | 504 i_assert(hdr->first_recent_uid <= first_recent_uid); |
505 if (hdr->first_recent_uid < first_recent_uid) { | |
6038
cadb5b7cd919
Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
506 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
|
507 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
|
508 &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
|
509 } |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 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
|
511 } |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
512 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
513 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
|
514 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
|
515 { |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
516 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
|
517 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
|
518 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
|
519 "maildir", 0, |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
520 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
|
521 sizeof(uint32_t)); |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
522 } |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
523 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
|
524 } |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
525 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
526 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
|
527 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
|
528 uint32_t seq) |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
529 { |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
530 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
|
531 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
|
532 const void *data; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
533 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
|
534 struct stat st; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
535 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
|
536 bool expunged; |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
537 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
538 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
|
539 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
|
540 rec = data; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
541 |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
542 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
|
543 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
|
544 /* 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
|
545 return 1; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
546 } |
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 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
|
549 box->name, |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
550 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
|
551 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
552 /* check if new/ changed */ |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
553 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
|
554 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
|
555 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
|
556 "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
|
557 return -1; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
558 } |
7043
7708a8c166d6
Compiler warning fixes on 32bit systems.
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
559 if ((time_t)rec->new_mtime != st.st_mtime) |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
560 return 1; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
561 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
562 /* check if cur/ changed */ |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
563 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
|
564 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
|
565 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
|
566 "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
|
567 return -1; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
568 } |
7043
7708a8c166d6
Compiler warning fixes on 32bit systems.
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
569 if ((time_t)rec->cur_mtime != st.st_mtime) |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
570 return 1; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
571 return 0; |
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 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
574 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
|
575 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
|
576 uint32_t seq) |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
577 { |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
578 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
|
579 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
|
580 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
|
581 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
|
582 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
|
583 const void *data; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
584 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
|
585 bool expunged; |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
586 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
587 /* get the current record */ |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
588 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
|
589 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
|
590 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
|
591 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
|
592 return 0; |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
593 old_rec = data; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
594 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
595 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
|
596 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
|
597 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
|
598 /* 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
|
599 } else { |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
600 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
|
601 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
|
602 } |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
603 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
604 if (old_rec == NULL || |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
605 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
|
606 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
|
607 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
|
608 &new_rec, NULL); |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
609 } |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
610 return 0; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
611 } |