[Mailman-Users] list subscription spammers
Will Yardley
mailman at veggiechinese.net
Thu Aug 27 04:14:35 CEST 2015
ps - Here are a couple of quick throwaway 'withlist' scripts I threw
together to add a regexp matching the spammers' email addresses, and to
purge pending subscription requests matching a similar regexp. Posting
here in case someone finds them useful for this, or some other, purpose.
% cat purge_requests.py
# quick "withlist" script.
# call via withlist -r purge_requests LISTNAME
# or via loop:
# for LIST in `./list_lists -b` ; do ./withlist -r purge_requests $LIST ; done
import re
from Mailman import mm_cfg
from Mailman.mm_cfg import DISCARD
email_re = re.compile('^(foo|bar.baz|blah)\+[0-9]+ at example\.com')
def purge_requests(m):
print "** Checking %s" % m.internal_name()
m.Lock()
for item in m.GetSubscriptionIds():
email_addr = m.GetRecord(item)[1]
if email_re.match(email_addr):
print ">> Discarding %s from %s" % (email_addr,
m.internal_name())
m.HandleRequest(item, DISCARD)
m.Save()
m.Unlock()
% cat set_banlist.py
# quick "withlist" script.
# call via withlist -r set_banlist LISTNAME
# or via loop:
# for LIST in `./list_lists -b` ; do ./withlist -r set_banlist $LIST ; done
# Obviously, the problem becomes a bit more complex if we want to adjust
# the existing rule, vs. adding a new one; then we'd have to track the
# item # within the list, and modify that item (this also shouldn't be
# too hard).
from Mailman import mm_cfg
# This will append the item below to the ban_list for $LISTNAME
# Note additional pattern below; that's just a check to see if the
# pattern already exists.
ban_item = '^(foo|bar.baz|blah)\\+[0-9]+ at example\.com'
def set_banlist(m):
# Rather than use regex, use this to see if substring is in list
if not rule_exists(m.ban_list):
print "**** Updating %s" % m.internal_name()
m.Lock()
m.ban_list.append(ban_item)
m.Save()
# Could probably do this a little more tersely with 'lambda'
def rule_exists(list):
for item in list:
if '\(foo' in item:
return 1
More information about the Mailman-Users
mailing list