Search code examples
procmail

Check whether at least two out of three procmail conditions are true


How do I check in procmail whether at least two out of three spam filters see the mail as spam? I don't want to have duplicate code due to multiple checks on the spam headers.

# Invoke bogofilter
:0 fw
| bogofilter -C -d /home/shared_directories/bogofilter -p -e

# Invoke bmf
:0 fw
| bmf -d /home/shared_directories/bmf -f text -p

# Invoke spambayes
:0 fw
| sb_filter -d /home/shared_directories/spambayes

# If two out of three filters agree it's spam, file it.
:0
* ^X-Bogosity: Spam
* ^X-Spam-Status: Yes
* ^X-Spambayes-Classification: spam
{
# Process the mail
}

Solution

  • You can use scoring with a base score of -1.

    :0
    * -1^0
    *  1^0 ^X-Bogosity: Spam
    *  1^0 ^X-Spam-Status: Yes
    *  1^0 ^X-Spambayes-Classification: spam
    {
      # ... stuff
    

    If a single condition matches, the score only goes to zero, so the compound result is no match. If two or more of the individual conditions bring the score above zero, the action is taken.

    The procmailsc manual page explains this mechanism. It's not very widely used, and it has a number of complexities, but the basics are easy and straightforward.