diff options
| -rw-r--r-- | Mailman/Handlers/Approve.py | 2 | ||||
| -rw-r--r-- | Mailman/Handlers/Decorate.py | 15 | ||||
| -rw-r--r-- | Mailman/Handlers/Hold.py | 26 | ||||
| -rw-r--r-- | Mailman/Handlers/Tagger.py | 17 |
4 files changed, 26 insertions, 34 deletions
diff --git a/Mailman/Handlers/Approve.py b/Mailman/Handlers/Approve.py index d0112e6fe..269572532 100644 --- a/Mailman/Handlers/Approve.py +++ b/Mailman/Handlers/Approve.py @@ -48,6 +48,6 @@ def process(mlist, msg, msgdata): # match? For now we'll let it percolate up for further determination. msgdata['approved'] = 1 # has this message already been posted to this list? - beentheres = [s.strip().lower() for s in msg.getall('x-beenthere')] + beentheres = [s.strip().lower() for s in msg.get_all('x-beenthere')] if mlist.GetListEmail().lower() in beentheres: raise Errors.LoopError diff --git a/Mailman/Handlers/Decorate.py b/Mailman/Handlers/Decorate.py index 63c86e608..60b1ac610 100644 --- a/Mailman/Handlers/Decorate.py +++ b/Mailman/Handlers/Decorate.py @@ -18,8 +18,7 @@ """ from types import ListType - -from mimelib.Text import Text +from email.MIMEText import MIMEText from Mailman import mm_cfg from Mailman import Errors @@ -37,7 +36,7 @@ def process(mlist, msg, msgdata): if msgdata.get('personalized'): # Calculate the extra personalization dictionary. Note that the # length of the recips list better be exactly 1. - recips = msgdata['recips'] + recips = msgdata.get('recips') assert type(recips) == ListType and len(recips) == 1 member = recips[0].lower() d['user_address'] = member @@ -56,21 +55,21 @@ def process(mlist, msg, msgdata): # concatenation when the message is a non-multipart of type text/plain. # Otherwise, if it is not a multipart, we make it a multipart, and then we # add the header and footer as text/plain parts. - if not msg.ismultipart() and msg.gettype() in (None, 'text/plain'): + if not msg.is_multipart() and msg.get_type('text/plain') == 'text/plain': payload = header + msg.get_payload() + footer msg.set_payload(payload) - elif msg.gettype() == 'multipart/mixed': + elif msg.get_type() == 'multipart/mixed': # The next easiest thing to do is just prepend the header and append # the footer as additional subparts - mimehdr = Text(header) - mimeftr = Text(footer) + mimehdr = MIMEText(header) + mimeftr = MIMEText(footer) payload = msg.get_payload() if not isinstance(payload, ListType): payload = [payload] payload.append(mimeftr) payload.insert(0, mimehdr) msg.set_payload(payload) - elif msg.getmaintype() <> 'multipart': + elif msg.get_main_type() <> 'multipart': # Okay, we've got some 'image/*' or 'audio/*' -like type. For now, we # simply refuse to add headers and footers to this message. BAW: # still trying to decide what the Right Thing To Do is. diff --git a/Mailman/Handlers/Hold.py b/Mailman/Handlers/Hold.py index 989c562b9..75cfa3a47 100644 --- a/Mailman/Handlers/Hold.py +++ b/Mailman/Handlers/Hold.py @@ -30,8 +30,9 @@ message handling should stop. import os import time +import email +import email.Utils from types import ClassType -from mimelib.MsgReader import MsgReader from Mailman import mm_cfg from Mailman import Utils @@ -169,13 +170,8 @@ def process(mlist, msg, msgdata): # Are there too many recipients to the message? if mlist.max_num_recipients > 0: # figure out how many recipients there are - recips = [] - toheader = msg['to'] - if toheader: - recips.extend([s.strip() for s in toheader.split(',')]) - ccheader = msg['cc'] - if ccheader: - recips.extend([s.strip() for s in ccheader.split(',')]) + recips = email.Utils.getaddresses(msg.get_all('to', []) + + msg.get_all('cc', [])) if len(recips) > mlist.max_num_recipients: hold_for_approval(mlist, msg, msgdata, TooManyRecipients) # no return @@ -200,12 +196,8 @@ def process(mlist, msg, msgdata): # # Is the message too big? if mlist.max_message_size > 0: - reader = MsgReader(msg) bodylen = 0 - while 1: - line = reader.readline() - if not line: - break + for line in email.Iterators.body_line_iterator(msg): bodylen += len(line) if bodylen/1024.0 > mlist.max_message_size: hold_for_approval(mlist, msg, msgdata, @@ -259,8 +251,8 @@ def hold_for_approval(mlist, msg, msgdata, exc): subject = _('Your message to %(listname)s awaits moderator approval') text = Utils.maketext('postheld.txt', d, lang=lang, mlist=mlist) msg = Message.UserNotification(sender, adminaddr, subject, text) - msg.addheader('Content-Type', 'text/plain', - charset=Utils.GetCharSet(lang)) + msg.add_header('Content-Type', 'text/plain', + charset=Utils.GetCharSet(lang)) msg.send(mlist) # Now the message for the list owners. Be sure to include the list # moderators in this message. This one should appear to come from @@ -279,8 +271,8 @@ def hold_for_approval(mlist, msg, msgdata, exc): # craft the admin notification message and deliver it subject = _('%(listname)s post from %(sender)s requires approval') msg = Message.UserNotification(owneraddr, owneraddr, subject, text) - msg.addheader('Content-Type', 'text/plain', - charset=Utils.GetCharSet(mlist.preferred_language)) + msg.add_header('Content-Type', 'text/plain', + charset=Utils.GetCharSet(mlist.preferred_language)) msg.send(mlist, **{'tomoderators': 1}) finally: i18n.set_translation(otranslation) diff --git a/Mailman/Handlers/Tagger.py b/Mailman/Handlers/Tagger.py index 27c178751..220dd884f 100644 --- a/Mailman/Handlers/Tagger.py +++ b/Mailman/Handlers/Tagger.py @@ -18,8 +18,8 @@ """ import re -from mimelib.Parser import Parser -from mimelib.MsgReader import MsgReader +import email +import email.Iterators from Mailman.Logging.Syslog import syslog @@ -80,11 +80,12 @@ def scanbody(msg, numlines=None): # Now that we have a Message object that meets our criteria, let's extract # the first numlines of body text. lines = [] - reader = MsgReader(msg) lineno = 0 + reader = email.Iterators.body_line_iterator(msg) while numlines is None or lineno < numlines: - line = reader.readline() - if not line: + try: + line = reader.pop(0) + except IndexError: break # Blank lines don't count if not line.strip(): @@ -95,7 +96,7 @@ def scanbody(msg, numlines=None): if line[0] not in ' \t' and line.find(':') < 0: break lines.append(line) - # Concatenate those body text lines with newlines, and then feed it to the - # mimelib message Parser - msg = Parser().parsestr(NL.join(lines)) + # Concatenate those body text lines with newlines, and then create a new + # message object from those lines. + msg = email.message_from_string(NL.join(lines)) return msg.getall('subject', []) + msg.getall('keywords', []) |
