procmail
[Top] [All Lists]

Re: deleting all field headers except ...

1996-04-25 14:34:08
David Tamkin suggested to Robert Brown:

|  > If you want to print out only one header (or a short specific list of
|  > headers) and the body,
|  > 
|  >   formail -kX'From ' < foo
|  > 
|  > will preserve the From_ line and the body.
|  > 
|  >   formail -kXFrom < foo
|  > 
|  > will keep the body and every line from the head that starts with 'From':
|  > i.e., the From_ line and the From: header.

| Thanks.  I ended up solving this by writing a sed script (since I can use
| a list of headers in that case).

It's better to use formail than sed, just in case a header you want to keep
is split onto one or more continuation lines.  That will fool sed, but
formail is specific for mail handling and knows about those things.

You can use a list with formail also.  If you want to keep only header1,
header2, and header3,

     formail -k -XHeader1: -XHeader2: -XHeader3:

with as many -X options as you need, as long as you don't exceed $LINEBUF (in
the command line, that is; it's ok if the actual headers exceed $LINEBUF).

And, if you keep a file of headers, say, for example:

     % cat headers-file
     From
     From:
     Date:
     To:
     Subject:
     Reply-To:
     Resent-By:
     Resent-Date:

Then you can use a command like this:

    formail -k `awk '{printf "-X%s: ", $1}' <headers-file`

To throw away all the headers but those mentioned in the file.

Alan

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