doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
class email.charset.Charset(input_charset=DEFAULT_CHARSET) Map character sets to their email properties. This class provides information about the requirements imposed on email for a specific character set. It also provides convenience routines for converting between character sets, given the availability of the appl...
python.library.email.charset#email.charset.Charset
body_encode(string) Body-encode the string string. The type of encoding (base64 or quoted-printable) will be based on the body_encoding attribute.
python.library.email.charset#email.charset.Charset.body_encode
body_encoding Same as header_encoding, but describes the encoding for the mail message’s body, which indeed may be different than the header encoding. Charset.SHORTEST is not allowed for body_encoding.
python.library.email.charset#email.charset.Charset.body_encoding
get_body_encoding() Return the content transfer encoding used for body encoding. This is either the string quoted-printable or base64 depending on the encoding used, or it is a function, in which case you should call the function with a single argument, the Message object being encoded. The function should then set t...
python.library.email.charset#email.charset.Charset.get_body_encoding
get_output_charset() Return the output character set. This is the output_charset attribute if that is not None, otherwise it is input_charset.
python.library.email.charset#email.charset.Charset.get_output_charset
header_encode(string) Header-encode the string string. The type of encoding (base64 or quoted-printable) will be based on the header_encoding attribute.
python.library.email.charset#email.charset.Charset.header_encode
header_encode_lines(string, maxlengths) Header-encode a string by converting it first to bytes. This is similar to header_encode() except that the string is fit into maximum line lengths as given by the argument maxlengths, which must be an iterator: each element returned from this iterator will provide the next maxi...
python.library.email.charset#email.charset.Charset.header_encode_lines
header_encoding If the character set must be encoded before it can be used in an email header, this attribute will be set to Charset.QP (for quoted-printable), Charset.BASE64 (for base64 encoding), or Charset.SHORTEST for the shortest of QP or BASE64 encoding. Otherwise, it will be None.
python.library.email.charset#email.charset.Charset.header_encoding
input_charset The initial character set specified. Common aliases are converted to their official email names (e.g. latin_1 is converted to iso-8859-1). Defaults to 7-bit us-ascii.
python.library.email.charset#email.charset.Charset.input_charset
input_codec The name of the Python codec used to convert the input_charset to Unicode. If no conversion codec is necessary, this attribute will be None.
python.library.email.charset#email.charset.Charset.input_codec
output_charset Some character sets must be converted before they can be used in email headers or bodies. If the input_charset is one of them, this attribute will contain the name of the character set output will be converted to. Otherwise, it will be None.
python.library.email.charset#email.charset.Charset.output_charset
output_codec The name of the Python codec used to convert Unicode to the output_charset. If no conversion codec is necessary, this attribute will have the same value as the input_codec.
python.library.email.charset#email.charset.Charset.output_codec
__eq__(other) This method allows you to compare two Charset instances for equality.
python.library.email.charset#email.charset.Charset.__eq__
__ne__(other) This method allows you to compare two Charset instances for inequality.
python.library.email.charset#email.charset.Charset.__ne__
__str__() Returns input_charset as a string coerced to lower case. __repr__() is an alias for __str__().
python.library.email.charset#email.charset.Charset.__str__
class email.contentmanager.ContentManager Base class for content managers. Provides the standard registry mechanisms to register converters between MIME content and other representations, as well as the get_content and set_content dispatch methods. get_content(msg, *args, **kw) Look up a handler function based on...
python.library.email.contentmanager#email.contentmanager.ContentManager
add_get_handler(key, handler) Record the function handler as the handler for key. For the possible values of key, see get_content().
python.library.email.contentmanager#email.contentmanager.ContentManager.add_get_handler
add_set_handler(typekey, handler) Record handler as the function to call when an object of a type matching typekey is passed to set_content(). For the possible values of typekey, see set_content().
python.library.email.contentmanager#email.contentmanager.ContentManager.add_set_handler
get_content(msg, *args, **kw) Look up a handler function based on the mimetype of msg (see next paragraph), call it, passing through all arguments, and return the result of the call. The expectation is that the handler will extract the payload from msg and return an object that encodes information about the extracted...
python.library.email.contentmanager#email.contentmanager.ContentManager.get_content
set_content(msg, obj, *args, **kw) If the maintype is multipart, raise a TypeError; otherwise look up a handler function based on the type of obj (see next paragraph), call clear_content() on the msg, and call the handler function, passing through all arguments. The expectation is that the handler will transform and ...
python.library.email.contentmanager#email.contentmanager.ContentManager.set_content
email.contentmanager.get_content(msg, errors='replace') Return the payload of the part as either a string (for text parts), an EmailMessage object (for message/rfc822 parts), or a bytes object (for all other non-multipart types). Raise a KeyError if called on a multipart. If the part is a text part and errors is spec...
python.library.email.contentmanager#email.contentmanager.get_content
email.contentmanager.raw_data_manager This content manager provides only a minimum interface beyond that provided by Message itself: it deals only with text, raw byte strings, and Message objects. Nevertheless, it provides significant advantages compared to the base API: get_content on a text part will return a unico...
python.library.email.contentmanager#email.contentmanager.raw_data_manager
email.contentmanager.set_content(msg, <'str'>, subtype="plain", charset='utf-8', cte=None, disposition=None, filename=None, cid=None, params=None, headers=None) email.contentmanager.set_content(msg, <'bytes'>, maintype, subtype, cte="base64", disposition=None, filename=None, cid=None, params=None, headers=None) ema...
python.library.email.contentmanager#email.contentmanager.set_content
email.encoders.encode_7or8bit(msg) This doesn’t actually modify the message’s payload, but it does set the Content-Transfer-Encoding header to either 7bit or 8bit as appropriate, based on the payload data.
python.library.email.encoders#email.encoders.encode_7or8bit
email.encoders.encode_base64(msg) Encodes the payload into base64 form and sets the Content-Transfer-Encoding header to base64. This is a good encoding to use when most of your payload is unprintable data since it is a more compact form than quoted-printable. The drawback of base64 encoding is that it renders the tex...
python.library.email.encoders#email.encoders.encode_base64
email.encoders.encode_noop(msg) This does nothing; it doesn’t even set the Content-Transfer-Encoding header.
python.library.email.encoders#email.encoders.encode_noop
email.encoders.encode_quopri(msg) Encodes the payload into quoted-printable form and sets the Content-Transfer-Encoding header to quoted-printable 1. This is a good encoding to use when most of your payload is normal printable data, but contains a few unprintable characters.
python.library.email.encoders#email.encoders.encode_quopri
exception email.errors.BoundaryError Deprecated and no longer used.
python.library.email.errors#email.errors.BoundaryError
exception email.errors.HeaderParseError Raised under some error conditions when parsing the RFC 5322 headers of a message, this class is derived from MessageParseError. The set_boundary() method will raise this error if the content type is unknown when the method is called. Header may raise this error for certain bas...
python.library.email.errors#email.errors.HeaderParseError
exception email.errors.MessageError This is the base class for all exceptions that the email package can raise. It is derived from the standard Exception class and defines no additional methods.
python.library.email.errors#email.errors.MessageError
exception email.errors.MessageParseError This is the base class for exceptions raised by the Parser class. It is derived from MessageError. This class is also used internally by the parser used by headerregistry.
python.library.email.errors#email.errors.MessageParseError
exception email.errors.MultipartConversionError Raised when a payload is added to a Message object using add_payload(), but the payload is already a scalar and the message’s Content-Type main type is not either multipart or missing. MultipartConversionError multiply inherits from MessageError and the built-in TypeErr...
python.library.email.errors#email.errors.MultipartConversionError
class email.generator.BytesGenerator(outfp, mangle_from_=None, maxheaderlen=None, *, policy=None) Return a BytesGenerator object that will write any message provided to the flatten() method, or any surrogateescape encoded text provided to the write() method, to the file-like object outfp. outfp must support a write m...
python.library.email.generator#email.generator.BytesGenerator
clone(fp) Return an independent clone of this BytesGenerator instance with the exact same option settings, and fp as the new outfp.
python.library.email.generator#email.generator.BytesGenerator.clone
flatten(msg, unixfrom=False, linesep=None) Print the textual representation of the message object structure rooted at msg to the output file specified when the BytesGenerator instance was created. If the policy option cte_type is 8bit (the default), copy any headers in the original parsed message that have not been m...
python.library.email.generator#email.generator.BytesGenerator.flatten
write(s) Encode s using the ASCII codec and the surrogateescape error handler, and pass it to the write method of the outfp passed to the BytesGenerator’s constructor.
python.library.email.generator#email.generator.BytesGenerator.write
class email.generator.DecodedGenerator(outfp, mangle_from_=None, maxheaderlen=None, fmt=None, *, policy=None) Act like Generator, except that for any subpart of the message passed to Generator.flatten(), if the subpart is of main type text, print the decoded payload of the subpart, and if the main type is not text, i...
python.library.email.generator#email.generator.DecodedGenerator
class email.generator.Generator(outfp, mangle_from_=None, maxheaderlen=None, *, policy=None) Return a Generator object that will write any message provided to the flatten() method, or any text provided to the write() method, to the file-like object outfp. outfp must support a write method that accepts string data. If...
python.library.email.generator#email.generator.Generator
clone(fp) Return an independent clone of this Generator instance with the exact same options, and fp as the new outfp.
python.library.email.generator#email.generator.Generator.clone
flatten(msg, unixfrom=False, linesep=None) Print the textual representation of the message object structure rooted at msg to the output file specified when the Generator instance was created. If the policy option cte_type is 8bit, generate the message as if the option were set to 7bit. (This is required because strin...
python.library.email.generator#email.generator.Generator.flatten
write(s) Write s to the write method of the outfp passed to the Generator’s constructor. This provides just enough file-like API for Generator instances to be used in the print() function.
python.library.email.generator#email.generator.Generator.write
email.header.decode_header(header) Decode a message header value without converting the character set. The header value is in header. This function returns a list of (decoded_string, charset) pairs containing each of the decoded parts of the header. charset is None for non-encoded parts of the header, otherwise a low...
python.library.email.header#email.header.decode_header
class email.header.Header(s=None, charset=None, maxlinelen=None, header_name=None, continuation_ws=' ', errors='strict') Create a MIME-compliant header that can contain strings in different character sets. Optional s is the initial header value. If None (the default), the initial header value is not set. You can late...
python.library.email.header#email.header.Header
append(s, charset=None, errors='strict') Append the string s to the MIME header. Optional charset, if given, should be a Charset instance (see email.charset) or the name of a character set, which will be converted to a Charset instance. A value of None (the default) means that the charset given in the constructor is ...
python.library.email.header#email.header.Header.append
encode(splitchars=';, \t', maxlinelen=None, linesep='\n') Encode a message header into an RFC-compliant format, possibly wrapping long lines and encapsulating non-ASCII parts in base64 or quoted-printable encodings. Optional splitchars is a string containing characters which should be given extra weight by the splitt...
python.library.email.header#email.header.Header.encode
__eq__(other) This method allows you to compare two Header instances for equality.
python.library.email.header#email.header.Header.__eq__
__ne__(other) This method allows you to compare two Header instances for inequality.
python.library.email.header#email.header.Header.__ne__
__str__() Returns an approximation of the Header as a string, using an unlimited line length. All pieces are converted to unicode using the specified encoding and joined together appropriately. Any pieces with a charset of 'unknown-8bit' are decoded as ASCII using the 'replace' error handler. Changed in version 3.2:...
python.library.email.header#email.header.Header.__str__
email.header.make_header(decoded_seq, maxlinelen=None, header_name=None, continuation_ws=' ') Create a Header instance from a sequence of pairs as returned by decode_header(). decode_header() takes a header value string and returns a sequence of pairs of the format (decoded_string, charset) where charset is the name ...
python.library.email.header#email.header.make_header
class email.headerregistry.Address(display_name='', username='', domain='', addr_spec=None) The class used to represent an email address. The general form of an address is: [display_name] <username@domain> or: username@domain where each part must conform to specific syntax rules spelled out in RFC 5322. As a conven...
python.library.email.headerregistry#email.headerregistry.Address
addr_spec The username@domain portion of the address, correctly quoted for use as a bare address (the second form shown above). This attribute is not mutable.
python.library.email.headerregistry#email.headerregistry.Address.addr_spec
display_name The display name portion of the address, if any, with all quoting removed. If the address does not have a display name, this attribute will be an empty string.
python.library.email.headerregistry#email.headerregistry.Address.display_name
domain The domain portion of the address.
python.library.email.headerregistry#email.headerregistry.Address.domain
username The username portion of the address, with all quoting removed.
python.library.email.headerregistry#email.headerregistry.Address.username
__str__() The str value of the object is the address quoted according to RFC 5322 rules, but with no Content Transfer Encoding of any non-ASCII characters.
python.library.email.headerregistry#email.headerregistry.Address.__str__
class email.headerregistry.AddressHeader Address headers are one of the most complex structured header types. The AddressHeader class provides a generic interface to any address header. This header type provides the following additional attributes: groups A tuple of Group objects encoding the addresses and groups...
python.library.email.headerregistry#email.headerregistry.AddressHeader
addresses A tuple of Address objects encoding all of the individual addresses from the header value. If the header value contains any groups, the individual addresses from the group are included in the list at the point where the group occurs in the value (that is, the list of addresses is “flattened” into a one dime...
python.library.email.headerregistry#email.headerregistry.AddressHeader.addresses
groups A tuple of Group objects encoding the addresses and groups found in the header value. Addresses that are not part of a group are represented in this list as single-address Groups whose display_name is None.
python.library.email.headerregistry#email.headerregistry.AddressHeader.groups
class email.headerregistry.BaseHeader(name, value) name and value are passed to BaseHeader from the header_factory call. The string value of any header object is the value fully decoded to unicode. This base class defines the following read-only properties: name The name of the header (the portion of the field be...
python.library.email.headerregistry#email.headerregistry.BaseHeader
defects A tuple of HeaderDefect instances reporting any RFC compliance problems found during parsing. The email package tries to be complete about detecting compliance issues. See the errors module for a discussion of the types of defects that may be reported.
python.library.email.headerregistry#email.headerregistry.BaseHeader.defects
fold(*, policy) Return a string containing linesep characters as required to correctly fold the header according to policy. A cte_type of 8bit will be treated as if it were 7bit, since headers may not contain arbitrary binary data. If utf8 is False, non-ASCII data will be RFC 2047 encoded.
python.library.email.headerregistry#email.headerregistry.BaseHeader.fold
max_count The maximum number of headers of this type that can have the same name. A value of None means unlimited. The BaseHeader value for this attribute is None; it is expected that specialized header classes will override this value as needed.
python.library.email.headerregistry#email.headerregistry.BaseHeader.max_count
name The name of the header (the portion of the field before the ‘:’). This is exactly the value passed in the header_factory call for name; that is, case is preserved.
python.library.email.headerregistry#email.headerregistry.BaseHeader.name
class email.headerregistry.ContentDispositionHeader A ParameterizedMIMEHeader class that handles the Content-Disposition header. content_disposition inline and attachment are the only valid values in common use.
python.library.email.headerregistry#email.headerregistry.ContentDispositionHeader
content_disposition inline and attachment are the only valid values in common use.
python.library.email.headerregistry#email.headerregistry.ContentDispositionHeader.content_disposition
class email.headerregistry.ContentTransferEncoding Handles the Content-Transfer-Encoding header. cte Valid values are 7bit, 8bit, base64, and quoted-printable. See RFC 2045 for more information.
python.library.email.headerregistry#email.headerregistry.ContentTransferEncoding
cte Valid values are 7bit, 8bit, base64, and quoted-printable. See RFC 2045 for more information.
python.library.email.headerregistry#email.headerregistry.ContentTransferEncoding.cte
class email.headerregistry.ContentTypeHeader A ParameterizedMIMEHeader class that handles the Content-Type header. content_type The content type string, in the form maintype/subtype. maintype subtype
python.library.email.headerregistry#email.headerregistry.ContentTypeHeader
content_type The content type string, in the form maintype/subtype.
python.library.email.headerregistry#email.headerregistry.ContentTypeHeader.content_type
maintype
python.library.email.headerregistry#email.headerregistry.ContentTypeHeader.maintype
subtype
python.library.email.headerregistry#email.headerregistry.ContentTypeHeader.subtype
class email.headerregistry.DateHeader RFC 5322 specifies a very specific format for dates within email headers. The DateHeader parser recognizes that date format, as well as recognizing a number of variant forms that are sometimes found “in the wild”. This header type provides the following additional attributes: d...
python.library.email.headerregistry#email.headerregistry.DateHeader
datetime If the header value can be recognized as a valid date of one form or another, this attribute will contain a datetime instance representing that date. If the timezone of the input date is specified as -0000 (indicating it is in UTC but contains no information about the source timezone), then datetime will be ...
python.library.email.headerregistry#email.headerregistry.DateHeader.datetime
class email.headerregistry.Group(display_name=None, addresses=None) The class used to represent an address group. The general form of an address group is: display_name: [address-list]; As a convenience for processing lists of addresses that consist of a mixture of groups and single addresses, a Group may also be use...
python.library.email.headerregistry#email.headerregistry.Group
addresses A possibly empty tuple of Address objects representing the addresses in the group.
python.library.email.headerregistry#email.headerregistry.Group.addresses
display_name The display_name of the group. If it is None and there is exactly one Address in addresses, then the Group represents a single address that is not in a group.
python.library.email.headerregistry#email.headerregistry.Group.display_name
__str__() The str value of a Group is formatted according to RFC 5322, but with no Content Transfer Encoding of any non-ASCII characters. If display_name is none and there is a single Address in the addresses list, the str value will be the same as the str of that single Address.
python.library.email.headerregistry#email.headerregistry.Group.__str__
class email.headerregistry.HeaderRegistry(base_class=BaseHeader, default_class=UnstructuredHeader, use_default_map=True) This is the factory used by EmailPolicy by default. HeaderRegistry builds the class used to create a header instance dynamically, using base_class and a specialized class retrieved from a registry ...
python.library.email.headerregistry#email.headerregistry.HeaderRegistry
map_to_type(self, name, cls) name is the name of the header to be mapped. It will be converted to lower case in the registry. cls is the specialized class to be used, along with base_class, to create the class used to instantiate headers that match name.
python.library.email.headerregistry#email.headerregistry.HeaderRegistry.map_to_type
__call__(name, value) Retrieves the specialized header associated with name from the registry (using default_class if name does not appear in the registry) and composes it with base_class to produce a class, calls the constructed class’s constructor, passing it the same argument list, and finally returns the class in...
python.library.email.headerregistry#email.headerregistry.HeaderRegistry.__call__
__getitem__(name) Construct and return a class to handle creating a name header.
python.library.email.headerregistry#email.headerregistry.HeaderRegistry.__getitem__
class email.headerregistry.MIMEVersionHeader There is really only one valid value for the MIME-Version header, and that is 1.0. For future proofing, this header class supports other valid version numbers. If a version number has a valid value per RFC 2045, then the header object will have non-None values for the foll...
python.library.email.headerregistry#email.headerregistry.MIMEVersionHeader
major The major version number as an integer
python.library.email.headerregistry#email.headerregistry.MIMEVersionHeader.major
minor The minor version number as an integer
python.library.email.headerregistry#email.headerregistry.MIMEVersionHeader.minor
version The version number as a string, with any whitespace and/or comments removed.
python.library.email.headerregistry#email.headerregistry.MIMEVersionHeader.version
class email.headerregistry.ParameterizedMIMEHeader MIME headers all start with the prefix ‘Content-‘. Each specific header has a certain value, described under the class for that header. Some can also take a list of supplemental parameters, which have a common format. This class serves as a base for all the MIME head...
python.library.email.headerregistry#email.headerregistry.ParameterizedMIMEHeader
params A dictionary mapping parameter names to parameter values.
python.library.email.headerregistry#email.headerregistry.ParameterizedMIMEHeader.params
class email.headerregistry.SingleAddressHeader A subclass of AddressHeader that adds one additional attribute: address The single address encoded by the header value. If the header value actually contains more than one address (which would be a violation of the RFC under the default policy), accessing this attrib...
python.library.email.headerregistry#email.headerregistry.SingleAddressHeader
address The single address encoded by the header value. If the header value actually contains more than one address (which would be a violation of the RFC under the default policy), accessing this attribute will result in a ValueError.
python.library.email.headerregistry#email.headerregistry.SingleAddressHeader.address
class email.headerregistry.UnstructuredHeader An “unstructured” header is the default type of header in RFC 5322. Any header that does not have a specified syntax is treated as unstructured. The classic example of an unstructured header is the Subject header. In RFC 5322, an unstructured header is a run of arbitrary ...
python.library.email.headerregistry#email.headerregistry.UnstructuredHeader
email.iterators.body_line_iterator(msg, decode=False) This iterates over all the payloads in all the subparts of msg, returning the string payloads line-by-line. It skips over all the subpart headers, and it skips over any subpart with a payload that isn’t a Python string. This is somewhat equivalent to reading the f...
python.library.email.iterators#email.iterators.body_line_iterator
email.iterators.typed_subpart_iterator(msg, maintype='text', subtype=None) This iterates over all the subparts of msg, returning only those subparts that match the MIME type specified by maintype and subtype. Note that subtype is optional; if omitted, then subpart MIME type matching is done only with the main type. m...
python.library.email.iterators#email.iterators.typed_subpart_iterator
email.iterators._structure(msg, fp=None, level=0, include_default=False) Prints an indented representation of the content types of the message object structure. For example: >>> msg = email.message_from_file(somefile) >>> _structure(msg) multipart/mixed text/plain text/plain multipart/digest messa...
python.library.email.iterators#email.iterators._structure
class email.message.EmailMessage(policy=default) If policy is specified use the rules it specifies to update and serialize the representation of the message. If policy is not set, use the default policy, which follows the rules of the email RFCs except for line endings (instead of the RFC mandated \r\n, it uses the P...
python.library.email.message#email.message.EmailMessage
add_alternative(*args, content_manager=None, **kw) If the message is a multipart/alternative, create a new message object, pass all of the arguments to its set_content() method, and attach() it to the multipart. If the message is a non-multipart or multipart/related, call make_alternative() and then proceed as above....
python.library.email.message#email.message.EmailMessage.add_alternative
add_attachment(*args, content_manager=None, **kw) If the message is a multipart/mixed, create a new message object, pass all of the arguments to its set_content() method, and attach() it to the multipart. If the message is a non-multipart, multipart/related, or multipart/alternative, call make_mixed() and then procee...
python.library.email.message#email.message.EmailMessage.add_attachment
add_header(_name, _value, **_params) Extended header setting. This method is similar to __setitem__() except that additional header parameters can be provided as keyword arguments. _name is the header field to add and _value is the primary value for the header. For each item in the keyword argument dictionary _params...
python.library.email.message#email.message.EmailMessage.add_header
add_related(*args, content_manager=None, **kw) If the message is a multipart/related, create a new message object, pass all of the arguments to its set_content() method, and attach() it to the multipart. If the message is a non-multipart, call make_related() and then proceed as above. If the message is any other type...
python.library.email.message#email.message.EmailMessage.add_related
as_bytes(unixfrom=False, policy=None) Return the entire message flattened as a bytes object. When optional unixfrom is true, the envelope header is included in the returned string. unixfrom defaults to False. The policy argument may be used to override the default policy obtained from the message instance. This can b...
python.library.email.message#email.message.EmailMessage.as_bytes
as_string(unixfrom=False, maxheaderlen=None, policy=None) Return the entire message flattened as a string. When optional unixfrom is true, the envelope header is included in the returned string. unixfrom defaults to False. For backward compatibility with the base Message class maxheaderlen is accepted, but defaults t...
python.library.email.message#email.message.EmailMessage.as_string