Using Procmail for SCOMP rewrites

Using Procmail for SCOMP rewrites

am 04.01.2006 18:31:22 von Garrett White

Hello,

I'm attempting to use procmail to rewrite information from AOL Scomp
reports as they come in. The Word to the Wise Scompfilter
(http://word-to-the-wise.com/scompfilter/index.html) has been a great
help in rewriting the subject of inbound reports, however it uses the
sender and the subject, and not the IP involved, which is preferrable.
Any input as to how I could modify or write a new filter for procmail
to change inbound Scomp reports to do so would be greatly appreciated!

Re: Using Procmail for SCOMP rewrites

am 04.01.2006 22:57:29 von Garen Erdoisa

Garrett White wrote:
> Hello,
>
> I'm attempting to use procmail to rewrite information from AOL Scomp
> reports as they come in. The Word to the Wise Scompfilter
> (http://word-to-the-wise.com/scompfilter/index.html) has been a great
> help in rewriting the subject of inbound reports, however it uses the
> sender and the subject, and not the IP involved, which is preferrable.
> Any input as to how I could modify or write a new filter for procmail
> to change inbound Scomp reports to do so would be greatly appreciated!
>

I'm making some asumptions about what you want in the following, but it
should give you some ideas of how to accomplish what you want.

# Define the location of formail on your system.
FORMAIL=/usr/bin/formail

# Define a newline character to keep procmail LOG lines neater.
NL="
"

# Enumerate the Recieved: headers using cat. use sed (stream edit) to
# eliminate multiple tabs and spaces, replacing them with just
# spaces, also put the recieved headers each on just one line.
# Store the results in the ${RECIEVEDHEAD} variable.

# This leaves the original headers intact, and it makes it easier to
# do future pattern matching based on the contents of the RECIEVEDHEAD
# variable without having to deal with a lot of variations in header
# styles. Note the backtics which launch the shell script.

:0 W
* H ?? 1^1 ^Received:
{
RECEIVEDCOUNT=$=
RECIEVEDHEAD=`${FORMAIL} -cX"Received:" |\
cat -n |\
sed -e 's/\t/ /g' -e 's/[ ]\+/ /g' -e 's/^ //' -e 's/^[0-9]\+/&:/' \
`

# Optional: write a copy of what you just extracted to your
# procmail logfile

LOG="[$$]$_: Debug:
RECEIVEDCOUNT=${RECEIVEDCOUNT}${NL}RECIEVEDHEAD=${NL}${RECIE VEDHEAD}${NL}"
}

# Extract the IP from the 1st received header in the RECIEVEDHEAD
# variable you just created above.
# You may have to adjust the regular expression pattern match
# depending on what your headers actually look like.
# Headers I use are generated by sendmail
:0
* RECIEVEDHEAD ?? ^1: Received: from .*\(.*\[\/[0-9.]+
{
IP=${MATCH}
LOG="[$$]$_: Debug: Extracted IP=${IP}${NL}"
}

# If you want to grab the IP's from subsequent Received headers you can
# probabaly do so just by changing the number. Though Recieved headers
# vary depending on the type of software that created them, so the
# information in them may be questionable and you will have to create
# quite a few recipes to parse them all properly.

# Capture the original subject into a SUBJECT variable
# then rewrite it into a NEWSUBJECT variable.

:0
* H ?? ^Subject: \/
{
SUBJECT=${MATCH}
NEWSUBJECT="Report: ${IP} With Subject: (${SUBJECT})"
LOG="[$$]$_: Debug: Re-writing subject line to ${NEWSUBJECT}${NL}"

# Use a procmail filter recipe to re-write the subject header
# This actually modifis the mail in the main procmail pipe
# before delivery.
:0 f
|${FORMAIL} -A "X-OriginalSubject: ${SUBJECT}"\
-I "Subject: ${NEWSUBJECT}"
}

# Else the email has no subject header, so log the fact.
# and maybe do other stuff here if that is the case.
:0 E
{ LOG="[$$]$_: Debug: Missing Subject Header.${NL}" }

Garen

Re: Using Procmail for SCOMP rewrites

am 04.01.2006 23:20:16 von Garrett White

Thanks for your reply! I'm diving into it now~

Re: Using Procmail for SCOMP rewrites

am 05.01.2006 00:23:39 von Garen Erdoisa

Garrett White wrote:
> Thanks for your reply! I'm diving into it now~
>

No prob.

One typo correction to the recipe.

This line is:
* H ?? ^Subject: \/

Should read:
* H ?? ^Subject: \/.*

Otherwise the match will be always be an empty string.

Garen