|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.mailet.MailAddress
public class MailAddress
A representation of an email address.
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
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(javax.mail.internet.InternetAddress address)
Constructs a MailAddress from an InternetAddress, using only the email address portion (an "addr-spec", not "name-addr", as defined in the RFC2822 3.4. |
|
MailAddress(java.lang.String address)
Constructs a MailAddress by parsing the provided address. |
|
MailAddress(java.lang.String localPart,
java.lang.String domain)
Constructs a MailAddress with the provided local part and domain. |
Method Summary | |
---|---|
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. |
java.lang.String |
getDomain()
Returns the domain part per RFC2822 3.4.1. |
java.lang.String |
getHost()
Deprecated. use getDomain() , whose name was changed to
align with RFC2822 3.4.1. addr-spec specification |
java.lang.String |
getLocalPart()
Returns the local-part per RFC2822 3.4.1. |
java.lang.String |
getUser()
Deprecated. use getLocalPart() , whose name was changed to
align with the RFC2822 3.4.1. addr-spec specification |
int |
hashCode()
Returns a hash code value for this object. |
javax.mail.internet.InternetAddress |
toInternetAddress()
Returns an InternetAddress representing the same address as this MailAddress. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final long serialVersionUID
Constructor Detail |
---|
public MailAddress(java.lang.String address) throws javax.mail.internet.AddressException
address
- the email address, compliant to the RFC2822 3.4.1. addr-spec specification
javax.mail.internet.AddressException
- if the parse failedpublic MailAddress(java.lang.String localPart, java.lang.String domain) throws javax.mail.internet.AddressException
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 specification
javax.mail.internet.AddressException
- if the parse failedpublic MailAddress(javax.mail.internet.InternetAddress address) throws javax.mail.internet.AddressException
address
- the address
javax.mail.internet.AddressException
- if the parse failedMethod Detail |
---|
public java.lang.String getHost()
getDomain()
, whose name was changed to
align with RFC2822 3.4.1. addr-spec specification
public java.lang.String getDomain()
public java.lang.String getUser()
getLocalPart()
, whose name was changed to
align with the RFC2822 3.4.1. addr-spec specification
public java.lang.String getLocalPart()
public java.lang.String toString()
toString
in class java.lang.Object
public javax.mail.internet.InternetAddress toInternetAddress()
public boolean equals(java.lang.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.
equals
in class java.lang.Object
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.
hashCode
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |