org.apache.mailet
Class MailAddress
java.lang.Object
org.apache.mailet.MailAddress
- All Implemented Interfaces:
- Serializable
- public class MailAddress
- extends Object
- implements Serializable
A representation of an email address.
This class encapsulates functionalities to access to different
parts of an email address without dealing with its parsing.
A MailAddress is an address specified in the MAIL FROM and
RCPT TO commands in SMTP sessions. These are either passed by
an external server to the mailet-compliant SMTP server, or they
are created programmatically by the mailet-compliant server to
send to another (external) SMTP server. Mailets and matchers
use the MailAddress for the purpose of evaluating the sender
and recipient(s) of a message.
MailAddress parses an email address as defined in RFC 821
(SMTP) p. 30 and 31 where addresses are defined in BNF convention.
As the mailet API does not support the aged "SMTP-relayed mail"
addressing protocol, this leaves all addresses to be a ,
as per the spec.
This class is a good way to validate email addresses as there are
some valid addresses which would fail with a simpler approach
to parsing address. It also removes parsing burden from
mailets and matchers that might not realize the flexibility of an
SMTP address. For instance, "serge@home"@lokitech.com is a valid
SMTP address (the quoted text serge@home is the local-part and
lokitech.com is the domain). This means all current parsing to date
is incorrect as we just find the first @ and use that to separate
local-part from domain.
This parses an address as per the BNF specification for
from RFC 821 on page 30 and 31, section 4.1.2. COMMAND SYNTAX.
http://www.freesoft.org/CIE/RFC/821/15.htm
- Version:
- 1.0
- See Also:
- Serialized Form
Field Summary |
static long |
serialVersionUID
We hardcode the serialVersionUID
This version (2779163542539434916L) retains compatibility back to Mailet version 1.2 (James 1.2) so that MailAddress will be deserializable and mail doesn't get lost after an upgrade. |
Constructor Summary |
MailAddress(InternetAddress address)
Constructs a MailAddress from a JavaMail InternetAddress, using only the
email address portion, discarding the personal name. |
MailAddress(String address)
Construct a MailAddress parsing the provided String object. |
MailAddress(String localPart,
String domain)
Construct a MailAddress with the provided personal name and email
address. |
serialVersionUID
public static final long serialVersionUID
- We hardcode the serialVersionUID
This version (2779163542539434916L) retains compatibility back to Mailet version 1.2 (James 1.2) so that MailAddress will be deserializable and mail doesn't get lost after an upgrade.
- See Also:
- Constant Field Values
MailAddress
public MailAddress(String address)
throws AddressException
Construct a MailAddress parsing the provided String
object.
The personal
variable is left empty.
- Parameters:
address
- the email address compliant to the RFC2822 3.4.1. Addr-spec specification
- Throws:
AddressException
- if the parse failed
MailAddress
public MailAddress(String localPart,
String domain)
throws AddressException
- Construct a MailAddress with the provided personal name and email
address.
- Parameters:
localPart
- The local-part portion is a domain dependent string. In addresses, it is simply interpreted on the particular host as a name of a particular mailbox. per RFC2822 3.4.1. Addr-spec specificationdomain
- The domain portion identifies the point to which the mail is delivered per RFC2822 3.4.1. Addr-spec specification
- Throws:
AddressException
- if the parse failed
MailAddress
public MailAddress(InternetAddress address)
throws AddressException
- Constructs a MailAddress from a JavaMail InternetAddress, using only the
email address portion, discarding the personal name. (an "addr-spec" not a "name-addr" as defined in RFC2822 3.4. Address Specification
- Parameters:
address
-
- Throws:
AddressException
getHost
public String getHost()
- Deprecated. use getDomain() - name change to align with RFC2822 3.4.1. Addr-spec specification
- Return the host part.
- Returns:
- a
String
object representing the host part
of this email address. If the host is of the dotNum form
(e.g. [yyy.yyy.yyy.yyy]) then strip the braces first.
getDomain
public String getDomain()
- Return the domain part per RFC2822 3.4.1. Addr-spec specification
- Returns:
- a
String
object representing the domain part
of this email address. If the domain is of the domain-literal form (e.g. [yyy.yyy.yyy.yyy]) the braces will have been stripped returning the raw IP address.
getUser
public String getUser()
- Deprecated. use getLocalPart() - name change to align with RFC2822 3.4.1. Addr-spec specification
- Return the user part.
- Returns:
- a
String
object representing the user part
of this email address.
- Throws:
AddressException
- if the parse failed
getLocalPart
public String getLocalPart()
- Return the local-part per RFC2822 3.4.1. Addr-spec specification
- Returns:
- a
String
object representing the local-part
of this email address as defined by RFC2822 3.4.1. Addr-spec specification.
The local-part portion is a domain dependent string. In addresses, it is simply interpreted on the particular host as a name of a particular mailbox.
It is the part before the "@"
- Throws:
AddressException
- if the parse failed
toString
public String toString()
toInternetAddress
public InternetAddress toInternetAddress()
- Return MailAddress as InternetAddress
- Returns:
- the address
equals
public boolean equals(Object obj)
hashCode
public int hashCode()
- Return a hashCode for this object which should be identical for addresses
which are equivalent. This is implemented by obtaining the default
hashcode of the String representation of the MailAddress. Without this
explicit definition, the default hashCode will create different hashcodes
for separate object instances.
- Returns:
- the hashcode.
Copyright (c) 2008 Apache Software Foundation Apache 2.0 Licensed.