public abstract class Message extends java.lang.Object implements Part
A message is retrieved from a folder, and is normally a lightweight object that retrieves its properties on demand. Fetch profiles may be used to prefetch certain properties of a message.
To send a message, an appropriate subclsass is instantiated, its
properties set, and it is then delivered via a transport using the
Transport.sendMessage
method.
Part
Modifier and Type | Class and Description |
---|---|
static class |
Message.RecipientType
The types of recipients to which a message can be sent.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
expunged
True if this message has been expunged.
|
protected Folder |
folder
The containing folder.
|
protected int |
msgnum
The number of this message within its folder, starting from 1,
or 0 if the message was not retrieved from a folder.
|
protected Session |
session
The session in scope for this message.
|
ATTACHMENT, INLINE
Modifier | Constructor and Description |
---|---|
protected |
Message()
Constructor with no folder or session.
|
protected |
Message(Folder folder,
int msgnum)
Constructor with a folder and a message number.
|
protected |
Message(Session session)
Constructor with a session.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
addFrom(Address[] addresses)
Adds addresses to the identity of the person sending this message.
|
void |
addRecipient(Message.RecipientType type,
Address address)
Adds the recipient address of the given type.
|
abstract void |
addRecipients(Message.RecipientType type,
Address[] addresses)
Adds the recipient addresses of the given type.
|
Address[] |
getAllRecipients()
Returns all the recipient addresses in the message.
|
abstract Flags |
getFlags()
Returns the flags for this message.
|
Folder |
getFolder()
Returns the folder from which this message was obtained.
|
abstract Address[] |
getFrom()
Returns the identity of the person(s) who ordered the sending of
this message.
|
int |
getMessageNumber()
Returns the message number for this message within its folder.
|
abstract java.util.Date |
getReceivedDate()
Returns the date this message was received.
|
abstract Address[] |
getRecipients(Message.RecipientType type)
Returns all the recipient addresses of the specified type.
|
Address[] |
getReplyTo()
Returns the addresses to which replies should be directed.
|
abstract java.util.Date |
getSentDate()
Returns the date this message was sent.
|
Session |
getSession()
Returns the session in use when the message was created.
|
abstract java.lang.String |
getSubject()
Returns the subject of this message.
|
boolean |
isExpunged()
Indicates whether this message is expunged.
|
boolean |
isSet(Flags.Flag flag)
Indicates whether the specified flag is set in this message.
|
boolean |
match(SearchTerm term)
Indicates whether the specified search term applies to this message.
|
abstract Message |
reply(boolean replyToAll)
Returns a new message suitable for a reply to this message.
|
abstract void |
saveChanges()
Save any changes made to this message into its underlying store, if
the message was obtained from a folder.
|
protected void |
setExpunged(boolean expunged)
Sets the expunged flag for this message.
|
void |
setFlag(Flags.Flag flag,
boolean set)
Sets the specified flag on this message to the given value.
|
abstract void |
setFlags(Flags flag,
boolean set)
Sets the specified flags on this message to the given value.
|
abstract void |
setFrom()
Sets the identity of the person sending this message, as obtained
from the property "mail.user".
|
abstract void |
setFrom(Address address)
Sets the identity of the person sending this message.
|
protected void |
setMessageNumber(int msgnum)
Sets the message number for this message.
|
void |
setRecipient(Message.RecipientType type,
Address address)
Sets the recipient address of the specified type.
|
abstract void |
setRecipients(Message.RecipientType type,
Address[] addresses)
Sets the recipient addresses of the specified type.
|
void |
setReplyTo(Address[] addresses)
Sets the addresses to which replies should be directed.
|
abstract void |
setSentDate(java.util.Date date)
Sets the date this message was sent.
|
abstract void |
setSubject(java.lang.String subject)
Sets the subject of this message.
|
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
- the containing foldermsgnum
- the sequence number within the folderprotected Message(Session session)
session
- the session in scopepublic Session getSession()
public abstract Address[] getFrom() throws MessagingException
In certain implementations, this may be different from the entity that actually sent the message.
MessagingException
public abstract void setFrom() throws MessagingException
IllegalWriteException
- if the underlying implementation does
not support modification of existing valuesjava.lang.IllegalStateException
- if this message is obtained from a
READ_ONLY folderMessagingException
public abstract void setFrom(Address address) 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 void addFrom(Address[] addresses) throws MessagingException
addresses
- the sendersIllegalWriteException
- 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
type
- the recipient typeMessagingException
public Address[] getAllRecipients() throws MessagingException
MessagingException
public abstract void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
type
- the recipient typeaddresses
- the addressesIllegalWriteException
- 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 void setRecipient(Message.RecipientType type, Address address) throws MessagingException
IllegalWriteException
- if the underlying implementation
does not support modification of existing valuesMessagingException
public abstract void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
type
- the recipient typeaddresses
- the addressesIllegalWriteException
- 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 void addRecipient(Message.RecipientType type, Address address) throws MessagingException
IllegalWriteException
- if the underlying implementation
does not support modification of existing valuesMessagingException
public Address[] getReplyTo() throws MessagingException
MessagingException
public void setReplyTo(Address[] addresses) throws MessagingException
MessagingException
public abstract java.lang.String getSubject() throws MessagingException
MessagingException
public abstract void setSubject(java.lang.String subject) throws MessagingException
subject
- the subjectIllegalWriteException
- 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 java.util.Date getSentDate() throws MessagingException
MessagingException
public abstract void setSentDate(java.util.Date date) throws MessagingException
date
- the sent date of this messageIllegalWriteException
- 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 java.util.Date getReceivedDate() throws MessagingException
MessagingException
public abstract Flags getFlags() throws MessagingException
Modifying any of these flags does not affect the message flags.
Use the setFlags
method to change the message's flags.
MessagingException
public boolean isSet(Flags.Flag flag) throws MessagingException
flag
- the flagMessagingException
public abstract void setFlags(Flags flag, boolean set) throws MessagingException
flag
- the flags to be setset
- the value to be setIllegalWriteException
- 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 void setFlag(Flags.Flag flag, boolean set) throws MessagingException
flag
- the flag to be setset
- the value to be setIllegalWriteException
- 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 int getMessageNumber()
msgnum
protected void setMessageNumber(int msgnum)
msgnum
public Folder getFolder()
public boolean isExpunged()
Folder.expunge()
protected void setExpunged(boolean expunged)
public abstract Message reply(boolean replyToAll) throws MessagingException
The subject field is filled in with the original subject prefixed with "Re:" (unless it already starts with "Re:").
replyToAll
- if the reply should be sent to all recipients of
this messageMessagingException
public abstract void saveChanges() throws MessagingException
This method ensures that any header fields are consistent with the changed message contents.
IllegalWriteException
- 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 boolean match(SearchTerm term) throws MessagingException
term
- the search termMessagingException