diff options
| author | bwarsaw | 2002-10-14 22:14:40 +0000 |
|---|---|---|
| committer | bwarsaw | 2002-10-14 22:14:40 +0000 |
| commit | 01d2770219798020b9da7933e82e69bc5045fa8a (patch) | |
| tree | 8dc6b7cba3ee20dbba9f70345d747e7246d73a33 | |
| parent | ef341f1ed3c01bdbe35215014016ae7365b986f7 (diff) | |
| download | mailman-01d2770219798020b9da7933e82e69bc5045fa8a.tar.gz mailman-01d2770219798020b9da7933e82e69bc5045fa8a.tar.zst mailman-01d2770219798020b9da7933e82e69bc5045fa8a.zip | |
__setstate__(): This plus email-2.4.3 should fix (most of) Peer
Heinlein's recent problems. This patch adds several things to better
update pickled Message objects to the latest email package.
Specifically,
__init__(): Add a version number to Message objects so that we can
make __setstate__() more efficient (I don't want to do the next bit of
hackery for every single unpickled Message object).
__setstate__(): For Message objects older than the current email
package version, we'll ensure that the data format is the same. We
keep the previous updates and add one that trolls through the message
headers, ensuring that if any of the headers are Header instances,
that their chunks all have 2nd items as Charset instances, not
strings. This is an invariant for email 2.4.3, but older Message
instances might not conform.
| -rw-r--r-- | Mailman/Message.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/Mailman/Message.py b/Mailman/Message.py index 8d4cd141f..77cd48733 100644 --- a/Mailman/Message.py +++ b/Mailman/Message.py @@ -20,22 +20,29 @@ This is a subclass of mimeo.Message but provides a slightly extended interface which is more convenient for use inside Mailman. """ +import email import email.Message import email.Utils - from email.Charset import Charset from email.Header import Header -from types import ListType +from types import ListType, StringType from Mailman import mm_cfg from Mailman import Utils COMMASPACE = ', ' +VERSION = tuple([int(s) for s in email.__version__.split('.')]) + class Message(email.Message.Message): + def __init__(self): + # We need a version number so that we can optimize __setstate__() + self.__version__ = VERSION + email.Message.Message.__init__(self) + # BAW: For debugging w/ bin/dumpdb. Apparently pprint uses repr. def __repr__(self): return self.__str__() @@ -46,6 +53,11 @@ class Message(email.Message.Message): # upgrading the email package. We shouldn't burden email with this, # so we handle schema updates here. self.__dict__ = d + # We know that email 2.4.3 is up-to-date + version = d.get('__version__', (0, 0, 0)) + d['__version__'] = VERSION + if version >= VERSION: + return # Messages grew a _charset attribute between email version 0.97 and 1.1 if not d.has_key('_charset'): self._charset = None @@ -55,6 +67,25 @@ class Message(email.Message.Message): # inside a multipart/digest or not, so I think this is the best we # can do. self._default_type = 'text/plain' + # Header instances used to allow both strings and Charsets in their + # _chunks, but by email 2.4.3 now it's just Charsets. + headers = [] + hchanged = 0 + for k, v in self._headers: + if isinstance(v, Header): + chunks = [] + cchanged = 0 + for s, charset in v._chunks: + if isinstance(charset, StringType): + charset = Charset(charset) + cchanged = 1 + chunks.append((s, charset)) + if cchanged: + v._chunks = chunks + hchanged = 1 + headers.append((k, v)) + if hchanged: + self._headers = headers # I think this method ought to eventually be deprecated def get_sender(self, use_envelope=None, preserve_case=0): |
