public class MailAddress extends Object
This class encapsulates functionality to access 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 <mailbox>
,
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 the 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
Constructor and Description |
---|
MailAddress(String address)
Constructs a MailAddress by parsing the provided address.
|
MailAddress(String localPart,
String domain)
Constructs a MailAddress with the provided local part and domain.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
String |
getDomain()
Returns the domain part per RFC2822 3.4.1.
|
String |
getLocalPart()
Returns the local-part per RFC2822 3.4.1.
|
int |
hashCode()
Returns a hash code value for this object.
|
boolean |
isNullSender()
Return
true if the MailAddress should represent a null sender (<>) |
static MailAddress |
nullSender() |
String |
toString() |
public MailAddress(String address) throws MailAddressException
address
- the email address, compliant to the RFC2822 3.4.1. addr-spec specificationMailAddressException
- if the parse failedpublic MailAddress(String localPart, String domain) throws MailAddressException
localPart
- the local-part portion. This 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. This identifies the point to which the mail
is delivered per RFC2822 3.4.1. addr-spec specificationAddressException
- if the parse failedMailAddressException
public static MailAddress nullSender()
public String getDomain()
public String getLocalPart()
public boolean equals(Object obj)
equals
method by allowing an instance to equal to a
String
. It is recommended that implementations avoid
relying on this design which may be removed in a future release.public int hashCode()
This method is implemented by returning the hash code of the canonical string representation of this address, so that all instances representing the same address will return an identical hash code.
public boolean isNullSender()
true
if the MailAddress
should represent a null sender (<>)Copyright © 2010-2012 The Apache Software Foundation. All Rights Reserved.