java.lang.Object | +--javax.mail.Message
This class models an email message. This is an abstract class. Subclasses provide actual implementations.
Message implements the Part interface. Message contains a set of attributes and a "content". Messages within a folder also have a set of flags that describe its state within the folder.
Message defines some new attributes in addition to those defined
in the Part
interface. These attributes specify meta-data
for the message - i.e., addressing and descriptive information about
the message.
Message objects are obtained either from a Folder or by constructing a new Message object of the appropriate subclass. Messages that have been received are normally retrieved from a folder named "INBOX".
A Message object obtained from a folder is just a lightweight
reference to the actual message. The Message is 'lazily' filled
up (on demand) when each item is requested from the message. Note
that certain folder implementations may return Message objects that
are pre-filled with certain user-specified items.
To send a message, an appropriate subclass of Message (e.g.,
MimeMessage) is instantiated, the attributes and content are
filled in, and the message is sent using the Transport.send
method.
Part
static class
Message.RecipientType
protected int
msgnum
void
addRecipient(Message.RecipientType type,
Address address)
abstract void
addRecipients(Message.RecipientType type,
Address[] addresses)
abstract Address[]
getRecipients(Message.RecipientType type)
boolean
isSet(Flags.Flag flag)
flag
argument is set in this message.
abstract void
saveChanges()
void
setFlag(Flags.Flag flag,
boolean set)
abstract void
setFlags(Flags flag,
boolean set)
abstract void
setRecipients(Message.RecipientType type,
Address[] addresses)
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addHeader, getAllHeaders, getContent, getContentType, getDataHandler, getDescription, getDisposition, getFileName, getHeader, getInputStream, getLineCount, getMatchingHeaders, getNonMatchingHeaders, getSize, isMimeType, removeHeader, setContent, setContent, setDataHandler, setDescription, setDisposition, setFileName, setHeader, setText, writeTo
protected int msgnum
protected boolean expunged
protected Folder folder
protected Session session
protected Message()
protected Message(Folder folder, int msgnum)
folder
- containing foldermsgnum
- this message's sequence number within this folderprotected Message(Session session)
session
- A Session objectpublic abstract Address[] getFrom() throws MessagingException
In certain implementations, this may be different from the entity that actually sent the message.
This method returns null
if this attribute
is not present in this message. Returns an empty array if
this attribute is present, but contains no addresses.
MessagingException
- public abstract void setFrom() throws MessagingException
MessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.public abstract void setFrom(Address address) throws MessagingException
address
- the senderMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.public abstract void addFrom(Address[] addresses) throws MessagingException
address
- the senderIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public abstract Address[] getRecipients(Message.RecipientType type) throws MessagingException
This method returns null
if the header for
the given type is not present in this message. Returns an
empty array if the header is present, but contains no addresses.
type
- the recipient typeMessagingException
- Message.RecipientType.TO
,
Message.RecipientType.CC
,
Message.RecipientType.BCC
public Address[] getAllRecipients() throws MessagingException
getRecipients
method.MessagingException
- Message.RecipientType.TO
,
Message.RecipientType.CC
,
Message.RecipientType.BCC
,
getRecipients(javax.mail.Message.RecipientType)
public abstract void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
type
- the recipient typeaddresses
- the addressesMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.public void setRecipient(Message.RecipientType type, Address address) throws MessagingException
The default implementation uses the setRecipients
method.
type
- the recipient typeaddress
- the addressMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuespublic abstract void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
type
- the recipient typeaddresses
- the addressesMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.public void addRecipient(Message.RecipientType type, Address address) throws MessagingException
The default implementation uses the addRecipients
method.
type
- the recipient typeaddress
- the addressMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuespublic Address[] getReplyTo() throws MessagingException
The default implementation simply calls the getFrom
method.
This method returns null
if the corresponding
header is not present. Returns an empty array if the header
is present, but contains no addresses.
MessagingException
- getFrom()
public void setReplyTo(Address[] addresses) throws MessagingException
The default implementation provided here just throws the MethodNotSupportedException.
addresses
- addresses to which replies should be directedMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MethodNotSupportedException
- if the underlying
implementation does not support setting this
attributepublic abstract java.lang.String getSubject() throws MessagingException
MessagingException
- public abstract void setSubject(java.lang.String subject) throws MessagingException
subject
- the subjectMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.public abstract java.util.Date getSentDate() throws MessagingException
MessagingException
- public abstract void setSentDate(java.util.Date date) throws MessagingException
date
- the sent date of this messageMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.public abstract java.util.Date getReceivedDate() throws MessagingException
MessagingException
- public abstract Flags getFlags() throws MessagingException
Flags
object containing the flags for
this message.
Modifying any of the flags in this returned Flags object will
not affect the flags of this message. Use setFlags()
to do that.
MessagingException
- Flags
,
setFlags(javax.mail.Flags, boolean)
public boolean isSet(Flags.Flag flag) throws MessagingException
flag
argument is set in this message.
The default implementation uses getFlags
.
flag
- the flagMessagingException
- Flags.Flag
,
Flags.Flag.ANSWERED
,
Flags.Flag.DELETED
,
Flags.Flag.DRAFT
,
Flags.Flag.FLAGGED
,
Flags.Flag.RECENT
,
Flags.Flag.SEEN
public abstract void setFlags(Flags flag, boolean set) throws MessagingException
Flags
object are unaffected.
This will result in a MessageChangedEvent
being
delivered to any MessageChangedListener registered on this
Message's containing folder.
flag
- Flags object containing the flags to be setset
- the value to be setMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing values.java.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessageChangedEvent
public void setFlag(Flags.Flag flag, boolean set) throws MessagingException
MessageChangedEvent
being
delivered to any MessageChangedListener registered on this
Message's containing folder.
The default implementation uses the setFlags
method.
flag
- Flags.Flag object containing the flag to be setset
- the value to be setMessagingException
- IllegalWriteException
- if the underlying
implementation does not support modification
of existing values.java.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessageChangedEvent
public int getMessageNumber()
Valid message numbers start at 1. Messages that do not belong to any folder (like newly composed or derived messages) have 0 as their message number.
protected void setMessageNumber(int msgnum)
public Folder getFolder()
public boolean isExpunged()
getMessageNumber()
are invalid on an expunged
Message object.
Messages that are expunged due to an explict expunge()
request on the containing Folder are removed from the Folder
immediately. Messages that are externally expunged by another source
are marked "expunged" and return true for the isExpunged() method,
but they are not removed from the Folder until an explicit
expunge()
is done on the Folder.
See the description of expunge()
for more details on
expunge handling.
Folder.expunge()
protected void setExpunged(boolean expunged)
expunged
- the expunged flagpublic abstract Message reply(boolean replyToAll) throws MessagingException
If replyToAll
is set, the new Message will be addressed
to all recipients of this message. Otherwise, the reply will be
addressed to only the sender of this message (using the value
of the getReplyTo
method).
The "Subject" field is filled in with the original subject prefixed with "Re:" (unless it already starts with "Re:").
The reply message will use the same session as this message.
replyToAll
- reply should be sent to all recipients
of this messageMessagingException
- public abstract void saveChanges() throws MessagingException
Messages obtained from folders opened READ_ONLY should not be modified and saveChanges should not be called on such messages.
MessagingException
- java.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.IllegalWriteException
- if the underlying
implementation does not support modification
of existing values.public boolean match(SearchTerm term) throws MessagingException
term
- the Search criterionMessagingException
- SearchTerm