Plugins.Lazyexpunge.txt   [plain text]


Lazy expunge
============

The idea behind this plugin is that expunged mails and deleted mailboxes stay
around for a while, so that user can undelete them without assistance from
sysadmin. The expunged mails won't be counted in user's quota. The plugin
itself doesn't clean up the expunged messages, you'll have to do it some other
way (see below).

The plugin is configured by defining namespaces where the mails are moved. You
can decide if you want the namespaces to be visible to clients, or if you want
to show them only via some special webmail interface.

You can use either one or three namespaces:

3 namespaces
------------

The namespaces are:

 1. Expunged messages namespace. Whenever a message is expunged in mailbox
    /<name>/, it's moved to a mailbox /<name>/ in this namespace. The mailboxes
    are created automatically as needed.
 2. Deleted mailboxes namespace. Whenever a mailbox /<name>/ is deleted, it's
    moved here with name /<name>-YYYMMDD-hhmmss/. The timestamp is there so
    that the mailbox can be deleted multiple times. If the mailbox is deleted
    multiple times within a second, random 16bit hex value is appended to it.
 3. Expunged messages in a deleted mailbox namespace. When a mailbox is deleted
    and it has messages in its expunged namespace, the mailbox is moved from
    the expunged namespace to this namespace. The destination mailbox name is
    the same as in the 2nd namespace (ie. contains the same timestamp).

Example configuration:

---%<-------------------------------------------------------------------------
# the default namespace
namespace {
  prefix =
  separator = /
  inbox = yes
}

# namespaces for lazy_expunge plugin:
namespace {
  prefix = .EXPUNGED/
  separator = /
  location = maildir:~/Maildir/expunged
}
namespace {
  prefix = .DELETED/
  separator = /
  location = maildir:~/Maildir/deleted
}
namespace {
  prefix = .DELETED/.EXPUNGED/
  separator = /
  location = maildir:~/Maildir/deleted/expunged
}

mail_plugins = $mail_plugins lazy_expunge
plugin {
  lazy_expunge = .EXPUNGED/ .DELETED/ .DELETED/.EXPUNGED/
}
---%<-------------------------------------------------------------------------

1 namespace
-----------

You create only a single namespace. When a message is expunged from mailbox
/<name>/, it's moved to a mailbox /<name>/ in the expunge namespace. When an
entire mailbox /<name>/ is deleted, it's also moved to this namespace as
/<name>/. If it already exists, their contents are merged.

Example configuration:

---%<-------------------------------------------------------------------------
# the default namespace
namespace {
  prefix =
  separator = /
  inbox = yes
}

# namespace for lazy_expunge plugin:
namespace {
  prefix = .EXPUNGED/
  separator = /
  location = maildir:~/Maildir/expunged
}

mail_plugins = $mail_plugins lazy_expunge
plugin {
  lazy_expunge = .EXPUNGED/
}
---%<-------------------------------------------------------------------------

Multi-dbox
----------

With multi-dbox use different MAILBOXDIRs (so copying between namespaces works
quickly within the same storage):

---%<-------------------------------------------------------------------------
# the default namespace
namespace {
  prefix =
  inbox = yes
  location = mdbox:~/mdbox
}

# lazy_expunge namespace(s):
namespace {
  prefix = .EXPUNGED/
  location = mdbox:~/mdbox:MAILBOXDIR=expunged
}
---%<-------------------------------------------------------------------------

Cleaning up
-----------

cronjob
-------

Run something like this for each user every night (not actually tested if it
works, and vulnerable to TOCTTOU if the user can place symlinks in any of the
directories find is traversing):

---%<-------------------------------------------------------------------------
# delete a day old mails
find Maildir/expunged Maildir/deleted Maildir/deleted/expunged \
  -type f ! -cmin 1440 -print0 | xargs -0 rm
---%<-------------------------------------------------------------------------

Trash plugin
------------

<Trash plugin> [Plugins.Trash.txt] with some help from <Quota plugin>
[Quota.txt] could probably be used to keep the expunged and deleted mailboxes
under a specified size (not tested).

Expire plugin
-------------

<Expire plugin> [Plugins.Expire.txt] was created to keep track of mails in
specific mailboxes, and expunge them when they've been there for a specified
amount of time. It keeps an internal database (e.g. SQL) of all such mailboxes,
so it doesn't have to go through all the mailboxes for all the users.

(This file was created from the wiki on 2011-11-16 14:09)