'Handle lines received in response to a SELECT or EXAMINE command.
See RFC 3501, section 6.3.1.'

def __cbSelect(self, result, rw):

    (lines, tagline) = result
    datum = {'READ-WRITE': rw}
    lines.append(parseNestedParens(tagline))
    for split in lines:
        if ((len(split) > 0) and (split[0].upper() == 'OK')):
            content = split[1]
            key = content[0].upper()
            if (key == 'READ-ONLY'):
                datum['READ-WRITE'] = False
            elif (key == 'READ-WRITE'):
                datum['READ-WRITE'] = True
            elif (key == 'UIDVALIDITY'):
                datum['UIDVALIDITY'] = self._intOrRaise(content[1], split)
            elif (key == 'UNSEEN'):
                datum['UNSEEN'] = self._intOrRaise(content[1], split)
            elif (key == 'UIDNEXT'):
                datum['UIDNEXT'] = self._intOrRaise(content[1], split)
            elif (key == 'PERMANENTFLAGS'):
                datum['PERMANENTFLAGS'] = tuple(content[1])
            else:
                log.err(('Unhandled    SELECT    response    (2):    %s' % (split,)))
        elif (len(split) == 2):
            if (split[0].upper() == 'FLAGS'):
                datum['FLAGS'] = tuple(split[1])
            elif isinstance(split[1], str):
                if (split[1].upper() == 'EXISTS'):
                    datum['EXISTS'] = self._intOrRaise(split[0], split)
                elif (split[1].upper() == 'RECENT'):
                    datum['RECENT'] = self._intOrRaise(split[0], split)
                else:
                    log.err(('Unhandled    SELECT    response    (0):    %s' % (split,)))
            else:
                log.err(('Unhandled    SELECT    response    (1):    %s' % (split,)))
        else:
            log.err(('Unhandled    SELECT    response    (4):    %s' % (split,)))
    return datum
