title: Python Imaplib: Get new gmail mails without reconnect
body: <p>I'm writing a python script that regularly checks for new email matching a certain search. However it never shows new emails without reconnecting.</p>
  
  <pre><code>mail = imaplib.IMAP4_SSL('imap.gmail.com')
  mail.login(user,passwd)
  mail.select("inbox")
  while True:
      result, idData = mail.uid('search', query, "ALL")
      processIDs(idData)
      time.sleep(60)
  </code></pre>
  
  <p>The search finds all emails that match my query at login time, but it never finds emails that arrive while it's running. As soon as I stop the script and restart it, all emails instantly show up.</p>
  
  <p>If googled and looked through the imaplib docs, but couldn't find anything useful.</p>
  
  <p>How can I get the new emails to show without reconnecting to the imap server?</p>
  
  <p>Edit: The reason I want to avoid reconnecting is because of gmail rate limits.</p>