X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FAddress.java;fp=src%2Forg%2Fibex%2Fmail%2FAddress.java;h=ebf349b0e83405a2f2dc7c53e2fb6b5bb0cdc11f;hb=071000f577ab3a75dc06560dfa1983331df2bd98;hp=92bdbc89e2cfe18ac708d9a8879ceec7f5b93052;hpb=8bc0112af0cd8efc628e17d529d515ece107c968;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/Address.java b/src/org/ibex/mail/Address.java index 92bdbc8..ebf349b 100644 --- a/src/org/ibex/mail/Address.java +++ b/src/org/ibex/mail/Address.java @@ -7,25 +7,26 @@ import java.util.*; import java.net.*; import java.io.*; +// FIXME this should be more forgiving public class Address extends JSReflection { public final String user; public final String host; public final String description; + public static Address parse(String s) { try { return 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 s) throws Address.Malformed { - s = s.trim(); - if (s.indexOf('<') != -1) { + public Address(String s0) throws Address.Malformed { + String s = s0.trim(); + if (s.indexOf('<') == -1) description = ""; + 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('>')); - } else { - description = ""; } - if (s.indexOf('@') == -1) { throw new Malformed("no @-sign in email address"); } + 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 coerceToString() { return toString(); } public String toString() { return description.equals("") ? (user +"@"+ host) : description+" <" + user +"@"+ host + ">"; } - public static class Malformed extends MailException.Malformed { public Malformed(String s) { super(s); } } + public static class Malformed extends RuntimeException { public Malformed(String s) { super(s); } } }