userSB.append(parseQuotedLocalPart(address));
} else {
userSB.append(parseUnquotedLocalPart(address));
}
if (userSB.toString().length() == 0) {
throw new ParseException("No local-part (user account) found at position " + (pos + 1));
}
//find @
if (address.charAt(pos) != '@') {
throw new ParseException("Did not find @ between local-part and domain at position " + (pos + 1));
}
pos++;
//parse domain
//<domain> ::= <element> | <element> "." <domain>
//<element> ::= <name> | "#" <number> | "[" <dotnum> "]"
while (true) {
if (address.charAt(pos) == '#') {
hostSB.append(parseNumber(address));
} else if (address.charAt(pos) == '[') {
hostSB.append(parseDotNum(address));
} else {
hostSB.append(parseDomainName(address));
}
if (pos >= address.length()) {
break;
}
if (address.charAt(pos) == '.') {
hostSB.append('.');
pos++;
continue;
}
break;
}
if (hostSB.toString().length() == 0) {
throw new ParseException("No domain found at position " + (pos + 1));
}
} catch (IndexOutOfBoundsException ioobe) {
throw new ParseException("Out of data at position " + (pos + 1));
}
user = userSB.toString();
host = hostSB.toString();
}