Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/plugins/expire/expire-plugin.c @ 9490:fd84592e817b HEAD
dovecot-example.conf: Updated dict comments.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 23 Nov 2009 13:08:47 -0500 |
parents | 00757d350812 |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8471
diff
changeset
|
1 /* Copyright (c) 2006-2009 Dovecot authors, see the included COPYING file */ |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
2 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
4 #include "ioloop.h" |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
5 #include "array.h" |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
6 #include "str.h" |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
7 #include "dict.h" |
5577 | 8 #include "mail-namespace.h" |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
9 #include "index-mail.h" |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
10 #include "index-storage.h" |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
11 #include "expire-env.h" |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
12 #include "expire-plugin.h" |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
13 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
14 #include <stdlib.h> |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
15 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
16 #define EXPIRE_CONTEXT(obj) \ |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
17 MODULE_CONTEXT(obj, expire_storage_module) |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
18 #define EXPIRE_MAIL_CONTEXT(obj) \ |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
19 MODULE_CONTEXT(obj, expire_mail_module) |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
20 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
21 struct expire { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
22 struct dict *db; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
23 struct expire_env *env; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
24 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
25 void (*next_hook_mail_storage_created)(struct mail_storage *storage); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
26 }; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
27 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
28 struct expire_mailbox { |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
29 union mailbox_module_context module_ctx; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
30 time_t expire_secs; |
7423
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
31 unsigned int altmove:1; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
32 }; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
33 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
34 struct expire_transaction_context { |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
35 union mailbox_transaction_module_context module_ctx; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
36 |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
37 unsigned int saves:1; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
38 unsigned int first_expunged:1; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
39 }; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
40 |
5185
24f4a959a24c
Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents:
4523
diff
changeset
|
41 const char *expire_plugin_version = PACKAGE_VERSION; |
24f4a959a24c
Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents:
4523
diff
changeset
|
42 |
9210
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
43 static bool expire_debug; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
44 static struct expire expire; |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
45 static MODULE_CONTEXT_DEFINE_INIT(expire_storage_module, |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
46 &mail_storage_module_register); |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
47 static MODULE_CONTEXT_DEFINE_INIT(expire_mail_module, &mail_module_register); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
48 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
49 static struct mailbox_transaction_context * |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
50 expire_mailbox_transaction_begin(struct mailbox *box, |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
51 enum mailbox_transaction_flags flags) |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
52 { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
53 struct expire_mailbox *xpr_box = EXPIRE_CONTEXT(box); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
54 struct mailbox_transaction_context *t; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
55 struct expire_transaction_context *xt; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
56 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
57 t = xpr_box->module_ctx.super.transaction_begin(box, flags); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
58 xt = i_new(struct expire_transaction_context, 1); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
59 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
60 MODULE_CONTEXT_SET(t, expire_storage_module, xt); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
61 return t; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
62 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
63 |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6270
diff
changeset
|
64 static void first_nonexpunged_timestamp(struct mailbox_transaction_context *_t, |
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6270
diff
changeset
|
65 time_t *stamp_r) |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
66 { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
67 struct index_transaction_context *t = |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
68 (struct index_transaction_context *)_t; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
69 struct mail_index_view *view = t->trans_view; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
70 const struct mail_index_header *hdr; |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
71 struct mail *mail; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
72 uint32_t seq; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
73 |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
74 mail = mail_alloc(_t, 0, NULL); |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
75 |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
76 /* find the first non-expunged mail. we're here because the first |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
77 mail was expunged, so don't bother checking it. */ |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
78 hdr = mail_index_get_header(view); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
79 for (seq = 2; seq <= hdr->messages_count; seq++) { |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6270
diff
changeset
|
80 if (!mail_index_is_expunged(view, seq)) { |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
81 mail_set_seq(mail, seq); |
7423
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
82 if (mail_get_save_date(mail, stamp_r) == 0) |
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
83 break; |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6270
diff
changeset
|
84 } |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
85 } |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
86 mail_free(&mail); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
87 |
7423
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
88 if (seq > hdr->messages_count) { |
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
89 /* everything expunged */ |
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
90 *stamp_r = 0; |
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
91 } |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
92 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
93 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
94 static int |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
95 expire_mailbox_transaction_commit(struct mailbox_transaction_context *t, |
6270 | 96 uint32_t *uid_validity_r, |
5572
896845fbc4ed
Added mailbox_transaction_commit_get_uids() which returns the UID range for
Timo Sirainen <tss@iki.fi>
parents:
5450
diff
changeset
|
97 uint32_t *first_saved_uid_r, |
896845fbc4ed
Added mailbox_transaction_commit_get_uids() which returns the UID range for
Timo Sirainen <tss@iki.fi>
parents:
5450
diff
changeset
|
98 uint32_t *last_saved_uid_r) |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
99 { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
100 struct expire_mailbox *xpr_box = EXPIRE_CONTEXT(t->box); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
101 struct expire_transaction_context *xt = EXPIRE_CONTEXT(t); |
8253
c9b9b551eb3f
Expire plugin was crashing because of previous change.
Timo Sirainen <tss@iki.fi>
parents:
8243
diff
changeset
|
102 struct mailbox *box = t->box; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
103 time_t new_stamp; |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
104 bool update_dict = FALSE; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
105 int ret; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
106 |
7423
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
107 if (xpr_box->altmove) { |
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
108 /* only moving mails - don't update the move stamps */ |
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
109 } else if (xt->first_expunged) { |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
110 /* first mail expunged. dict needs updating. */ |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6270
diff
changeset
|
111 first_nonexpunged_timestamp(t, &new_stamp); |
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6270
diff
changeset
|
112 update_dict = TRUE; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
113 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
114 |
5572
896845fbc4ed
Added mailbox_transaction_commit_get_uids() which returns the UID range for
Timo Sirainen <tss@iki.fi>
parents:
5450
diff
changeset
|
115 if (xpr_box->module_ctx.super. |
6512
1a3604c8ee05
mailbox_transaction_commit*() doesn't sync the mailbox anymore, so it
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
116 transaction_commit(t, uid_validity_r, |
6270 | 117 first_saved_uid_r, last_saved_uid_r) < 0) { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
118 i_free(xt); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
119 return -1; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
120 } |
8253
c9b9b551eb3f
Expire plugin was crashing because of previous change.
Timo Sirainen <tss@iki.fi>
parents:
8243
diff
changeset
|
121 /* transaction is freed now */ |
c9b9b551eb3f
Expire plugin was crashing because of previous change.
Timo Sirainen <tss@iki.fi>
parents:
8243
diff
changeset
|
122 t = NULL; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
123 |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
124 if (xt->first_expunged || xt->saves) T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
125 const char *key, *value; |
9437
00757d350812
expire: Mailbox names should be written to dict using their virtual name.
Timo Sirainen <tss@iki.fi>
parents:
9210
diff
changeset
|
126 string_t *vname = t_str_new(128); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
127 |
9437
00757d350812
expire: Mailbox names should be written to dict using their virtual name.
Timo Sirainen <tss@iki.fi>
parents:
9210
diff
changeset
|
128 mail_namespace_get_vname(box->storage->ns->user->namespaces, |
00757d350812
expire: Mailbox names should be written to dict using their virtual name.
Timo Sirainen <tss@iki.fi>
parents:
9210
diff
changeset
|
129 vname, box->name); |
8471
f82ba0d5ed30
Expire plugin works now with multiple struct mail_users.
Timo Sirainen <tss@iki.fi>
parents:
8404
diff
changeset
|
130 key = t_strconcat(DICT_EXPIRE_PREFIX, |
f82ba0d5ed30
Expire plugin works now with multiple struct mail_users.
Timo Sirainen <tss@iki.fi>
parents:
8404
diff
changeset
|
131 box->storage->ns->user->username, "/", |
9437
00757d350812
expire: Mailbox names should be written to dict using their virtual name.
Timo Sirainen <tss@iki.fi>
parents:
9210
diff
changeset
|
132 str_c(vname), NULL); |
9209
76cff789dae2
expire plugin: If a transaction expunges all messages and saves a new one, don't delete expire row.
Timo Sirainen <tss@iki.fi>
parents:
9190
diff
changeset
|
133 if (xt->first_expunged) { |
76cff789dae2
expire plugin: If a transaction expunges all messages and saves a new one, don't delete expire row.
Timo Sirainen <tss@iki.fi>
parents:
9190
diff
changeset
|
134 if (new_stamp == 0 && xt->saves) |
76cff789dae2
expire plugin: If a transaction expunges all messages and saves a new one, don't delete expire row.
Timo Sirainen <tss@iki.fi>
parents:
9190
diff
changeset
|
135 new_stamp = ioloop_time; |
76cff789dae2
expire plugin: If a transaction expunges all messages and saves a new one, don't delete expire row.
Timo Sirainen <tss@iki.fi>
parents:
9190
diff
changeset
|
136 } else { |
76cff789dae2
expire plugin: If a transaction expunges all messages and saves a new one, don't delete expire row.
Timo Sirainen <tss@iki.fi>
parents:
9190
diff
changeset
|
137 i_assert(xt->saves); |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
138 /* saved new mails. dict needs to be updated only if |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
139 this is the first mail in the database */ |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
140 ret = dict_lookup(expire.db, pool_datastack_create(), |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
141 key, &value); |
7482
955ae7b7ad1a
Handle dict_init() and dict_lookup() failures without crashing.
Timo Sirainen <tss@iki.fi>
parents:
7462
diff
changeset
|
142 update_dict = ret == 0 || |
955ae7b7ad1a
Handle dict_init() and dict_lookup() failures without crashing.
Timo Sirainen <tss@iki.fi>
parents:
7462
diff
changeset
|
143 (ret > 0 && strtoul(value, NULL, 10) == 0); |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
144 /* may not be exactly the first message's save time |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
145 but a few second difference doesn't matter */ |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
146 new_stamp = ioloop_time; |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
147 } |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
148 |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
149 if (update_dict) { |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
150 struct dict_transaction_context *dctx; |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
151 |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
152 dctx = dict_transaction_begin(expire.db); |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
153 if (new_stamp == 0) { |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
154 /* everything expunged */ |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
155 dict_unset(dctx, key); |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
156 } else { |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
157 new_stamp += xpr_box->expire_secs; |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
158 dict_set(dctx, key, dec2str(new_stamp)); |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
159 } |
8108
b46b0158eb64
dict API: deinit functions now take pointer-to-pointer parameter which gets NULLed.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
160 dict_transaction_commit(&dctx); |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
161 } |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
162 } T_END; |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
163 i_free(xt); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
164 return 0; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
165 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
166 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
167 static void |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
168 expire_mailbox_transaction_rollback(struct mailbox_transaction_context *t) |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
169 { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
170 struct expire_mailbox *xpr_box = EXPIRE_CONTEXT(t->box); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
171 struct expire_transaction_context *xt = EXPIRE_CONTEXT(t); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
172 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
173 xpr_box->module_ctx.super.transaction_rollback(t); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
174 i_free(xt); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
175 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
176 |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6270
diff
changeset
|
177 static void expire_mail_expunge(struct mail *_mail) |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
178 { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
179 struct mail_private *mail = (struct mail_private *)_mail; |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
180 union mail_module_context *xpr_mail = EXPIRE_MAIL_CONTEXT(mail); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
181 struct expire_transaction_context *xt = |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
182 EXPIRE_CONTEXT(_mail->transaction); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
183 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
184 if (_mail->seq == 1) { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
185 /* first mail expunged, database needs to be updated */ |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
186 xt->first_expunged = TRUE; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
187 } |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6270
diff
changeset
|
188 xpr_mail->super.expunge(_mail); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
189 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
190 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
191 static struct mail * |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
192 expire_mail_alloc(struct mailbox_transaction_context *t, |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
193 enum mail_fetch_field wanted_fields, |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
194 struct mailbox_header_lookup_ctx *wanted_headers) |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
195 { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
196 struct expire_mailbox *xpr_box = EXPIRE_CONTEXT(t->box); |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
197 union mail_module_context *xpr_mail; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
198 struct mail *_mail; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
199 struct mail_private *mail; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
200 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
201 _mail = xpr_box->module_ctx.super. |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
202 mail_alloc(t, wanted_fields, wanted_headers); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
203 mail = (struct mail_private *)_mail; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
204 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
205 xpr_mail = p_new(mail->pool, union mail_module_context, 1); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
206 xpr_mail->super = mail->v; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
207 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
208 mail->v.expunge = expire_mail_expunge; |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
209 MODULE_CONTEXT_SET_SELF(mail, expire_mail_module, xpr_mail); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
210 return _mail; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
211 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
212 |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
213 static int expire_save_finish(struct mail_save_context *ctx) |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
214 { |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
215 struct expire_transaction_context *xt = |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
216 EXPIRE_CONTEXT(ctx->transaction); |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
217 struct expire_mailbox *xpr_box = EXPIRE_CONTEXT(ctx->transaction->box); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
218 |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
219 xt->saves = TRUE; |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
220 return xpr_box->module_ctx.super.save_finish(ctx); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
221 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
222 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
223 static int |
8726
68db63cc32b3
Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
224 expire_copy(struct mail_save_context *ctx, struct mail *mail) |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
225 { |
8726
68db63cc32b3
Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
226 struct expire_transaction_context *xt = |
68db63cc32b3
Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
227 EXPIRE_CONTEXT(ctx->transaction); |
68db63cc32b3
Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
228 struct expire_mailbox *xpr_box = EXPIRE_CONTEXT(ctx->transaction->box); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
229 |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
230 xt->saves = TRUE; |
8726
68db63cc32b3
Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
231 return xpr_box->module_ctx.super.copy(ctx, mail); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
232 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
233 |
7423
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
234 static void |
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
235 mailbox_expire_hook(struct mailbox *box, time_t expire_secs, bool altmove) |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
236 { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
237 struct expire_mailbox *xpr_box; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
238 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
239 xpr_box = p_new(box->pool, struct expire_mailbox, 1); |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
240 xpr_box->module_ctx.super = box->v; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
241 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
242 box->v.transaction_begin = expire_mailbox_transaction_begin; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
243 box->v.transaction_commit = expire_mailbox_transaction_commit; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
244 box->v.transaction_rollback = expire_mailbox_transaction_rollback; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
245 box->v.mail_alloc = expire_mail_alloc; |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
246 box->v.save_finish = expire_save_finish; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
247 box->v.copy = expire_copy; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
248 |
7423
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
249 xpr_box->altmove = altmove; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
250 xpr_box->expire_secs = expire_secs; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
251 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
252 MODULE_CONTEXT_SET(box, expire_storage_module, xpr_box); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
253 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
254 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
255 static struct mailbox * |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
256 expire_mailbox_open(struct mail_storage *storage, const char *name, |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
257 struct istream *input, enum mailbox_open_flags flags) |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
258 { |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
259 union mail_storage_module_context *xpr_storage = |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
260 EXPIRE_CONTEXT(storage); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
261 struct mailbox *box; |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
262 string_t *vname; |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
263 unsigned int secs; |
7423
bd54359bfb3a
If first message is expunged from expire_altmove mailbox, don't update dict.
Timo Sirainen <tss@iki.fi>
parents:
7335
diff
changeset
|
264 bool altmove; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
265 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
266 box = xpr_storage->super.mailbox_open(storage, name, input, flags); |
9210
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
267 if (box == NULL) |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
268 return NULL; |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
269 |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
270 vname = t_str_new(128); |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
271 (void)mail_namespace_get_vname(storage->ns, vname, name); |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
272 |
9210
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
273 secs = expire_box_find_min_secs(expire.env, str_c(vname), &altmove); |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
274 if (expire_debug) { |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
275 if (secs == 0) { |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
276 i_info("expire: No expiring in mailbox: %s", |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
277 str_c(vname)); |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
278 } else { |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
279 i_info("expire: Mails expire in %u secs in mailbox: %s", |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
280 secs, str_c(vname)); |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
281 } |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
282 } |
9210
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
283 if (secs != 0) |
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
284 mailbox_expire_hook(box, secs, altmove); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
285 return box; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
286 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
287 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
288 static void expire_mail_storage_created(struct mail_storage *storage) |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
289 { |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
290 union mail_storage_module_context *xpr_storage; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
291 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
292 xpr_storage = |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
293 p_new(storage->pool, union mail_storage_module_context, 1); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
294 xpr_storage->super = storage->v; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
295 storage->v.mailbox_open = expire_mailbox_open; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
296 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5338
diff
changeset
|
297 MODULE_CONTEXT_SET_SELF(storage, expire_storage_module, xpr_storage); |
7462
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7423
diff
changeset
|
298 |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7423
diff
changeset
|
299 if (expire.next_hook_mail_storage_created != NULL) |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7423
diff
changeset
|
300 expire.next_hook_mail_storage_created(storage); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
301 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
302 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
303 void expire_plugin_init(void) |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
304 { |
9174
eed86bcc33aa
dict proxy: Use base_dir as the default dict-server location.
Timo Sirainen <tss@iki.fi>
parents:
8726
diff
changeset
|
305 const char *expunge_env, *altmove_env, *dict_uri, *base_dir; |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
306 |
9210
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
307 expire_debug = getenv("DEBUG") != NULL; |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
308 expunge_env = getenv("EXPIRE"); |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
309 altmove_env = getenv("EXPIRE_ALTMOVE"); |
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
310 if (expunge_env != NULL || altmove_env != NULL) { |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
311 dict_uri = getenv("EXPIRE_DICT"); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
312 if (dict_uri == NULL) |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
313 i_fatal("expire plugin: expire_dict setting missing"); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
314 |
7335
969656b58e7f
Added wildcard support to expire plugin. Added a new expire_altmove setting
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
315 expire.env = expire_env_init(expunge_env, altmove_env); |
8471
f82ba0d5ed30
Expire plugin works now with multiple struct mail_users.
Timo Sirainen <tss@iki.fi>
parents:
8404
diff
changeset
|
316 /* we're using only shared dictionary, the username |
f82ba0d5ed30
Expire plugin works now with multiple struct mail_users.
Timo Sirainen <tss@iki.fi>
parents:
8404
diff
changeset
|
317 doesn't matter. */ |
9174
eed86bcc33aa
dict proxy: Use base_dir as the default dict-server location.
Timo Sirainen <tss@iki.fi>
parents:
8726
diff
changeset
|
318 base_dir = getenv("BASE_DIR"); |
eed86bcc33aa
dict proxy: Use base_dir as the default dict-server location.
Timo Sirainen <tss@iki.fi>
parents:
8726
diff
changeset
|
319 if (base_dir == NULL) |
eed86bcc33aa
dict proxy: Use base_dir as the default dict-server location.
Timo Sirainen <tss@iki.fi>
parents:
8726
diff
changeset
|
320 base_dir = PKG_RUNDIR; |
eed86bcc33aa
dict proxy: Use base_dir as the default dict-server location.
Timo Sirainen <tss@iki.fi>
parents:
8726
diff
changeset
|
321 expire.db = dict_init(dict_uri, DICT_DATA_TYPE_UINT32, "", |
eed86bcc33aa
dict proxy: Use base_dir as the default dict-server location.
Timo Sirainen <tss@iki.fi>
parents:
8726
diff
changeset
|
322 base_dir); |
7482
955ae7b7ad1a
Handle dict_init() and dict_lookup() failures without crashing.
Timo Sirainen <tss@iki.fi>
parents:
7462
diff
changeset
|
323 if (expire.db == NULL) |
955ae7b7ad1a
Handle dict_init() and dict_lookup() failures without crashing.
Timo Sirainen <tss@iki.fi>
parents:
7462
diff
changeset
|
324 i_fatal("expire plugin: dict_init() failed"); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
325 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
326 expire.next_hook_mail_storage_created = |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
327 hook_mail_storage_created; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
328 hook_mail_storage_created = expire_mail_storage_created; |
9210
df2d4e398c06
expire plugin: If mail_debug=yes, log more debug information.
Timo Sirainen <tss@iki.fi>
parents:
9209
diff
changeset
|
329 } else if (expire_debug && getenv("EXPIRE_TOOL_BINARY") == NULL) { |
8404
d3cbd3494a8c
Plugins: If mail_debug=yes, log "plugin disabled" if plugin's required setting isn't set.
Timo Sirainen <tss@iki.fi>
parents:
8253
diff
changeset
|
330 i_info("expire: No expire or expire_altmove settings - " |
d3cbd3494a8c
Plugins: If mail_debug=yes, log "plugin disabled" if plugin's required setting isn't set.
Timo Sirainen <tss@iki.fi>
parents:
8253
diff
changeset
|
331 "plugin disabled"); |
4523
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
332 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
333 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
334 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
335 void expire_plugin_deinit(void) |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
336 { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
337 if (expire.db != NULL) { |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
338 hook_mail_storage_created = |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
339 expire.next_hook_mail_storage_created; |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
340 |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
341 dict_deinit(&expire.db); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
342 expire_env_deinit(expire.env); |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
343 } |
99699cf9df43
Initial import of expire plugin code. Seems to work with at least one user. :)
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
344 } |