dovecot-1.1: Trash plugin: Assign storage to all mailboxes at st...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Oct 18 21:21:22 EEST 2008
details: http://hg.dovecot.org/dovecot-1.1/rev/90a1d5c1e16e
changeset: 7951:90a1d5c1e16e
user: Timo Sirainen <tss at iki.fi>
date: Sat Oct 18 21:21:18 2008 +0300
description:
Trash plugin: Assign storage to all mailboxes at startup so errors are caught immediately.
diffstat:
1 file changed, 48 insertions(+), 33 deletions(-)
src/plugins/trash/trash-plugin.c | 81 ++++++++++++++++++++++----------------
diffs (149 lines):
diff -r 12d991f2b2da -r 90a1d5c1e16e src/plugins/trash/trash-plugin.c
--- a/src/plugins/trash/trash-plugin.c Sat Oct 18 20:48:48 2008 +0300
+++ b/src/plugins/trash/trash-plugin.c Sat Oct 18 21:21:18 2008 +0300
@@ -35,6 +35,8 @@ struct trash_mailbox {
const char *trash_plugin_version = PACKAGE_VERSION;
+static void (*trash_next_hook_mail_namespaces_created)
+ (struct mail_namespace *namespaces);
static int (*trash_next_quota_test_alloc)(struct quota_transaction_context *,
uoff_t, bool *);
@@ -85,25 +87,6 @@ static int trash_clean_mailbox_get_next(
return 1;
}
-static void trash_find_storage(struct trash_mailbox *trash)
-{
- struct mail_storage *const *storages;
- unsigned int i, count;
- const char *name;
-
- storages = array_get("a_set->storages, &count);
- for (i = 0; i < count; i++) {
- name = trash->name;
- if (mail_namespace_update_name(storages[i]->ns, &name)) {
- if (name != trash->name)
- trash->name = p_strdup(config_pool, name);
- trash->storage = storages[i];
- return;
- }
- }
- i_fatal("trash: Namespace not found for mailbox '%s'", trash->name);
-}
-
static int trash_try_clean_mails(struct quota_transaction_context *ctx,
uint64_t size_needed)
{
@@ -122,9 +105,6 @@ static int trash_try_clean_mails(struct
for (j = i; j < count; j++) {
if (trashes[j].priority != trashes[i].priority)
break;
-
- if (trashes[j].storage == NULL)
- trash_find_storage(&trashes[j]);
ret = trash_clean_mailbox_get_next(&trashes[j],
&received);
@@ -229,6 +209,25 @@ trash_quota_test_alloc(struct quota_tran
return 0;
}
+static bool trash_find_storage(struct trash_mailbox *trash)
+{
+ struct mail_storage *const *storages;
+ unsigned int i, count;
+ const char *name;
+
+ storages = array_get("a_set->storages, &count);
+ for (i = 0; i < count; i++) {
+ name = trash->name;
+ if (mail_namespace_update_name(storages[i]->ns, &name)) {
+ if (name != trash->name)
+ trash->name = p_strdup(config_pool, name);
+ trash->storage = storages[i];
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
static int trash_mailbox_priority_cmp(const void *p1, const void *p2)
{
const struct trash_mailbox *t1 = p1, *t2 = p2;
@@ -242,11 +241,11 @@ static int read_configuration(const char
const char *line, *name;
struct trash_mailbox *trash;
unsigned int count;
- int fd;
+ int fd, ret = 0;
fd = open(path, O_RDONLY);
if (fd == -1) {
- i_error("open(%s) failed: %m", path);
+ i_error("trash plugin: open(%s) failed: %m", path);
return -1;
}
@@ -265,6 +264,12 @@ static int read_configuration(const char
trash->priority = atoi(t_strdup_until(line, name));
trash->search_arg.type = SEARCH_ALL;
+ if (!trash_find_storage(trash)) {
+ i_error("trash: Namespace not found for mailbox '%s'",
+ trash->name);
+ ret = -1;
+ }
+
if (getenv("DEBUG") != NULL) {
i_info("trash plugin: Added '%s' with priority %d",
trash->name, trash->priority);
@@ -275,12 +280,16 @@ static int read_configuration(const char
trash = array_get_modifiable(&trash_boxes, &count);
qsort(trash, count, sizeof(*trash), trash_mailbox_priority_cmp);
- return 0;
-}
-
-void trash_plugin_init(void)
+ return ret;
+}
+
+static void
+trash_hook_mail_namespaces_created(struct mail_namespace *namespaces)
{
const char *env;
+
+ if (trash_next_hook_mail_namespaces_created != NULL)
+ trash_next_hook_mail_namespaces_created(namespaces);
env = getenv("TRASH");
if (env == NULL) {
@@ -299,15 +308,21 @@ void trash_plugin_init(void)
BUFFER_APPROX_SIZE +
INIT_TRASH_MAILBOX_COUNT *
(sizeof(struct trash_mailbox) + 32));
- if (read_configuration(env) < 0)
- return;
-
- trash_next_quota_test_alloc = quota_set->test_alloc;
- quota_set->test_alloc = trash_quota_test_alloc;
+ if (read_configuration(env) == 0) {
+ trash_next_quota_test_alloc = quota_set->test_alloc;
+ quota_set->test_alloc = trash_quota_test_alloc;
+ }
+}
+
+void trash_plugin_init(void)
+{
+ trash_next_hook_mail_namespaces_created = hook_mail_namespaces_created;
+ hook_mail_namespaces_created = trash_hook_mail_namespaces_created;
}
void trash_plugin_deinit(void)
{
+ hook_mail_namespaces_created = trash_hook_mail_namespaces_created;
quota_set->test_alloc = trash_next_quota_test_alloc;
if (config_pool != NULL)
More information about the dovecot-cvs
mailing list