procmail
[Top] [All Lists]

Re: Received: headers after From:

1997-11-08 08:46:59
At 10:47 PM 11/7/97 -0600, David W. Tamkin wrote:
On second though, feh and triple-feh.  I'm going to revise the approach in
the sed instructions.  The logic will be the same but the implementation will
be saner.  Unfortunately, the difficulty of embedding newlines in the action
line of a procmail recipe requires the silly multiple -e syntax.  The last
brackets, of course, enclose a space and a tab.

 RECPAT="^[Rr][Ee][Cc][Ee][Ii][Vv][Ee][Dd]:" savemetas=$SHELLMETAS SHELLMETAS
 :0fwh # All carets are OUTSIDE the brackets!
 * ^From:(.*$)+Received:
 | sed -ne '1,/^[Ff][Rr][Oo][Mm]:/bx' -e :y "/$RECPAT/!bx" -e :z -e n \
   -e '/^[    ]/bz' -e by -e :x -e p
 SHELLMETAS=$savemetas

The logic is very similar: anything up through From: and anything thereafter
that isn't a Received: is passed.  A Received: is dropped and starts an inner
loop of dropping indented lines; when a non-indented line is found, go back
to the outer loop (in case it is a Received:).  The closing empty line at the
neck, even if the last header is a Received:, gets handled properly without
the extra code that the previous approach needed.

Whew!!!

How about a conceptually simpler (to me, anyway) awk solution which just
relies on three states in effect after we have dealt with each line:
        s==0    haven't yet seen From
        s==1    have seen From, want to keep next line if continued
        s==2    have seen From, want to discard next line if continued

Then:
  :0fwh
  * ^From:(.*$)+Received:
  | gawk 's==0 && !/^[Ff][Rr][Oo][Mm]:/ {print;next}\
  s==2 && /^[   ]/ || /^[Re][Ee][Cc][Ee][Ii][Vv][Ee][Dd]:/ {s=2;next}\
  {s=1;print}'

(I guess you can play with SHELLMETAS and/or RECPAT here too if you want.)

Cheers,
Stan

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