56
56
"""See `IBanManager`."""
58
def __init__(self, mailing_list=None):
59
self._list_id = (None if mailing_list is None
60
else mailing_list.list_id)
59
def ban(self, store, email, mailing_list=None):
63
def ban(self, store, email):
60
64
"""See `IBanManager`."""
61
bans = store.find(Ban, email=email, mailing_list=mailing_list)
65
bans = store.find(Ban, email=email, list_id=self._list_id)
62
66
if bans.count() == 0:
63
ban = Ban(email, mailing_list)
67
ban = Ban(email, self._list_id)
67
def unban(self, store, email, mailing_list=None):
71
def unban(self, store, email):
68
72
"""See `IBanManager`."""
69
ban = store.find(Ban, email=email, mailing_list=mailing_list).one()
73
ban = store.find(Ban, email=email, list_id=self._list_id).one()
70
74
if ban is not None:
74
def is_banned(self, store, email, mailing_list=None):
78
def is_banned(self, store, email):
75
79
"""See `IBanManager`."""
76
# A specific mailing list ban is being checked, however the email
77
# address could be banned specifically, or globally.
78
if mailing_list is not None:
79
# Try specific bans first.
80
bans = store.find(Ban, email=email, mailing_list=mailing_list)
80
list_id = self._list_id
82
# The client is asking for global bans. Look up bans on the
83
# specific email address first.
84
bans = store.find(Ban, email=email, list_id=None)
87
# And now look for global pattern bans.
88
bans = store.find(Ban, list_id=None)
90
if (ban.email.startswith('^') and
91
re.match(ban.email, email, re.IGNORECASE) is not None):
94
# This is a list-specific ban.
95
bans = store.find(Ban, email=email, list_id=list_id)
81
96
if bans.count() > 0:
83
98
# Try global bans next.
84
bans = store.find(Ban, email=email, mailing_list=None)
99
bans = store.find(Ban, email=email, list_id=None)
85
100
if bans.count() > 0:
87
102
# Now try specific mailing list bans, but with a pattern.
88
bans = store.find(Ban, mailing_list=mailing_list)
103
bans = store.find(Ban, list_id=list_id)
90
105
if (ban.email.startswith('^') and
91
106
re.match(ban.email, email, re.IGNORECASE) is not None):
93
108
# And now try global pattern bans.
94
bans = store.find(Ban, mailing_list=None)
96
if (ban.email.startswith('^') and
97
re.match(ban.email, email, re.IGNORECASE) is not None):
100
# The client is asking for global bans. Look up bans on the
101
# specific email address first.
102
bans = store.find(Ban, email=email, mailing_list=None)
105
# And now look for global pattern bans.
106
bans = store.find(Ban, mailing_list=None)
109
bans = store.find(Ban, list_id=None)
108
111
if (ban.email.startswith('^') and
109
112
re.match(ban.email, email, re.IGNORECASE) is not None):