diff options
author | R David Murray <rdmurray@bitdance.com> | 2012-04-09 02:36:07 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2012-04-09 02:36:07 (GMT) |
commit | b019ee752a6be0bcd4f640f09bce0c5f5215e880 (patch) | |
tree | f133252dfbd0da52f86a59a2c489c595c911ebad /Lib/mailbox.py | |
parent | c988e242408ea793052320fc2174fd124f193a77 (diff) | |
download | cpython-b019ee752a6be0bcd4f640f09bce0c5f5215e880.zip cpython-b019ee752a6be0bcd4f640f09bce0c5f5215e880.tar.gz cpython-b019ee752a6be0bcd4f640f09bce0c5f5215e880.tar.bz2 |
#12537: in mailbox avoid depending on knowledge of email package internals
Previously mailbox was copying a list of attributes from one message object to
another in order to "copy the message data". This means that any time new
attributes were added to email.message.Message, mailbox broke. Now instead it
copies all attributes from the source object to the target object, skipping
any mailbox-object-specific attributes to produce the same clean initial
state it was previously getting by copying only the "known" attributes.
David Lam assisted in the development of this patch.
Diffstat (limited to 'Lib/mailbox.py')
-rw-r--r-- | Lib/mailbox.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 325b9c9..7a29555 100644 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1462,9 +1462,10 @@ class Message(email.message.Message): def _become_message(self, message): """Assume the non-format-specific state of message.""" - for name in ('_headers', '_unixfrom', '_payload', '_charset', - 'preamble', 'epilogue', 'defects', '_default_type'): - self.__dict__[name] = message.__dict__[name] + type_specific = getattr(message, '_type_specific_attributes', []) + for name in message.__dict__: + if name not in type_specific: + self.__dict__[name] = message.__dict__[name] def _explain_to(self, message): """Copy format-specific state to message insofar as possible.""" @@ -1477,6 +1478,8 @@ class Message(email.message.Message): class MaildirMessage(Message): """Message with Maildir-specific properties.""" + _type_specific_attributes = ['_subdir', '_info', '_date'] + def __init__(self, message=None): """Initialize a MaildirMessage instance.""" self._subdir = 'new' @@ -1584,6 +1587,8 @@ class MaildirMessage(Message): class _mboxMMDFMessage(Message): """Message with mbox- or MMDF-specific properties.""" + _type_specific_attributes = ['_from'] + def __init__(self, message=None): """Initialize an mboxMMDFMessage instance.""" self.set_from('MAILER-DAEMON', True) @@ -1699,6 +1704,8 @@ class mboxMessage(_mboxMMDFMessage): class MHMessage(Message): """Message with MH-specific properties.""" + _type_specific_attributes = ['_sequences'] + def __init__(self, message=None): """Initialize an MHMessage instance.""" self._sequences = [] @@ -1769,6 +1776,8 @@ class MHMessage(Message): class BabylMessage(Message): """Message with Babyl-specific properties.""" + _type_specific_attributes = ['_labels', '_visible'] + def __init__(self, message=None): """Initialize an BabylMessage instance.""" self._labels = [] |