title: How to handle Python 3.x UnicodeDecodeError in Email package?
body: <p>I try to read an email from a file, like this:</p>
  
  <pre><code>import email
  with open("xxx.eml") as f:
     msg = email.message_from_file(f)
  </code></pre>
  
  <p>and I get this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "I:\fakt\real\maildecode.py", line 53, in &lt;module&gt;
      main()
    File "I:\fakt\real\maildecode.py", line 50, in main
      decode_file(infile, outfile)
    File "I:\fakt\real\maildecode.py", line 30, in decode_file
      msg = email.message_from_file(f)  #, policy=mypol
    File "C:\Python33\lib\email\__init__.py", line 56, in message_from_file
      return Parser(*args, **kws).parse(fp)
    File "C:\Python33\lib\email\parser.py", line 55, in parse
      data = fp.read(8192)
    File "C:\Python33\lib\encodings\cp1252.py", line 23, in decode
      return codecs.charmap_decode(input,self.errors,decoding_table)[0]
  UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1920: character maps to &lt;undefined&gt;
  </code></pre>
  
  <p>The file contains a multipart email, where the part is encoded in UTF-8.  The file's content or encoding might be broken, but I have to handle it anyway.  </p>
  
  <p>How can I read the file, even if it has Unicode errors?  I cannot find the policy object <code>compat32</code> and there seems to be no way to handle an exception and let Python continue right where the exception occured.</p>
  
  <p>What can I do?</p>