procmail
[Top] [All Lists]

formail recipe help please

2006-01-18 19:06:06
Hopefully someone can assist me. I have a formail recipe embeded in 
my .procmailrc which is used to add the following at the end of message 
headers:

X-SenderIP: 65.54.169.39
X-ASN: ASN-8075
X-CIDR: 65.54.160.0/19

This works fine for my main isp, earthlink. However, I'd also like the same
to be added to mail from my domain, toadnet.com, and to mail I pull down
from my yahoo account using fetchyahoo.  I'm getting output as below:

ASN= From MAILER-DAEMON(_at_)toadnet(_dot_)com  Tue Jan  3 17:17:07 2006
 Subject: {Virus?} Mail delivery failed: returning message to sender
  Folder: /home/chris/Maildir/.Spam/new/1136330227.12501_2.cpollock.lo     
6221
procmail: Skipped "Server"
procmail: Skipped "|by toadnet\.com \(8\.12\.11/8\.12\.11\)|by 
mta[0-9]*\.mail\..*\.yahoo\.com)"
ASN= 11456From simon(_at_)yahoo(_dot_)com  Tue Jan  3 17:25:37 2006
 Subject: Valium as low as $3.41 
  Folder: /home/chris/Maildir/.Spam/new/1136330737.13087_2.cpollock.lo    
10118
procmail: Skipped "Server"
procmail: Skipped "|by toadnet\.com \(8\.12\.11/8\.12\.11\)|by 
mta[0-9]*\.mail\..*\.yahoo\.com)"

There is something wrong with the regex on the SMTP server line.  Here is 
the whole recipe.  Everything is on one line inmy .procmailrc.  It works 
fine for my main ISP, Earthlink and works if the only thing on the server 
line is EarthLink SMTP Server.

# $Id: asn-header,v 1.2 2004/03/08 00:06:50 karsten Exp karsten $
#
# Add X-ASN header
# KMSelf Sun Jul 11 04:05:32 PDT 2004
#
# Add headers for ASN and originating IP.
# Original author:  Karsten M. Self
# 
# Requires FORMAIL variable be set (most procmail recipe sets do this).
#
# You must set your SMTP_SERVER identifier.
#
# Run this BEFORE any spamassassin processing.  The header tag itself
# should start being scored as a Bayesian attributed.

# FORMAIL = /usr/bin/formail

SMTP_SERVER = (EarthLink SMTP Server|by toadnet\.com 
\(8\.12\.11/8\.12\.11\)|by mta[0-9]*\.mail\..*\.yahoo\.com)

# EarthLink SMTP Server

# ----------------------------------------------------------------------
# Parse out the sender's IP address.
SENDERIP = `formail -c -XReceived | grep "$SMTP_SERVER" | \
    tr '[][\t <>()]' '\n' | \
    grep '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' | \
     tail -1`

# Reverse IP for reverse DNS query
REVERSE_SENDERIP = `expr "$SENDERIP" | \
    sed "s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1/"`

# Query asn.routeviews.org for the ASN.
# Note that this is pretty aggressive:  wait six seconds, retry ten
# times, may slow mail processing, but tends to improve data quality.
# Run a caching DNS server for improved performance.
# Raw is a mostly unmunged output (save quotes and prefix).  Contains
# ASN, IP, and CIDR prefix.
RAW_ASN = `host -W 6 -R 10 -t txt $REVERSE_SENDERIP.asn.routeviews.org | \
    sed -e 's/.* text //' -e 's/"//g'`
ASN = `echo $RAW_ASN | cut -d ' ' -f 1`
ASN_CIDR = `echo $RAW_ASN | cut -d ' ' -f 2`/`echo $RAW_ASN | cut -d ' ' -f
3`

# LOG = "SENDERIP= $SENDERIP"

# LOG = "REVERSE_SENDERIP= $REVERSE_SENDERIP"
LOG = "ASN= $ASN"

# ------------------------------------------------------------------------ 
# Add X-SenderIP header.
:0 fhw
* ! ^X-SenderIP:
| $FORMAIL -a "X-SenderIP: $SENDERIP"
# ------------------------------------------------------------------------ 

# ------------------------------------------------------------------------ 
# Add X-ASN header.
:0 fhw
* ! ^X-ASN:
| $FORMAIL -a "X-ASN: ASN-$ASN"
# ------------------------------------------------------------------------ 

# ------------------------------------------------------------------------ 
# Add X-CIDR header.
:0 fhw
* ! ^X-CIDR:
| $FORMAIL -a "X-CIDR: $ASN_CIDR"
# ------------------------------------------------------------------------  

Thanks for any assistance.

-- 
Chris
Registered Linux User 283774 http://counter.li.org
19:37:33 up 9 days, 1:23, 1 user, load average: 0.19, 0.28, 0.17
Mandriva Linux 10.1 Official, kernel 2.6.8.1-12mdk

Attachment: pgppJsfSRPfFz.pgp
Description: PGP signature

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail
<Prev in Thread] Current Thread [Next in Thread>