Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: decode 7bit or 8bit encoded email body

https://docs.python.org/2/library/email.encoders.html lists way to encode the email payload. Is there a way to decode the payload that was received over email?

I need to decode the html body from the email encoded in base64 or 7/8bit or quoted printable formats and mine some data. Luckily there are modules that can deal with quoted printable(quopri) and base64 formats.

I tried finding one for the 7/8bit encoded emails, but was unable to find anything satisfactory. What is the best way to decode such email payloads?

like image 924
sisanared Avatar asked Dec 01 '25 17:12

sisanared


1 Answers

Looks like the easiest way to decode 7bit data is to use the quopri module in python. Essentially quoted-printable is a format which is used to send 8bit data over a 7bit channel. The code below is working well for me:

import quopri
quopri.decodestring(email_multipart_payload) # payload has 7bit encoded data
like image 164
sisanared Avatar answered Dec 04 '25 07:12

sisanared



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!