Method code for $smtp.parse_email_address()

[Turn on line numbering]
arg address, @lookup;
var name, host, ip, h;

if (!address)
    throw(~invemail, "No email address supplied.");
address = explode(address, "@");
if (listlen(address) != 2)
    throw(~invemail, "\"" + address.join("@") + "\" is not a valid email address.");
[name, host] = address;
if (!match_regexp(name, valid_email_regexp))
    throw(~invemail, "'" + name + "' is not a valid Internet mail username");
if (lookup) {
    ip = $dns.ip(host);
    if (!ip || ip == "-1")
        throw(~invemail, "'" + host + "' does not resolv to an IP address");
    h = $dns.hostname(ip);
    if (!$dns.valid_hostname(h))
        throw(~invemail, "Invalid DNS entry for: " + host + "/" + ip);
    host = h;
} else if (!$dns.valid_hostname(host)) {
    throw(~invemail, "Invalid hostname \"" + host + "\"");
}
return [name, host, ip];

// Created 13-Oct-1996 as a part of ColdCore, see: @help Credit

Tlon