54
54
implements(IBanManager)
56
def ban(self, email, mailing_list=None):
57
def ban(self, store, email, mailing_list=None):
57
58
"""See `IBanManager`."""
58
bans = config.db.store.find(
59
Ban, email=email, mailing_list=mailing_list)
59
bans = store.find(Ban, email=email, mailing_list=mailing_list)
60
60
if bans.count() == 0:
61
61
ban = Ban(email, mailing_list)
62
config.db.store.add(ban)
64
def unban(self, email, mailing_list=None):
65
def unban(self, store, email, mailing_list=None):
65
66
"""See `IBanManager`."""
66
ban = config.db.store.find(
67
Ban, email=email, mailing_list=mailing_list).one()
67
ban = store.find(Ban, email=email, mailing_list=mailing_list).one()
68
68
if ban is not None:
69
config.db.store.remove(ban)
71
def is_banned(self, email, mailing_list=None):
72
def is_banned(self, store, email, mailing_list=None):
72
73
"""See `IBanManager`."""
73
74
# A specific mailing list ban is being checked, however the email
74
75
# address could be banned specifically, or globally.
75
76
if mailing_list is not None:
76
77
# Try specific bans first.
77
bans = config.db.store.find(
78
Ban, email=email, mailing_list=mailing_list)
78
bans = store.find(Ban, email=email, mailing_list=mailing_list)
79
79
if bans.count() > 0:
81
81
# Try global bans next.
82
bans = config.db.store.find(Ban, email=email, mailing_list=None)
82
bans = store.find(Ban, email=email, mailing_list=None)
83
83
if bans.count() > 0:
85
85
# Now try specific mailing list bans, but with a pattern.
86
bans = config.db.store.find(Ban, mailing_list=mailing_list)
86
bans = store.find(Ban, mailing_list=mailing_list)
88
88
if (ban.email.startswith('^') and
89
89
re.match(ban.email, email, re.IGNORECASE) is not None):
91
91
# And now try global pattern bans.
92
bans = config.db.store.find(Ban, mailing_list=None)
92
bans = store.find(Ban, mailing_list=None)
94
94
if (ban.email.startswith('^') and
95
95
re.match(ban.email, email, re.IGNORECASE) is not None):
98
98
# The client is asking for global bans. Look up bans on the
99
99
# specific email address first.
100
bans = config.db.store.find(
101
Ban, email=email, mailing_list=None)
100
bans = store.find(Ban, email=email, mailing_list=None)
102
101
if bans.count() > 0:
104
103
# And now look for global pattern bans.
105
bans = config.db.store.find(Ban, mailing_list=None)
104
bans = store.find(Ban, mailing_list=None)
107
106
if (ban.email.startswith('^') and
108
107
re.match(ban.email, email, re.IGNORECASE) is not None):