[Mailman-Users] Writing a custom handler
cnulk at scu.edu
Wed Jul 3 16:40:43 CEST 2013
On 7/2/2013 5:23 PM, Mark Sapiro wrote:
> On 07/02/2013 03:09 PM, Chris Nulk wrote:
>> In the updated code, I did change the populating of the banlist in the
>> Read_GlobalBan_File function. Now, it strips and lowercases the
>> addresses before it checks if the address is in the banlist. Before, it
>> checked then populated a stripped, lowercase version. This could have
>> resulted in duplicates if the address in the banlist but the address
>> checked had a different case profile.
>> # Go through possible senders. Check if any of them are
>> # on the global ban list
>> for sender in msg.get_senders():
>> if sender.lower() in banlist:
> Not necessary to lowercase sender here as msg.get_senders() always
> returns lowercased addresses unless called with a preserve_case argument
> with a True value.
Thanks. It was more of a just to make sure thing.
Actually, I code I was referring to was in Read_GlobalBan_File:
with open(ban_file) as f:
for addr in f:
# strip and lowercase addr
addr = addr.lower().strip()
# if addr is not in banlist, add it - to avoid
duplicates, should not add blank addresses
if (addr) and (addr not in banlist):
In previous versions, lower() and strip() were in the banlist.append not
where they are now. That would have allowed the possibility of
duplicates if the same addr was presented with different cases (i.e.
jdoe at example.com and JDoe at example.com)
>> # copied almost verbatim from Mailman/Handlers/Moderate.py
>> def do_discard_globalban(mlist, msg, sender):
>> # forward auto-discards to list owners?
>> if mlist.forward_auto_discards:
> Note that no forwarding of the discard occurs unless the list's Privacy
> options... -> Sender filters -> forward_auto_discards is set to Yes.
> Otherwise, no notice is sent and the only indication is a "Message
> discarded, msgid: ..." entry in the 'vette' log.
> You may wish to remove the above condition.
I will let the list-owners decide if they want the messages. Granted, it
will be all or nothing for the discards.
>> lang = mlist.preferred_language
>> nmsg = Message.UserNotification(mlist.GetOwnerEmail(),
> mlist.GetOwnerEmail() returns the LISTNAME-owner address which is the
> recipient of this mail. This argument can be a string with a single
> address as it's value as it is here or a list of strings, each of which
> is an address. So the above line could be changed to
> nmsg = Message.UserNotification([
> 'you at example.com',
> with whatever list of addresses you want, or maybe since list owners
> aren't much involved with this ban list
> nmsg = Message.UserNotification('you at example.com',
Okay. Makes sense. Here is the modified do_discard_globalban code:
def do_discard_globalban(mlist, msg, sender):
# forward discarded message to site administrator(s) if defined
# in mm_cfg.GLOBALBANLIST_NOTIFY
notifylist = 
# forward auto-discards to list owners?
# Send message if notifylist is not empty
lang = mlist.preferred_language
nmsg = Message.UserNotification(notifylist,
_('Global Ban List Auto-discard
text = MIMEText(Utils.wrap(_("""\
The sender - %(sender)s - of the attached message is on the Global Ban
list. Therefore, the message
has been automatically discarded.""")),
# Discard the message
Thanks again for the help,
More information about the Mailman-Users