procmail
[Top] [All Lists]

Re: Appending text to subject line

2000-02-14 02:59:15
On Sat, 12 Feb 2000 19:19:19 -0600 (CST), Glen Lee Edwards
<GLEdwards(_at_)uswest(_dot_)net> wrote:
On Sun, 6 Feb 2000, Tom Adler wrote:
How would I, for example, add the text "xyz" to the end of the
subject line of the forwarded message?
:0 c
{
  :0 fwh: perl.lock
  | perl -pe 's/(Subject:.*)/$1xyz/;'

  :0 a 
  ! secondaddress(_at_)isp(_dot_)com
}

I would recommend against Perl in this situation. To borrow a phrase
from Randal L. Schwartz, don't bring out the combine harvester just to
tidy up the flower pot.

The use of a lock file is also probably an error (unless you have a
plan for world domination which involves preventing more than one
computer in the universe from running Perl, or something).

This creates a copy of every letter, and then has Perl do a check for
any line in the header that starts with Subject:.  The regex
s/(Subject:.*)/ will match the whole line.

Actually, there is nothing there to confine this to lines which
+begin+ with "Subject:". In fact, a line containing

    X-Warning: Don't mess with the Subject: header, please!

would also get matched and rewritten.

:0 fwh: perl.lock tells procmail that this recipe is a filter (f),
to send only the header to the filter (h), and to check the exit
code for success or failure (w).

Actually the w also means Procmail will hang around and wait for the
filter to finish running. (This is something you somehow associated
with the a flag.)

My understanding is that if the filter fails the only thing
procmail does is note so in your procmail log file if you have one
set up.

Correct. You can verify this e.g. by changing "perl" to something
bogus and run a test message through.

If you need to include the full perl path you might have to change
the perl line to:
  | /usr/bin/perl -pe 's/(Subject:.*)/$1xyz/;'

I would recommend fixing your PATH instead.

The Formail solution which David posted whould be a lot more
lightweight. For comparison, you might want to do some timings. Try
running 1,000 instances of this Perl script and 1,000 instances of the
corresponding Formail invocation with /dev/null as standard input and
standard output, and see which finishes first.

I'm not kidding. Doing things in the most effective way you can think
of is friendly towards the people you share your mail host with, and
sometimes the difference between a slow system and a crashed system
when you get hit by something unexpected.

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

<Prev in Thread] Current Thread [Next in Thread>