procmail
[Top] [All Lists]

Re: Appending text to subject line

2000-02-24 02:57:23
On Thu, 24 Feb 2000 09:59:42 +0100, "Ruud H.G. van Tol"
<rvtol(_at_)isolution(_dot_)nl> wrote:
MATCH
:0fwh
* other conditions
* 1^0 ^Subject:\/.*
* 1^0
| formail -I "Subject: start-text$MATCH"
In case one wants to fight what might follow 'Subject:' (like 20
tabs or so :)
:0fwh
* other conditions
* ^Subject:[  ]\/[^  ].*
| formail -I "Subject: start-text $MATCH"

Minor typo: You probably meant to add a "zero or more" repetition
count to the whitespace after the colon.

    :0fwh
    * other conditions
    * ^Subject:[        ]*\/[^  ].*
    | formail -I "Subject: start-text $MATCH"

and of course, ditto for the solution to append a text after the
existing Subject instead of before.

The [  ] contains a space and a tab.
I am not sure whether the [^  ] is necessary here,
and if not it might even slow down things.

Being more specific usually speeds things up. Here's what happens:

 $ cat <<'HERE' >scratch/testing.rc
SHELL=/bin/sh  # always!
DEFAULT=/dev/null # good idea for testing, just in case
NL="
"  # convenient shorthand: NL is a string containing a newline

:0
* ^Subject:[         ]*\/.*
{ LOG="MATCH is \`$MATCH'$NL" }

:0
* ^Subject:[         ]*\/.+
{ LOG="MATCH is \`$MATCH'$NL" }

:0
* ^Subject:[         ]*\/[^  ].*
{ LOG="MATCH is \`$MATCH'$NL" }

# Just testing, discard the test message now
:0
/dev/null
HERE

And here, a simple test, with a lot of random spaces and tabs where
you see whitespace:

 $ echo "Subject:               not funny               " |
procmail -m scratch/testing.rc
 MATCH is `             not funny               '
 MATCH is `             not funny               '
 MATCH is `not funny            '

So yes, you really do need the [^       ] to anchor the start of the
\/ grabbing operation.

Think of how many ways Procmail has of guessing what you mean by .*.*
or .*.+ and what strategies it might employ to solve that. Adding the
\/ operator between the wildcard expressions does change the way
Procmail looks at this, a little bit, but the fundamental answer is
still that it's good to be as specific as possible if you want to
avoid surprises.

Hope this helps,

/* 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