[Linux-Anyway] Re: Procmailrc thing

  • From: Godwin Stewart <gstewart@xxxxxxxxxxx>
  • To: Linux-Anyway@xxxxxxxxxxxxx
  • Date: Tue, 9 Nov 2004 23:58:55 +0100

On Tue, 9 Nov 2004 14:37:26 -0800 (PST), Meph Istopheles <Meph@xxxxxxxxxx>
wrote:

>    Sorry I asked -- I didn't think it would anger you;-).

Angered, moi!? :o)

>    I'll look into writing up such a script.  Thanks.

Check if you have formail installed on your box. It could simplify things
greatly - as in turn it into a 5-line bash script, something like this:

#!/bin/bash
cat > /tmp/acmescript$$
NEWSUBJECT="[your tag here]`formail -xSubject < /tmp/acmescript$$`"
cat /tmp/acmescript$$ | formail -I "Subject: $NEWSUBJECT"
rm /tmp/acmescript$$

Note the absence of a space between the closing bracket of your tag and the
opening backtick...

What this does is basically as follows:

cat > /tmp/acmescript$$
Sucks up the mail being passed to it by procmail on stdin and places this in
a file under /tmp with a unique name (the environment variable $$ is the PID
of the running shell).

NEWSUBJECT="[your tag here]`formail -xSubject < /tmp/acmescript$$`"
formail -xSubject < /tmp/acmescript$$ will push the data through formail,
which will look for the Subject: header and output everything on the line
after the colon, including the space which separates the colon from the
content. This is tagged on to the end of [your tag here] and put in the
variable NEWSUBJECT.

cat /tmp/acmescript$$ | formail -I "Subject: $NEWSUBJECT"
The mail is pumped through formail once again, this time replacing the
"Subject:" header with your new subject, and the result is pumped out
through stdout and therefore picked up again by procmail.

rm /tmp/acmescript$$
Just cleans up after the job was done.

-- 
A budget is wondering why you should balance yours
if the government can not balance theirs.
To unsubcribe send e-mail with the word unsubscribe in the body to:   
Linux-Anyway-Request@xxxxxxxxxxxxx?body=unsubscribe

Other related posts: