title: Why is there a Imaplib.abort EOF error after 10 correctly crawled messages?
body: <p>I need to Copy every mail from my 'inbox'+sub folders to 2 new folders, one for short subjects and another for the long ones. 
  The crawl always abort after the 10th mail, and I need to repeat the process for 10 000 of them.. if someone had a solution I would be very grateful, here is my code :</p>
  
  <pre><code>import imaplib, getpass, re, email
  pattern_uid = re.compile(b'\d+ \(UID (?P&lt;uid&gt;\d+)\)')
  
  def parse_mailbox(data):
      flags, b, c = data.partition(' ')
      separator, b, name = c.partition(' ')
      return (flags, separator.replace('"', ''), name.replace('"', ''))
  
  def connect(email):
      imap = imaplib.IMAP4_SSL("outlook.office365.com",993)
      password = "*******" 
      imap.login(email, password)
      return imap
  
  def disconnect(imap):
      imap.logout()
  
  def parse_uid(data):
      match = pattern_uid.match(data)
      return match.group('uid')
  
  if __name__ == '__main__':
      imap = connect('************')
      rv,data = imap.list()
      # print(data)
      if rv == 'OK':
          for mbox in data:
              flags,separator,name = parse_mailbox(bytes.decode(mbox))
              print(name)
              if 'HasNoChildren' in flags and '2' in name:
                  name = name.replace('/ Inbox','Inbox')
                  rv2, data2 = imap.select('"'+name+'"')
                  print(rv2)
                  resp, items = imap.search(None, 'All')
                  email_ids  = items[0].split()
                  # print(items)
                  print(email_ids)
                   # Assuming that you are moving the latest email.
                  # for mail in email_ids:
                  #     if
                  print(len(email_ids))
                  for i in range(0,len(email_ids)):
                      print('NOUVEAU MESSAGE \n')
                      print(email_ids[i])
                      resp, data = imap.fetch(email_ids[i], "(UID)")
                      rv,sujet = imap.fetch(email_ids[i],("(RFC822)"))
                      varSubject= ""
                      for response_part in sujet:
                          if isinstance(response_part, tuple):
  
                              msg = email.message_from_bytes(response_part[1])
                              varSubject = msg['subject']
                              break
                      print(varSubject)
                      print(i)
                      print(type(data[0]))
                      print(data[0])
                      try : 
                          msg_uid = parse_uid(data[0])
                      except AttributeError:
                          continue
                      num = ""
                      dossier = ""
                      if  len(varSubject) &lt;= 20:
                          dossier =  'INBOX/sujets_courts'
                          imap.create(dossier)
                      elif  len(varSubject) &gt; 20:
                          dossier =  'INBOX/sujets_longs'
                          imap.create(dossier)
                      print(varSubject+'******'+dossier)
                      print(msg_uid)
  
                      result = imap.uid('COPY', msg_uid, dossier)
  
              # if result[0] == 'OK':
              #     mov, data = imap.uid('STORE', msg_uid , '+FLAGS', '(\Deleted)')
              #     imap.expunge()
  
      disconnect(imap)
  </code></pre>
  
  <p>The email and the password are substituted by '****' </p>
  
  <p>Thanks a lot :)</p>
  
  <p>console output : </p>
  
  <pre><code>    Traceback (most recent call last):
    File "C:\Users\lschaub\AppData\Local\Programs\Python\Python36-32\lib\imaplib.py", line 1011, in _command_complete
      typ, data = self._get_tagged_response(tag)
    File "C:\Users\lschaub\AppData\Local\Programs\Python\Python36-32\lib\imaplib.py", line 1131, in _get_tagged_response
      self._get_response()
    File "C:\Users\lschaub\AppData\Local\Programs\Python\Python36-32\lib\imaplib.py", line 1039, in _get_response
      resp = self._get_line()
    File "C:\Users\lschaub\AppData\Local\Programs\Python\Python36-32\lib\imaplib.py", line 1143, in _get_line
      raise self.abort('socket error: EOF')
  imaplib.abort: socket error: EOF
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "movemail.py", line 44, in &lt;module&gt;
      resp, data = imap.fetch(email_ids[i], "(UID)")
    File "C:\Users\lschaub\AppData\Local\Programs\Python\Python36-32\lib\imaplib.py", line 526, in fetch
      typ, dat = self._simple_command(name, message_set, message_parts)
    File "C:\Users\lschaub\AppData\Local\Programs\Python\Python36-32\lib\imaplib.py", line 1188, in _simple_command
      return self._command_complete(name, self._command(name, *args))
    File "C:\Users\lschaub\AppData\Local\Programs\Python\Python36-32\lib\imaplib.py", line 1013, in _command_complete
      raise self.abort('command: %s =&gt; %s' % (name, val))
  imaplib.abort: command: FETCH =&gt; socket error: EOF
  </code></pre>