Mercurial > dovecot > original-hg > dovecot-1.2
comparison src/plugins/trash/trash-plugin.c @ 4748:5fb199ed254a HEAD
Trash plugin was completely broken before.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 04 Nov 2006 21:51:23 +0200 |
parents | 444edc8abef9 |
children | 49c9e7588de4 |
comparison
equal
deleted
inserted
replaced
4747:e46eb913bcee | 4748:5fb199ed254a |
---|---|
22 struct mail_storage *storage; | 22 struct mail_storage *storage; |
23 | 23 |
24 /* temporarily set while cleaning: */ | 24 /* temporarily set while cleaning: */ |
25 struct mailbox *box; | 25 struct mailbox *box; |
26 struct mailbox_transaction_context *trans; | 26 struct mailbox_transaction_context *trans; |
27 struct mail_search_arg search_arg; | |
27 struct mail_search_context *search_ctx; | 28 struct mail_search_context *search_ctx; |
28 struct mail *mail; | 29 struct mail *mail; |
29 | 30 |
30 unsigned int mail_set:1; | 31 unsigned int mail_set:1; |
31 }; | 32 }; |
35 | 36 |
36 static pool_t config_pool; | 37 static pool_t config_pool; |
37 /* trash_boxes ordered by priority, highest first */ | 38 /* trash_boxes ordered by priority, highest first */ |
38 static ARRAY_DEFINE(trash_boxes, struct trash_mailbox); | 39 static ARRAY_DEFINE(trash_boxes, struct trash_mailbox); |
39 | 40 |
41 static int sync_mailbox(struct mailbox *box) | |
42 { | |
43 struct mailbox_sync_context *ctx; | |
44 struct mailbox_sync_rec sync_rec; | |
45 struct mailbox_status status; | |
46 | |
47 ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ); | |
48 while (mailbox_sync_next(ctx, &sync_rec) > 0) | |
49 ; | |
50 return mailbox_sync_deinit(&ctx, &status); | |
51 } | |
52 | |
40 static int trash_clean_mailbox_open(struct trash_mailbox *trash) | 53 static int trash_clean_mailbox_open(struct trash_mailbox *trash) |
41 { | 54 { |
42 struct mail_search_arg search_arg; | |
43 | |
44 trash->box = mailbox_open(trash->storage, trash->name, NULL, | 55 trash->box = mailbox_open(trash->storage, trash->name, NULL, |
45 MAILBOX_OPEN_KEEP_RECENT); | 56 MAILBOX_OPEN_KEEP_RECENT); |
57 if (sync_mailbox(trash->box) < 0) | |
58 return -1; | |
59 | |
46 trash->trans = mailbox_transaction_begin(trash->box, 0); | 60 trash->trans = mailbox_transaction_begin(trash->box, 0); |
47 | 61 |
48 memset(&search_arg, 0, sizeof(search_arg)); | 62 trash->search_ctx = mailbox_search_init(trash->trans, NULL, |
49 search_arg.type = SEARCH_ALL; | 63 &trash->search_arg, NULL); |
50 | |
51 trash->search_ctx = | |
52 mailbox_search_init(trash->trans, NULL, &search_arg, NULL); | |
53 trash->mail = mail_alloc(trash->trans, MAIL_FETCH_PHYSICAL_SIZE | | 64 trash->mail = mail_alloc(trash->trans, MAIL_FETCH_PHYSICAL_SIZE | |
54 MAIL_FETCH_RECEIVED_DATE, NULL); | 65 MAIL_FETCH_RECEIVED_DATE, NULL); |
55 | 66 |
56 return mailbox_search_next(trash->search_ctx, trash->mail); | 67 return mailbox_search_next(trash->search_ctx, trash->mail); |
57 } | 68 } |
85 uint64_t size; | 96 uint64_t size; |
86 int ret = 0; | 97 int ret = 0; |
87 | 98 |
88 trashes = array_get_modifiable(&trash_boxes, &count); | 99 trashes = array_get_modifiable(&trash_boxes, &count); |
89 for (i = 0; i < count; ) { | 100 for (i = 0; i < count; ) { |
101 if (trashes[i].storage == NULL) { | |
102 /* FIXME: this is really ugly. it'll do however until | |
103 we get proper namespace support for lib-storage. */ | |
104 struct mail_storage *const *storage; | |
105 | |
106 storage = array_idx("a->storages, 0); | |
107 trashes[i].storage = *storage; | |
108 } | |
90 /* expunge oldest mails first in all trash boxes with | 109 /* expunge oldest mails first in all trash boxes with |
91 same priority */ | 110 same priority */ |
92 oldest_idx = count; | 111 oldest_idx = count; |
93 oldest = (time_t)-1; | 112 oldest = (time_t)-1; |
94 for (j = i; j < count; j++) { | 113 for (j = i; j < count; j++) { |
128 | 147 |
129 __err: | 148 __err: |
130 for (i = 0; i < count; i++) { | 149 for (i = 0; i < count; i++) { |
131 struct trash_mailbox *trash = &trashes[i]; | 150 struct trash_mailbox *trash = &trashes[i]; |
132 | 151 |
152 trash->mail_set = FALSE; | |
133 mail_free(&trash->mail); | 153 mail_free(&trash->mail); |
134 (void)mailbox_search_deinit(&trash->search_ctx); | 154 (void)mailbox_search_deinit(&trash->search_ctx); |
135 | 155 |
136 if (size_needed == 0) { | 156 if (size_needed == 0) { |
137 (void)mailbox_transaction_commit(&trash->trans, | 157 (void)mailbox_transaction_commit(&trash->trans, |
206 continue; | 226 continue; |
207 | 227 |
208 trash = array_append_space(&trash_boxes); | 228 trash = array_append_space(&trash_boxes); |
209 trash->name = p_strdup(config_pool, name+1); | 229 trash->name = p_strdup(config_pool, name+1); |
210 trash->priority = atoi(t_strdup_until(line, name)); | 230 trash->priority = atoi(t_strdup_until(line, name)); |
231 trash->search_arg.type = SEARCH_ALL; | |
211 } | 232 } |
212 i_stream_destroy(&input); | 233 i_stream_destroy(&input); |
213 (void)close(fd); | 234 (void)close(fd); |
214 | 235 |
215 trash = array_get_modifiable(&trash_boxes, &count); | 236 trash = array_get_modifiable(&trash_boxes, &count); |