org.jcoderz.commons.types
Class EmailAddress

java.lang.Object
  extended by org.jcoderz.commons.types.EmailAddress
All Implemented Interfaces:
Serializable

public class EmailAddress
extends Object
implements Serializable

This class represents an email addresses compliant to RFC 2822, chapter 3.4.1. Addr-spec specification. This class does not support obsolete addressing (see ch. 4.4. Obsolete Addressing).

 atext           =       ALPHA / DIGIT / ; Any character except controls,
                         "!" / "#" /     ;  SP, and specials.
                         "$" / "%" /     ;  Used for atoms
                         "&" / "'" /
                         "*" / "+" /
                         "-" / "/" /
                         "=" / "?" /
                         "^" / "_" /
                         "`" / "{" /
                         "|" / "}" /
                         "~"
 atom            =       [CFWS] 1*atext [CFWS]
 dot-atom        =       [CFWS] dot-atom-text [CFWS]
 dot-atom-text   =       1*atext *("." 1*atext)
 addr-spec       = local-part "@" domain
 local-part      = dot-atom / quoted-string
 qtext           =       NO-WS-CTL /     ; Non white space controls
                         %d33 /          ; The rest of the US-ASCII
                         %d35-91 /       ;  characters not including "\"
                         %d93-126        ;  or the quote character
 qcontent        =       qtext / quoted-pair
 quoted-string   = [CFWS]
                   DQUOTE *([FWS] qcontent) [FWS] DQUOTE
                   [CFWS]
 domain          = dot-atom / domain-literal
 domain-literal  = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS]
 dcontent        = dtext / quoted-pair
 dtext           = NO-WS-CTL /     ; Non white space controls
                   %d33-90 /       ; The rest of the US-ASCII
                   %d94-126        ;  characters not including "[",
                                   ;  "]", or "\"
 FWS             =       ([*WSP CRLF] 1*WSP) /   ; Folding white space
                         obs-FWS
 ctext           =       NO-WS-CTL /     ; Non white space controls
                         %d33-39 /       ; The rest of the US-ASCII
                         %d42-91 /       ;  characters not including "(",
                         %d93-126        ;  ")", or "\"
 ccontent        =       ctext / quoted-pair / comment
 comment         =       "(" *([FWS] ccontent) [FWS] ")"
 CFWS            =       *([FWS] comment) (([FWS] comment) / FWS)
 

The maximum length of an email address is: 64+1+255 characters (local-part + @ + domain). The minimum length of an email address is: 1+1+4 characters (local-part + @ + domain).

A valid list of top-level domains is defined by the IANA. A top-level domain which is not part of the official list will be rejected.

Author:
Michael Rumpf
See Also:
Serialized Form

Constructor Summary
EmailAddress(String email)
          This is the constructor of the EmailAddress type.
 
Method Summary
 boolean equals(Object obj)
          Returns the true if this email address equals the other.
static EmailAddress fromString(String email)
          Factory method for converting a String into an instance of type EmailAddress.
 String getAddress()
          Returns the full email address.
 String getDomain()
          Returns the domain name of the address.
 String getName()
          Returns the local part of the address.
 String getTopLevelDomain()
          Returns the top-level domain name of the address.
 int hashCode()
          Returns the hash code for this email.
 String toString()
          Returns the full email address.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EmailAddress

public EmailAddress(String email)
This is the constructor of the EmailAddress type.

Parameters:
email - The email address.
Method Detail

fromString

public static EmailAddress fromString(String email)
Factory method for converting a String into an instance of type EmailAddress.

Parameters:
email - the email address to parse
Returns:
An instance of type EmailAddress

getName

public String getName()
Returns the local part of the address.

Returns:
the local part of the address.

getDomain

public String getDomain()
Returns the domain name of the address.

Returns:
the domain name of the address.

getTopLevelDomain

public String getTopLevelDomain()
Returns the top-level domain name of the address.

Returns:
the top-level domain name of the address.

getAddress

public String getAddress()
Returns the full email address.

Returns:
the full email address.

toString

public String toString()
Returns the full email address.

Overrides:
toString in class Object
Returns:
the full email address.

equals

public boolean equals(Object obj)
Returns the true if this email address equals the other.

Overrides:
equals in class Object
Parameters:
obj - the object to compare to.
Returns:
the true if this email address equals the other.
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Returns the hash code for this email.

Overrides:
hashCode in class Object
Returns:
the hash code for this email.


Copyright 2007 The jCoderZ Project.