[Mailman-Users] Additional questions about ban_list

Mark Sapiro mark at msapiro.net
Fri Oct 16 00:07:17 CEST 2015


On 10/15/2015 02:37 PM, Chris Nulk wrote:
> 
> The question now is if I change the following in Mailman/MailList.py
> 
>     def GetBannedPattern(self, email):
>         """Returns matched entry in ban_list if email matches.
>         Otherwise returns None.
>         """
>         ban = False
>         for pattern in self.ban_list:
>             if pattern.startswith('^'):
>                 # This is a regular expression match
>                 try:
>                     if re.search(pattern, email, re.IGNORECASE):
>                         ban = True
>                         break
>                 except re.error:
>                     # BAW: we should probably remove this pattern
>                     pass
>             else:
>                 # Do the comparison case insensitively
>                 if pattern.lower() == email.lower():
>                     ban = True
>                     break
>         if ban:
>             return pattern
>         else:
>             return None
> 
> to the following ( I have added ** at the beginning of the lines I added
> to indicate the changes - in practice the ** would be spaces)
> 
>     def GetBannedPattern(self, email):
>         """Returns matched entry in ban_list if email matches.
>         Otherwise returns None.
>         """
>         ban = False
>         for pattern in self.ban_list:
>             if pattern.startswith('^'):
>                 # This is a regular expression match
>                 try:
>                     if re.search(pattern, email, re.IGNORECASE):
>                         ban = True
>                         break
>                 except re.error:
>                     # BAW: we should probably remove this pattern
>                     pass
> **          elif pattern.startswith('@'):
> **              listname = self.internal_name()  # is this correct?
> **              try:
> **                  mname = pattern[1:].lower().strip()
> **                  if mname == listname:
> **                      # don't reference your own list
> **                      syslog('error',
> **                          'Ban_list listfor %s references own list',
> **                          listname)
> **                  else:
> **                      mother = MailList(mname, lock=0)
> **                      if mother.isMember(email):
> **                          ban = True
> **                          break
> **              except Errors.MMUnknownListError:
> **                  syslog('error',
> **                      'Ban_list for list %s references non-existent
> list %s',
> **                      listname, mname)
>             else:
>                 # Do the comparison case insensitively
>                 if pattern.lower() == email.lower():
>                     ban = True
>                     break
>         if ban:
>             return pattern
>         else:
>             return None
> 
> Am I on the correct path?


Yes.


> Mark, if you have the time and/or inclination, could you explain your
> comments about
> 
>     Allowing @list_name in ban_list is a simple code modification if you
>     don't care if various 'error' log messages such as list references
>     itself or references non-existent list refer to
>     'subscribe_auto_approval' even if the error is in ban_list.


In Mailman 2.1.19 much of the code in the GetBannedPattern() method was
moved to a new GetPattern() method which optionally supports the
@listname convention. This was done for subscribe_auto_approval, and
while it's kind of kludgy, the error log messages that you have above
for 'Ban_list listfor %s references own list' and 'Ban_list for list %s
references non-existent list %s' refer to subscribe_auto_approval rather
than ban_list or something variable.

Thus if you had 2.1.19 or later, the code change is much simpler if you
don't mind the error log messages saying subscribe_auto_approval when
they might mean ban_list.

See
<http://bazaar.launchpad.net/~mailman-coders/mailman/2.1/view/head:/Mailman/MailList.py>.

-- 
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