procmail replacement in Python

Gerhard Häring gh_pythonlist at
Tue Jun 18 20:16:01 EDT 2002

* Sean 'Shaleh' Perry <shalehperry at> [2002-06-18 17:04 -0700]:
> On 18-Jun-2002 Gerhard Häring wrote:
> > Does such a thing exist? 
> there is also a nice filter language from CMU called Sieve (I think).  You
> could implement a python based Sieve interpreter.

I'd just switch to Cyrus IMAP instead. I'm currently using Courier IMAP
and am quite satisfied, so I have little reason to switch. I even found
Cyrus difficult to install, even though it's also available as a FreeBSD
package (just like Courier).

All that I'm currently using from procmail are regexes on header fields,
combined with AND, and maybe OR conditions. And having two custom
filters before matching the header fields:

- spamassassin
- this one to fight stupidity in the setup of the German freemailer GMX:
  they have some braindead software that does mbox-like From_ quoting on
  their POP3 setup :-(

#!/usr/bin/env python
import re, sys

BROKEN_FROM = re.compile(r"^(>+)(from )(.*)", re.I | re.DOTALL)

for line in sys.stdin.xreadlines():
    match = BROKEN_FROM.match(line)
    if not match:
        # Remove one quote char added by braindead GMX software
        groups = match.groups()
        escape_chars = groups[0][:-1]
        sys.stdout.write(escape_chars + groups[1] + groups[2])

This sig powered by Python!
Außentemperatur in München: 23.1 °C      Wind: 0.9 m/s

More information about the Python-list mailing list