Gangabass has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Monks.

I need to redirect email (the email is unchanged, and any recipient can reply to the original sender easily) but only want to change Subject a bit. But i don't want to reinvent a wheel.

I'm thinking about parsing email with Mail::Message and changing To: and Subject: headers. Is this the right way?

Thanks.
Roman

Replies are listed 'Best First'.
Re: Redirect email
by ambrus (Abbot) on Nov 29, 2009 at 10:41 UTC

    I use an ugly but working procmail configuration for something like this. It adds an address to the List-Id header of the email, or creates that header if it doesn't exist. You could do the same with Subject. Here are the relevant lines from the procmailrc on that host.

    The first rule says to save a copy of the mail to a local mailbox. The second changes the headers. The third rule asks procmail to do the forwarding. The two email addresses are changed to an example here.

    :0 c inmails :0 fhw | perl -pe '$d = "Some Label <some.label\@example.com>"; $t or do { s/ +(^List -Id\s*:\s*)/$1$d, /i || s/^$/List-Id: $d\n/ and $t++; }' :0 !forward.target@example.net
Re: Redirect email
by happy.barney (Friar) on Nov 29, 2009 at 08:22 UTC