email.utils.formataddr()

email.utils.formataddr(pair, charset='utf-8') The inverse of parseaddr(), this takes a 2-tuple of the form (realname, email_address) and returns the string value suitable for a To or Cc header. If the first element of pair is false, then the second element is returned unmodified. Optional charset is the character set that will be used in the RFC 2047 encoding of the realname if the realname contains non-ASCII characters. Can be an instance of str or a Charset. Defaults to utf-8. Changed in

email.utils.encode_rfc2231()

email.utils.encode_rfc2231(s, charset=None, language=None) Encode the string s according to RFC 2231. Optional charset and language, if given is the character set name and language name to use. If neither is given, s is returned as-is. If charset is given but language is not, the string is encoded using the empty string for language.

email.utils.collapse_rfc2231_value()

email.utils.collapse_rfc2231_value(value, errors='replace', fallback_charset='us-ascii') When a header parameter is encoded in RFC 2231 format, Message.get_param may return a 3-tuple containing the character set, language, and value. collapse_rfc2231_value() turns this into a unicode string. Optional errors is passed to the errors argument of str‘s encode() method; it defaults to 'replace'. Optional fallback_charset specifies the character set to use if the one in the RFC 2231 header is not

email.policy.Policy.register_defect()

register_defect(obj, defect) Register a defect on obj. In the email package, defect will always be a subclass of Defect. The default implementation calls the append method of the defects attribute of obj. When the email package calls handle_defect, obj will normally have a defects attribute that has an append method. Custom object types used with the email package (for example, custom Message objects) should also provide such an attribute, otherwise defects in parsed messages will raise unex

email.policy.Policy.raise_on_defect

raise_on_defect If True, any defects encountered will be raised as errors. If False (the default), defects will be passed to the register_defect() method.

email.policy.strict

email.policy.strict Convenience instance. The same as default except that raise_on_defect is set to True. This allows any policy to be made strict by writing: somepolicy + policy.strict

email.policy.Policy.max_line_length

max_line_length The maximum length of any line in the serialized output, not counting the end of line character(s). Default is 78, per RFC 5322. A value of 0 or None indicates that no line wrapping should be done at all.

email.policy.Policy.header_store_parse()

header_store_parse(name, value) The email package calls this method with the name and value provided by the application program when the application program is modifying a Message programmatically (as opposed to a Message created by a parser). The method should return the (name, value) tuple that is to be stored in the Message to represent the header. If an implementation wishes to retain compatibility with the existing email package policies, the name and value should be strings or string s

email.policy.Policy.header_source_parse()

header_source_parse(sourcelines) The email package calls this method with a list of strings, each string ending with the line separation characters found in the source being parsed. The first line includes the field header name and separator. All whitespace in the source is preserved. The method should return the (name, value) tuple that is to be stored in the Message to represent the parsed header. If an implementation wishes to retain compatibility with the existing email package policies,

email.policy.Policy.mangle_from_

mangle_from_ If True, lines starting with “From “ in the body are escaped by putting a > in front of them. This parameter is used when the message is being serialized by a generator. Default: False. New in version 3.5: The mangle_from_ parameter.