public class MailImpl extends Object implements Disposable, org.apache.mailet.Mail
Wraps a MimeMessage adding routing information (from SMTP) and some simple API enhancements.
From James version > 2.2.0a8 "mail attributes" have been added. Backward and forward compatibility is supported:
Modifier and Type | Field and Description |
---|---|
static long |
serialVersionUID
We hardcode the serialVersionUID so that from James 1.2 on, MailImpl will
be deserializable (so your mail doesn't get lost)
|
Constructor and Description |
---|
MailImpl()
A constructor that creates a new, uninitialized MailImpl
|
MailImpl(org.apache.mailet.Mail mail)
Create a copy of the input mail and assign it a new name
|
MailImpl(org.apache.mailet.Mail mail,
String newName) |
MailImpl(String name,
org.apache.mailet.MailAddress sender,
Collection recipients)
A constructor that creates a MailImpl with the specified name, sender,
and recipients.
|
MailImpl(String name,
org.apache.mailet.MailAddress sender,
Collection recipients,
InputStream messageIn)
A constructor that creates a MailImpl with the specified name, sender,
recipients, and message data.
|
MailImpl(String name,
org.apache.mailet.MailAddress sender,
Collection recipients,
javax.mail.internet.MimeMessage message)
A constructor that creates a MailImpl with the specified name, sender,
recipients, and MimeMessage.
|
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Dispose the object
|
org.apache.mailet.Mail |
duplicate()
Duplicate the MailImpl.
|
org.apache.mailet.Mail |
duplicate(String newName)
Duplicate the MailImpl, replacing the mail name with the one passed in as
an argument.
|
Serializable |
getAttribute(String key) |
Iterator |
getAttributeNames() |
HashMap |
getAttributesRaw()
This method is necessary, when Mail repositories needs to deal explicitly
with storing Mail attributes as a Serializable
|
String |
getErrorMessage()
Get the error message associated with this MailImpl.
|
static String |
getId()
Generate a new identifier/name for a mail being processed by this server.
|
Date |
getLastUpdated()
Get the last updated time for this MailImpl.
|
javax.mail.internet.MimeMessage |
getMessage()
Get the MimeMessage associated with this MailImpl.
|
long |
getMessageSize()
Return the size of the message including its headers.
|
String |
getName()
Get the name of this MailImpl.
|
Collection |
getRecipients()
Get the recipients of this MailImpl.
|
String |
getRemoteAddr()
Get the remote address associated with this MailImpl.
|
String |
getRemoteHost()
Get the remote host associated with this MailImpl.
|
org.apache.mailet.MailAddress |
getSender()
Get the sender of this MailImpl.
|
String |
getState()
Get the state of this MailImpl.
|
boolean |
hasAttributes() |
static String |
newName(org.apache.mailet.Mail mail)
Create a unique new primary key name for the given MailObject.
|
void |
removeAllAttributes() |
Serializable |
removeAttribute(String key) |
Serializable |
setAttribute(String key,
Serializable object) |
void |
setAttributesRaw(HashMap attr)
This method is necessary, when Mail repositories needs to deal explicitly
with retriving Mail attributes as a Serializable
|
void |
setErrorMessage(String msg)
Set the error message associated with this MailImpl.
|
void |
setLastUpdated(Date lastUpdated)
Set the date this mail was last updated.
|
void |
setMessage(javax.mail.internet.MimeMessage message)
Set the MimeMessage associated with this MailImpl.
|
void |
setName(String name)
Set the name of this MailImpl.
|
void |
setRecipients(Collection recipients)
Set the recipients for this MailImpl.
|
void |
setRemoteAddr(String remoteAddr)
Set the remote address associated with this MailImpl.
|
void |
setRemoteHost(String remoteHost)
Set the remote address associated with this MailImpl.
|
void |
setSender(org.apache.mailet.MailAddress sender)
Set the sender of this MailImpl.
|
void |
setState(String state)
Set the state of this MailImpl.
|
void |
writeMessageTo(OutputStream out)
Writes the message out to an OutputStream.
|
public static final long serialVersionUID
public MailImpl()
public MailImpl(String name, org.apache.mailet.MailAddress sender, Collection recipients)
name
- the name of the MailImplsender
- the sender for this MailImplrecipients
- the collection of recipients of this MailImplpublic MailImpl(org.apache.mailet.Mail mail) throws javax.mail.MessagingException
mail
- original mailjavax.mail.MessagingException
- when the message is not clonablepublic MailImpl(org.apache.mailet.Mail mail, String newName) throws javax.mail.MessagingException
mail
- newName
- javax.mail.MessagingException
public MailImpl(String name, org.apache.mailet.MailAddress sender, Collection recipients, InputStream messageIn) throws javax.mail.MessagingException
name
- the name of the MailImplsender
- the sender for this MailImplrecipients
- the collection of recipients of this MailImplmessageIn
- a stream containing the message sourcejavax.mail.MessagingException
public MailImpl(String name, org.apache.mailet.MailAddress sender, Collection recipients, javax.mail.internet.MimeMessage message) throws javax.mail.MessagingException
name
- the name of the MailImplsender
- the sender for this MailImplrecipients
- the collection of recipients of this MailImplmessage
- the MimeMessage associated with this MailImpljavax.mail.MessagingException
public org.apache.mailet.Mail duplicate()
public org.apache.mailet.Mail duplicate(String newName)
newName
- the name for the duplicated mailpublic String getErrorMessage()
getErrorMessage
in interface org.apache.mailet.Mail
public javax.mail.internet.MimeMessage getMessage() throws javax.mail.MessagingException
getMessage
in interface org.apache.mailet.Mail
javax.mail.MessagingException
public void setName(String name)
setName
in interface org.apache.mailet.Mail
name
- the name of this MailImplpublic String getName()
getName
in interface org.apache.mailet.Mail
public Collection getRecipients()
getRecipients
in interface org.apache.mailet.Mail
public org.apache.mailet.MailAddress getSender()
getSender
in interface org.apache.mailet.Mail
public String getState()
getState
in interface org.apache.mailet.Mail
public String getRemoteHost()
getRemoteHost
in interface org.apache.mailet.Mail
public String getRemoteAddr()
getRemoteAddr
in interface org.apache.mailet.Mail
public Date getLastUpdated()
getLastUpdated
in interface org.apache.mailet.Mail
public long getMessageSize() throws javax.mail.MessagingException
Return the size of the message including its headers. MimeMessage.getSize() method only returns the size of the message body.
Note: this size is not guaranteed to be accurate - see Sun's documentation of MimeMessage.getSize().
getMessageSize
in interface org.apache.mailet.Mail
javax.mail.MessagingException
- if a problem occurs while computing the message sizepublic void setErrorMessage(String msg)
setErrorMessage
in interface org.apache.mailet.Mail
msg
- the new error message associated with this MailImplpublic void setMessage(javax.mail.internet.MimeMessage message)
setMessage
in interface org.apache.mailet.Mail
message
- the new MimeMessage associated with this MailImplpublic void setRecipients(Collection recipients)
setRecipients
in interface org.apache.mailet.Mail
recipients
- the recipients for this MailImplpublic void setSender(org.apache.mailet.MailAddress sender)
sender
- the sender of this MailImplpublic void setState(String state)
setState
in interface org.apache.mailet.Mail
state
- the state of this MailImplpublic void setRemoteHost(String remoteHost)
remoteHost
- the new remote host associated with this MailImplpublic void setRemoteAddr(String remoteAddr)
remoteAddr
- the new remote address associated with this MailImplpublic void setLastUpdated(Date lastUpdated)
setLastUpdated
in interface org.apache.mailet.Mail
lastUpdated
- the date the mail was last updatedpublic void writeMessageTo(OutputStream out) throws IOException, javax.mail.MessagingException
out
- the OutputStream to which to write the contentjavax.mail.MessagingException
- if the MimeMessage is not set for this MailImplIOException
- if an error occurs while reading or writing from the streampublic void dispose()
Disposable
dispose
in interface Disposable
Disposable.dispose()
public HashMap getAttributesRaw()
This method is necessary, when Mail repositories needs to deal explicitly with storing Mail attributes as a Serializable
Note: This method is not exposed in the Mail interface, it is for internal use by James only.
public void setAttributesRaw(HashMap attr)
This method is necessary, when Mail repositories needs to deal explicitly with retriving Mail attributes as a Serializable
Note: This method is not exposed in the Mail interface, it is for internal use by James only.
attr
- Serializable of the entire attributes collectionpublic Serializable getAttribute(String key)
getAttribute
in interface org.apache.mailet.Mail
Mail.getAttribute(String)
public Serializable setAttribute(String key, Serializable object)
setAttribute
in interface org.apache.mailet.Mail
Mail.setAttribute(String,Serializable)
public Serializable removeAttribute(String key)
removeAttribute
in interface org.apache.mailet.Mail
Mail.removeAttribute(String)
public void removeAllAttributes()
removeAllAttributes
in interface org.apache.mailet.Mail
Mail.removeAllAttributes()
public Iterator getAttributeNames()
getAttributeNames
in interface org.apache.mailet.Mail
Mail.getAttributeNames()
public boolean hasAttributes()
hasAttributes
in interface org.apache.mailet.Mail
Mail.hasAttributes()
public static String newName(org.apache.mailet.Mail mail) throws javax.mail.MessagingException
mail
- the mail to use as the basis for the new mail namejavax.mail.MessagingException
public static String getId()
Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.