diff options
| author | bwarsaw | 2001-02-15 04:36:29 +0000 |
|---|---|---|
| committer | bwarsaw | 2001-02-15 04:36:29 +0000 |
| commit | f97b4ee51d876e1fa6da8b755b6302e3e9cb9111 (patch) | |
| tree | 79e8aea3c7f31264f42f95ee5fbae65cea0d330b | |
| parent | 682cc1de88ecf10315e92b79c6f0f5ae52105114 (diff) | |
| download | mailman-f97b4ee51d876e1fa6da8b755b6302e3e9cb9111.tar.gz mailman-f97b4ee51d876e1fa6da8b755b6302e3e9cb9111.tar.zst mailman-f97b4ee51d876e1fa6da8b755b6302e3e9cb9111.zip | |
Conversion to mimelib.
De-string-module-ify
Other Python 2.0 constructs used where appropriate.
All exceptions now use Errors.MessageHeld as their base class
(MessageHeld was moved from the obsolete HandlerAPI module to the
Errors module).
Remove the pickle imports.
| -rw-r--r-- | Mailman/Handlers/Hold.py | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/Mailman/Handlers/Hold.py b/Mailman/Handlers/Hold.py index 6947016cd..6e64f98a0 100644 --- a/Mailman/Handlers/Hold.py +++ b/Mailman/Handlers/Hold.py @@ -1,4 +1,4 @@ -# Copyright (C) 1998,1999,2000 by the Free Software Foundation, Inc. +# Copyright (C) 1998,1999,2000,2001 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -31,49 +31,44 @@ message handling should stop. import os import time from types import ClassType +from mimelib.MsgReader import MsgReader -try: - import cPickle - pickle = cPickle -except ImportError: - import pickle - -import HandlerAPI -from Mailman import Message from Mailman import mm_cfg from Mailman import Utils +from Mailman import Errors +from Mailman import Message from Mailman.i18n import _ from Mailman.Logging.Syslog import syslog -class ForbiddenPoster(HandlerAPI.MessageHeld): +class ForbiddenPoster(Errors.MessageHeld): "Sender is explicitly forbidden" rejection = _('You are forbidden from posting messages to this list.') -class ModeratedPost(HandlerAPI.MessageHeld): +class ModeratedPost(Errors.MessageHeld): "Post to moderated list" rejection = _('Your message was deemed inappropriate by the moderator.') -class NonMemberPost(HandlerAPI.MessageHeld): +class NonMemberPost(Errors.MessageHeld): "Post by non-member to a members-only list" rejection = _('Non-members are not allowed to post messages to this list.') -class NotExplicitlyAllowed(HandlerAPI.MessageHeld): +class NotExplicitlyAllowed(Errors.MessageHeld): "Posting to a restricted list by sender requires approval" rejection = _('This list is restricted; your message was not approved.') -class TooManyRecipients(HandlerAPI.MessageHeld): +class TooManyRecipients(Errors.MessageHeld): "Too many recipients to the message" rejection = _('Please trim the recipient list; it is too long.') -class ImplicitDestination(HandlerAPI.MessageHeld): +class ImplicitDestination(Errors.MessageHeld): "Message has implicit destination" rejection = _('''Blind carbon copies or other implicit destinations are not allowed. Try reposting your message by explicitly including the list address in the To: or Cc: fields.''') -class Administrivia(HandlerAPI.MessageHeld): +class Administrivia(Errors.MessageHeld): "Message may contain administrivia" def rejection_notice(self, mlist): @@ -84,18 +79,18 @@ instructions.""") % {'listurl': mlist.GetScriptURL('listinfo', absolute=1), 'request': mlist.GetRequestEmail(), } -class SuspiciousHeaders(HandlerAPI.MessageHeld): +class SuspiciousHeaders(Errors.MessageHeld): "Message has a suspicious header" rejection = _('Your message had a suspicious header.') -class MessageTooBig(HandlerAPI.MessageHeld): +class MessageTooBig(Errors.MessageHeld): "Message body is too big: %d bytes but there's a limit of %d KB" def __init__(self, msgsize, limit): self.__msgsize = msgsize self.__limit = limit def __str__(self): - return HandlerAPI.MessageHeld.__str__(self) % ( + return Errors.MessageHeld.__str__(self) % ( self.__msgsize, self.__limit) def rejection_notice(self, mlist): @@ -107,18 +102,18 @@ class MessageTooBig(HandlerAPI.MessageHeld): def process(mlist, msg, msgdata): if msgdata.get('approved'): return - # get the sender of the message + # Get the sender of the message listname = mlist.internal_name() adminaddr = listname + '-admin' - sender = msg.GetSender() + sender = msg.get_sender() # Special case an ugly sendmail feature: If there exists an alias of the # form "owner-foo: bar" and sendmail receives mail for address "foo", # sendmail will change the envelope sender of the message to "bar" before # delivering. This feature does not appear to be configurable. *Boggle*. if not sender or sender[:len(listname)+6] == adminaddr: - sender = msg.GetSender(use_envelope=0) + sender = msg.get_sender(use_envelope=0) # - # is the poster in the list of explicitly forbidden posters? + # Is the poster in the list of explicitly forbidden posters? if len(mlist.forbidden_posters): forbiddens = Utils.List2Dict(mlist.forbidden_posters) addrs = Utils.FindMatchingAddresses(sender, forbiddens) @@ -126,7 +121,7 @@ def process(mlist, msg, msgdata): hold_for_approval(mlist, msg, msgdata, ForbiddenPoster) # no return # - # is the list moderated? if so and the sender is not in the list of + # Is the list moderated? If so and the sender is not in the list of # allowed posters then hold the message. if mlist.moderated: posters = Utils.List2Dict(mlist.posters) @@ -135,9 +130,9 @@ def process(mlist, msg, msgdata): hold_for_approval(mlist, msg, msgdata, ModeratedPost) # no return # - # postings only from list members? mlist.posters are allowed in addition - # to list members. If not set, then only the members in posters are - # allowed to post without approval. + # Postings allowed only from list members? mlist.posters are allowed in + # addition to list members. If not set, then only the members in posters + # are allowed to post without approval. if mlist.member_posting_only: posters = Utils.List2Dict([s.lower() for s in mlist.posters]) if not mlist.IsMember(sender) and \ @@ -154,46 +149,52 @@ def process(mlist, msg, msgdata): hold_for_approval(mlist, msg, msgdata, NotExplicitlyAllowed) # no return # - # are there too many recipients to the message? + # Are there too many recipients to the message? if mlist.max_num_recipients > 0: # figure out how many recipients there are recips = [] - toheader = msg.getheader('to') + toheader = msg['to'] if toheader: recips.extend([s.strip() for s in toheader.split(',')]) - ccheader = msg.getheader('cc') + ccheader = msg['cc'] if ccheader: recips.extend([s.strip() for s in ccheader.split(',')]) if len(recips) > mlist.max_num_recipients: hold_for_approval(mlist, msg, msgdata, TooManyRecipients) # no return # - # implicit destination? Note that message originating from the Usenet - # side of the world should never be implicitly destined + # Implicit destination? Note that message originating from the Usenet + # side of the world should never be checked for implicit destination. if mlist.require_explicit_destination and \ - not mlist.HasExplicitDest(msg) and \ - not msgdata.get('fromusenet'): + not mlist.HasExplicitDest(msg) and \ + not msgdata.get('fromusenet'): # then hold_for_approval(mlist, msg, msgdata, ImplicitDestination) # no return # - # possible administrivia? - if mlist.administrivia and Utils.IsAdministrivia(msg): + # Possible administrivia? + if mlist.administrivia and Utils.is_administrivia(msg): hold_for_approval(mlist, msg, msgdata, Administrivia) # no return # - # suspicious headers? + # Suspicious headers? if mlist.bounce_matching_headers: - triggered = mlist.HasMatchingHeader(msg) + triggered = mlist.hasMatchingHeader(msg) if triggered: # TBD: Darn - can't include the matching line for the admin # message because the info would also go to the sender hold_for_approval(mlist, msg, msgdata, SuspiciousHeaders) # no return # - # message too big? + # Is the message too big? if mlist.max_message_size > 0: - bodylen = len(msg.body) + reader = MsgReader(msg) + bodylen = 0 + while 1: + line = reader.readline() + if not line: + break + bodylen += len(line) if bodylen/1024.0 > mlist.max_message_size: hold_for_approval(mlist, msg, msgdata, MessageTooBig(bodylen, mlist.max_message_size)) @@ -202,16 +203,16 @@ def process(mlist, msg, msgdata): def hold_for_approval(mlist, msg, msgdata, exc): - # TBD: This should really be tied into the email confirmation system so + # BAW: This should really be tied into the email confirmation system so # that the message can be approved or denied via email as well as the - # Web. That's for later though, because it would mean a revamp of the + # web. That's for later though, because it would mean a revamp of the # MailCommandHandler too. # if type(exc) is ClassType: # Go ahead and instantiate it now. exc = exc() listname = mlist.real_name - sender = msg.GetSender() + sender = msg.get_sender() adminaddr = mlist.GetAdminEmail() # BAW: I don't like using $LANG :( os.environ['LANG'] = mlist.preferred_language @@ -243,7 +244,7 @@ def hold_for_approval(mlist, msg, msgdata, exc): text = Utils.maketext('postauth.txt', d, raw=1) # craft the admin notification message and deliver it msg = Message.UserNotification(adminaddr, adminaddr, subject, text) - HandlerAPI.DeliverToUser(mlist, msg) + msg.send(mlist) if not fromusenet and not mlist.dont_respond_to_post_requests: # jcrey: We need to translate certains parts to user's preferred # language. @@ -253,7 +254,7 @@ def hold_for_approval(mlist, msg, msgdata, exc): d['subject'] = usersubject text = Utils.maketext('postheld.txt', d, pluser) msg = Message.UserNotification(sender, adminaddr, subject, text) - HandlerAPI.DeliverToUser(mlist, msg) + msg.send(mlist) # Log the held message syslog('vette', '%s post from %s held: %s' % (listname, sender, reason)) # raise the specific MessageHeld exception to exit out of the message |
