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