title: How to detect and correct the Content-Type charset in email header in python?
body: <p>What is the correct way to programatically detect and correct the <code>Content-Type</code> <code>charset</code> in an email header in python?</p>
  
  <p>I have a 1000s of emails extracted to <code>.eml</code> (basically plain text) files and some are encoded <code>shift_jis</code>, but the charset in the email header doesn't mention this, so they don't display correctly in any email program. Adding in the <code>charset</code> manually to the <code>Content-Type</code> header corrects this.</p>
  
  <p>Was:</p>
  
  <pre><code>Content-Type: text/plain; format=flowed
  </code></pre>
  
  <p>Needs to be:</p>
  
  <pre><code>Content-Type: text/plain; charset="shift_jis"; format=flowed
  </code></pre>
  
  <p>What's the correct way to do this in python preserving the email body and other parts of the header?</p>
  
  <p>Also, is there a way to detect which encoding, and only correct those with that encoding? I can't just convert all blindly, since some are <code>iso_2022_jp</code>, and those are already displaying correctly.</p>