Method code for $smtp.parse_email_address()

[Turn off line numbering]
  1: arg address, @lookup;
  2: var name, host, ip, h;
  3: 
  4: if (!address)
  5:     throw(~invemail, "No email address supplied.");
  6: address = explode(address, "@");
  7: if (listlen(address) != 2)
  8:     throw(~invemail, "\"" + address.join("@") + "\" is not a valid email address.");
  9: [name, host] = address;
 10: if (!match_regexp(name, valid_email_regexp))
 11:     throw(~invemail, "'" + name + "' is not a valid Internet mail username");
 12: if (lookup) {
 13:     ip = $dns.ip(host);
 14:     if (!ip || ip == "-1")
 15:         throw(~invemail, "'" + host + "' does not resolv to an IP address");
 16:     h = $dns.hostname(ip);
 17:     if (!$dns.valid_hostname(h))
 18:         throw(~invemail, "Invalid DNS entry for: " + host + "/" + ip);
 19:     host = h;
 20: } else if (!$dns.valid_hostname(host)) {
 21:     throw(~invemail, "Invalid hostname \"" + host + "\"");
 22: }
 23: return [name, host, ip];

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

Tlon