maildirproc is a program that processes one or several existing mail boxes in the maildir format. It is primarily focused on mail sorting — i.e., moving, copying, forwarding and deleting mail according to a set of rules. It can be seen as an alternative to procmail, but instead of being a delivery agent (which wants to be part of the delivery chain), maildirproc only processes already delivered mail. And that's a feature, not a bug.
So, what's good about using maildirproc instead of a more conventional setup, with a delivery agent like procmail? For me (the author) it's this:
- It's small. maildirproc is just a small Python program that is easy to understand.
- It's robust. If there's a syntax error in the configuration, or a bug that makes the program crash, then nothing happens; the mail will not disappear. And as a consequence of using maildirs, no locks are needed.
- The configuration language is relatively easy to understand and use, yet very powerful. The rules are expressed in a full-blown computer language (Python).
- It's easy to test new configuration. Since maildirproc is not part of the delivery chain, it's just a matter of taking down or disabling the process, modifying the configuration and running maildirproc in test mode. When the new configuration is ready, just start or enable the process again.
Version 1.0, released 2014-12-13 (see NEWS for a list of changes):
Source code repository
For a long time, I used procmail to sort my mail, but I was not entirely happy with its configuration language. I subscribe to a lot of mailing lists and I use several e-mail addresses, so the .procmailrc file was quite large and complex and I found it hard to express mail sorting rules elegantly. I wanted to be able to define and use functions, data structures, if statements, loops and other imperative language constructs and felt that procmail's rule-based vocabulary was limiting. I thought about writing a program to generate the configuration from some higher-level rules, but I never got to it. I also didn't feel comfortable with e-mail sorting being part of the delivery chain. (Granted, procmail can be used in other setups too.)
Then one day I stumbled upon a program called Maildird, written by Jörgen Cederlöf, and I liked its basic design:
Since Maildird was not configurable (at least not at the time) in the way I wanted, I decided to write my own program that worked somewhat similarly but with a configuration style that suited me. If you like it, you are welcome to use (or improve) it too.
See the maildirproc reference.
See the examples directory.
maildirproc has no other dependencies than a working Python on a Unixish system. No special installation is needed; just copy the maildirproc file to a suitable place and run it. You can also run run python setup.py install.
You can run maildirproc in several diffent ways, e.g.:
Manually: You could, for example, run
maildirproc --once -r foo.rc -b . -m Maildirto apply the program in foo.rc once on a maildir directory called Maildir in the current directory.
By cron: Put a row like
* * * * * maildirproc --oncein your crontab to run maildirproc each minute (using the default RC file ~/.maildirproc/default.rc).
- As a long-running process: Just start maildirproc (without the --once flag).
- Using some service supervision framework, for example runit.