diff -r de81e0fe4905 Lib/email/_policybase.py --- a/Lib/email/_policybase.py Sun Mar 02 20:29:18 2014 +0100 +++ b/Lib/email/_policybase.py Mon Mar 03 14:33:40 2014 +0100 @@ -155,6 +155,7 @@ linesep = '\n' cte_type = '8bit' max_line_length = 78 + mangle_from_ = True def handle_defect(self, obj, defect): """Based on policy, either raise defect or call register_defect. diff -r de81e0fe4905 Lib/email/generator.py --- a/Lib/email/generator.py Sun Mar 02 20:29:18 2014 +0100 +++ b/Lib/email/generator.py Mon Mar 03 14:33:40 2014 +0100 @@ -36,16 +36,16 @@ # Public interface # - def __init__(self, outfp, mangle_from_=True, maxheaderlen=None, *, + def __init__(self, outfp, mangle_from_=None, maxheaderlen=None, *, policy=None): """Create the generator for message flattening. outfp is the output file-like object for writing the message to. It must have a write() method. - Optional mangle_from_ is a flag that, when True (the default), escapes - From_ lines in the body of the message by putting a `>' in front of - them. + Optional mangle_from_ is a flag that, when True (the default if policy + is not set), escapes From_ lines in the body of the message by putting + a `>' in front of them. Optional maxheaderlen specifies the longest length for a non-continued header. When a header line is longer (in characters, with tabs @@ -59,6 +59,9 @@ backward compatibility. """ + + if mangle_from_ is None: + mangle_from_ = True if policy is None else policy.mangle_from_ self._fp = outfp self._mangle_from_ = mangle_from_ self.maxheaderlen = maxheaderlen @@ -450,7 +453,7 @@ Like the Generator base class, except that non-text parts are substituted with a format string representing the part. """ - def __init__(self, outfp, mangle_from_=True, maxheaderlen=78, fmt=None): + def __init__(self, outfp, mangle_from_=None, maxheaderlen=78, fmt=None): """Like Generator.__init__() except that an additional optional argument is allowed. diff -r de81e0fe4905 Lib/email/policy.py --- a/Lib/email/policy.py Sun Mar 02 20:29:18 2014 +0100 +++ b/Lib/email/policy.py Mon Mar 03 14:33:40 2014 +0100 @@ -75,6 +75,7 @@ refold_source = 'long' header_factory = HeaderRegistry() content_manager = raw_data_manager + mangle_from_ = False def __init__(self, **kw): # Ensure that each new instance gets a unique header factory