aboutsummaryrefslogtreecommitdiffstats
path: root/Mailman/Message.py
diff options
context:
space:
mode:
authorMark Sapiro <mark@msapiro.net>2009-08-01 16:15:35 -0700
committerMark Sapiro <mark@msapiro.net>2009-08-01 16:15:35 -0700
commite469619d91f4f15574e233a2cfa4b07c8d7f36d6 (patch)
tree68ed37abcbd7b340a50cdd045c66c316119606fb /Mailman/Message.py
parentfdfee4b34c818c410dd586e86ab1dad99c2a5f4c (diff)
downloadmailman2-e469619d91f4f15574e233a2cfa4b07c8d7f36d6.tar.gz
mailman2-e469619d91f4f15574e233a2cfa4b07c8d7f36d6.tar.xz
mailman2-e469619d91f4f15574e233a2cfa4b07c8d7f36d6.zip
Mailman no longer folds long sub-part headers in multipart messages.
In addition, Mailman no longer escapes From_ lines in the body of messages sent to regular list members, although MTA's may do it anyway. This is to avoid breaking signatures per Bug #265967. Changes include - Message.py, added a Generator class to avoid header folding and an as_string() method wirth a mangle_from_ argument. - Mailbox.py, uses new Message.Generator class. - SMTPDirect.py, uses as_string(mangle_from_=False) to flatten message. - Scrubber.py, removed unused ScrubberGenerator class.
Diffstat (limited to 'Mailman/Message.py')
-rw-r--r--Mailman/Message.py39
1 files changed, 37 insertions, 2 deletions
diff --git a/Mailman/Message.py b/Mailman/Message.py
index 3c2ef605..84e4aa26 100644
--- a/Mailman/Message.py
+++ b/Mailman/Message.py
@@ -1,4 +1,4 @@
-# Copyright (C) 1998-2007 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2009 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
@@ -17,12 +17,15 @@
"""Standard Mailman message object.
-This is a subclass of mimeo.Message but provides a slightly extended interface
+This is a subclass of email.Message but provides a slightly extended interface
which is more convenient for use inside Mailman.
"""
import re
+from cStringIO import StringIO
+
import email
+import email.Generator
import email.Message
import email.Utils
from email.Charset import Charset
@@ -40,6 +43,24 @@ VERSION = tuple([int(s) for s in mo.group().split('.')])
+class Generator(email.Generator.Generator):
+ """Generates output from a Message object tree, keeping signatures.
+
+ Headers will by default _not_ be folded in attachments.
+ """
+ def __init__(self, outfp, mangle_from_=True,
+ maxheaderlen=78, children_maxheaderlen=0):
+ email.Generator.Generator.__init__(self, outfp,
+ mangle_from_=mangle_from_, maxheaderlen=maxheaderlen)
+ self.__children_maxheaderlen = children_maxheaderlen
+
+ def clone(self, fp):
+ """Clone this generator with maxheaderlen set for children"""
+ return self.__class__(fp, self._mangle_from_,
+ self.__children_maxheaderlen, self.__children_maxheaderlen)
+
+
+
class Message(email.Message.Message):
def __init__(self):
# We need a version number so that we can optimize __setstate__()
@@ -208,6 +229,20 @@ class Message(email.Message.Message):
return failobj
+ def as_string(self, unixfrom=False, mangle_from_=True):
+ """Return entire formatted message as a string using
+ Mailman.Message.Generator.
+
+ Operates like email.Message.Message.as_string, only
+ using Mailman's Message.Generator class. Only the top headers will
+ get folded.
+ """
+ fp = StringIO()
+ g = Generator(fp, mangle_from_=mangle_from_)
+ g.flatten(self, unixfrom=unixfrom)
+ return fp.getvalue()
+
+
class UserNotification(Message):
"""Class for internally crafted messages."""