Maildrop, IMAP, and Postfixadmin

I have recently configured my mail server to use IMAP. I started doing this when I was attending so that I could read urgent mail using my EeePC while at the conference and then be able to deal with the more complex stuff using my laptop later on.

The next logical step is to have mail delivered to different folders in the IMAP account. While there are ways of doing this via the Subject and other header fields, my needs are not that great. All I need to do is to support going to a folder named extension in the user’s mail store. While changing my mail server I decided to install Postfixadmin at the same time.

My first attempt to use Maildrop was to put the following in the /etc/postfix/ file:
mailbox_command = /usr/bin/maildrop -d mail -f “$SENDER” “$DOMAIN” “$USER” “$EXTENSION”

That seems to only work when you have local accounts, so I ended up setting fallback_transport = maildrop and then putting the following in /etc/postfix/

maildrop unix – n n – – pipe flags=DRhu user=vmail argv=/usr/bin/maildrop -d vmail ${nexthop} ${user} ${extension}

Where vmail is a Unix account I created for storing mail. Then I added the following to /etc/postfix/ Some of these are probably redundant (such as the virtual_mailbox_base). The recipient limit is set to 1 because there are no command-line parameters for maildrop to support two recipients for the same message.
virtual_alias_maps = mysql:/etc/postfix/
virtual_mailbox_domains = mysql:/etc/postfix/
virtual_mailbox_maps = mysql:/etc/postfix/
virtual_gid_maps = static:2000
virtual_uid_maps = static:2000
virtual_mailbox_base = /mail
vmaildir_destination_recipient_limit = 1
virtual_transport = maildrop
maildrop_destination_recipient_limit = 1

The files /etc/postfix/mysql* all have fields user=, password=, hosts=, and dbname=. The queries in each of the files are as follows: = SELECT goto FROM alias WHERE address='%s' AND active = 1 = SELECT domain FROM domain WHERE domain='%s' = SELECT maildir FROM mailbox WHERE username='%s' AND active = 1

The /etc/courier/maildroprc file has the following contents:

# log the maildrop actions
logfile "/var/log/maildrop.log"
# parameters 1, 2, and 3 are the domain, user, and extension
# try making a backup (cc) copy of the mail but do not abort if it fails
exception {
  cc "$DEFAULT/.backup/"
# try delivering to the extension folder but do not abort if it fails
exception {
  if(length("$EXTENSION") != 0 && "$EXTENSION" ne "backup")
# deliver to the main inbox if there is no folder matching the extension or if no extension is specified
to "$DEFAULT/"

Installing Postfixadmin [1] was another challenge entirely. One of the complications of this is that there is no Debian package for Lenny (it seems that there will be one in Squeeze – Lenny+1).

I found David Goodwin’s tutorial on installing Postfixadmin and lots of other things on Debian/Etch [2] to be a very useful resource. I look forward to seeing a Lenny version of that document.

Please let me know if you can think of any way to improve this.

7 comments to Maildrop, IMAP, and Postfixadmin

  • Ivà

    You should try procmail.

  • etbe

    Iva: I’ve used procmail before. While it does have a good feature set, it seems to be unmaintained and I’m concerned about it’s security.

    In this instance Courier Maildrop does everything I need.

  • Postfixadmin offers a debian package to download. It is what i use myself on etch.

  • flihp

    I’ve had good results using sieve filters (RFC 3028) with exim4. It wasn’t supported out of the box on Etch using Maildir but the few bugs that I ran into along the way were minor with known fixes. There was enough info available on mailing lists to solve the problem in two sittings (and I’m a noob to exim4 configuration).

  • Not really a better way, but I like the idea of delivering email using the IMAP program itself.

    Thus dovecot with its own delivery agent often makes for very simple configurations, when maildrop and friends seem to be getting out of hand.

    Bitter experience as a system admin tells me that if I write a script it’ll have a bug in, where as if I can do the same in one line of cut and paste from a good howto….

    In this case you can give Dovecot LDA very similar config to the Postges database configuration for users, but you don’t have to repeat any of it in the authentication for IMAP login, because well Dovecot does that as well.

    I don’t do the extension thing myself, but I keep looking at Sieve – thinking that is clearly the right sort of thing to do – but never getting around to figuring out a clean implementation that I’d be happy to live with.

  • FWIW, I use Postfix too with no complaints, and I like the Postfixadmin interface, but ended up rewriting a lot of it to use XML and XSL. I mainly use the new software for rendering text files, which I then feed to postmap-cdb.

  • flihp – hmm – inspired to look, now seems that (a choice of two) Sieve plugin can be run from the dovecot LDA, which seems to fit my set up excellently.