summaryrefslogtreecommitdiff
path: root/Lib/email/message.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-02-04 14:55:16 -0800
committerSteve Dower <steve.dower@microsoft.com>2017-02-04 14:55:16 -0800
commitb53654b6dbfce8318a7d4d1cdaddca7a7fec194b (patch)
tree204df61b2fb23424603db767732db35a687529c6 /Lib/email/message.py
parente1ac7d87afad9c07ec25e5705bb135b71347b581 (diff)
parent2296b978597ce62ec2185b78a43811610af2c0ea (diff)
downloadcpython-b53654b6dbfce8318a7d4d1cdaddca7a7fec194b.tar.gz
Issue #29416: Prevent infinite loop in pathlib.Path.mkdir
Diffstat (limited to 'Lib/email/message.py')
-rw-r--r--Lib/email/message.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/Lib/email/message.py b/Lib/email/message.py
index 4b042836ad..b6512f2198 100644
--- a/Lib/email/message.py
+++ b/Lib/email/message.py
@@ -4,18 +4,17 @@
"""Basic message object for the email package object model."""
-__all__ = ['Message']
+__all__ = ['Message', 'EmailMessage']
import re
import uu
import quopri
-import warnings
from io import BytesIO, StringIO
# Intrapackage imports
from email import utils
from email import errors
-from email._policybase import compat32
+from email._policybase import Policy, compat32
from email import charset as _charset
from email._encoded_words import decode_b
Charset = _charset.Charset
@@ -951,6 +950,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'