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 thePart
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 theTransport.send
method.
Part
Message.RecipientType This inner class defines the types of recipients allowed by the Message class. |
expunged True if this message has been expunged. | |
folder The containing folder, if this message is obtained from a folder | |
msgnum The number of this message within its folder, or zero if the message was not retrieved from a folder. | |
session The Session object for this Message |
Fields inherited from interface javax.mail.Part |
ATTACHMENT,INLINE |
Message() No-arg version of the constructor. | |
Message(Folder folder, int msgnum) Constructor that takes a Folder and a message number. | |
Message(Session session) Constructor that takes a Session. |
addFrom(Address[] addresses) Add these addresses to the existing "From" attribute | |
addRecipient(Message.RecipientType type,Address address) Add this recipient address to the existing ones of the given type. | |
addRecipients(Message.RecipientType type,Address[] addresses) Add these recipient addresses to the existing ones of the given type. | |
getAllRecipients() Get all the recipient addresses for the message. | |
getFlags() Returns a Flags object containing the flags for this message. | |
getFolder() Get the folder from which this message was obtained. | |
getFrom() Returns the "From" attribute. | |
getMessageNumber() Get the Message number for this Message. | |
getReceivedDate() Get the date this message was received. | |
getRecipients(Message.RecipientType type) Get all the recipient addresses of the given type. | |
getReplyTo() Get the addresses to which replies should be directed. | |
getSentDate() Get the date this message was sent. | |
getSubject() Get the subject of this message. | |
isExpunged() Checks whether this message is expunged. | |
isSet(Flags.Flag flag) Check whether the flag specified in the flag argument is set in this message. | |
match(SearchTerm term) Apply the specified Search criterion to this message. | |
reply(boolean replyToAll) Get a new Message suitable for a reply to this message. | |
saveChanges() Save any changes made to this message into the message-store when the containing folder is closed, if the message is contained in a folder. | |
setExpunged(boolean expunged) Sets the expunged flag for this Message. | |
setFlag(Flags.Flag flag, boolean set) Set the specified flag on this message to the specified value. | |
setFlags(Flags flag, boolean set) Set the specified flags on this message to the specified value. | |
setFrom() Set the "From" attribute in this Message. | |
setFrom(Address address) Set the "From" attribute in this Message. | |
setMessageNumber(int msgnum) Set the Message number for this Message. | |
setRecipient(Message.RecipientType type,Address address) Set the recipient address. | |
setRecipients(Message.RecipientType type,Address[] addresses) Set the recipient addresses. | |
setReplyTo(Address[] addresses) Set the addresses to which replies should be directed. | |
setSentDate(java.util.Date date) Set the sent date of this message. | |
setSubject(java.lang.String subject) Set the subject of this message. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
protected intmsgnum
protected booleanexpunged
protectedFolderfolder
protectedSessionsession
protectedMessage()
protectedMessage(Folder folder, int msgnum)
folder
- containing foldermsgnum
- this message's sequence number within this folderprotectedMessage(Session session)
session
- A Session objectpublic abstractAddress[]getFrom() throwsMessagingException
In certain implementations, this may be different from the entity that actually sent the message.
This method returnsnull
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 voidsetFrom() throwsMessagingException
MessagingException
- IllegalWriteException
- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.public abstract voidsetFrom(Address address) throwsMessagingException
address
- the senderMessagingException
- IllegalWriteException
- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.public abstract voidaddFrom(Address[] addresses) throwsMessagingException
address
- the senderIllegalWriteException
- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public abstractAddress[]getRecipients(Message.RecipientType type) throwsMessagingException
This method returnsnull
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
publicAddress[]getAllRecipients() throwsMessagingException
getRecipients
method.MessagingException
- Message.RecipientType.TO
,Message.RecipientType.CC
,Message.RecipientType.BCC
,getRecipients(javax.mail.Message.RecipientType)
public abstract voidsetRecipients(Message.RecipientType type,Address[] addresses) throwsMessagingException
type
- the recipient typeaddresses
- the addressesMessagingException
- IllegalWriteException
- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.public voidsetRecipient(Message.RecipientType type,Address address) throwsMessagingException
The default implementation uses thesetRecipients
method.
type
- the recipient typeaddress
- the addressMessagingException
- IllegalWriteException
- if the underlying implementation does not support modification of existing valuespublic abstract voidaddRecipients(Message.RecipientType type,Address[] addresses) throwsMessagingException
type
- the recipient typeaddresses
- the addressesMessagingException
- IllegalWriteException
- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.public voidaddRecipient(Message.RecipientType type,Address address) throwsMessagingException
The default implementation uses theaddRecipients
method.
type
- the recipient typeaddress
- the addressMessagingException
- IllegalWriteException
- if the underlying implementation does not support modification of existing valuespublicAddress[]getReplyTo() throwsMessagingException
The default implementation simply calls thegetFrom
method.
This method returnsnull
if the corresponding header is not present. Returns an empty array if the header is present, but contains no addresses.
MessagingException
- getFrom()
public voidsetReplyTo(Address[] addresses) throwsMessagingException
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 isobtained from a READ_ONLY folder.MethodNotSupportedException
- if the underlying implementation does not support setting thisattributepublic abstract java.lang.StringgetSubject() throwsMessagingException
MessagingException
- public abstract voidsetSubject(java.lang.String subject) throwsMessagingException
subject
- the subjectMessagingException
- IllegalWriteException
- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.public abstract java.util.DategetSentDate() throwsMessagingException
MessagingException
- public abstract voidsetSentDate(java.util.Date date) throwsMessagingException
date
- the sent date of this messageMessagingException
- IllegalWriteException
- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.public abstract java.util.DategetReceivedDate() throwsMessagingException
MessagingException
- public abstractFlagsgetFlags() throwsMessagingException
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. UsesetFlags()
to do that.
MessagingException
- Flags
,setFlags(javax.mail.Flags, boolean)
public booleanisSet(Flags.Flag flag) throwsMessagingException
flag
argument is set in this message. The default implementation usesgetFlags
.
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 voidsetFlags(Flags flag, boolean set) throwsMessagingException
Flags
object are unaffected. This will result in aMessageChangedEvent
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 isobtained from a READ_ONLY folder.MessageChangedEvent
public voidsetFlag(Flags.Flag flag, boolean set) throwsMessagingException
MessageChangedEvent
being delivered to any MessageChangedListener registered on this Message's containing folder. The default implementation uses thesetFlags
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 isobtained from a READ_ONLY folder.MessageChangedEvent
public intgetMessageNumber()
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 voidsetMessageNumber(int msgnum)
publicFoldergetFolder()
public booleanisExpunged()
getMessageNumber()
are invalid on an expunged Message object. Messages that are expunged due to an explictexpunge()
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 explicitexpunge()
is done on the Folder.
See the description ofexpunge()
for more details on expunge handling.
Folder.expunge()
protected voidsetExpunged(boolean expunged)
expunged
- the expunged flagpublic abstractMessagereply(boolean replyToAll) throwsMessagingException
IfreplyToAll
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 thegetReplyTo
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 recipientsof this messageMessagingException
- public abstract voidsaveChanges() throwsMessagingException
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 isobtained from a READ_ONLY folder.IllegalWriteException
- if the underlying implementation does not support modification of existing values.public booleanmatch(SearchTerm term) throwsMessagingException
term
- the Search criterionMessagingException
- SearchTerm