Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if the mail content is quoted-printable encoded?

My Python program is decoding all the receiving emails and forwarding some of them with some conditions.

It seems most of the emails have contents with ASCII characters or base64 encoded characters.

But some of them have contents with quoted-printable (QP) encoded characters.

I can decode QP encoded strings with quopri module.

But how can I check if the content is QP encoded or not?

I want something like:

content = message.get_payload()
if is_qp_encoded(content): # Checking if QP encoded
    decoded_string = quopri.decodestring(content)
    print(decoded_string.decode('utf-8'))
like image 251
yoon Avatar asked Sep 03 '25 14:09

yoon


1 Answers

I am not familiar with Python's email module, but check whether the message or any body part of it has a "Content-Transfer-Encoding" header field with the value "quoted-printable".

like image 155
Peter O. Avatar answered Sep 05 '25 17:09

Peter O.



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!