The 'moderate-list' script
Moderate-list is a specialised perl MUA script to aid internet mailing list moderation, with support for ezmlm and MailMan 2.1.x list servers. (These mailing list managers both produce 'message awaiting moderation' mails with enough info to allow this to operate.)
Given an MH or Maildir-format mail folder full of 'moderation required' messages, it will iterate through each one, picking out the ones it understands. Each message is scanned using SpamAssassin, using full network tests and whatever other SpamAssassin features you choose to use for moderation, such as its own Bayes database.
Messages that score over the spam threshold are automatically blocked; messages that score under are kept aside for moderation.
If the script is run in automatic mode (with the '--auto' switch), or if STDIN is not connected to a tty, the script will exit with exit code 22 so that calling code will know that the messages were unmoderated. If the script is being run interactively (without '--auto' and with a tty on STDIN), an text-mode interactive UI is used, whereby the user is presented a preview of the message like so:
+------------------------------------------------------------------------ | From: Felicia <[email protected]> | To: [email protected] | Subject: Your one stop prescription shop! | List-Id: | | Preview: 36 hours: for all your needs :) | http://recognizable./?lamplightxtvuynaivelyzgvscallops | | | Perpetual optimism is a force multiplier. | [....cut] | SpamAssassin: score=0.501/5 rules=AWL,BAYES_50 +------------------------------------------------------------------------ Moderation action [ynab] (y=yes, n=no, a=allow in future, b=block in future)?
The user then presses one of the choice keys to select the moderation action to perform:
y=yes: Yes, allow this single message to be posted
n=no: No, do not allow this single message to be posted
a=allow: allow this message and all future messages from that From address
b=block: block this message and all future messages from that From address
Based on the keys pressed, the script will perform the appropriate action by mailing the moderation addresses defined in the moderation message.
A full log of a sample run can be read at ModerateListSampleRun.
Automatic Mode And Workflow
Automatic moderation is performed using the --auto switch and (optionally) the 'moderate-list-auto-filter' shell script. If you have an incoming mail filter which detects list moderation messages, and can filter incoming mail from that through a shell script filter, this may be useful.
Here are the patterns I'm using for filtering. These match MailMan and the ASF ezmlm lists:
^X-List-Administrivia:.*yes ^From:.*\S+-reject-\d+\.\[email protected]\S*apache.org ^Subject:.*post from \S+ requires approval
If a message arrives with these patterns, it is passed through 'moderate-list-auto-filter'. The messages should NOT be spam scanned beforehand -- otherwise you run the risk that your spam scanner will think a message from your MLM notifying you of a spam requiring moderator rejection, is in itself spam!
The 'moderate-list-auto-filter' script runs 'moderate-list' with the --auto switch, and will add a new header to the top of the message indicating if the message was handled automatically or not:
X-Moderate-List-Performed: yes
That "yes" may be "no" if the moderation could not proceed automatically. You can then move aside messages that have the "yes" pattern, after that filter executes, into an 'auto-moderated' folder.
All other moderation messages should be filed into a 'moderation-required' folder to be processed interactively with 'moderate-list' later.
(TODO: I'm not using procmail, but a procmail rule that implements the above would be nice for other users!)
Synopsis
moderate-list [options] { --dir maildir | --file filename } [... script outputs message synopsis...] Moderation action [ynab] (y=yes, n=no, a=allow in future, b=block in future)? [... script mails the correct address appropriately.]
moderate-list --auto [options] { --dir maildir | --file filename } [... script operates automatically with no user intervention...]
Files
State files are kept in ~/.moderate_sa.
- moderate.cf: This includes the list of allowed and blocked addresses, and mailing list passwords. It's set to mode 0700 by default so that the passwords are not visible to other users.
user_prefs: a SpamAssassin user preferences file. This is used to set moderation-specific preferences for SpamAssassin.
Download
Setup
- First, ensure that you have set up your mail delivery filters to file incoming 'moderation-required' messages to their own mail folder. This folder must be in MH or Maildir format; mbox is not yet supported.
- Download the two script files in the 'Download' section.
Install SpamAssassin. Ensure it works with spamassassin --lint. You do not need to run spamd for moderate-list to work.
- (Optional, but recommended): set up a user preferences file in ~/.moderate_sa/user_prefs:
mkdir ~/.moderate_sa echo " use_bayes 1 bayes_path ~/.moderate_sa/bayes trusted_networks 212.17.35.15 212.17.35.167 64.81.84.115 trusted_networks 213.228.0/24 internal_networks 10.19.72/24 # (...possibly other SpamAssassin configuration if desired) " > ~/.moderate_sa/user_prefs
- Set up a basic configuration file, listing the path to your MH or Maildir folder which contains the moderation-required messages:
echo " defaultdir /home/you/path/to/moderate/folder blockscore 5 " > ~/.moderate_sa/moderate.cf
That's it, you're ready to go. Run moderate-list to perform moderation.
- (Optional): Implement the 'moderate-list-auto-filter' workflow above in your mail filter rules.
Setup For Various MUAs and MDAs
TODO: not yet described. If you do implement the workflow in various clients, feel free to edit this section.
Comments
(please edit the page to add comments, or use this QT forum if you don't want to have to register.)