"Alan S. Dobkin" <ADobkin(_at_)emory(_dot_)edu> writes:
...
I would like to process all incoming mail to a certain account, extract
the subject header, and move it to the top of the message body. Then I
would like to add my own static subject header. So, for example, a
message comes in like this:
From: Me
To: AccountX
Subject: MyTopic
This is my message body.
I would like it to be replaced with this:
From: Me
To: AccountX
Subject: NewSubject
Subject: MyTopic
This is my message body.
Is this possible with formail or other tools? If so, how would I do it?
This calls for both procmail and formail, the latter invoked from the
former. The following .procmailrc will work with procmail 3.10 and
later.
# Extract the Subject: value
:0
* ^Subject: *\/[^ ].*
{
# do nothing here, as the action on this recipe will only
# be run if the message has a non-empty Subject:
}
# Put the captured value at the top of the body and change the
# Subject: header in one pass. The trick is that the header
# ends at the first blank line. When procmail pipes the header
# into the action of this recipe, formail will eat it all, change
# the Subject:, then spit it out, including the blank line that
# procmail feeds it. Then the echos will run, and since their
# output appears after the blank line, they'll be interpreted as
# being the first lines of the body. The ${VAR+:text} form will
# expand to the value of the "VAR" variable if it has a non-empty
# value, or "text" if it [VAR] doesn't have a value or has an
# empty value.
:0 fh
| formail -I"Subject: NewSubject"; \
echo "${MATCH+:No subject given}"; echo ''
Does that all make sense (it's not immeadiately obvious, so don't be
afraid to say you don't understand)?
Philip Guenther