gnu.mail.providers

Class ReadOnlyMessage

Implemented Interfaces:
MimePart, Part
Known Direct Subclasses:
IMAPMessage, MaildirMessage, MboxMessage, POP3Message

public abstract class ReadOnlyMessage
extends MimeMessage

Abstract read-only message. The superclass of mail provider messages that do not support message editing in-place.

Nested Class Summary

Field Summary

Fields inherited from class javax.mail.internet.MimeMessage

content, contentStream, dh, flags, headers, modified, saved

Fields inherited from class javax.mail.Message

expunged, folder, msgnum, session

Fields inherited from interface javax.mail.Part

ATTACHMENT, INLINE

Constructor Summary

ReadOnlyMessage(Folder folder, InputStream in, int msgnum)
Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream.
ReadOnlyMessage(Folder folder, int msgnum)
Constructs an empty MimeMessage object with the given Folder and message number.
ReadOnlyMessage(Folder folder, InternetHeaders headers, byte[] content, int msgnum)
Constructs a MimeMessage from the given InternetHeaders object and content.
ReadOnlyMessage(MimeMessage message)
Constructs a new MimeMessage with content initialized from the source MimeMessage.

Method Summary

void
addHeader(String name, String value)
Add this value to the existing values for this header_name.
void
addHeaderLine(String line)
Add a raw RFC 822 header-line.
void
removeHeader(String name)
Remove all headers with this name.
void
saveChanges()
Updates the appropriate header fields of this message to be consistent with the message's contents.
void
setContent(Object o, String type)
A convenience method for setting this Message's content.
void
setContent(Multipart mp)
This method sets the Message's content to a Multipart object.
void
setFlags(Flags flag, boolean set)
Set the flags for this message.
void
setHeader(String name, String value)
Set the value for this header_name.

Methods inherited from class javax.mail.internet.MimeMessage

addFrom, addHeader, addHeaderLine, addRecipients, addRecipients, createInternetHeaders, getAllHeaderLines, getAllHeaders, getAllRecipients, getContent, getContentID, getContentLanguage, getContentMD5, getContentStream, getContentType, getDataHandler, getDescription, getDisposition, getEncoding, getFileName, getFlags, getFrom, getHeader, getHeader, getInputStream, getLineCount, getMatchingHeaderLines, getMatchingHeaders, getMessageID, getNonMatchingHeaderLines, getNonMatchingHeaders, getRawInputStream, getReceivedDate, getRecipients, getReplyTo, getSender, getSentDate, getSize, getSubject, isMimeType, isSet, parse, removeHeader, reply, saveChanges, setContent, setContent, setContentID, setContentLanguage, setContentMD5, setDataHandler, setDescription, setDescription, setDisposition, setFileName, setFlags, setFrom, setFrom, setHeader, setRecipients, setRecipients, setReplyTo, setSender, setSentDate, setSubject, setSubject, setText, setText, updateHeaders, writeTo, writeTo

Methods inherited from class javax.mail.Message

addFrom, addRecipient, addRecipients, getAllRecipients, getFlags, getFolder, getFrom, getMessageNumber, getReceivedDate, getRecipients, getReplyTo, getSentDate, getSubject, isExpunged, isSet, match, reply, saveChanges, setExpunged, setFlag, setFlags, setFrom, setFrom, setMessageNumber, setRecipient, setRecipients, setReplyTo, setSentDate, setSubject

Constructor Details

ReadOnlyMessage

protected ReadOnlyMessage(Folder folder,
                          InputStream in,
                          int msgnum)
            throws MessagingException
Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. The InputStream will be left positioned at the end of the data for the message. Note that the input stream parse is done within this constructor itself.

This method is for providers subclassing MimeMessage.

Parameters:
folder - The containing folder.
msgnum - Message number of this message within its folder


ReadOnlyMessage

protected ReadOnlyMessage(Folder folder,
                          int msgnum)
            throws MessagingException
Constructs an empty MimeMessage object with the given Folder and message number.

This method is for providers subclassing MimeMessage.


ReadOnlyMessage

protected ReadOnlyMessage(Folder folder,
                          InternetHeaders headers,
                          byte[] content,
                          int msgnum)
            throws MessagingException
Constructs a MimeMessage from the given InternetHeaders object and content. This method is for providers subclassing MimeMessage.

Parameters:
folder - The containing folder.
headers - The message headers.
content - the content as an array of bytes
msgnum - Message number of this message within its folder


ReadOnlyMessage

protected ReadOnlyMessage(MimeMessage message)
            throws MessagingException
Constructs a new MimeMessage with content initialized from the source MimeMessage. The new message is independent of the original.

Note: The current implementation is rather inefficient, copying the data more times than strictly necessary.

Parameters:

Method Details

addHeader

public void addHeader(String name,
                      String value)
            throws MessagingException
Add this value to the existing values for this header_name. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must have been encoded as per the rules of RFC 2047.
Specified by:
addHeader in interface Part
Overrides:
addHeader in interface MimeMessage

Parameters:
name - header name
value - header value


addHeaderLine

public void addHeaderLine(String line)
            throws MessagingException
Add a raw RFC 822 header-line.
Specified by:
addHeaderLine in interface MimePart
Overrides:
addHeaderLine in interface MimeMessage

Parameters:
line - the line to add


removeHeader

public void removeHeader(String name)
            throws MessagingException
Remove all headers with this name.
Specified by:
removeHeader in interface Part
Overrides:
removeHeader in interface MimeMessage

Parameters:
name - header name


saveChanges

public void saveChanges()
            throws MessagingException
Updates the appropriate header fields of this message to be consistent with the message's contents. If this message is contained in a Folder, any changes made to this message are committed to the containing folder.

If any part of a message's headers or contents are changed, saveChanges must be called to ensure that those changes are permanent. Otherwise, any such modifications may or may not be saved, depending on the folder implementation.

Messages obtained from folders opened READ_ONLY should not be modified and saveChanges should not be called on such messages.

This method sets the modified flag to true, the save flag to true, and then calls the updateHeaders method.

Overrides:
saveChanges in interface MimeMessage


setContent

public void setContent(Object o,
                       String type)
            throws MessagingException
A convenience method for setting this Message's content.

The content is wrapped in a DataHandler object. Note that a DataContentHandler class for the specified type should be available to the JavaMail implementation for this to work right. i.e., to do setContent(foobar, "application/x-foobar"), a DataContentHandler for "application/x-foobar" should be installed. Refer to the Java Activation Framework for more information.

Specified by:
setContent in interface Part
Overrides:
setContent in interface MimeMessage

Parameters:
o - the content object
type - Mime type of the object

See Also:
MimeBodyPart.setContent


setContent

public void setContent(Multipart mp)
            throws MessagingException
This method sets the Message's content to a Multipart object.
Specified by:
setContent in interface Part
Overrides:
setContent in interface MimeMessage

Parameters:
mp - The multipart object that is the Message's content

See Also:
MimeBodyPart.setContent(Multipart)


setFlags

public void setFlags(Flags flag,
                     boolean set)
            throws MessagingException
Set the flags for this message.

This implementation modifies the flags field.

Overrides:
setFlags in interface MimeMessage


setHeader

public void setHeader(String name,
                      String value)
            throws MessagingException
Set the value for this header_name. Replaces all existing header values with this new value. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must have been encoded by the caller as per the rules of RFC 2047.
Specified by:
setHeader in interface Part
Overrides:
setHeader in interface MimeMessage

Parameters:
name - header name
value - header value