In subsequent discussions on the procmail list, it was noted, that if the
SA markup attachment isn't present that the SA headers should still be
removed.
Further, I suppose that it should check for Subject: [SPAM] tags, but that
is a bit problematic because the nature of those tags is site dependent,
and might even vary over time. Here's the update version.
DEFAULT=|
SHELL=/bin/sh
#VERBOSE=yes
NL="
"
SPACE=" "
TAB=" "
WS="$SPACE$TAB"
:0 B
* $ H ?? ^Content-Type:[$WS]+multipart/mixed;
* $ ^Content-Type:[$WS]+message/rfc822;[$WS]+x-spam-type=original
* $ ^Content-Description:[$WS]+original message before SpamAssassin
* $ ^Content-Disposition:[$WS]+attachment
{
# SA markup is present, pick up the boundary
:0
* $ ^Content-Type:[$WS]+multipart/mixed;[$WS]+boundary=\"\/[^\"]*
{ BOUNDARY = "--$MATCH" }
# sed script to pull out the original message (yikes)
# technically, '.'s inside boundary should be escaped,
# but we hope the rest of the chars. in the boundary
# string are sufficiently unique to ensure a correct
# match.
SED_GET_MSG_PART='
1{h;d}
2,/^'"$BOUNDARY"'$/d
/^'"$BOUNDARY"'$/,/^'"$BOUNDARY"'--$/{
/^'"$BOUNDARY"'$/,/^$/d
/^'"$BOUNDARY"'--$/d
H;d}
$!d
/^$/!H
x'
# Run it through sed to remove the markup.
:0 hbfw
| sed -e "$SED_GET_MSG_PART"
}
# if no mark-up attachment found, just remove the SA headers
# Maybe we need to remove the subject tag here as well?
:0 E fw
| formail -IX-Spam