Update get_payload to decode the Content-Transfer-Encoding header#4
Update get_payload to decode the Content-Transfer-Encoding header#4noahbass wants to merge 1 commit into
Conversation
This will decode the message payload if it's in base64 or quoted-printable See get_payload documentation for details on using `decode=True`: https://docs.python.org/2/library/email.message.html#email.message.Message.get_payload
|
I don't know how many emails it would affect but it seems like setting |
|
Maybe this block would work better? (Untested) msg_body = ""
for part in msg.walk():
if part.get_content_maintype() == 'multipart':
continue
if part.get_content_type() == 'text/plain':
msg_body = part.get_payload(decode=True)
|
|
Well, actually I've thought about it and since the loop walks through each part in a message (which could be a multipart message): msg_body = ""
for part in msg.walk():
if part.get_content_type() == 'text/plain':
msg_body = part.get_payload(decode=True)
breakWhen it reaches |
|
I think that looks good. EDIT: Actually what about an else clause so that |
Addresses some issues in #2.
This will decode the message payload if it's in
base64orquoted-printableas theContent-Transfer-Encodingheader.So with these changes, this message with a
quoted-printableContent-Transfer-Encoding header:Will now be output as this:
See
get_payloaddocumentation for details on usingdecode=True.