#!/usr/bin/procmail

PMDIR=${PMDIR:-$HOME/.etc/mailfilter/procmail}

:0
* !PMVAR ?? .
{
  # PMVAR is not defined, so we are being called as filter
  # thus source the standard defines
  INCLUDERC=$PMDIR/defines
  # prevent feeding back to procmail and delete the leading From line
  PROCMAIL='/bin/cat'
  # and tell the fucking procmail piece-of-shit to continue to be a filter
  DEFAULT='|$PROCMAIL'
}

# unpack SA report_safe mails
:0
* B ?? ^Content-Type: message/rfc822; x-spam-type=original$
{
  LOG="cleanup:     unpacking SA MIME-wrapped spam mail$NL"
  :0 fw
  |$SPAMASSASSIN -d
}

# remove headers from other spamfilters
:0 fw
|$FORMAIL -IX-Spam -IX-CRM114

# now should be idempotent