'Select a mailbox.
Flush all untagged responses.
(typ, [data]) = <instance>.select(mailbox=\'INBOX\', readonly=False)
\'data\' is count of messages in mailbox (\'EXISTS\' response).
Mandated responses are (\'FLAGS\', \'EXISTS\', \'RECENT\', \'UIDVALIDITY\'), so
other responses should be obtained via <instance>.response(\'FLAGS\') etc.'

def select(self, mailbox='INBOX', readonly=False):

    self.untagged_responses = {}
    self.is_readonly = readonly
    if readonly:
        name = 'EXAMINE'
    else:
        name = 'SELECT'
    (typ, dat) = self._simple_command(name, mailbox)
    if (typ != 'OK'):
        self.state = 'AUTH'
        return (typ, dat)
    else:
        self.state = 'SELECTED'
        if (('READ-ONLY' in self.untagged_responses) and (not readonly)):
            raise self.readonly(('%s    is    not    writable' % mailbox))
        return (typ, self.untagged_responses.get('EXISTS', [None]))
