HighDots Forums  

Re: regexp help

Python Python programming language mailing list


Discuss Re: regexp help in the Python forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mark Sapiro
 
Posts: n/a

Default Re: regexp help - 11-03-2009 , 06:00 PM






Savoy, Jim wrote:

Quote:
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 (DOT) ca is set to forward mail to the
mailing
list abc-l (AT) uleth (DOT) ca, which should accept it, regardless of who sent it
to
test.account (AT) uleth (DOT) 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'?


Quote:
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.


Quote:
Or do I need a more specific or accompanying
regexp in
the re.compile statement? eg

cre = re.compile('test.account (AT) uleth (DOT) ca', re.IGNORECASE)

You could do that, or even 'test\.account@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 (DOT) ca address?

Some non-list member could mail

To: <abc-l@...>, <my-test-account (AT) example (DOT) 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@uleth\.ca($|[\s>])'

to require the exact address test.account (AT) uleth (DOT) 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 (DOT) ca' is there and 'abc-l@...' 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 (DOT) ca and send it directly to the abc-l list.

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

------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.