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 sanitizer.pl 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 --
#!/bin/bash
mkdir -p /tmp/filter.$USER || exit 1
TMPFILE=/tmp/filter.$USER/$$
tee $TMPFILE.org \
| sanitizer.pl /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
else
cat $TMPFILE.org
fi
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 santizer.pl 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
message.
This can of course all be done much more elegantly by writing a
replacement for the sanitizer.pl 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
forth.
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 103140@xyz.molar.is -><- http://bre.klaki.net/Check out my open-source email sanitizer: http://mailtools.anomy.net/ Spammers, please send lots of mail to: 103270@xyz.molar.is
Was I helpful? Let others know: http://svcs.affero.net/rm.php?r=Juggler