[Mailman-Users] Regexp for blocking addresses

Mark Sapiro mark at msapiro.net
Sat Sep 26 06:01:04 CEST 2015


On 9/25/15 7:57 AM, Matthew Saltzman wrote:
>
> That's still much more aggressive than what I was trying to say. I
> actually want to ban precisely all variants of the one address
>
>     joeblow at gmail.com
>
> (and about a dozen other addresses) that include embedded periods
> anywhere and the suffix, but not other gmail addresses.


Here's another idea.

Find the following in /path/to/mailman/Mailman/MailList.py

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

and change it to

bad_users = ['joeblow at gmailcom',
             'johndoe at gmailcom',
             'jackblack at gmailcom',
             ...                       (the rest of the addrs to ban)
            ]
    def GetBannedPattern(self, email):
        """Returns matched entry in ban_list if email matches.
        Otherwise returns None.
        """
        if re.sub('\.', '' re.sub('\+.*@', '@', email.lower())) in
bad_users:
            return 'bad_user'
        return self.GetPattern(email, self.ban_list)

Note that the line

if re.sub('\.', '' re.sub('\+.*@', '@', email.lower())) in bad_users:

should be indented 8 spaces as shown above, but still all one line. What
this does is lower-case the email address, then replace a '+' if any and
all that follows up to an '@' with just the '@' and finally removes all
the '.' and if the result is in the bad_users list, the address will be
banned for matching 'bad_user'.  Note too that there is no '.' in the
gmailcom part of the bad addresses as we will have removed that before
the test.

If you do this, you have to restart Mailman after modifying 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