procmail
[Top] [All Lists]

Re: Just thought I got a hang of it

2007-05-21 23:27:28
At 13:13 2007-05-22 +0800, DR. Lee - NS1 wrote:
:0
* ^Subject:.*GENERATE:\/.*[^:PASSWD]

condition is:

^               anchored to beginning of line
Subject:        (literal)
.*              zero or more of ANYTHING
GENERATE:       (literal)
\/              begin $MATCH assignment
.*              zero or more of ANYTHING
[^:PASSWD]      character class NOT containing colon, P, A, S, W, or D. and
                 being only ONE character in length (though any number of
                 characters may follow this)

My guess, is you're looking to delimit the name on a colon.  You still have 
to match at two levels.  You should also anchor the initial match on EOL 
(so no trailing characters are omitted from the password), and I doubt you 
want Fwd: and Re: type messages to apply, so lose the wildcard line prefix 
- just match whitespace.

:0
* ^Subject:[    ]*GENERATE:\/[^:]*:PASSWD$
* $MATCH ?? ()^\/[^:]*
{
         LOGIN=$MATCH
}

on the first condition, it'll match the SYNTAX, on the second (which will 
only run if the first evaluated true), the MATCH assignment from the first 
is then matched only for the first portion which you want to keep - that 
is, everything up to, but not including, the colon.

procmail: Assigning "MATCH="
procmail: Matched "flook:SNURB
"
procmail: Match on "^Subject:[  ]*GENERATE:\/[^:]*:SNURB$"
procmail: Matched "flook"
procmail: Match on "()^\/[^:]*"
procmail: Assigning "LOGIN=flook"

If you were to change the password on the MESSAGE to SNURBLERFIN, it 
wouldn't match (because there's an EOL as part of the condition).  Note 
that the zero or more construct means that an EMPTY username field would 
still evaluate true, and then assign an empty string to LOGIN (which would 
be the correct thing to do).  If you expect a username string of one or 
more characters, then change the [^:]* to [^:]+


I want to make sure that the subject line MUST have the exact format
like:

             GENERATE:kflee:PASSWD

and the LOGIN returned would be kflee. Null would be returned if it does
not match exactly.

Well, the condition should NOT be matched, and LOGIN would not be changed 
(meaning, if it previously contained something, it'd still contain that).

I thought \/.*[^:PASSWD] expression means to return the right hand side
but chop off the part
starting with :PASSWD.

Wrong.  To top it off, [] syntax specifies a CHARACTER CLASS - not a whole 
string.

---
  Sean B. Straw / Professional Software Engineering

  Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
  Please DO NOT carbon me on list replies.  I'll get my copy from the list.


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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