X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FAddress.java;h=1197a308e0810c543f7cdbbcd132b3cfb696d664;hb=1fceeb3f8780b18f3def747fccdf8e4b8ac8d55d;hp=694523d9396c0f0da37b329c231155e926d7a48a;hpb=50ce84c208fe23f6019ccfbc8caa8dbb44a96072;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/Address.java b/src/org/ibex/mail/Address.java index 694523d..1197a30 100644 --- a/src/org/ibex/mail/Address.java +++ b/src/org/ibex/mail/Address.java @@ -19,36 +19,55 @@ public class Address extends JSReflection implements Serializable { public static Address parse(String s) { try { return s==null?null:new Address(s); } catch (Malformed _) { return null; } } public Address(String user, String host, String description) {this.user=user;this.host=host;this.description=description;} public Address(String s0) throws Address.Malformed { - String s = s0.trim(); - if (s.indexOf('<') == -1) { - if (s.indexOf(' ') == -1) { - description = ""; + boolean good = false; + try { + String s = s0.trim(); + if (s.indexOf('<') == -1) { + if (s.indexOf(' ') == -1) { + description = ""; + } else { + description = s.substring(s.indexOf(' ')).trim(); + s = s.substring(0, s.indexOf(' ')); + } } else { - description = s.substring(s.indexOf(' ')).trim(); - s = s.substring(0, s.indexOf(' ')); + if (s.indexOf('>') == -1) { throw new Malformed("found open-angle-bracket (<) but not close-angle-bracket (>)"); } + description = s.substring(0, s.indexOf('<')) + s.substring(s.indexOf('>') + 1); + s = s.substring(s.indexOf('<') + 1, s.indexOf('>')); } - } else { - if (s.indexOf('>') == -1) { throw new Malformed("found open-angle-bracket (<) but not close-angle-bracket (>)"); } - description = s.substring(0, s.indexOf('<')) + s.substring(s.indexOf('>') + 1); - s = s.substring(s.indexOf('<') + 1, s.indexOf('>')); + if (s.trim().length() == 0) { + user = null; + host = null; + good = true; + } else if (s.indexOf('@') == -1) { throw new Malformed("no @-sign in email address \""+s0+"\""); + } else { + user = s.substring(0, s.indexOf('@')); + host = s.substring(s.indexOf('@')+1); + good = true; + } + } finally { + if (!good) Log.error(Address.class, "problem parsing: \""+s0+"\""); } - if (s.indexOf('@') == -1) { throw new Malformed("no @-sign in email address \""+s0+"\""); } - user = s.substring(0, s.indexOf('@')); - host = s.substring(s.indexOf('@')+1); } - public String toString() { return user + "@" + host; } + public String toString() { return (user == null && host == null) ? "" : (user + "@" + host); } + public String coerceToString() { return toString(); } public String toString(boolean desc) { return desc && description != null && description.length() > 0 ? (description+" <" + toString() + ">") : toString(); } - public String coerceToString() { return toString(); } public static class Malformed extends Message.Malformed { public Malformed(String s) { super(s); } } + /** in case of flaky DNS */ + private static HashSet local = new HashSet(); public boolean isLocal() { - InetAddress[] mx = SMTP.getMailExchangerIPs(host); - for(int i=0; i