title: python imaplib - error 'unexpected repsonse'
body: <p>Hi I've suddenly encountered an error using imaplib on some code that worked fine before.</p>
  
  <pre><code>import imaplib
  m = imaplib.IMAP4('myserver','port')
  m.login(r'username','password')
  m.select()
  </code></pre>
  
  <p>gives me the error </p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python2.7/imaplib.py", line 649, in select
      typ, dat = self._simple_command(name, mailbox)
    File "/usr/lib/python2.7/imaplib.py", line 1070, in _simple_command
      return self._command_complete(name, self._command(name, *args))
    File "/usr/lib/python2.7/imaplib.py", line 899, in _command_complete
      raise self.abort('command: %s =&gt; %s' % (name, val))
  imaplib.abort: command: SELECT =&gt; unexpected response: '*  1520 EXISTS'
  </code></pre>
  
  <p>I'm not sure what it means. Emails are otherwise coming through fine, and I'm using davmail as a server.</p>
  
  <p>The program in its entirety saves attachments with a certain name in a specific folder. </p>
  
  <p>I've stepped through it and its definitely the <code>m.select()</code> that is where its falling over.</p>
  
  <p>This same program worked absolutely fine until recently.</p>
  
  <p>What am I doing wrong, and how do I fix it?</p>
  
  <p>The log of activity is as follows</p>
  
  <pre><code>&gt;&gt;&gt; import imaplib
  &gt;&gt;&gt; m = imaplib.IMAP4('server','port')
  &gt;&gt;&gt; Debug=4
  &gt;&gt;&gt; m.debug
  0
  &gt;&gt;&gt; m.debug=4
  &gt;&gt;&gt; m.debug
  4
  &gt;&gt;&gt; m.login(r'username','password')
    01:26.55 &gt; HLFI1 LOGIN "username" "password"
    01:30.76 &lt; HLFI1 OK Authenticated
  ('OK', ['Authenticated'])
  &gt;&gt;&gt; m.list()
    01:56.33 &gt; HLFI2 LIST "" *
    02:00.04 &lt; * LIST (\HasNoChildren) "/" "Trash/Sent Messages"
    02:00.04 &lt; * LIST (\HasNoChildren) "/" "Sync Issues/Server Failures"
    02:00.04 &lt; * LIST (\HasNoChildren) "/" "Sync Issues/Local Failures"
    02:00.04 &lt; * LIST (\HasNoChildren) "/" "Sync Issues/Conflicts"
    02:00.04 &lt; * LIST (\HasChildren) "/" "Sync Issues"
    02:00.04 &lt; * LIST (\HasNoChildren) "/" "Junk E-mail"
    02:00.04 &lt; * LIST (\HasNoChildren) "/" "Drafts"
    02:00.04 &lt; * LIST (\HasChildren) "/" "Trash"
    02:00.04 &lt; * LIST (\HasNoChildren) "/" "Sent"
    02:00.04 &lt; * LIST (\HasNoChildren) "/" "Outbox"
    02:00.04 &lt; * LIST (\HasNoChildren) "/" "INBOX"
    02:00.04 &lt; HLFI2 OK LIST completed
  ('OK', ['(\\HasNoChildren) "/" "Trash/Sent Messages"', '(\\HasNoChildren) "/" "Sync Issues/Server Failures"', '(\\HasNoChildren) "/" "Sync Issues/Local Failures"', '(\\HasNoChildren) "/" "Sync Issues/Conflicts"', '(\\HasChildren) "/" "Sync Issues"', '(\\HasNoChildren) "/" "Junk E-mail"', '(\\HasNoChildren) "/" "Drafts"', '(\\HasChildren) "/" "Trash"', '(\\HasNoChildren) "/" "Sent"', '(\\HasNoChildren) "/" "Outbox"', '(\\HasNoChildren) "/" "INBOX"'])
  &gt;&gt;&gt; m.select()
    02:21.37 &gt; HLFI3 SELECT INBOX
    02:30.87 &lt; *  1548 EXISTS
    02:30.87 last 4 IMAP4 interactions:
    00:16.73 &lt; * OK [CAPABILITY IMAP4REV1 AUTH=LOGIN MOVE] IMAP4rev1 DavMail 4.3.0-2125 server ready
    00:16.73 &gt; HLFI0 CAPABILITY
    00:16.74 &lt; * CAPABILITY IMAP4REV1 AUTH=LOGIN MOVE
    00:16.77 &lt; HLFI0 OK CAPABILITY completed
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python2.7/imaplib.py", line 649, in select
      typ, dat = self._simple_command(name, mailbox)
    File "/usr/lib/python2.7/imaplib.py", line 1070, in _simple_command
      return self._command_complete(name, self._command(name, *args))
    File "/usr/lib/python2.7/imaplib.py", line 899, in _command_complete
      raise self.abort('command: %s =&gt; %s' % (name, val))
  imaplib.abort: command: SELECT =&gt; unexpected response: '*  1548 EXISTS'
  </code></pre>
  
  <p>** UPDATE **</p>
  
  <p>I've now filed a bug at python-dev under</p>
  
  <p><a href="http://bugs.python.org/issue18153" rel="nofollow">Bug report on Python</a></p>
  
  <p>Where David Murray says the response is non RFC compliant</p>
  
  <p>And a second at davmail sourceforge under </p>
  
  <p><a href="http://sourceforge.net/p/davmail/bugs/532/" rel="nofollow">davmail bug report</a></p>
  
  <p>M guessant says it is necessary for the IMAP keep alive.</p>
  
  <p>I'll keep this updated with developments..</p>