public MailAddress()

in core/src/main/java/org/apache/james/core/MailAddress.java [174:252]


    public MailAddress(String address) throws AddressException {
        address = address.trim();
        int pos = 0;

        // Test if mail address has source routing information (RFC-821) and get rid of it!!
        //must be called first!! (or at least prior to updating pos)
        stripSourceRoute(address, pos);

        StringBuilder localPartSB = new StringBuilder();
        StringBuilder domainSB = new StringBuilder();
        //Begin parsing
        //<mailbox> ::= <local-part> "@" <domain>

        try {
            //parse local-part
            //<local-part> ::= <dot-string> | <quoted-string>
            if (address.charAt(pos) == '\"') {
                pos = parseQuotedLocalPartOrThrowException(localPartSB, address, pos);
            } else {
                pos = parseUnquotedLocalPartOrThrowException(localPartSB, address, pos);
            }

            //find @
            if (pos >= address.length() || address.charAt(pos) != '@') {
                throw new AddressException("Did not find @ between local-part and domain at position " +
                        (pos + 1) + " in '" + address + "'", address, pos + 1);
            }
            pos++;

            //parse domain
            //<domain> ::=  <element> | <element> "." <domain>
            //<element> ::= <name> | "#" <number> | "[" <dotnum> "]"
            while (true) {
                if (address.charAt(pos) == '#') {
                    pos = parseNumber(domainSB, address, pos);
                } else if (address.charAt(pos) == '[') {
                    pos = parseDomainLiteral(domainSB, address, pos);
                } else {
                    pos = parseDomain(domainSB, address, pos);
                }
                if (pos >= address.length()) {
                    break;
                }
                if (address.charAt(pos) == '.') {
                    char lastChar = address.charAt(pos - 1);
                    if (lastChar == '@' || lastChar == '.') {
                        throw new AddressException("Subdomain expected before '.' or duplicate '.' in " + address);
                    }
                    domainSB.append('.');
                    pos++;
                    continue;
                }
                break;
            }

            if (domainSB.length() == 0) {
                throw new AddressException("No domain found at position " +
                        (pos + 1) + " in '" + address + "'", address, pos + 1);
            }
        } catch (IndexOutOfBoundsException ioobe) {
            throw new AddressException("Out of data at position " +
                    (pos + 1) + " in '" + address + "'", address, pos + 1);
        }

        localPart = localPartSB.toString();

        if (localPart.startsWith(".")
            || localPart.endsWith(".")
            || haveDoubleDot(localPart)) {
            throw new AddressException("Addresses cannot start end with '.' or contain two consecutive dots");
        }

        // not handle by jakarta.mail
        if (haveBackSlashComma(localPart)) {
            throw new AddressException("Addresses cannot contain \\,");
        }

        domain = createDomain(domainSB.toString());
    }