1 21 package org.jsmtpd.core.mail; 22 23 import java.io.Serializable ; 24 25 30 public class EmailAddress implements Serializable { 31 32 private String user = ""; 33 private String host = ""; 34 private String authContext = ""; 35 36 42 public static EmailAddress parseAddress(String input) throws InvalidAddress { 43 if ((input==null) || input.equals("")) 44 throw new InvalidAddress(); 45 46 if (input.equals("<>")) { 47 EmailAddress e = new EmailAddress(); 48 e.setUser("<>"); 49 return e; 50 } 51 EmailAddress e = new EmailAddress(); 52 String mailPart; 53 String tmp = input.toLowerCase().trim(); 54 if (tmp.indexOf(" auth=")!=-1) { 55 String [] res = input.trim().split(" "); 56 e.setAuthContext(res[1].trim()); 57 mailPart=res[0].trim(); 58 } else 59 mailPart=input.trim(); 60 61 if (mailPart.indexOf('@') == -1) 62 throw new InvalidAddress(); 63 String [] res = mailPart.split("@"); 64 65 if ((res[0].length() > 512) || (res[1].length() > 512)) 66 throw new InvalidAddress(); 67 68 69 e.setUser(res[0]); 70 e.setHost(res[1].toLowerCase()); 71 return e; 72 } 73 74 77 public String toString() { 78 if (user.equals("<>")) 79 return user; 80 81 return (user + "@" + host); 82 } 83 84 public String getHost() { 85 return host; 86 } 87 88 public void setHost(String host) { 89 this.host = host; 90 } 91 92 public String getUser() { 93 return user; 94 } 95 96 public void setUser(String user) { 97 this.user = user; 98 } 99 100 105 public boolean isEqual(EmailAddress in) { 106 if (in == this) 107 return true; 108 109 if (in.getHost().equals(this.host) && in.getUser().equals(this.user)) 110 return true; 111 112 if (in.getHost().equals(this.host) && in.getUser().equals("*")) 113 return true; 114 115 return false; 116 117 } 118 119 120 121 public int hashCode() { 122 String tmp=host; 123 return tmp.hashCode(); 124 } 125 public boolean equals(Object obj) { 126 if (! (obj instanceof EmailAddress)) 127 return false; 128 return isEqual((EmailAddress)obj); 129 } 130 131 public EmailAddress () { 132 133 } 134 135 public EmailAddress (EmailAddress original) { 136 setHost(new String (original.getHost())); 137 setUser(new String (original.getUser())); 138 } 139 140 141 public String getAuthContext() { 142 return authContext; 143 } 144 145 146 public void setAuthContext(String authContext) { 147 this.authContext = authContext; 148 } 149 } | Popular Tags |