Python - Auto Detect Email Content Encoding
<p>I am writing a script to process emails, and I have access to the raw string content of the emails. </p>

<p>I am currently looking for the string "Content-Transfer-Encoding:" and scanning the characters that follow immediately after, to determine the encoding. Example encodings: base64 or 7bit or quoted-printable ..</p>

<p>Is there a better way to automatically determine the email encoding(at least a more pythonic way)?</p>

<p>Thank you.</p>

<p><a href="https://stackoverflow.com/questions/436220/python-is-there-a-way-to-determine-the-encoding-of-text-file">Python: Is there a way to determine the encoding of text file?</a> has some good answers. Basically there's no way to do it perfectly reliably, and the initial approach you're using is the best (and should be checked first), but if it isn't there then there are a few options that can work sometimes.</p>

python email encoding html-email