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:
def Read_GlobalBan_File(ban_file):
try:
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):
banlist.append(addr)
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.
j...@example.com and j...@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([
mlist.GetOwnerEmail(),
'y...@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('y...@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 = []
if mm_cfg.GLOBALBANLIST_NOTIFY:
notifylist.append(mm_cfg.GLOBALBANLIST_NOTIFY)
# forward auto-discards to list owners?
if mlist.forward_auto_discards:
notifylist.append(mlist.GetOwnerEmail())
# Send message if notifylist is not empty
if notifylist:
lang = mlist.preferred_language
nmsg = Message.UserNotification(notifylist,
mlist.GetBouncesEmail(),
_('Global Ban List Auto-discard
notification'),
lang=lang)
nmsg.set_type('multipart/mixed')
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.""")),
_charset=Utils.GetCharSet(lang))
nmsg.attach(text)
nmsg.attach(MIMEMessage(msg))
nmsg.send(mlist)
# Discard the message
raise Errors.DiscardMessage
Thanks again for the help,
Chris
------------------------------------------------------
Mailman-Users mailing list Mailman-Users@python.org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe:
http://mail.python.org/mailman/options/mailman-users/archive%40jab.org