procmail
[Top] [All Lists]

Walking down the chain of "Received: from" headers

1999-07-10 20:17:03
  The following applies to procmail on systems where the
incoming mailserver is running either sendmail or Exim.
For one of my filters, I need to walk down the chain of
"Received: from" headers until I met a specific condition.
Running the following snippet, with VERBOSE turned on,
lists the first 4 "Received: headers in an email.

 VERBOSE=YES
 LINEBUF=65536
 :0
 * ^^.*$+\/Received: from.*$
 * ^^.*$+Received: from(.*$)+\/Received: from.*$
 * ^^.*$+Received: from(.*$)+Received: from(.*$)+\/Received: from.*$
 * ^^.*$+Received: from(.*$)+Received: from(.*$)+Received: 
from(.*$)+\/Received: from.*
 /dev/null

  Needless to say, the expressions get rather ugly as you
walk down the chain.  There is a way to simplify things
with variable expansions.  There is a definite pattern.
The beginning of each expression is "^^.*$+".  The tail
is "\/Received: from.*$".  There are a variable number of
insertions of the string "Received: from(.*$)+".  So we
can replace the above code with...

 VERBOSE=YES
 LINEBUF=65536

 HEAD="^^.*$+"
 INSERT="Received: from(.*$)+"
 TAIL="\/Received: from.*$"

 :0
 *$ ${HEAD}${TAIL}
 *$ ${HEAD}${INSERT}${TAIL}
 *$ ${HEAD}${INSERT}${INSERT}${TAIL}
 *$ ${HEAD}${INSERT}${INSERT}${INSERT}${TAIL}
 /dev/null

  This is a lot easier to type.  Can we have assurance
from the developers that this won't break in future
releases?

-- 
Walter Dnes <waltdnes(_at_)interlog(_dot_)com> procmail spamfilter
http://www.interlog.com/~waltdnes/spamdunk/spamdunk.htm
Why a fiscal conservative opposes Toronto 2008 OWE-lympics
http://www.interlog.com/~waltdnes/owe-lympics/owe-lympics.htm

<Prev in Thread] Current Thread [Next in Thread>