javax.mail

Class Message

public abstract class Message extends Object implements Part

An abstract mail message, consisting of headers and content.

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.

Version: 1.3

Author: Chris Burdess

See Also: Part

Nested Class Summary
static classMessage.RecipientType
The types of recipients to which a message can be sent.
Field Summary
protected booleanexpunged
True if this message has been expunged.
protected Folderfolder
The containing folder.
protected intmsgnum
The number of this message within its folder, starting from 1, or 0 if the message was not retrieved from a folder.
protected Sessionsession
The session in scope for this message.
Constructor Summary
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.
Method Summary
abstract voidaddFrom(Address[] addresses)
Adds addresses to the identity of the person sending this message.
voidaddRecipient(Message.RecipientType type, Address address)
Adds the recipient address of the given type.
abstract voidaddRecipients(Message.RecipientType type, Address[] addresses)
Adds the recipient addresses of the given type.
Address[]getAllRecipients()
Returns all the recipient addresses in the message.
abstract FlagsgetFlags()
Returns the flags for this message.
FoldergetFolder()
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.
intgetMessageNumber()
Returns the message number for this message within its folder.
abstract DategetReceivedDate()
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 DategetSentDate()
Returns the date this message was sent.
abstract StringgetSubject()
Returns the subject of this message.
booleanisExpunged()
Indicates whether this message is expunged.
booleanisSet(Flags.Flag flag)
Indicates whether the specified flag is set in this message.
booleanmatch(SearchTerm term)
Indicates whether the specified search term applies to this message.
abstract Messagereply(boolean replyToAll)
Returns a new message suitable for a reply to this message.
abstract voidsaveChanges()
Save any changes made to this message into its underlying store, if the message was obtained from a folder.
protected voidsetExpunged(boolean expunged)
Sets the expunged flag for this message.
voidsetFlag(Flags.Flag flag, boolean set)
Sets the specified flag on this message to the given value.
abstract voidsetFlags(Flags flag, boolean set)
Sets the specified flags on this message to the given value.
abstract voidsetFrom()
Sets the identity of the person sending this message, as obtained from the property "mail.user".
abstract voidsetFrom(Address address)
Sets the identity of the person sending this message.
protected voidsetMessageNumber(int msgnum)
Sets the message number for this message.
voidsetRecipient(Message.RecipientType type, Address address)
Sets the recipient address of the specified type.
abstract voidsetRecipients(Message.RecipientType type, Address[] addresses)
Sets the recipient addresses of the specified type.
voidsetReplyTo(Address[] addresses)
Sets the addresses to which replies should be directed.
abstract voidsetSentDate(Date date)
Sets the date this message was sent.
abstract voidsetSubject(String subject)
Sets the subject of this message.

Field Detail

expunged

protected boolean expunged
True if this message has been expunged.

folder

protected Folder folder
The containing folder.

msgnum

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.

session

protected Session session
The session in scope for this message.

Constructor Detail

Message

protected Message()
Constructor with no folder or session.

Message

protected Message(Folder folder, int msgnum)
Constructor with a folder and a message number. Used by folder implementations.

Parameters: folder the containing folder msgnum the sequence number within the folder

Message

protected Message(Session session)
Constructor with a session. Used to create messages for sending.

Parameters: session the session in scope

Method Detail

addFrom

public abstract void addFrom(Address[] addresses)
Adds addresses to the identity of the person sending this message.

Parameters: addresses the senders

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder.

addRecipient

public void addRecipient(Message.RecipientType type, Address address)
Adds the recipient address of the given type.

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values

addRecipients

public abstract void addRecipients(Message.RecipientType type, Address[] addresses)
Adds the recipient addresses of the given type.

Parameters: type the recipient type addresses the addresses

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder.

getAllRecipients

public Address[] getAllRecipients()
Returns all the recipient addresses in the message.

getFlags

public abstract Flags getFlags()
Returns the flags for this message.

Modifying any of these flags does not affect the message flags. Use the setFlags method to change the message's flags.

getFolder

public Folder getFolder()
Returns the folder from which this message was obtained.

getFrom

public abstract Address[] getFrom()
Returns the identity of the person(s) who ordered the sending of this message.

In certain implementations, this may be different from the entity that actually sent the message.

getMessageNumber

public int getMessageNumber()
Returns the message number for this message within its folder.

See Also: msgnum

getReceivedDate

public abstract Date getReceivedDate()
Returns the date this message was received.

getRecipients

public abstract Address[] getRecipients(Message.RecipientType type)
Returns all the recipient addresses of the specified type.

Parameters: type the recipient type

getReplyTo

public Address[] getReplyTo()
Returns the addresses to which replies should be directed. This defaults to the sender of the message.

getSentDate

public abstract Date getSentDate()
Returns the date this message was sent.

getSubject

public abstract String getSubject()
Returns the subject of this message.

isExpunged

public boolean isExpunged()
Indicates whether this message is expunged.

See Also: Folder

isSet

public boolean isSet(Flags.Flag flag)
Indicates whether the specified flag is set in this message.

Parameters: flag the flag

match

public boolean match(SearchTerm term)
Indicates whether the specified search term applies to this message.

Parameters: term the search term

reply

public abstract Message reply(boolean replyToAll)
Returns a new message suitable for a reply to this message. The new message will have its recipients set appropriately, but will have no content.

The subject field is filled in with the original subject prefixed with "Re:" (unless it already starts with "Re:").

Parameters: replyToAll if the reply should be sent to all recipients of this message

saveChanges

public abstract void saveChanges()
Save any changes made to this message into its underlying store, if the message was obtained from a folder. The message may be saved immediately or when its containing folder is closed.

This method ensures that any header fields are consistent with the changed message contents.

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder.

setExpunged

protected void setExpunged(boolean expunged)
Sets the expunged flag for this message.

setFlag

public void setFlag(Flags.Flag flag, boolean set)
Sets the specified flag on this message to the given value.

Parameters: flag the flag to be set set the value to be set

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder.

setFlags

public abstract void setFlags(Flags flag, boolean set)
Sets the specified flags on this message to the given value. Any flags in this message that are not specified in the given flags are unaffected.

Parameters: flag the flags to be set set the value to be set

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder.

setFrom

public abstract void setFrom()
Sets the identity of the person sending this message, as obtained from the property "mail.user". If this property is absent, the system property "user.name" is used.

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder

setFrom

public abstract void setFrom(Address address)
Sets the identity of the person sending this message.

Parameters: address the sender

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder.

setMessageNumber

protected void setMessageNumber(int msgnum)
Sets the message number for this message.

See Also: msgnum

setRecipient

public void setRecipient(Message.RecipientType type, Address address)
Sets the recipient address of the specified type.

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values

setRecipients

public abstract void setRecipients(Message.RecipientType type, Address[] addresses)
Sets the recipient addresses of the specified type.

Parameters: type the recipient type addresses the addresses

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder.

setReplyTo

public void setReplyTo(Address[] addresses)
Sets the addresses to which replies should be directed.

setSentDate

public abstract void setSentDate(Date date)
Sets the date this message was sent.

Parameters: date the sent date of this message

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder.

setSubject

public abstract void setSubject(String subject)
Sets the subject of this message.

Parameters: subject the subject

Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder.

© Copyright 2003, 2004 The Free Software Foundation, All rights reserved