It's not clear what exactly is wrong, but if you want to append text at the beginning, you obviously need to echo
before cat
, and work on the body (b
), not the headers (h
).
:0 fbw
| echo "Insert this"; cat -
I suppose you could technically break the headers by appending something at the end, but if you want it to appear in the body, it needs to have a neck (a newline) before it.
:0 fhw
| cat -; echo; echo "Insert this"
There is also a sed
syntax which allows for somewhat more flexible manipulation (sed
addressing lets you say things like "before the first line which starts with >
for example) but getting newlines into sed
command lines inside Procmail is hairy. As a workaround, I often use a string, and then just interpolate that. (How hairy exactly depends on details of sed
syntax which are not standard. Some implementations seem to require newlines in the a
and i
commands.)
sedscript='1i\
insert this\
'
:0 fbw
| sed "$sedscript"
(If you are lucky, your sed
will accept something simpler like sed '1i insert this'
. The variant above seems to be the only one I can get to work on macOS, and thus probably generally *BSD.)
As an aside, a message which is 1000 bytes long isn't by any means large. I recall calculating an average message length of about 4k in my own inbox, but this was before people started to use HTML email clients. Depending on your inbound topology, just the headers could easily be more than 1000 bytes.