Conditional filtering, adding headers, etc.

From: Bjarni R. Einarsson (
Date: Wed 19 Nov 2003 - 00:10:20 GMT

  • Next message: Carlos Eduardo Vianna - SouthTech: "Commercial Support"

    On 2003-11-19, 10:42:33 (+1100), Noel Clarkson wrote:
    > You mention
    > that there is a way to do this using the next level up (procmail etc)
    > but that it requires more io. I'm not that worried about the extra
    > overhead but have not been able to work out how to do this, and from
    > comments on the list I understand that there are a number of others in
    > the same boat.

    OK. :-)

    Here's the most simple strategy - wrap the script within
    a shell which does some tees and pipes and greps. Something like this
    (warning, I'm writing directly into the mail, this is untested code):

    -- cut here --

    mkdir -p /tmp/filter.$USER || exit 1

    tee $ \
     | /path/to/config 'feat_log_stderr = 1' \
    > $TMPFILE.san 2>$TMPFILE.log

    if [ "$(grep -e 'interesting-stuff' $TMPFILE.log >/dev/null)" -gt 0 ]; then
        cat $TMPFILE.san
        cat $
    rm -f $TMPFILE.*

    -- cut here --

    You'll obviously have to replace 'interesting-stuff' with whatever
    stuff you're looking for in the sanitizer log, and provide the correct
    path to the sanitizer and it's configuration file (or write the config
    directly into the script using command line arguments).

    Invoke that script instead of from within your procmail
    rules (or from other parts of your MTA), and you should have much more
    control. People who want to add headers and things like that could
    use a similar strategy - dump the sanitizer log to stderr and then use
    follow-up procmail filter rules (invoking formmail) to add headers
    depending on the result of grepping the stderr log file.

    Another simple modification would be to simply use a script or
    procmail ruleset to create a "quarantine" of all modified messages, so
    when the sanitizer breaks something, you can retrieve the original

    This can of course all be done much more elegantly by writing a
    replacement for the script in Perl, which will
    procedurally invoke the Sanitizer engine, add hooks to the log object
    which count interesting stuff and ignore boring things (this is
    more precise and more efficient than grepping log files), and so

    Such a script is actually included with the F-Prot Antivirus mail
    server product... I'm not sure I'm allowed to release it as an
    open-source solution though. ;-)

    Bjarni R. Einarsson                           PGP: 02764305, B7A3AB89                -><-    

    Check out my open-source email sanitizer: Spammers, please send lots of mail to:

    Was I helpful? Let others know:

    hosted by