Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/maildir/maildir-sync-index.c @ 9464:939edf3ed09b HEAD
maildir: Having a lot of keywords assert-crashed with "stack frame changed".
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 02 Nov 2009 17:54:17 -0500 |
parents | f2a6a99ff9ea |
children | 00cd9aacd03c |
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> |
8625
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
14 #include <stdlib.h> |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #include <unistd.h> |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 struct maildir_index_sync_context { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 struct maildir_mailbox *mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 struct maildir_sync_context *maildir_sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 struct mail_index_view *view; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 struct mail_index_sync_ctx *sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 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
|
24 struct mail_index_transaction *trans; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 |
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
|
26 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
|
27 struct index_sync_changes_context *sync_changes; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 enum mail_flags flags; |
8625
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
29 ARRAY_TYPE(keyword_indexes) keywords, idx_keywords; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 |
6038
cadb5b7cd919
Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
31 uint32_t seq, uid; |
9376
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
32 bool update_maildir_hdr_cur; |
5920
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 return 1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 if (errno == ENOENT) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 return 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 mail_storage_set_critical(&mbox->storage->storage, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 "unlink(%s) failed: %m", path); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 return -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 } |
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 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
|
63 struct maildir_index_sync_context *ctx) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 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
|
66 struct stat st; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 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
|
68 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
|
69 uint8_t flags8; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 fname = strrchr(path, '/'); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 i_assert(fname != NULL); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 fname++; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 dir = t_strdup_until(path, fname); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 /* get the current flags and keywords */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 maildir_filename_get_flags(ctx->keywords_sync_ctx, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 fname, &ctx->flags, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 /* apply changes */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 flags8 = ctx->flags; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 index_sync_changes_apply(ctx->sync_changes, NULL, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 &flags8, &ctx->keywords, &sync_type); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 ctx->flags = flags8; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 /* and try renaming with the new name */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 newfname = maildir_filename_set_flags(ctx->keywords_sync_ctx, fname, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 ctx->flags, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 newpath = t_strconcat(dir, newfname, NULL); |
8576
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
90 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
|
91 /* 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
|
92 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
|
93 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
|
94 if (errno == ENOENT) |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
95 return 0; |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
96 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
|
97 "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
|
98 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
|
99 } |
8576
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
100 } else { |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
101 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
|
102 if (errno == ENOENT) |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
103 return 0; |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
104 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
|
105 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
|
106 "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
|
107 path, newpath); |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
108 } |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
109 return -1; |
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
110 } |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 } |
8576
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
112 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
|
113 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
|
114 index_sync_type_convert(sync_type)); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 } |
8576
d077e608a2d6
Maildir: Avoid rename() when source and dest are identical, stat() instead.
Timo Sirainen <tss@iki.fi>
parents:
8554
diff
changeset
|
116 return 1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 |
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
|
119 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
|
120 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
|
121 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
|
122 { |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
123 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
|
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 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
|
126 /* 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
|
127 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
|
128 } |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
129 |
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 /* 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
|
131 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
|
132 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
|
133 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
|
134 /* 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 } |
ac05ec8c7171
If we see expunged messages coming back, log a warning and give them a new
Timo Sirainen <tss@iki.fi>
parents:
5920
diff
changeset
|
140 |
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 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
|
142 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
|
143 MAILDIR_UIDLIST_SYNC_PARTIAL | |
68be663e79ec
Fixed reassigning new UIDs to more than one message.
Timo Sirainen <tss@iki.fi>
parents:
5983
diff
changeset
|
144 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
|
145 &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
|
146 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
|
147 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
|
148 } |
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
|
149 |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 |
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 /* 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
|
157 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
|
158 |
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 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
|
160 "(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
|
161 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
|
162 } |
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
|
163 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 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
|
165 struct maildir_sync_context *maildir_sync_ctx, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 struct maildir_index_sync_context **ctx_r) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 struct maildir_index_sync_context *ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 struct mail_index_sync_ctx *sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 struct mail_index_view *view; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 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
|
172 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
|
173 |
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
174 sync_flags = 0; |
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
175 /* 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
|
176 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
|
177 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
|
178 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 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
|
180 sync_flags) < 0) { |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 mail_storage_set_index_error(&mbox->ibox); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
182 return -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 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
|
186 ctx->mbox = mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 ctx->maildir_sync_ctx = maildir_sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 ctx->sync_ctx = sync_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 ctx->view = view; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 ctx->trans = trans; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 ctx->keywords_sync_ctx = |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 maildir_keywords_sync_init(mbox->keywords, mbox->ibox.index); |
8626
a9dd29e7dc4f
Cleaned up read-only mailbox handling. Fixes a bug with Maildir syncing.
Timo Sirainen <tss@iki.fi>
parents:
8625
diff
changeset
|
193 ctx->sync_changes = |
a9dd29e7dc4f
Cleaned up read-only mailbox handling. Fixes a bug with Maildir syncing.
Timo Sirainen <tss@iki.fi>
parents:
8625
diff
changeset
|
194 index_sync_changes_init(&mbox->ibox, ctx->sync_ctx, |
a9dd29e7dc4f
Cleaned up read-only mailbox handling. Fixes a bug with Maildir syncing.
Timo Sirainen <tss@iki.fi>
parents:
8625
diff
changeset
|
195 ctx->view, ctx->trans, |
a9dd29e7dc4f
Cleaned up read-only mailbox handling. Fixes a bug with Maildir syncing.
Timo Sirainen <tss@iki.fi>
parents:
8625
diff
changeset
|
196 mbox->ibox.backend_readonly); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 *ctx_r = ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 return 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 |
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
|
202 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
|
203 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
|
204 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
|
205 { |
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 #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
|
207 ((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
|
208 (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
|
209 |
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 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 |
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 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
|
220 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
|
221 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
|
222 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
|
223 } |
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 |
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 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
|
226 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
|
227 { |
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 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
|
229 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
|
230 size_t data_size; |
9376
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
231 struct stat st; |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
232 |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
233 if (ctx->update_maildir_hdr_cur && |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
234 stat(t_strconcat(mbox->path, "/cur", NULL), &st) == 0) { |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
235 if ((time_t)mbox->maildir_hdr.cur_check_time < st.st_mtime) |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
236 mbox->maildir_hdr.cur_check_time = st.st_mtime; |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
237 mbox->maildir_hdr.cur_mtime = st.st_mtime; |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
238 mbox->maildir_hdr.cur_mtime_nsecs = ST_MTIME_NSEC(st); |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
239 } |
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
|
240 |
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 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
|
242 &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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 } |
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
|
249 } |
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
|
250 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 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
|
252 bool failed, bool cancel) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 struct maildir_index_sync_context *ctx = *_ctx; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 struct maildir_mailbox *mbox = ctx->mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 int ret = failed ? -1 : 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 *_ctx = NULL; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 if (ret < 0 || cancel) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 mail_index_sync_rollback(&ctx->sync_ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 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
|
263 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
|
264 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 /* 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
|
266 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
|
267 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
|
268 start a second index sync and crash. */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 mbox->syncing_commit = TRUE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 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
|
271 mail_storage_set_index_error(&mbox->ibox); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 ret = -1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 } else { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 mbox->ibox.commit_log_file_seq = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 mbox->ibox.commit_log_file_offset = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 mbox->syncing_commit = FALSE; |
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 |
6409
7f733ba453bf
Changed *_deinit() APIs to take ** pointer and set it to NULL.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
280 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
|
281 index_sync_changes_deinit(&ctx->sync_changes); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 i_free(ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 return ret; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 |
8625
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
286 static int uint_cmp(const void *p1, const void *p2) |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
287 { |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
288 const unsigned int *i1 = p1, *i2 = p2; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
289 |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
290 if (*i1 < *i2) |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
291 return -1; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
292 else if (*i1 > *i2) |
8690
80486913baf3
maildir: Handling keywords was more or less broken because of a broken sort compare function.
Timo Sirainen <tss@iki.fi>
parents:
8636
diff
changeset
|
293 return 1; |
8625
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
294 else |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
295 return 0; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
296 } |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
297 |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
298 static void |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
299 maildir_sync_mail_keywords(struct maildir_index_sync_context *ctx, uint32_t seq) |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
300 { |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
301 struct maildir_mailbox *mbox = ctx->mbox; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
302 struct mail_keywords *kw; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
303 unsigned int i, j, old_count, new_count, *old_indexes, *new_indexes; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
304 bool have_indexonly_keywords; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
305 int diff; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
306 |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
307 mail_index_lookup_keywords(ctx->view, seq, &ctx->idx_keywords); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
308 if (index_keyword_array_cmp(&ctx->keywords, &ctx->idx_keywords)) { |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
309 /* no changes - we should get here usually */ |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
310 return; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
311 } |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
312 |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
313 /* sort the keywords */ |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
314 old_indexes = array_get_modifiable(&ctx->idx_keywords, &old_count); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
315 qsort(old_indexes, old_count, sizeof(*old_indexes), uint_cmp); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
316 new_indexes = array_get_modifiable(&ctx->keywords, &new_count); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
317 qsort(new_indexes, new_count, sizeof(*new_indexes), uint_cmp); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
318 |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
319 /* drop keywords that are in index-only. we don't want to touch them. */ |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
320 have_indexonly_keywords = FALSE; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
321 for (i = old_count; i > 0; i--) { |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
322 if (old_indexes[i-1] < MAILDIR_MAX_KEYWORDS) |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
323 break; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
324 have_indexonly_keywords = TRUE; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
325 array_delete(&ctx->idx_keywords, i-1, 1); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
326 } |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
327 |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
328 if (!have_indexonly_keywords) { |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
329 /* no index-only keywords found, so something changed. |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
330 just replace them all. */ |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
331 kw = mail_index_keywords_create_from_indexes(mbox->ibox.index, |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
332 &ctx->keywords); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
333 mail_index_update_keywords(ctx->trans, seq, MODIFY_REPLACE, kw); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
334 mail_index_keywords_free(&kw); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
335 return; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
336 } |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
337 |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
338 /* check again if non-index-only keywords changed */ |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
339 if (index_keyword_array_cmp(&ctx->keywords, &ctx->idx_keywords)) |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
340 return; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
341 |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
342 /* we can't reset all the keywords or we'd drop indexonly keywords too. |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
343 so first remove the unwanted keywords and then add back the wanted |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
344 ones. we can get these lists easily by removing common elements |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
345 from old and new keywords. */ |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
346 new_indexes = array_get_modifiable(&ctx->keywords, &new_count); |
8636
11e18a303661
Maildir: Fix to earlier >26 keywords handling change.
Timo Sirainen <tss@iki.fi>
parents:
8626
diff
changeset
|
347 for (i = j = 0; i < old_count && j < new_count; ) { |
8625
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
348 diff = (int)old_indexes[i] - (int)new_indexes[j]; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
349 if (diff == 0) { |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
350 array_delete(&ctx->keywords, j, 1); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
351 array_delete(&ctx->idx_keywords, i, 1); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
352 old_indexes = array_get_modifiable(&ctx->idx_keywords, |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
353 &old_count); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
354 new_indexes = array_get_modifiable(&ctx->keywords, |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
355 &new_count); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
356 } else if (diff < 0) { |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
357 i++; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
358 } else { |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
359 j++; |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
360 } |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
361 } |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
362 |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
363 if (array_count(&ctx->idx_keywords) > 0) { |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
364 kw = mail_index_keywords_create_from_indexes(mbox->ibox.index, |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
365 &ctx->idx_keywords); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
366 mail_index_update_keywords(ctx->trans, seq, MODIFY_REMOVE, kw); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
367 mail_index_keywords_free(&kw); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
368 } |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
369 |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
370 if (array_count(&ctx->keywords) > 0) { |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
371 kw = mail_index_keywords_create_from_indexes(mbox->ibox.index, |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
372 &ctx->keywords); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
373 mail_index_update_keywords(ctx->trans, seq, MODIFY_ADD, kw); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
374 mail_index_keywords_free(&kw); |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
375 } |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
376 } |
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
377 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
378 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
|
379 bool partial) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
381 struct maildir_mailbox *mbox = ctx->mbox; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 struct mail_index_view *view = ctx->view; |
7067 | 383 struct mail_index_view *view2; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 struct maildir_uidlist_iter_ctx *iter; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
385 struct mail_index_transaction *trans = ctx->trans; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
386 const struct mail_index_header *hdr; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 struct mail_index_header empty_hdr; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
388 const struct mail_index_record *rec; |
7067 | 389 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
|
390 enum maildir_uidlist_rec_flag uflags; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 const char *filename; |
7067 | 392 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
|
393 uint32_t first_uid; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
394 unsigned int changes = 0; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
395 int ret = 0; |
8876
88aeadb32151
Added maildir_very_dirty_syncs setting.
Timo Sirainen <tss@iki.fi>
parents:
8690
diff
changeset
|
396 time_t time_before_sync; |
7067 | 397 bool expunged, full_rescan = FALSE; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
398 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
399 i_assert(!mbox->syncing_commit); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
400 |
7464
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
401 first_uid = 1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
402 hdr = mail_index_get_header(view); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
403 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
|
404 if (uid_validity != hdr->uid_validity && |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 uid_validity != 0 && hdr->uid_validity != 0) { |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
406 /* 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
|
407 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
|
408 new */ |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
409 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
|
410 mbox->path, hdr->uid_validity, uid_validity); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 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
|
412 index_mailbox_reset_uidvalidity(&mbox->ibox); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
413 |
7464
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
414 first_uid = hdr->messages_count + 1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
415 memset(&empty_hdr, 0, sizeof(empty_hdr)); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
416 empty_hdr.next_uid = 1; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
417 hdr = &empty_hdr; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
418 } |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
419 hdr_next_uid = hdr->next_uid; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
420 |
8876
88aeadb32151
Added maildir_very_dirty_syncs setting.
Timo Sirainen <tss@iki.fi>
parents:
8690
diff
changeset
|
421 time_before_sync = time(NULL); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
422 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
|
423 seq = prev_uid = 0; first_recent_uid = I_MAX(hdr->first_recent_uid, 1); |
9464
939edf3ed09b
maildir: Having a lot of keywords assert-crashed with "stack frame changed".
Timo Sirainen <tss@iki.fi>
parents:
9376
diff
changeset
|
424 i_array_init(&ctx->keywords, MAILDIR_MAX_KEYWORDS); |
939edf3ed09b
maildir: Having a lot of keywords assert-crashed with "stack frame changed".
Timo Sirainen <tss@iki.fi>
parents:
9376
diff
changeset
|
425 i_array_init(&ctx->idx_keywords, MAILDIR_MAX_KEYWORDS); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
426 iter = maildir_uidlist_iter_init(mbox->uidlist); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
427 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
|
428 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
|
429 &ctx->flags, &ctx->keywords); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
431 i_assert(uid > prev_uid); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
432 prev_uid = uid; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 /* 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
|
435 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
|
436 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
|
437 |
6412 | 438 again: |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 ctx->seq = ++seq; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 ctx->uid = uid; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
441 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 if (seq > hdr->messages_count) { |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
443 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
|
444 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
|
445 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
|
446 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
|
447 ret = -1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 seq--; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
449 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
450 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 |
7067 | 452 /* Trust uidlist recent flags only for newly added |
453 messages. When saving/copying messages with flags | |
454 they're stored to cur/ and uidlist treats them | |
455 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
|
456 if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RECENT) == 0) { |
7067 | 457 if (uid >= first_recent_uid) |
458 first_recent_uid = uid + 1; | |
459 } | |
460 | |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
461 hdr_next_uid = uid + 1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 mail_index_append(trans, uid, &seq); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 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
|
464 ctx->flags); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
465 if (array_count(&ctx->keywords) > 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
466 struct mail_keywords *kw; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 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
|
469 mbox->ibox.index, &ctx->keywords); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
470 mail_index_update_keywords(trans, seq, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 MODIFY_REPLACE, kw); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 mail_index_keywords_free(&kw); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
474 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
475 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
477 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
|
478 if (uid > rec->uid) { |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 /* expunged */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 mail_index_expunge(trans, seq); |
6412 | 481 goto again; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
482 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 |
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
|
484 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
|
485 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
|
486 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
|
487 ret = -1; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
488 seq--; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
489 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
490 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
491 |
6278
ce83635191d4
mail_index_sync_next() can't fail anymore.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
492 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
|
493 if (expunged) { |
5930 | 494 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
|
495 maildir_expunge, ctx) >= 0) { |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
496 /* successful expunge */ |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
497 mail_index_expunge(trans, seq); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
498 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
499 if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0) |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 maildir_sync_notify(ctx->maildir_sync_ctx); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
503 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
504 /* 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
|
505 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
|
506 |
6205
65e12fa51d4d
We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents:
6098
diff
changeset
|
507 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
|
508 /* 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 } |
65e12fa51d4d
We didn't update flags to maildir filenames when maildir was fully synced.
Timo Sirainen <tss@iki.fi>
parents:
6098
diff
changeset
|
515 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
516 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
|
517 /* partial syncing */ |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
518 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
|
519 /* 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
|
520 not there anymore. possibly expunged, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
521 make sure. */ |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
522 full_rescan = TRUE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
523 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
524 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
527 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
|
528 /* 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
|
529 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
|
530 continue; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
531 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
532 |
6037
d911d943438e
Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents:
6028
diff
changeset
|
533 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
|
534 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
|
535 ctx->flags); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
536 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
537 |
8625
de27a19a8721
maildir: Fixes to handling over 26 keywords.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
538 maildir_sync_mail_keywords(ctx, seq); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
539 } |
6409
7f733ba453bf
Changed *_deinit() APIs to take ** pointer and set it to NULL.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
540 maildir_uidlist_iter_deinit(&iter); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
541 mbox->syncing_commit = FALSE; |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
542 |
7067 | 543 if (!partial) { |
544 /* expunge the rest */ | |
545 for (seq++; seq <= hdr->messages_count; seq++) | |
546 mail_index_expunge(trans, seq); | |
547 } | |
548 | |
549 /* add \Recent flags. use updated view so it contains newly | |
550 appended messages. */ | |
551 view2 = mail_index_transaction_open_updated_view(trans); | |
552 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
|
553 &seq, &seq2) && seq2 >= first_uid) { |
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
554 if (seq < first_uid) { |
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
555 /* 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
|
556 seq = first_uid; |
4dc5542f58aa
Fixes to handling recent flags with UIDVALIDITY changing.
Timo Sirainen <tss@iki.fi>
parents:
7463
diff
changeset
|
557 } |
7067 | 558 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
|
559 } |
7067 | 560 mail_index_view_close(&view2); |
561 | |
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
|
562 if (ctx->uidlist_sync_ctx != NULL) { |
9018
0bb192fe0abd
Maildir: More fixes to uidlist handling.
Timo Sirainen <tss@iki.fi>
parents:
8876
diff
changeset
|
563 if (maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx, |
0bb192fe0abd
Maildir: More fixes to uidlist handling.
Timo Sirainen <tss@iki.fi>
parents:
8876
diff
changeset
|
564 TRUE) < 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
|
565 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
|
566 } |
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
|
567 |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
568 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
|
569 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
|
570 |
9376
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
571 /* check cur/ mtime later. if we came here from saving messages they |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
572 could still be moved to cur/ directory. */ |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
573 ctx->update_maildir_hdr_cur = TRUE; |
f2a6a99ff9ea
maildir: Save cur/ mtime to index after moving saved messages there, not before.
Timo Sirainen <tss@iki.fi>
parents:
9375
diff
changeset
|
574 mbox->maildir_hdr.cur_check_time = time_before_sync; |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
575 |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
576 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
|
577 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
|
578 maildir_get_uidvalidity_next(mbox->ibox.box.storage); |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
579 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
|
580 } |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
581 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
|
582 |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
583 if (uid_validity != hdr->uid_validity) { |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
584 mail_index_update_header(trans, |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
585 offsetof(struct mail_index_header, uid_validity), |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
586 &uid_validity, sizeof(uid_validity), TRUE); |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
587 } |
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
588 |
5932
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
589 next_uid = maildir_uidlist_get_next_uid(mbox->uidlist); |
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
590 if (hdr_next_uid < next_uid) { |
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
591 mail_index_update_header(trans, |
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
592 offsetof(struct mail_index_header, next_uid), |
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
593 &next_uid, sizeof(next_uid), FALSE); |
6ac8d6c93d34
Handle next_uid changes better.
Timo Sirainen <tss@iki.fi>
parents:
5931
diff
changeset
|
594 } |
6038
cadb5b7cd919
Fixes to recent handling. Now it should work properly.
Timo Sirainen <tss@iki.fi>
parents:
6037
diff
changeset
|
595 |
7067 | 596 i_assert(hdr->first_recent_uid <= first_recent_uid); |
597 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
|
598 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
|
599 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
|
600 &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
|
601 } |
9464
939edf3ed09b
maildir: Having a lot of keywords assert-crashed with "stack frame changed".
Timo Sirainen <tss@iki.fi>
parents:
9376
diff
changeset
|
602 array_free(&ctx->keywords); |
939edf3ed09b
maildir: Having a lot of keywords assert-crashed with "stack frame changed".
Timo Sirainen <tss@iki.fi>
parents:
9376
diff
changeset
|
603 array_free(&ctx->idx_keywords); |
5920
00c5e3cbeaf0
Moved index syncing code to its own file.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
604 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
|
605 } |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
606 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
607 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
|
608 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
|
609 { |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
610 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
|
611 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
|
612 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
|
613 "maildir", 0, |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
614 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
|
615 sizeof(uint32_t)); |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
616 } |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
617 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
|
618 } |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
619 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
620 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
|
621 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
|
622 uint32_t seq) |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
623 { |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
624 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
|
625 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
|
626 const void *data; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
627 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
|
628 struct stat st; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
629 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
|
630 bool expunged; |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
631 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
632 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
|
633 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
|
634 rec = data; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
635 |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
636 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
|
637 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
|
638 /* 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
|
639 return 1; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
640 } |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
641 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
642 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
|
643 box->name, |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
644 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
|
645 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
646 /* check if new/ changed */ |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
647 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
|
648 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
|
649 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
|
650 "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
|
651 return -1; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
652 } |
7043
7708a8c166d6
Compiler warning fixes on 32bit systems.
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
653 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
|
654 return 1; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
655 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
656 /* check if cur/ changed */ |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
657 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
|
658 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
|
659 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
|
660 "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
|
661 return -1; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
662 } |
7043
7708a8c166d6
Compiler warning fixes on 32bit systems.
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
663 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
|
664 return 1; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
665 return 0; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
666 } |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
667 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
668 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
|
669 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
|
670 uint32_t seq) |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
671 { |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
672 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
|
673 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
|
674 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
|
675 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
|
676 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
|
677 const void *data; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
678 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
|
679 bool expunged; |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
680 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
681 /* get the current record */ |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
682 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
|
683 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
|
684 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
|
685 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
|
686 return 0; |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
687 old_rec = data; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
688 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
689 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
|
690 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
|
691 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
|
692 /* 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
|
693 } else { |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
694 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
|
695 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
|
696 } |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
697 |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
698 if (old_rec == NULL || |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
699 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
|
700 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
|
701 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
|
702 &new_rec, NULL); |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
703 } |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
704 return 0; |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6052
diff
changeset
|
705 } |