Hello all,

I would like to thank Aditya Jain and Mark Sapiro for the help with adding my negative regexp to the ban_list. I apologize for being late in my response. I was OBE'd.

Next, in my original message, I forgot to mention I am using Mailman v2.1.18-1 so the kind code assistance Mark provided doesn't quite match. My fault for not putting in the version of Mailman. However, looking at the code, it seems to be remarkably similar to code I had to modify when using an earlier version of Mailman.

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?

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.

Thanks to everyone for the help,
Chris



On 10/6/2015 5:43 PM, Mark Sapiro wrote:
On 10/06/2015 08:07 AM, Chris Nulk wrote:
1. The ban_list attribute is to help prevent unwanted people from
subscribing to a list, however, I want to restrict who can subscribe to
the list and ban anyone else.  I have the regex for who I want to allow
to subscribe but there isn't an allow_list attribute.  Is there an easy
way of allowing a regex to control who is able to subscribe?  Or, is
there a way to easily invert the regex logic and use it in ban_list?  As
an example (not the real regex), say I want to only allow @gmail.com to
subscribe to the list but no one else.

As Aditya Jain replied, you can use Python RE negative lookahead
assertions to create regexps with "doesn't match" conditions. See
<https://docs.python.org/2/library/re.html#regular-expression-syntax>.


Although the posted regexp modified for gmail

^[^@]+@(?!(.*\.)?gmail\.com$)

will not match and hence allow, addresses like u...@subdomain.gmail.com.
To allow only '@gmail.com' addresses, e.g. to ban all non-'@gmail.com'
addresses, use

^[^@]+@(?!gmail\.com$)

Often, if you have the regexp to allow, the regexp to ban may be as
simple as

^(?!the_allow_regexp)


2. An additional requirement is to restrict a subgroup of the addresses
from subscribing.  In short, I want to allow all @gmail.com addresses to
subscribe except for a known subgroup.  Now the known subgroup is in a
Mailman list.  So, can I use a Mailman list in the ban_list attribute
similar to using a list in *_these_members attributes?  Or, would I have
to modify the code to allow using a Mailman list in the ban_list attribute?

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.

The change would be in this code in Mailman/Mail.List.py

     def GetBannedPattern(self, email):
         """Returns matched entry in ban_list if email matches.
         Otherwise returns None.
         """
         return self.GetPattern(email, self.ban_list)

change the last line to

         return self.GetPattern(email, self.ban_list, at_list=True)

Or, if you've installed the GLOBAL_BAN_LIST mod, make the change in each
of the two lines in

         return (self.GetPattern(email, self.ban_list) or
                 self.GetPattern(email, mm_cfg.GLOBAL_BAN_LIST)
                )


------------------------------------------------------
Mailman-Users mailing list Mailman-Users@python.org
https://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: 
https://mail.python.org/mailman/options/mailman-users/archive%40jab.org

Reply via email to