procmail
[Top] [All Lists]

Re: Removing line-wrapped header

2004-09-09 06:44:47
Toen wij Volker Kuhlmann kietelden, kwam er dit uit:

David's formail -c | grep -iv would work, but leaves
the remaining headers in a funny state.

What is exactly this 'funny state'?

Look up what -c does :)
I unwraps all headers by removing newlines. Necessary for the grep,
but can't be undone. Run any of your mails through formail -c and
look at the received:.

From the sed-users yahoogroups list:

sed -e '
   # skip processing unwanted lines
   /^Headername:/!b

   # spotted a valid header start line
   # so now go look for a header-ending line
   :loop
   $bend
   N
   /\n[^ ]/!bloop

   # managed to put in pattern space one header and also
   # the start of the next header/non-header stuff
   h

   s/^\(.*\)\n.*$/\1/; # just retain the first header info only

   /\<search-string\>/{
      # GOTCH YEAH, the header to be deleted
      g; # retrieve the header (to be del. + start of next header)
      s/^\(.*\)\(\n.*\)$/\2/; # remove the header to be del.
      D; # go back for reading more
   }

   # ok, this was a header that needs printing
   p; # print the first header info only
   g; # retrieve the first header + start of next header
   s/^\(.*\)\(\n.*\)$/\2/; # remove the first header as it is printed
   D;# go back for more

   # we come here when while in the process of filling in the
   # pattern space with the current header, we reach the EOF
   # but the header end has not gotten yet. Or, could be
   # there is nothing after this header
   :end
   /\<search-string\>/b
   d
' yourfile

Of course, replace 'Headername' and 'search-string' by your own.


This solution was promptly provided by Gudermez. Often, 
other solutions follow shortly.

-- 
Grtz, Ruud

____________________________________________________________
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