Mailbox parseMailboxAddress()

in dom/src/main/java/org/apache/james/mime4j/field/address/LenientAddressParser.java [136:183]


    Mailbox parseMailboxAddress(
            final String openingText, final ByteSequence buf, final ParserCursor cursor) {
        if (cursor.atEnd()) {
            return createMailbox(null, null, openingText, null);
        }
        int pos = cursor.getPos();
        char current = (char) (buf.byteAt(pos) & 0xff);
        if (current == OPENING_BRACKET) {
            cursor.updatePos(pos + 1);
        } else {
            return createMailbox(null, null, openingText, null);
        }
        DomainList domainList = parseRoute(buf, cursor, CLOSING_BRACKET_ONLY);
        String localPart = this.parser.parseValue(buf, cursor, AT_AND_CLOSING_BRACKET);
        if (cursor.atEnd()) {
            return createMailbox(openingText, domainList, localPart, null);
        }
        pos = cursor.getPos();
        current = (char) (buf.byteAt(pos) & 0xff);
        if (current == AT || current == CLOSING_BRACKET) {
            cursor.updatePos(pos + 1);
        } else {
            return createMailbox(openingText, domainList, localPart, null);
        }
        String domain = parseDomain(buf, cursor, CLOSING_BRACKET_ONLY);
        if (cursor.atEnd()) {
            return createMailbox(openingText, domainList, localPart, domain);
        }
        pos = cursor.getPos();
        current = (char) (buf.byteAt(pos) & 0xff);
        if (current == CLOSING_BRACKET) {
            cursor.updatePos(pos + 1);
        } else {
            return createMailbox(openingText, domainList, localPart, domain);
        }
        while (!cursor.atEnd()) {
            pos = cursor.getPos();
            current = (char) (buf.byteAt(pos) & 0xff);
            if (CharsetUtil.isWhitespace(current)) {
                this.parser.skipWhiteSpace(buf, cursor);
            } else if (current == '(') {
                this.parser.skipComment(buf, cursor);
            } else {
                break;
            }
        }
        return createMailbox(openingText, domainList, localPart, domain);
    }