------------------------------------------------------------ revno: 1584 committer: Mark Sapiro <m...@msapiro.net> branch nick: 2.1 timestamp: Thu 2015-10-15 21:06:52 -0700 message: 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. modified: Mailman/Handlers/Moderate.py Mailman/MailList.py NEWS
-- lp:mailman/2.1 https://code.launchpad.net/~mailman-coders/mailman/2.1 Your team Mailman Checkins is subscribed to branch lp:mailman/2.1. To unsubscribe from this branch go to https://code.launchpad.net/~mailman-coders/mailman/2.1/+edit-subscription
=== modified file 'Mailman/Handlers/Moderate.py' --- Mailman/Handlers/Moderate.py 2015-01-23 23:50:47 +0000 +++ Mailman/Handlers/Moderate.py 2015-10-16 04:06:52 +0000 @@ -97,15 +97,27 @@ 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 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: === modified file 'Mailman/MailList.py' --- Mailman/MailList.py 2015-08-21 16:26:28 +0000 +++ Mailman/MailList.py 2015-10-16 04:06:52 +0000 @@ -1574,17 +1574,29 @@ 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 @@ 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 === modified file 'NEWS' --- NEWS 2015-10-14 16:42:19 +0000 +++ NEWS 2015-10-16 04:06:52 +0000 @@ -22,6 +22,10 @@ Bug fixes and other patches + - 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. + - Changed CookHeaders to default to using space rather than tab as continuation_ws when folding headers. (LP: #1505878)
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org