From 2ce10b5087e4d8ca305e2d39c1d326acc72c8ca9 Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Wed, 21 Nov 2001 17:21:38 +0000 Subject: process(): Simplify by calling out to matches_p() to do the actual match of the sender against the nonmember addresses. matches_p(): Implements the matching rules: - match literal addresses first - match re's next (they must start with a ^ which stays as part of the regular expression) --- Mailman/Handlers/Moderate.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/Mailman/Handlers/Moderate.py b/Mailman/Handlers/Moderate.py index 149bd0399..d957213b0 100644 --- a/Mailman/Handlers/Moderate.py +++ b/Mailman/Handlers/Moderate.py @@ -17,6 +17,7 @@ """Posting moderation filter. """ +import re from email.MIMEMessage import MIMEMessage from email.MIMEText import MIMEText @@ -47,19 +48,18 @@ def process(mlist, msg, msgdata): # this point? No, because further pipeline handlers will need to do # their own thing. return - # From here on out, we're dealing with non-members - addrdict = Utils.List2Dict(mlist.accept_these_nonmembers, foldcase=1) - if addrdict.has_key(sender): + # From here on out, we're dealing with non-members. + if matches_p(sender, mlist.accept_these_nonmembers): return - addrdict = Utils.List2Dict(mlist.hold_these_nonmembers, foldcase=1) - if addrdict.has_key(sender): + if matches_p(sender, mlist.hold_these_nonmembers): Hold.hold_for_approval(mlist, msg, msgdata, Hold.ModeratedPost) - addrdict = Utils.List2Dict(mlist.reject_these_nonmembers, foldcase=1) - if addrdict.has_key(sender): + # No return + if matches_p(sender, mlist.reject_these_nonmembers): do_reject(mlist) - addrdict = Utils.List2Dict(mlist.discard_these_nonmembers, foldcase=1) - if addrdict.has_key(sender): + # No return + if matches_p(sender, mlist.discard_these_nonmembers): do_discard(mlist, msg) + # No return # Okay, so the sender wasn't specified explicitly by any of the non-member # moderation configuration variables. Handle by way of generic non-member # action. @@ -75,6 +75,25 @@ def process(mlist, msg, msgdata): do_discard(mlist, msg) + +def matches_p(sender, nonmembers): + # First strip out all the regular expressions + plainaddrs = [addr for addr in nonmembers if not addr.startswith('^')] + addrdict = Utils.List2Dict(plainaddrs, foldcase=1) + if addrdict.has_key(sender): + return 1 + # Now do the regular expression matches + for are in nonmembers: + if are.startswith('^'): + try: + cre = re.compile(are, re.IGNORECASE) + except re.error: + continue + if cre.search(sender): + return 1 + return 0 + + def do_reject(mlist): listowner = mlist.GetOwnerEmail() -- cgit v1.3.1