procmail
[Top] [All Lists]

Re: Appending text to subject line

2000-02-12 20:49:31
Tom,

If you want to move the text to after Subject: but before the actual subject
line you can use:

:0 c
{
  :0 fwh: perl.lock
  | perl -pe 's/(Subject: )(.*)/$1xyz$2/;'

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

Using this script you can easily modify it to:

  | perl -pe 's/(Subject: )(.*)/$1$2xyz/;'

if you change your mind and decide to put your addition at the end of the
subject line.  Technically s/Subject: /Subject: xyz/ would be the
recommended use of the regex. 

Glen

On Sat, 12 Feb 2000, Glen Lee Edwards wrote:

On Sun, 6 Feb 2000, Tom Adler wrote:

I currently have a procmail recipe that forwards a copy of my e-mail to a 
second
e-mail address.  I would like to append a short string of text to the subject
line of each forwarded message. My recipe is something like this:

:0c
!secondaddress(_at_)isp(_dot_)com

How would I, for example, add the text "xyz" to the end of the subject line of
the forwarded message?

Tom,

Try this:

:0 c
{
 :0 fwh: perl.lock
 | perl -pe 's/(Subject:.*)/$1xyz/;'

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

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.  The portion /$1xyz/ tells Perl
to keep the whole line (this is what $1 does) and add in xyz after the
original match (the end of the line in this case).  You can change xyz to
whatever you need.  :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).  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.  The next recipe, :0 a tells procmail not to
execute this recipe until the previous one successfully ends (a).

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/;'

Hope this helps.

Glen



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