procmail
[Top] [All Lists]

Re: getting rid of the body, keepin the header

1997-03-21 13:21:02
Stefan Monnier suggested to Timothy Luoma, who wanted to get rid of the body
of an incoming message,

| To get rid of the body:
| 
|         :0 fb
|         | >/dev/null

That way invokes a shell.  This should be easier:

         :0fbi
         | /bin/true

Although I wonder about Timothy's original need; did he want to get rid of
the body and go on with more recipes, or could he get rid of the body at
final delivery?  In the latter case, an `h' flag on the delivering recipe
is all he needs.

| to only keep the subject from the headers:
| 
|         :0 hf
|         | grep ^Subject:

Not so good.  If the subject is divided onto an indented continuation line,
that will keep only the first physical line of the subject.  Also, to filter
the head that way and go on handling recipes with no From_ line at the top
will upset procmail unless you remember to put an `r' flag onto every recipe
such a message might hit after the grep.

Someone else had a better idea, to put the subject lines into the file where
Timothy is keeping them right then and there, but again, that person sug-
gested using grep to extract them, and formail is better in case of continu-
ation lines:

       :0h: # :0hc: to work on a copy and file the original later
       | formail -cXSubject: >> subjects-file

or, since the subjects file doesn't need to have "Subject: " repeated on
every line,

       :0h: # :0hc: to work on a copy and file the original later
       | formail -czxSubject: >> subjects-file
     
| I don't know how well procmail deals with emptied bodies though (not that I
| would expect it to be buggy, but I seem to remember something about the "empty
| line separator" being lost with some filtering rules)

Emptied bodies do not bother procmail.  It simply assumes a blank line at the
end of the text, which now means at the end of the head, and that puts every-
thing aright.  I've had a lot of messages without bodies (or whose bodies get
removed by earlier procmailrc filters) and they never cause trouble for me.

The problem comes when the empty line that separates the head from the body
is removed; then procmail assumes that everything up to the first empty line
is the head, even if it includes things that are not valid as header lines. 
If the message encounters formail again, formail will insert an empty line
above the first line that shouldn't be in the head, and thereafter procmail
will assume that the body begins at the line after the first blank line.