get_payload(i=None, decode=False)
Return the current payload, which will be a list of Message
objects when is_multipart()
is True
, or a string when is_multipart()
is False
. If the payload is a list and you mutate the list object, you modify the message’s payload in place.
With optional argument i, get_payload()
will return the i-th element of the payload, counting from zero, if is_multipart()
is True
. An IndexError
will be raised if i is less than 0 or greater than or equal to the number of items in the payload. If the payload is a string (i.e. is_multipart()
is False
) and i is given, a TypeError
is raised.
Optional decode is a flag indicating whether the payload should be decoded or not, according to the Content-Transfer-Encoding header. When True
and the message is not a multipart, the payload will be decoded if this header’s value is quoted-printable
or base64
. If some other encoding is used, or Content-Transfer-Encoding header is missing, the payload is returned as-is (undecoded). In all cases the returned value is binary data. If the message is a multipart and the decode flag is True
, then None
is returned. If the payload is base64 and it was not perfectly formed (missing padding, characters outside the base64 alphabet), then an appropriate defect will be added to the message’s defect property (InvalidBase64PaddingDefect
or InvalidBase64CharactersDefect
, respectively).
When decode is False
(the default) the body is returned as a string without decoding the Content-Transfer-Encoding. However, for a Content-Transfer-Encoding of 8bit, an attempt is made to decode the original bytes using the charset
specified by the Content-Type header, using the replace
error handler. If no charset
is specified, or if the charset
given is not recognized by the email package, the body is decoded using the default ASCII charset.
Please login to continue.