list moderator script

Russ Nelson <[email protected]> 5 Feb 2008 16:20:53 -0000
Newsgroups gmane.mail.ezmlm
Message-ID <[email protected]>
I'm using this script to filter my list moderator emails.  Makes it
MUCH, MUCH easier to moderate the lists.

#!/usr/bin/python

import sys

state = 0

for line in sys.stdin:
    if state == 3:
        state = 4
    elif state == 4:
        state = 5
        sys.stdout.write(reply_to)
    elif state == 5 and line == "--%s--\n" % boundary:
        break
    elif state == 5 and line.startswith("Subject: "):
        sys.stdout.write("Subject: [%s]" % listname)
        sys.stdout.write(line[len("Subject: "):])
    elif state == 5 and line.startswith("Reply-To:"):
        pass
    elif state == 5:
        sys.stdout.write(line)
    elif state > 0:
        if line == "--%s\n" % boundary:
            state += 1
    elif line == "\n":
        state = 1
    elif line.startswith("Subject:"):
        # Subject: MODERATE for [email protected]
        fields = line.split()
        listname = fields[3].split('@')[0]
    elif line.startswith("Reply-To:"):
        reply_to = line
    elif line.startswith("Content-Type:"):
        # Content-Type: multipart/mixed; boundary=hfglocoaipienknljjne
        boundary = line.split()[2].split('=')[1]

-- 
--my blog is at    http://blog.russnelson.com   | Software that needs
Crynwr sells support for free software  | PGPok | documentation is software
521 Pleasant Valley Rd. | +1 315-323-1241       | that needs repair.
Potsdam, NY 13676-3213  |     Sheepdog          |