2 import org.ibex.crypto.*;
4 import org.ibex.util.*;
5 import org.ibex.mail.protocol.*;
10 // FIXME this should be more forgiving
11 public class Address extends JSReflection {
12 public final String user;
13 public final String host;
14 public final String description;
15 public static Address parse(String s) { try { return new Address(s); } catch (Malformed _) { return null; } }
16 public Address(String user, String host, String description) {this.user=user;this.host=host;this.description=description;}
17 public Address(String s0) throws Address.Malformed {
19 if (s.indexOf('<') == -1) description = "";
21 if (s.indexOf('>') == -1) { throw new Malformed("found open-angle-bracket (<) but not close-angle-bracket (>)"); }
22 description = s.substring(0, s.indexOf('<')) + s.substring(s.indexOf('>') + 1);
23 s = s.substring(s.indexOf('<') + 1, s.indexOf('>'));
25 if (s.indexOf('@') == -1) { throw new Malformed("no @-sign in email address \""+s0+"\""); }
26 user = s.substring(0, s.indexOf('@'));
27 host = s.substring(s.indexOf('@')+1);
29 public String coerceToString() { return toString(); }
30 public String toString() { return description.equals("") ? (user +"@"+ host) : description+" <" + user +"@"+ host + ">"; }
31 public static class Malformed extends RuntimeException { public Malformed(String s) { super(s); } }