procmail
[Top] [All Lists]

Re: Appending text to subject line

2000-02-14 20:30:35
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.

Your solution works good for those who are versed in formail, sed, or
other languages that execute quicker.  For the amateur programmer such as
myself who decide to learn more about one language rather than a little
about several languages, in my case perl is frequently my only option
(unless I persistently annoy this list).

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).

And there's something wrong with world domination?  {-_o}  Good point.
For a guy who never did drugs my brain sure kicks out some muddled stuff
at times!  For the life of me I don't know why I would try to put a lock
on the Perl interpreter.

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.

This is a typo on my part.  I forgot the "^", although in this case it
isn't a fatal error.

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.

With current trends - processors passing the gigaherz range, and more home
PCs running their own MTA's, eventually subtle differences such as this
won't matter.  Not everyone on a mail server passes 1000 emails in a short
time through a procmail recipe.  Most of those who rely on a mail server
are using Windows and have never heard of Procmail.  (I'm not trying to
start a debate - just an observation that, while perl is slower in
executing because of the time needed to run the interpreter and compile
the code, not enough people are currently doing this to sink the ship.
If the system does crash then the ISP is due for an upgrade.).

Glen

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