diff options
author | R David Murray <rdmurray@bitdance.com> | 2016-09-08 01:15:59 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2016-09-08 01:15:59 (GMT) |
commit | 29d1bc0842e5b086813aa7de4ab18f1c192d2291 (patch) | |
tree | b812609f72f860adb5203ba9cbb1d0c4299e39af /Lib/email/message.py | |
parent | 23e863378124229928e12b72c22df33f1428c61e (diff) | |
download | cpython-29d1bc0842e5b086813aa7de4ab18f1c192d2291.zip cpython-29d1bc0842e5b086813aa7de4ab18f1c192d2291.tar.gz cpython-29d1bc0842e5b086813aa7de4ab18f1c192d2291.tar.bz2 |
#24277: The new email API is no longer provisional.
This is a wholesale reorganization and editing of the email documentation to
make the new API the standard one, and the old API the 'legacy' one. The
default is still the compat32 policy, for backward compatibility. We will
change that eventually.
Diffstat (limited to 'Lib/email/message.py')
-rw-r--r-- | Lib/email/message.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/email/message.py b/Lib/email/message.py index 4b04283..c07da43 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -951,6 +951,26 @@ class MIMEPart(Message): policy = default Message.__init__(self, policy) + + def as_string(self, unixfrom=False, maxheaderlen=None, policy=None): + """Return the entire formatted message as a string. + + Optional 'unixfrom', when true, means include the Unix From_ envelope + header. maxheaderlen is retained for backward compatibility with the + base Message class, but defaults to None, meaning that the policy value + for max_line_length controls the header maximum length. 'policy' is + passed to the Generator instance used to serialize the mesasge; if it + is not specified the policy associated with the message instance is + used. + """ + policy = self.policy if policy is None else policy + if maxheaderlen is None: + maxheaderlen = policy.max_line_length + return super().as_string(maxheaderlen=maxheaderlen, policy=policy) + + def __str__(self): + return self.as_string(policy=self.policy.clone(utf8=True)) + def is_attachment(self): c_d = self.get('content-disposition') return False if c_d is None else c_d.content_disposition == 'attachment' |