org.clapper.util.mail
Class EmailAddress

java.lang.Object
  extended by org.clapper.util.mail.EmailAddress
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable

public class EmailAddress
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable

This class encodes an RFC822-compliant email address is a simplified container, hiding the gory details of the underlying Java Mail API.

Version:
$Revision: 6735 $
Author:
Copyright © 2004-2007 Brian M. Clapper
See Also:
EmailMessage

Constructor Summary
EmailAddress(EmailAddress emailAddress)
          Constructs a new copy of an existing EmailMessage object.
EmailAddress(java.lang.String address)
          Constructs a new EmailMessage object from an email address string.
 
Method Summary
 java.lang.Object clone()
          Clone this object.
 int compareTo(java.lang.Object obj)
          Compare two email addresses.
 boolean equals(java.lang.Object obj)
          Determine whether this email address is equivalent to another email address, by comparing the normalized address strings.
 java.lang.String getAddress()
          Get the RFC822-compliant email address string associated with this EmailAddress object.
 java.lang.String getPersonalName()
          Get the user friend personal name associated with this EmailAddress object.
 int hashCode()
          Get the hash code for this object.
static int parse(java.lang.String s, java.util.Collection<EmailAddress> collection)
          Parse a sequence of comma-separated email addresses into individual EmailAddress objects, enforcing strict Internet RFC822 email address syntax requirements.
 java.lang.String toString()
          Convert this object into an RFC822-compliant email address.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EmailAddress

public EmailAddress(java.lang.String address)
             throws EmailException
Constructs a new EmailMessage object from an email address string. The address string can be any RFC822-compliant email address. Examples include:
 renoir@example.com
 Pierre Auguste Renoir 
 "Pierre Auguste Renoir" 
 renoir@example.com (Pierre Auguste Renoir)
 
The @domain portion must be present.

Parameters:
address - the address
Throws:
EmailException - bad email address

EmailAddress

public EmailAddress(EmailAddress emailAddress)
             throws EmailException
Constructs a new copy of an existing EmailMessage object.

Parameters:
emailAddress - The EmailMessage object to copy
Throws:
EmailException - bad email address
Method Detail

equals

public boolean equals(java.lang.Object obj)
Determine whether this email address is equivalent to another email address, by comparing the normalized address strings.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the other email address. Must be an EmailAddress object.
Returns:
true if the addresses are equivalent, false otherwise

hashCode

public int hashCode()
Get the hash code for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

compareTo

public int compareTo(java.lang.Object obj)
Compare two email addresses.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - the other email address. Must be an EmailAddress object.
Returns:
A negative number if this email address is lexicographically less than obj; 0 if the two addresses are equivalent; a postive number if this email address is lexicographically greater than obj.

getAddress

public java.lang.String getAddress()
Get the RFC822-compliant email address string associated with this EmailAddress object.

Returns:
the email address string. This method will never return null
See Also:
getPersonalName()

getPersonalName

public java.lang.String getPersonalName()
Get the user friend personal name associated with this EmailAddress object.

Returns:
the personal name, or null if not present
See Also:
getAddress()

parse

public static int parse(java.lang.String s,
                        java.util.Collection<EmailAddress> collection)
                 throws EmailException
Parse a sequence of comma-separated email addresses into individual EmailAddress objects, enforcing strict Internet RFC822 email address syntax requirements. The resulting EmailAddress objects are stored in a supplied Collection.

Parameters:
s - comma-separated address strings
collection - where to stored the parsed EmailAddress objects
Returns:
the number of addresses parsed from the string
Throws:
EmailException - if a bad address is encountered

toString

public java.lang.String toString()
Convert this object into an RFC822-compliant email address.

Overrides:
toString in class java.lang.Object
Returns:
the email address

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone this object.

Overrides:
clone in class java.lang.Object
Returns:
the clone
Throws:
java.lang.CloneNotSupportedException


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.