dystill

Download dystill 0.2 ]

[ Roundcube Plugin 0.1 ]

**dystill **is a filtering MySQL-based Mail Delivery Agent written in Python and designed for small to medium sized deployments.

dystill is a tool I wrote to help ease my transition away from a hosted email provider to my hosting my own email. Many “freemail” type systems allow you to create rules and filters for sorting your mail into folders on the server side rather than on the client side. I have lots of filters on my current email address - I estimate there are probably over 200. I create these on the fly, too. Often, when I sign up for a website, the first thing I do after the confirmation email comes in is make a folder and accompanying filter for it.

While tools to do this - Mail Delivery Agents - already exist for mail servers (such as maildrop, procmail and qfilter), most aren’t database driven or are only partially database driven. All use file-based rule “recipes” to filter or process mail. My first attempt at making this work for me was to write a web interface that stores the rules in MySQL, and a cron job which would populate the recipes based on the database. But this is kinda ungraceful. So I decided to write my own, and dystill was born.

dystill is completely database driven - it reads the user information and rules in real time from MTA virtual email databases stored in MySQL.

Normal Mail Delivery

Normally, mail is delivered to the local maildirs by the MTA. No sorting or filtering is done. If your MTA is database enabled (such as for virtual mail users), it may use database lookups to determine what email addresses are valid and where on the filesystem to store them.

Mail Delivery Using dystill

When using dystill to deliver email, instead of the MTA delivering to the local maildirs, it instead hands the email off to dystill. It connects to the database, retrieves the delivery information as well as any rules, applies the rules to the message, then delivers it to the appropriate location within the maildir.

What dystill Can Do

  • Filter incoming mail based on headers using regular expression matching.

  • Can accept incoming data either by file or by stdin.

  • Perform multiple actions based on matching:

    • Mark as read

    • Delete

    • Forward to anther address

    • Flag

    • Modify the subject

    • Sort and organize into folders and subfolders

    • Add headers

    • Duplicate messages into multiple folders

    • Silent and noisy blacklisting

  • Unicorns and fairies.

It lis licensed under the BSD License and the source code is available from GitHub.

Installing

  • dystill requires the Python argparse and MySQLdb libraries in Python. Be sure you have them.

Download and install dystill. You can put the script anywhere you like - I went ahead and put it in /usr/bin. You will need to adjust the accompanying config as required and put it in /etc or specify it’s location on the command line.

I’ve only used and tested dystill with Postfix, but it’s pretty simple and should theoretically be able to work with just about any MTA that supports piping. Still, the instructions here are presented for Postfix.

First, add the included SQL schema to your email database. This works especially well if you have followed similar instructions to the ones I did when setting up my email server.

Next, be sure you have customized your /etc/dystill.conf file, and that all the database settings are correct.

Next, edit your master.cf file and add the following:

dystill  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/dystill.py -d ${recipient}

You may need to adjust this line for whatever user your are running your virtual mail hosting as. I use vmail.

Next, edit your main.cf file as follows:

mailbox_command = dystill
virtual_transport = dystill

Plugins

A plugin for the popular webmail client Roundcube is available. It provides rule editing through the settings section in Roundcube.