title: Python: What is this encoding and how to decode?
body: <p>I have a lot of strings from mail bodies, that print as such:</p>
  
  <pre><code>=C3=A9
  </code></pre>
  
  <p>This should be 'é' for example. </p>
  
  <p>What exactly is this encoding and how to decode it?</p>
  
  <p>I'm using python 3.5</p>
  
  <p>EDIT:</p>
  
  <p>I managed to get the body of the mail properly encoded by applying:</p>
  
  <pre><code>quopri.decodestring(sometext).decode('utf-8') 
  </code></pre>
  
  <p>However I still struggle to get the FROM , TO, SUBJECT, etc... parts get right. </p>
  
  <p>This is how I construct the e-mails:</p>
  
  <pre><code>import imaplib
  import email
  import quopri
  
  
  mail = imaplib.IMAP4_SSL('imap.gmail.com')
  mail.login('mail@gmail.com', '*******')
  mail.list()
  
  mail.select('"[Gmail]/All Mail"') 
  
  
  
  typ, data = mail.search(None, 'SUBJECT', '"{}"'.format('123456'))
  
  data[0].split()
  
  print(data[0].split())
  
  for e_mail in data[0].split():
      typ, data = mail.fetch('{}'.format(e_mail.decode()),'(RFC822)')
      raw_mail = data[0][1]
      email_message = email.message_from_bytes(raw_mail)
      if email_message.is_multipart():
          for part in email_message.walk():
              if part.get_content_type() == 'text/plain':
                  if part.get_content_type() == 'text/plain':
                      body = part.get_payload()
                      to = email_message['To']
  
                      utf = quopri.decodestring(to)
  
                      text = utf.decode('utf-8')
                      print(text)
  .
  .
  .
  </code></pre>
  
  <p>I still got this: =?UTF-8?B?UMOpdGVyIFBldMWRY3o=?=</p>