I 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).
If you're using it in a head-filtering recipe (with the `h' and `f' flags),
you still should use the -k option. Without it formail -X will not preserve
the blank line that separates the head from the body, and procmail will glue
the body back on without it. If the top line of the body doesn't look like a
legitimate header line, procmail will restore the blank line; but if it does
look like one, it (and any consecutive lines that look like headers) will get
agglutinated to the head, and procmail will restore the separation line above
the first line of the body that can't legally be joined to the head.