diff options
author | Mark Sapiro <mark@msapiro.net> | 2015-10-15 21:06:52 -0700 |
---|---|---|
committer | Mark Sapiro <mark@msapiro.net> | 2015-10-15 21:06:52 -0700 |
commit | ac9886b17e0462f70209cc2ee0bc3744dd9bd520 (patch) | |
tree | 762c9e8849d860f2911ab5e2031cb9db90c32128 /Mailman | |
parent | b7f4af5909c45a4084174d6b5a4c3ea9742fd997 (diff) | |
download | mailman2-ac9886b17e0462f70209cc2ee0bc3744dd9bd520.tar.gz mailman2-ac9886b17e0462f70209cc2ee0bc3744dd9bd520.tar.xz mailman2-ac9886b17e0462f70209cc2ee0bc3744dd9bd520.zip |
Refactored the GetPattern list method to simplify extending @listname
syntax to new attributes in the future. Changed Moderate.py to use the
GetPattern method to process the *_these_nonmembers lists.
Diffstat (limited to 'Mailman')
-rw-r--r-- | Mailman/Handlers/Moderate.py | 57 | ||||
-rwxr-xr-x | Mailman/MailList.py | 33 |
2 files changed, 38 insertions, 52 deletions
diff --git a/Mailman/Handlers/Moderate.py b/Mailman/Handlers/Moderate.py index dfc2c567..49ed1d7e 100644 --- a/Mailman/Handlers/Moderate.py +++ b/Mailman/Handlers/Moderate.py @@ -97,15 +97,27 @@ def process(mlist, msg, msgdata): sender = msg.get_sender() # From here on out, we're dealing with non-members. listname = mlist.internal_name() - if matches_p(sender, mlist.accept_these_nonmembers, listname): + if mlist.GetPattern(sender, + mlist.accept_these_nonmembers, + at_list='accept_these_nonmembers' + ): return - if matches_p(sender, mlist.hold_these_nonmembers, listname): + if mlist.GetPattern(sender, + mlist.hold_these_nonmembers, + at_list='hold_these_nonmembers' + ): Hold.hold_for_approval(mlist, msg, msgdata, Hold.NonMemberPost) # No return - if matches_p(sender, mlist.reject_these_nonmembers, listname): + if mlist.GetPattern(sender, + mlist.reject_these_nonmembers, + at_list='reject_these_nonmembers' + ): do_reject(mlist) # No return - if matches_p(sender, mlist.discard_these_nonmembers, listname): + if mlist.GetPattern(sender, + mlist.discard_these_nonmembers, + at_list='discard_these_nonmembers' + ): do_discard(mlist, msg) # No return # Okay, so the sender wasn't specified explicitly by any of the non-member @@ -124,43 +136,6 @@ def process(mlist, msg, msgdata): -def matches_p(sender, nonmembers, listname): - # First strip out all the regular expressions and listnames - plainaddrs = [addr for addr in nonmembers if not (addr.startswith('^') - or 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 - elif are.startswith('@'): - # XXX Needs to be reviewed for list@domain names. - try: - mname = are[1:].lower().strip() - if mname == listname: - # don't reference your own list - syslog('error', - '*_these_nonmembers in %s references own list', - listname) - else: - mother = MailList(mname, lock=0) - if mother.isMember(sender): - return 1 - except Errors.MMUnknownListError: - syslog('error', - '*_these_nonmembers in %s references non-existent list %s', - listname, mname) - return 0 - - - def do_reject(mlist): listowner = mlist.GetOwnerEmail() if mlist.nonmember_rejection_notice: diff --git a/Mailman/MailList.py b/Mailman/MailList.py index 2095d107..3acd6294 100755 --- a/Mailman/MailList.py +++ b/Mailman/MailList.py @@ -1574,17 +1574,29 @@ bad regexp in bounce_matching_header line: %s Otherwise returns False. """ auto_approve = False - if self.GetPattern(sender, self.subscribe_auto_approval, at_list=True): + if self.GetPattern(sender, + self.subscribe_auto_approval, + at_list='subscribe_auto_approval' + ): auto_approve = True syslog('vette', '%s: auto approved subscribe from %s', self.internal_name(), sender) return auto_approve - def GetPattern(self, email, pattern_list, at_list=False): + def GetPattern(self, email, pattern_list, at_list=None): """Returns matched entry in pattern_list if email matches. - Otherwise returns None. + Otherwise returns None. The at_list argument, if "true", + says process the @listname syntax and provides the name of + the list attribute for log messages. """ matched = None + # First strip out all the regular expressions and listnames because + # documentation says we do non-regexp first (Why?). + plainaddrs = [x.strip() for x in pattern_list if x.strip() and not + (x.startswith('^') or x.startswith('@'))] + addrdict = Utils.List2Dict(plainaddrs, foldcase=1) + if addrdict.has_key(email.lower()): + return email for pattern in pattern_list: if pattern.startswith('^'): # This is a regular expression match @@ -1603,24 +1615,23 @@ bad regexp in bounce_matching_header line: %s if mname == self.internal_name(): # don't reference your own list syslog('error', - 'subscribe_auto_approval in %s references own list', + '%s in %s references own list', + at_list, self.internal_name()) continue try: mother = MailList(mname, lock = False) except Errors.MMUnknownListError: syslog('error', - 'subscribe_auto_approval in %s references non-existent list %s', - self.internal_name(), mname) + '%s in %s references non-existent list %s', + at_list, + self.internal_name(), + mname + ) continue if mother.isMember(email.lower()): matched = pattern break - else: - # Do the comparison case insensitively - if pattern.lower() == email.lower(): - matched = pattern - break return matched |