6
6
mailing list or globally within the Mailman system. Both explicit email
7
7
addresses and email address patterns can be banned.
9
Bans are managed through the `Ban Manager`.
9
Bans are managed through the `Ban Manager`. There are ban managers for
10
specific lists, and there is a global ban manager. To get access to the
11
global ban manager, adapt ``None``.
11
>>> from zope.component import getUtility
12
13
>>> from mailman.interfaces.bans import IBanManager
13
>>> ban_manager = getUtility(IBanManager)
15
At first, no email addresses are banned, either globally...
17
>>> ban_manager.is_banned('anne@example.com')
14
>>> global_bans = IBanManager(None)
16
At first, no email addresses are banned globally.
18
>>> global_bans.is_banned('anne@example.com')
20
...or for a specific mailing list.
22
>>> ban_manager.is_banned('bart@example.com', 'test@example.com')
21
To get a list-specific ban manager, adapt the mailing list object.
23
>>> mlist = create_list('test@example.com')
24
>>> test_bans = IBanManager(mlist)
26
There are no bans for this particular list.
28
>>> test_bans.is_banned('bart@example.com')
29
35
An email address can be banned from a specific mailing list by adding a ban to
36
the list's ban manager.
32
>>> ban_manager.ban('cris@example.com', 'test@example.com')
33
>>> ban_manager.is_banned('cris@example.com', 'test@example.com')
38
>>> test_bans.ban('cris@example.com')
39
>>> test_bans.is_banned('cris@example.com')
35
>>> ban_manager.is_banned('bart@example.com', 'test@example.com')
41
>>> test_bans.is_banned('bart@example.com')
38
44
However, this is not a global ban.
40
>>> ban_manager.is_banned('cris@example.com')
46
>>> global_bans.is_banned('cris@example.com')
47
53
An email address can be banned globally, so that it cannot be subscribed to
50
>>> ban_manager.ban('dave@example.com')
52
Dave is banned from the test mailing list...
54
>>> ban_manager.is_banned('dave@example.com', 'test@example.com')
57
...and the sample mailing list.
59
>>> ban_manager.is_banned('dave@example.com', 'sample@example.com')
62
Dave is also banned globally.
64
>>> ban_manager.is_banned('dave@example.com')
56
>>> global_bans.ban('dave@example.com')
58
Because there is a global ban, Dave is also banned from the mailing list.
60
>>> test_bans.is_banned('dave@example.com')
63
Even when a new mailing list is created, Dave is still banned from this list
64
because of his global ban.
66
>>> sample = create_list('sample@example.com')
67
>>> sample_bans = IBanManager(sample)
68
>>> sample_bans.is_banned('dave@example.com')
71
Dave is of course banned globally.
73
>>> global_bans.is_banned('dave@example.com')
67
76
Cris however is not banned globally.
69
>>> ban_manager.is_banned('cris@example.com')
78
>>> global_bans.is_banned('cris@example.com')
72
81
Even though Cris is not banned globally, we can add a global ban for her.
74
>>> ban_manager.ban('cris@example.com')
75
>>> ban_manager.is_banned('cris@example.com')
78
Cris is obviously still banned from specific mailing lists.
80
>>> ban_manager.is_banned('cris@example.com', 'test@example.com')
82
>>> ban_manager.is_banned('cris@example.com', 'sample@example.com')
85
We can remove the global ban to once again just ban her address from the test
88
>>> ban_manager.unban('cris@example.com')
89
>>> ban_manager.is_banned('cris@example.com', 'test@example.com')
91
>>> ban_manager.is_banned('cris@example.com', 'sample@example.com')
83
>>> global_bans.ban('cris@example.com')
84
>>> global_bans.is_banned('cris@example.com')
87
Cris is now banned from all mailing lists.
89
>>> test_bans.is_banned('cris@example.com')
91
>>> sample_bans.is_banned('cris@example.com')
94
We can remove the global ban to once again just ban her address from just the
97
>>> global_bans.unban('cris@example.com')
98
>>> global_bans.is_banned('cris@example.com')
100
>>> test_bans.is_banned('cris@example.com')
102
>>> sample_bans.is_banned('cris@example.com')
100
111
when an entire domain is a spam faucet. When using a pattern, the email
101
112
address must start with a caret (^).
103
>>> ban_manager.ban('^.*@example.org', 'test@example.com')
105
Now, no one from example.org can subscribe to the test list.
107
>>> ban_manager.is_banned('elle@example.org', 'test@example.com')
109
>>> ban_manager.is_banned('eperson@example.org', 'test@example.com')
111
>>> ban_manager.is_banned('elle@example.com', 'test@example.com')
114
They are not, however banned globally.
116
>>> ban_manager.is_banned('elle@example.org', 'sample@example.com')
118
>>> ban_manager.is_banned('elle@example.org')
114
>>> test_bans.ban('^.*@example.org')
116
Now, no one from example.org can subscribe to the test mailing list.
118
>>> test_bans.is_banned('elle@example.org')
120
>>> test_bans.is_banned('eperson@example.org')
123
example.com addresses are not banned.
125
>>> test_bans.is_banned('elle@example.com')
128
example.org addresses are not banned globally, nor for any other mailing
131
>>> sample_bans.is_banned('elle@example.org')
133
>>> global_bans.is_banned('elle@example.org')
121
136
Of course, we can ban everyone from example.org globally too.
123
>>> ban_manager.ban('^.*@example.org')
124
>>> ban_manager.is_banned('elle@example.org', 'sample@example.com')
138
>>> global_bans.ban('^.*@example.org')
139
>>> sample_bans.is_banned('elle@example.org')
126
>>> ban_manager.is_banned('elle@example.org')
141
>>> global_bans.is_banned('elle@example.org')
129
144
We can remove the mailing list ban on the pattern, though the global ban will
130
145
still be in place.
132
>>> ban_manager.unban('^.*@example.org', 'test@example.com')
133
>>> ban_manager.is_banned('elle@example.org', 'test@example.com')
135
>>> ban_manager.is_banned('elle@example.org', 'sample@example.com')
137
>>> ban_manager.is_banned('elle@example.org')
147
>>> test_bans.unban('^.*@example.org')
148
>>> test_bans.is_banned('elle@example.org')
150
>>> sample_bans.is_banned('elle@example.org')
152
>>> global_bans.is_banned('elle@example.org')
140
155
But once the global ban is removed, everyone from example.org can subscribe to
141
156
the mailing lists.
143
>>> ban_manager.unban('^.*@example.org')
144
>>> ban_manager.is_banned('elle@example.org', 'test@example.com')
146
>>> ban_manager.is_banned('elle@example.org', 'sample@example.com')
148
>>> ban_manager.is_banned('elle@example.org')
158
>>> global_bans.unban('^.*@example.org')
159
>>> test_bans.is_banned('elle@example.org')
161
>>> sample_bans.is_banned('elle@example.org')
163
>>> global_bans.is_banned('elle@example.org')
155
170
It is not an error to add a ban more than once. These are just ignored.
157
>>> ban_manager.ban('fred@example.com', 'test@example.com')
158
>>> ban_manager.ban('fred@example.com', 'test@example.com')
159
>>> ban_manager.is_banned('fred@example.com', 'test@example.com')
172
>>> test_bans.ban('fred@example.com')
173
>>> test_bans.ban('fred@example.com')
174
>>> test_bans.is_banned('fred@example.com')
162
177
Nor is it an error to remove a ban more than once.
164
>>> ban_manager.unban('fred@example.com', 'test@example.com')
165
>>> ban_manager.unban('fred@example.com', 'test@example.com')
166
>>> ban_manager.is_banned('fred@example.com', 'test@example.com')
179
>>> test_bans.unban('fred@example.com')
180
>>> test_bans.unban('fred@example.com')
181
>>> test_bans.is_banned('fred@example.com')