0

I'm reading emails with imaplib, and found out that some email contents are encoded base64, and some 7bits.

I tried to decode it with 'Content-Transfer-Encoding' value.

But even more, some have 'Content-Transfer-Encoding' header in message object, whereas some have it in message.get_payload()[0].

I can deal with these some cases, but I think there can be more cases that I haven't found.

Is there any better way to decode email contents, no matter how they are encoded?

Thanks :)

yoon
  • 1,177
  • 2
  • 15
  • 28

1 Answers1

0

when using get_payload(), I added decode=True option, so that it can automatically decode if needed. link

And then, isinstance(content, bytes) tells you whether you have to uni-decode or not.

yoon
  • 1,177
  • 2
  • 15
  • 28