procmail
[Top] [All Lists]

Re: insert one line at the top of incoming message

1998-03-27 12:40:46
Michael Powe wrote of Ken Hooper's quote to Timothy Luoma of my suggestion to
Ken,

| This puts the message at the end of the file.

At the end, yes, but not at the end of the file: at the end of the INPUT.
Since the input is the head of the message, and the added text goes after
the blank line at the neck, it will be at the top of the body when the `hf'
recipe is done and procmail reattaches the unfiltered body.

| To enter a line at the beginning of the file, you need to use "i."

If we were using a `bf' recipe instead, 1i\\ (two backslashes because we're
inside soft quotes at that point rather than hard ones) would be correct in-
stead of $ a\\.  HOWEVER, generally the body is larger than the head, so it
takes less time to get the desired results by passing the head through the
filter and appending the new text below the neck than by prepending the new
text above the clavicle and then passing the original body.  If this line
would normally be inserted into very short messages where the body is smaller
than the head, a `bf' recipe with a filter through sed "1i\\" would, indeed,
be the better way to go.

| As far as I can see, sed will not expand shell variables, so unless
| procmail expands the variable before it passes the command to sed (I
| don't know -- does it?), it would be impossible to put in the name of
| the newsgroup in a simple manner like that.

If there are no characters from $SHELLMETAS in the command, procmail will
expand any variables; if there are characters from $SHELLMETAS, procmail
will export all variables and the shell will expand them.  Neither will
expand variables inside hard quotes: that is why I soft-quoted the whole
sed instruction and therefore had to use two backwhacks at a time.

I use several such `hf' recipes with sed "$ a\\" filters in my own rcfiles,
so I know for a fact that the code I recommend to Ken (and Ken in turn sug-
gested to Timothy) does work.