'Returns a list of indices for the given query, latest-first.
The search field can be FROM, DATE or SUBJECT.'

def search(self, q, field=FROM, cached=False):

    id = ('mail-%s-%s-%s-%s' % (self.parent._id, self.name, q, field))
    if (cached and (id in cache)):
        (status, response) = ('OK', [cache[id]])
    else:
        (status, response) = self.parent.imap4.select(self._name, readonly=1)
        (status, response) = self.parent.imap4.search(None, field.upper(), q)
        if cached:
            cache[id] = response[0]
    return sorted([(int(i) - 1) for i in response[0].split()], reverse=True)
