procmail
[Top] [All Lists]

Re: fgrep and regex matching

2006-09-30 12:58:11
On Sat, Sep 30, 2006 at 08:16:49PM +0100, Steve A wrote:

It may seem strange, but I use different mailboxes depending on the 
forum I am posting to (eg. procmail(_at_)mydomain(_dot_)com), and as I don't 
have a 
complete list of all mailboxes I've used, I can't just reject if not on 
the whitelist, but I *will* reject if the subject line is matched too.

Try to get out of the habit of using "mydomain.com" as a generic term
for a domain of yours.  There really is a mydomain.com, and it has
hundreds of thousands of users.

1.
If using a list defined in the recipe like below, I have to remember to 
*not* put a | symbol before the line continuation symbol for the last 
item in the list.  Otherwise, it matches everything (as it should).  To 
keep things simple (eg. leaving the closing bracket on a line by 
itself), should I just use a string that I don't think would ever appear 
in a subject line?

Sure, why not?  But personally, I've never liked or much used that
method, as it's just too ugly and unweildy.

Before I show an alternative, I'll add that you don't need those
right-hand asterisks in your regex for Subject:, unless I'm not
understanding something.  (I.e., I don't follow why you are quoting
the asterisks.  I think you've made a mistake in quoting them, and
the regexes won't work.)  You don't need the right-hand ".*" stuff
at all, in other words.

:0
* ^X-Original-To: \/[^(_at_)]+
* ! $? echo $MATCH | fgrep -i -x -f $RCPT_WHITELIST
* ^Subject: (\
         \*\*|\
         =\?|\
         \?\?|\
         auto.\*|\
         delivery.\*|\
         fail.\*|\
         mail.\*|\
         message.\*|\
         notifica.\*|\
         returned.\*|\
         undeliver.\*\
)
return-junk

One approach is to create a variable that you can use in the recipe.

  LUSERWORD = (=[?]|[?][?]|auto|(un)?deliver|[fm]ail|message|notifica|returned)

  :0  # in brackets just below are a space and a tab
  * $^Subject:[         ]*$LUSERWORD
  *  ^X-Original-To: \/[^(_at_)]+
  * $! ? echo $MATCH | fgrep -i -x -f $RCPT_WHITELIST
  
Note that I changed the order of your conditions for efficiency's sake.
Don't bother running fgrep unless the Subject: contains $LUSERWORD.


2.
Ideally, I would like to do a lookup in a list (like I do with 
RCPT_WHITELIST), but it seems that fgrep cannot perform regex matching. 
  Is that correct?  What would anyone recommend for this situation?

How about egrep?

Dallman

____________________________________________________________
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>