title: python imaplib fetch result is none with simple email from gmail
body: <p>i get None as a result for an email i wrote with Thunderbird or gmail webapp.</p>
  
  <p>For example my subject is "myfancysubject" and the text is just "hello"</p>
  
  <p>i get no data (NONE) by using imaplib fetch operation with </p>
  
  <pre><code> result, data = mail.fetch(latest_email_id, '(RFC822)') # fetch the email body (RFC822) for the given ID
  </code></pre>
  
  <p>my assumption is the mail has no RFC822 Tag ?</p>
  
  <p>But how can i get the content of that mail ?</p>
  
  <p>here is my full code:</p>
  
  <pre><code>import imaplib
  import email
  
  try:
      mail = imaplib.IMAP4_SSL('imap.gmail.com')
      mail.login('email@gmail.com', 'password')
      labels = mail.list()
      # Out: list of "folders" aka labels in gmail.
      inbox = mail.select("inbox") # connect to inbox.
      #result, data = mail.search(None, "ALL")
      result, data = mail.uid('search', None, '(HEADER Subject "myfancysubject")')
  
  
      ids = data[0] # data is a list.
      id_list = ids.split() # ids is a space separated string
  
      latest_email_id = None
      if len(id_list) == 1:
          latest_email_id = id_list[0] # get the latest
          pass
      else:
          latest_email_id = id_list[-1]
          pass
  
      result, data = mail.fetch(latest_email_id, '(RFC822)') # fetch the email body (RFC822) for the given ID
  
      print(data)
  
      raw_email = data[0][0]
      email_message = email.message_from_string(raw_email)
  
      print email_message['To']
  
      print email.utils.parseaddr(email_message['From'])
  
      print email_message.items() # print all headers
  
  except Exception:
      print('Ex')
  </code></pre>