Banning email addresses¶
Email addresses can be banned from ever subscribing, either to a specific mailing list or globally within the Mailman system. Both explicit email addresses and email address patterns can be banned.
Bans are managed through the Ban Manager. There are ban managers for
specific lists, and there is a global ban manager. To get access to the
global ban manager, adapt
>>> from mailman.interfaces.bans import IBanManager >>> global_bans = IBanManager(None)
At first, no email addresses are banned globally.
To get a list-specific ban manager, adapt the mailing list object.
>>> mlist = create_list('[email protected]') >>> test_bans = IBanManager(mlist)
There are no bans for this particular list.
An email address can be banned from a specific mailing list by adding a ban to the list’s ban manager.
However, this is not a global ban.
An email address can be banned globally, so that it cannot be subscribed to any mailing list.
>>> global_bans.ban('[email protected]')
Because there is a global ban, Dave is also banned from the mailing list.
>>> test_bans.is_banned('[email protected]') True
Even when a new mailing list is created, Dave is still banned from this list because of his global ban.
Dave is of course banned globally.
>>> global_bans.is_banned('[email protected]') True
Cris however is not banned globally.
Even though Cris is not banned globally, we can add a global ban for her.
Cris is now banned from all mailing lists.
We can remove the global ban to once again just ban her address from just the test list.
Regular expression bans¶
Entire email address patterns can be banned, both for a specific mailing list and globally, just as specific addresses can be banned. Use this for example, when an entire domain is a spam faucet. When using a pattern, the email address must start with a caret (^).
Now, no one from example.org can subscribe to the test mailing list.
example.com addresses are not banned.
example.org addresses are not banned globally, nor for any other mailing list.
Of course, we can ban everyone from example.org globally too.
We can remove the mailing list ban on the pattern, though the global ban will still be in place.
But once the global ban is removed, everyone from example.org can subscribe to the mailing lists.
Adding and removing bans¶
It is not an error to add a ban more than once. These are just ignored.
Nor is it an error to remove a ban more than once.