title: Search speed of IMAP as server gets more and more full
body: <p>In an app I am programming I am currently using IMAP's search function to get the email ID, this is nice as it is a simple and easy task however I was wondering as the server gets fuller will this be detrimental to the search speed (which is currently speedy) and if so is worth dealing with the IMAP idle command and twisted.internet.mail.</p>
  
  <p>I already have IDLE implemented by this</p>
  
  <pre><code>class Command(object):
      _1_RESPONSES = ('CAPABILITY', 'FLAGS', 'LIST', 'LSUB', 'STATUS', 'SEARCH', 'NAMESPACE')
      _2_RESPONSES = ('EXISTS', 'EXPUNGE', 'FETCH', 'RECENT')
      _OK_RESPONSES = ('UIDVALIDITY', 'UNSEEN', 'READ-WRITE', 'READ-ONLY', 'UIDNEXT', 'PERMANENTFLAGS')
      defer = None
  
      def __init__(self, command, args=None, wantResponse=(),
                   continuation=None, *contArgs, **contKw):
          self.command = command
          self.args = args
          self.wantResponse = wantResponse
          self.continuation = lambda x: continuation(x, *contArgs, **contKw)
          self.lines = []
  
      def format(self, tag):
          if self.args is None:
              return ' '.join((tag, self.command))
          return ' '.join((tag, self.command, self.args))
  
      def finish(self, lastLine, unusedCallback):
          send = []
          unuse = []
          for L in self.lines:
              names = parseNestedParens(L)
              N = len(names)
              if (N &gt;= 1 and names[0] in self._1_RESPONSES or
                  N &gt;= 2 and names[1] in self._2_RESPONSES or
                  N &gt;= 1 and names[0] in self.wantResponse or # allows for getting the responses you want, twisted doesn't seem to do that at least with the idle command
                  N &gt;= 2 and names[1] in self.wantResponse or # same as above line just with 2_RESPONSES check
                  N &gt;= 2 and names[0] == 'OK' and isinstance(names[1], types.ListType) and names[1][0] in self._OK_RESPONSES):
                  send.append(names)
              else:
                  unuse.append(names)
          d, self.defer = self.defer, None
          d.callback((send, lastLine))
          if unuse:
              unusedCallback(unuse)
  </code></pre>
  
  <p>IDLE Command being sent </p>
  
  <pre><code>    cmd = Command("IDLE", continuation = self.a)
      d = self.imap_connection.sendCommand(cmd)
      return d
  </code></pre>
  
  <p>Now the reason I am hesitant with IDLE is first off if the server doesn't support it I then can't use it (though this isn't the primary reason), I also don't wish to is because the response of the idle command are unmarked response and how to know they are for the IDLE command.</p>