]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lazy-expunge: If lazy_expunge is set to namespace root, save all mails to the root...
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 11 Mar 2016 05:01:33 +0000 (18:01 +1300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 16 Mar 2016 23:09:43 +0000 (10:09 +1100)
So the difference is:

namespace {
  prefix = expunged/
  ..
}
plugin {
  # Move expunged mails to expunged/INBOX, expunged/Trash, etc. mailboxes
  lazy_expunge = expunged/
  # Move all expunged mails to "expunged" mailbox, which is the namespace root.
  lazy_expunge = expunged
}

src/plugins/lazy-expunge/lazy-expunge-plugin.c

index 55a97c4be9eabcd66aaaf2458f846064c0e907ee..053f25182b4b9d9f1c042d3247621b9d92788008 100644 (file)
@@ -31,6 +31,7 @@ struct lazy_expunge_mail_user {
        union mail_user_module_context module_ctx;
 
        struct mail_namespace *lazy_ns;
+       const char *lazy_mailbox_vname;
        const char *env;
        bool copy_only_last_instance;
 };
@@ -69,9 +70,14 @@ static MODULE_CONTEXT_DEFINE_INIT(lazy_expunge_mail_user_module,
 static const char *
 get_dest_vname(struct mailbox_list *list, struct mailbox *src_box)
 {
+       struct lazy_expunge_mail_user *luser =
+               LAZY_EXPUNGE_USER_CONTEXT(list->ns->user);
        const char *name;
        char src_sep, dest_sep;
 
+       if (luser->lazy_mailbox_vname != NULL)
+               return luser->lazy_mailbox_vname;
+
        /* use the (canonical / unaliased) storage name */
        name = src_box->name;
        /* replace hierarchy separators with destination virtual separator */
@@ -435,6 +441,13 @@ lazy_expunge_mail_namespaces_created(struct mail_namespace *namespaces)
                return;
 
        luser->lazy_ns = mail_namespace_find_prefix(namespaces, luser->env);
+       if (luser->lazy_ns == NULL) {
+               /* see if it's set to namespace root itself. in that case we
+                  store all the expunged mails to the namespace root. */
+               luser->lazy_ns = mail_namespace_find_prefix_nosep(namespaces, luser->env);
+               luser->lazy_mailbox_vname = p_strndup(namespaces->user->pool,
+                       luser->lazy_ns->prefix, luser->lazy_ns->prefix_len-1);
+       }
        if (luser->lazy_ns == NULL)
                i_fatal("lazy_expunge: Unknown namespace: '%s'", luser->env);
        mail_namespace_ref(luser->lazy_ns);