the usual
inconsistent at best
procmail Notes

I don’t mess with procmail much anymore, but maybe these will be useful to someone.

Split a mailbox into separate files for each message:

$ formail -s sh -c 'cat - > foo.$FILENO' < klez.file

Resend a mailbox (foo) through a set of filters (rc.test):

$ formail -s procmail ./rc.test < foo

Move the last 10 messages from folder foo and put them in folder bar:

$ MSGS=`egrep '^From ' foo | wc -l`
$ formail +`expr $MSGS - 10` -s < foo > bar

Check which recipes triggered most often (based on a verbose log format):

$ grep 'Match on' spam.output | perl -ne 'chomp; $pat{$_}++;' -e 'END{ for $key ( reverse sort { $pat{$a} <=> $pat{$b} } keys %pat ) { print "$key => $pat{$key}\n"; } }'

Check which rules were most effective (from a verbose log format):

$ grep 'Score:' log.spam.new | perl -ne 'chomp; s/^procmail: Score:\s+(\d+)\s+\d+\s+//; $pat{$_}+=($1?1:0);' -e 'END{ for $key ( reverse sort { $pat{$a} <=> $pat{$b} } keys %pat ) { print "$key => $pat{$key}\n"; } }'

Getting last hop before delivery:

$ formail -s formail -cX"Received:" < spam | grep "by gatekeeper" > received
$ perl -pe 's{^.*?\(.*?\[(.*)\][^\)]*\).*}{$1}' received > received.ip
$ perl -lne '$ip{$_}++;' -e 'END { print "$_ => $ip{$_}" for sort { $ip{$b} <=> $ip{$a} } keys  %ip }' received.ip | less

Last modified on 2014-10-26