[Mailman-Users] regexp help

Mark Sapiro mark at msapiro.net
Wed Nov 4 00:00:49 CET 2009


Savoy, Jim wrote:

>Hi Mark,
>
>   I got it to compile properly, but it is still not working.
>I made the following changes in Foo.py:
>
>import re
>cre = re.compile('test.account', re.IGNORECASE)
>def process(mlist, msg, msgdata):
>    if mlist.internal_name <> 'abc-l':
>        return
>    if cre.search(msg.get('to', '')):
>        msgdata['approved'] = 1
>        # Used by the Emergency module
>        msgdata['adminapproved'] = 1
>
>
>Goal: The account test.account at uleth.ca is set to forward mail to the
>mailing
>list abc-l at uleth.ca, which should accept it, regardless of who sent it
>to
>test.account at uleth.ca (all other mail to this list from non-members will
>be
>rejected).


Did you put 'Foo' back in the GLOBAL_PIPELINE prior to 'Moderate' and
restart Mailman?

What happens when you mail to test.account? Is the mail rejected by
Mailman? Does the To: header in the mail in the reject notice contain
'test.account'?


>You also wrote:
>
>>if the contents of the To: header of the message matches the regexp in
>>re.compile() case insensitively, then the approved and adminapproved
>>flags will be set in the message metadata and the message won't be
>>subject to any holds.
>
>So when you say "matches the regexp" do you mean "exactly" matches? And
>if so,
>would your regexp work?


Since that regexp 'test.account' is not anchored and is searched for by
the re.search() method, it means if the string 'test' in any
combination of upper/lower case followed by any single character (the
. matches any character) followed by the string 'account' in any
combination of upper/lower case is in the To: header, it will match.


>Or do I need a more specific or accompanying
>regexp in
>the re.compile statement? eg
>
>cre = re.compile('test.account at uleth.ca', re.IGNORECASE)


You could do that, or even 'test\.account at uleth\.ca' or other, even
more restrictive tests on the To: header, but what are the chances of
some mail being delivered to the abc-l list from a non-member with
'test.account' somewhere in the To: header, if it wasn't sent to the
proper test.account at uleth.ca address?

Some non-list member could mail

To: <abc-l at ...>, <my-test-account at example.com>

and the regexp 'test.account' would accept that mail. If you're
concerned about this, you could use a regexp like

  '(^|[\s<])test\.account at uleth\.ca($|[\s>])'

to require the exact address test.account at uleth.ca delimited by white
space, angle brackets or the start and end of the string, but there
are probably better ways of doing this such as using email utilities
to parse the To: header for all addresses and then testing to see that
'test.account at uleth.ca' is there and 'abc-l at ...' is not, but all that
seems unnecessary unless you're going to look at Received: headers too.

I.e., if I'm trying to fool you, I can always create a message To:
test.account at uleth.ca and send it directly to the abc-l list.

-- 
Mark Sapiro <mark at msapiro.net>        The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan



More information about the Mailman-Users mailing list