Humberto Calvani wrote:
Hi there,
Is there a way in procmail to extract certain headers
(eg. Return Path:, Content Type: etc..) from a mail
message while keep the body of the message intact ?
It's repetitive and ugly, but it can be done. Assume
that your regular logfile is called LOGS and that you
want to store the headers to SELECTED_HEADERS. I'll
explain it for the "Date:" header. The other headers
are done similarly. I'll use short variable names like
D, F, M, CT, A, and CL...
- store a dummy value to D (the Date:-header variable)
in case it isn't found.
- try to match the header. You need "()\/^" (without
the quotes) before the header text, and ".*" (without
the quotes) after the header text.
- if it matches, the value is assigned by the line
inside the braces. The braces tell procmail that
this is *NOT* a "delivering" recipe, so the message
is still left for the next test.
- repeat for all headers
- save name of current logfile
- change logfile to point at SELECTED_HEADERS
- use the LOG= construct to capture the values
- note 1) $-sign causes variables to be
replaced with their literal values
- note 2) All newlines inside the quotes are
interpreted literally. Note the
location of the quotes.
LOGFILE=LOGS
D="Date: //ABSENT//"
:0
* ()\/^Date:.*
{ D=$MATCH }
F="From: //ABSENT//"
:0
* ()\/^From:.*
{ F=$MATCH }
M="Message-Id: //ABSENT//"
:0
* ()\/^Message-Id:.*
{ M=$MATCH }
CT="Content-Type: //ABSENT//"
:0
* ()\/^Content-Type:.*
{ CT=$MATCH }
A="Apparently-To: //ABSENT//"
:0
* ()\/^Apparently-To:.*
{ A=$MATCH }
CL="Content-Length: //ABSENT//"
:0
* ()\/^Content-Length:.*
{ CL=$MATCH }
OLD_LOGFILE=$LOGFILE
LOGFILE=SELECTED_HEADERS
LOG="
#####Message Separator#####
$D
$F
$M
$CT
$A
$CL
"
LOGFILE=$OLD_LOGFILE
--
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