'Handle a LIST command.
@type i: L{bytes} or L{None}
@param i: A 1-based message index.
@rtype: L{Deferred <defer.Deferred>}
@return: A deferred which triggers after the response to the LIST
command has been issued.'

def do_LIST(self, i=None):

    if (i is None):
        d = defer.maybeDeferred(self.mbox.listMessages)
        def cbMessages(msgs):
            return self._coiterate(formatListResponse(msgs))
        def ebMessages(err):
            self.failResponse(err.getErrorMessage())
            log.msg('Unexpected    do_LIST    failure:')
            log.err(err)
        return self._longOperation(d.addCallbacks(cbMessages, ebMessages))
    else:
        try:
            i = int(i)
            if (i < 1):
                raise ValueError()
        except ValueError:
            self.failResponse(('Invalid    message-number:    %r' % (i,)))
        else:
            d = defer.maybeDeferred(self.mbox.listMessages, (i - 1))
            def cbMessage(msg):
                self.successResponse(('%d    %d' % (i, msg)))
            def ebMessage(err):
                errcls = err.check(ValueError, IndexError)
                if (errcls is not None):
                    if (errcls is IndexError):
                        warnings.warn('twisted.mail.pop3.IMailbox.listMessages    may    not    raise    IndexError    for    out-of-bounds    message    numbers:    raise    ValueError    instead.', PendingDeprecationWarning)
                    self.failResponse(('Invalid    message-number:    %r' % (i,)))
                else:
                    self.failResponse(err.getErrorMessage())
                    log.msg('Unexpected    do_LIST    failure:')
                    log.err(err)
            return self._longOperation(d.addCallbacks(cbMessage, ebMessage))
