Expire plugin
=============

(v1.1+ only)

The expire plugin 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 (Berkeley DB or SQL) of all such mailboxes, so it doesn't
have to go through all the mailboxes for all the users.

The expire days are counted from when the message was saved. This may not be
exact if it's not cached in 'dovecot.index.cache':

 * mbox: The current lookup time is used and added to cache.
 * maildir: File's ctime is used.
 * dbox: Save/copy time is taken from the dbox file if it exists (it normally
   should), fallbacking to file's ctime if not.

Mailbox patterns can contain IMAP LIST command-compatible wildcards:

 * "*" works in a standard way: It matches any number of characters.
 * "%" works by matching any number of characters, but it stops at the
   hierarchy separator. Currently the separator is hardcoded to "/".

The expire plugin itself doesn't do anything except keep track of messages in
the mailboxes. To actually perform the expunging you need to run 'expire-tool'
in for example a nightly cronjob (can be run as often as you want though):

---%<-------------------------------------------------------------------------
dovecot --exec-mail ext /usr/libexec/dovecot/expire-tool
---%<-------------------------------------------------------------------------

You can also run it manually with '--test' parameter to see what would happen
without actually changing anything.

Authentication socket
---------------------

expire-tool requires an auth-master socket to find users' mailboxes. See
<LDA.txt> for how to configure one. If you're not using the default path for
the socket, you can change it by adding 'auth_socket_path' to plugin section.

Example configuration
---------------------

---%<-------------------------------------------------------------------------
protocol imap {
  mail_plugins = expire
}
protocol pop3 {
  mail_plugins = expire
}
protocol lda {
  # probably not necessary - just enables tracking messages on mailboxes
  # where messages are never saved via IMAP and never expunged
  mail_plugins = expire
}
dict {
  # NOTE: dict process currently runs as root, so this file will be owned as
root.
  expire = db:/var/lib/dovecot/expire.db
}
plugin {
  # Trash and its children 7d, Spam 30d
  expire = Trash 7 Trash/* 7 Spam 30
  expire_dict = proxy::expire

  # If you have a non-default path to auth-master, set also:
  #auth_socket_path = /var/run/dovecot/auth-master
}
---%<-------------------------------------------------------------------------

Alternative dbox directory expiration
-------------------------------------

Expire plugin can also be used to move old mail files to dbox alternative
directory. The idea behind this is that old mails are accessed rarely, so the
alternative directory may be located on a cheaper storage with lower I/O
capabilities.'expire_altmove' setting can be used to configure this:

---%<-------------------------------------------------------------------------
mail_location = dbox:~/dbox:ALT=/altstorage/%d/%n/dbox
# mail_plugin and dict settings as in above example
plugin {
  expire = Trash 7 Trash/* 7 Spam 30
  # Move all mails to slow storage after 31 days (so Trash/Spam is never moved)
  expire_altmove = * 31
  expire_dict = proxy::expire
}
---%<-------------------------------------------------------------------------

v1.0 cronjob equivalent
-----------------------

For Dovecot v1.0, this can be accomplished by running a daily shell script:

---%<-------------------------------------------------------------------------
# delete 30 day old mails
find /var/virtualmail/ -regex '.*/\.\(Trash\|Junk\)\(/.*\)?\/\(cur\|new\)/.*'
-type f  -ctime +30  -delete
# or -exec rm '{}' \; instead of -delete
---%<-------------------------------------------------------------------------

(This file was created from the wiki on 2008-06-20 04:42)
