def decode_content(message):
"""Decode the content of a message. This method do not checks if the message is
multipart or if the message mime type is plain text or html.
Parameters
----------
message: email.message.Message
Message to decode.
Returns
-------
content: str
Decoded content of the message
Raises
------
TypeError
If the parameter is not an instance of :class:`email.message.Message`.
"""
if not isinstance(message, email.message.Message):
raise TypeError("Expected a message object.")
encoding = message['Content-Transfer-Encoding']
if encoding and encoding.strip() == 'quoted-printable':
result = message.get_payload()
stream = cStringIO.StringIO(result)
output = cStringIO.StringIO()
mimetools.decode(stream, output, 'quoted-printable')
return output.getvalue()
return message.get_payload(decode=True)
评论列表
文章目录