javax.mail.internet
Class MimeMessage

java.lang.Object
  extended by javax.mail.Message
      extended by javax.mail.internet.MimeMessage
All Implemented Interfaces:
MimePart, Part
Direct Known Subclasses:
NNTPMessage, gnu.mail.providers.ReadOnlyMessage

public class MimeMessage
extends Message
implements MimePart

A MIME mail message. This may be a top-level part, or the content of a MIME body part with a "message/rfc822" Content-Type.

The string representation of RFC822 and MIME header fields must contain only US-ASCII characters. Non US-ASCII characters must be encoded as per the rules in RFC 2047. This class does not enforce those rules; the caller is expected to use MimeUtility to ensure that header values are correctly encoded.

Version:
1.4
Author:
Chris Burdess

Nested Class Summary
static class MimeMessage.RecipientType
          Additional recipient types specific to internet messages.
 
Field Summary
protected  byte[] content
          The bytes of the content of this message, if the message can be stored in memory.
protected  InputStream contentStream
          A SharedInputStream containing the byte content of this message, if the message cannot be stored in memory.
protected  DataHandler dh
          The data handler managing this message's content.
protected  Flags flags
          The message flags.
protected  InternetHeaders headers
          The message headers.
protected  boolean modified
          Indicates whether the message has been modified.
protected  boolean saved
          Indicates whether we do not need to call saveChanges on the message.
 
Fields inherited from class javax.mail.Message
expunged, folder, msgnum, session
 
Fields inherited from interface javax.mail.Part
ATTACHMENT, INLINE
 
Constructor Summary
protected MimeMessage(Folder folder, InputStream is, int msgnum)
          Constructor with a parent folder, message number, and RFC 822 input stream.
protected MimeMessage(Folder folder, int msgnum)
          Constructor with a parent folder and message number.
protected MimeMessage(Folder folder, InternetHeaders headers, byte[] content, int msgnum)
          Constructor with a parent folder, message number, headers and byte content.
  MimeMessage(MimeMessage source)
          Constructor with an existing message.
  MimeMessage(Session session)
          Constructor for an empty message.
  MimeMessage(Session session, InputStream is)
          Constructor with an input stream contining an RFC 822 message.
 
Method Summary
 void addFrom(Address[] addresses)
          Adds the specified addresses to From header field.
 void addHeader(String name, String value)
          Adds the specified header.
 void addHeaderLine(String line)
          Adds an RFC 822 header-line to this message.
 void addRecipients(Message.RecipientType type, Address[] addresses)
          Adds the given addresses to the recipients of the specified type.
 void addRecipients(Message.RecipientType type, String addresses)
          Adds the given addresses to the recipients of the specified type.
protected  InternetHeaders createInternetHeaders(InputStream is)
          Creates the headers from the given input stream.
protected  MimeMessage createMimeMessage(Session session)
          Creates a new MIME message.
 Enumeration getAllHeaderLines()
          Returns all the header-lines.
 Enumeration getAllHeaders()
          Returns all the headers.
 Address[] getAllRecipients()
          Returns all the recipients.
 Object getContent()
          Returns this message's content as a Java object.
 String getContentID()
          Returns the value of the Content-ID header field.
 String[] getContentLanguage()
          Returns the languages specified in the Content-Language header field of this message, as defined by RFC 1766.
 String getContentMD5()
          Returns the value of the Content-MD5 header field.
protected  InputStream getContentStream()
          Returns the unencoded bytes of the content.
 String getContentType()
          Returns the value of the RFC 822 Content-Type header field, or "text/plain" if the header is not available.
 DataHandler getDataHandler()
          Returns a data handler for accessing this message's content.
 String getDescription()
          Returns the Content-Description header field of this message.
 String getDisposition()
          Returns the value of the RFC 822 Content-Disposition header field, or null if the header is not available.
 String getEncoding()
          Returns the value of the Content-Transfer-Encoding header field.
 String getFileName()
          Returns the filename associated with this message.
 Flags getFlags()
          Returns the flags for this message.
 Address[] getFrom()
          Returns the value of the RFC 822 From header field.
 String[] getHeader(String name)
          Returns all the values for the specified header name.
 String getHeader(String name, String delimiter)
          Returns all the values for the specified header name as a single string, with headers separated by the given delimiter.
 InputStream getInputStream()
          Returns a decoded input stream for this message's content.
 int getLineCount()
          Returns the number of lines in the content of this message, or -1 if this number cannot be determined.
 Enumeration getMatchingHeaderLines(String[] names)
          Returns all the header-lines with any of the given names.
 Enumeration getMatchingHeaders(String[] names)
          Returns all the headers with any of the given names.
 String getMessageID()
          Returns the value of the Message-ID header field.
 Enumeration getNonMatchingHeaderLines(String[] names)
          Returns all the header-lines without any of the given names.
 Enumeration getNonMatchingHeaders(String[] names)
          Returns all the headers without any of the given names.
 InputStream getRawInputStream()
          Returns the unencoded bytes of the content without applying any content transfer encoding.
 Date getReceivedDate()
          Returns the date on which this message was received.
 Address[] getRecipients(Message.RecipientType type)
          Returns the recipients of the given type.
 Address[] getReplyTo()
          Returns the value of the RFC 822 Reply-To header field.
 Address getSender()
          Returns the value of the RFC 822 Sender header field.
 Date getSentDate()
          Returns the value of the RFC 822 Date field.
 int getSize()
          Returns the size of the content of this message in bytes, or -1 if the size cannot be determined.
 String getSubject()
          Returns the value of the Subject header field.
 boolean isMimeType(String mimeType)
          Indicates whether this message is of the specified MIME type.
 boolean isSet(Flags.Flag flag)
          Indicates whether the specified flag is set in this message.
protected  void parse(InputStream is)
          Parses the given input stream, setting the headers and content fields appropriately.
 void removeHeader(String name)
          Removes all headers with the specified name.
 Message reply(boolean replyToAll)
          Returns a new message suitable for a reply to this message.
 void saveChanges()
          Saves any changes to this message.
 void setContent(Multipart mp)
          Sets the content of this message to be the specified multipart.
 void setContent(Object o, String type)
          Sets the content of this message using the specified Java object and MIME type.
 void setContentID(String cid)
          Sets the Content-ID header field of this message.
 void setContentLanguage(String[] languages)
          Sets the Content-Language header of this message.
 void setContentMD5(String md5)
          Sets the Content-MD5 header field of this message.
 void setDataHandler(DataHandler datahandler)
          Sets the content of this part using the specified data handler.
 void setDescription(String description)
          Sets the Content-Description header field for this message.
 void setDescription(String description, String charset)
          Sets the Content-Description header field for this message.
 void setDisposition(String disposition)
          Sets the Content-Disposition header field of this message.
 void setFileName(String filename)
          Sets the filename associated with this part.
 void setFlags(Flags flag, boolean set)
          Sets the flags for this message.
 void setFrom()
          Sets the RFC 822 From header field using the value of the InternetAddress.getLocalAddress method.
 void setFrom(Address address)
          Sets the RFC 822 From header field.
 void setHeader(String name, String value)
          Sets the specified header.
 void setRecipients(Message.RecipientType type, Address[] addresses)
          Sets the recipients of the given type.
 void setRecipients(Message.RecipientType type, String addresses)
          Sets the recipients of the given type.
 void setReplyTo(Address[] addresses)
          Sets the RFC 822 Reply-To header field.
 void setSender(Address address)
          Sets the RFC 822 Sender header field.
 void setSentDate(Date date)
          Sets the RFC 822 Date header field.
 void setSubject(String subject)
          Sets the Subject header field.
 void setSubject(String subject, String charset)
          Sets the Subject header field.
 void setText(String text)
          Sets the content of this message using the specified text, and with a MIME type of "text/plain".
 void setText(String text, String charset)
          Sets the content of this message using the specified text, and with a MIME type of "text/plain".
 void setText(String text, String charset, String subtype)
          Sets the content of this message using the specified text, and with a text MIME type of the specified subtype.
protected  void updateHeaders()
          Updates the headers of this part, based on the content.
protected  void updateMessageId()
          Updates the Message-ID header.
 void writeTo(OutputStream os)
          Writes this message to the specified stream in RFC 822 format.
 void writeTo(OutputStream os, String[] ignoreList)
          Writes this message to the specified stream in RFC 822 format, without the specified headers.
 
Methods inherited from class javax.mail.Message
addRecipient, getFolder, getMessageNumber, isExpunged, match, setExpunged, setFlag, setMessageNumber, setRecipient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dh

protected DataHandler dh
The data handler managing this message's content.


content

protected byte[] content
The bytes of the content of this message, if the message can be stored in memory.


contentStream

protected InputStream contentStream
A SharedInputStream containing the byte content of this message, if the message cannot be stored in memory.


headers

protected InternetHeaders headers
The message headers.


flags

protected Flags flags
The message flags.


modified

protected boolean modified
Indicates whether the message has been modified. If false, any data in the content array is assumed to be valid and is used directly in the writeTo method. This field is set to true when an empty message is created or when the saveChanges method is called.


saved

protected boolean saved
Indicates whether we do not need to call saveChanges on the message. This flag is set to false by the public constructor and set to true by the saveChanges method. The writeTo method checks this flag and calls the saveChanges method as necessary.

Constructor Detail

MimeMessage

public MimeMessage(Session session)
Constructor for an empty message.


MimeMessage

public MimeMessage(Session session,
                   InputStream is)
            throws MessagingException
Constructor with an input stream contining an RFC 822 message. When this method returns, the stream will be positioned at the end of the data for the message.

Parameters:
session - the session context
is - the message input stream
Throws:
MessagingException

MimeMessage

public MimeMessage(MimeMessage source)
            throws MessagingException
Constructor with an existing message. This performs a deep copy of the target message.

Parameters:
source - the message to copy
Throws:
MessagingException

MimeMessage

protected MimeMessage(Folder folder,
                      int msgnum)
Constructor with a parent folder and message number.

Parameters:
folder - the parent folder
msgnum - the message number

MimeMessage

protected MimeMessage(Folder folder,
                      InputStream is,
                      int msgnum)
               throws MessagingException
Constructor with a parent folder, message number, and RFC 822 input stream. When this method returns, the stream will be positioned at the end of the data for the message.

Parameters:
folder - the parent folder
is - the message input stream
msgnum - the message number of this message within the folder
Throws:
MessagingException

MimeMessage

protected MimeMessage(Folder folder,
                      InternetHeaders headers,
                      byte[] content,
                      int msgnum)
               throws MessagingException
Constructor with a parent folder, message number, headers and byte content.

Parameters:
folder - the parent folder
headers - the headers
content - the content byte array
msgnum - the message number of this message within the folder
Throws:
MessagingException
Method Detail

parse

protected void parse(InputStream is)
              throws MessagingException
Parses the given input stream, setting the headers and content fields appropriately. This resets the modified flag.

Parameters:
is - the message input stream
Throws:
MessagingException

getFrom

public Address[] getFrom()
                  throws MessagingException
Returns the value of the RFC 822 From header field. If this header field is absent, the Sender header field is used instead.

Specified by:
getFrom in class Message
Throws:
MessagingException

setFrom

public void setFrom(Address address)
             throws MessagingException
Sets the RFC 822 From header field.

Specified by:
setFrom in class Message
Parameters:
address - the sender 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
MessagingException

setFrom

public void setFrom()
             throws MessagingException
Sets the RFC 822 From header field using the value of the InternetAddress.getLocalAddress method.

Specified by:
setFrom in class 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
MessagingException

addFrom

public void addFrom(Address[] addresses)
             throws MessagingException
Adds the specified addresses to From header field.

Specified by:
addFrom in class Message
Parameters:
addresses - the senders 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
MessagingException

getSender

public Address getSender()
                  throws MessagingException
Returns the value of the RFC 822 Sender header field.

Throws:
MessagingException
Since:
JavaMail 1.3

setSender

public void setSender(Address address)
               throws MessagingException
Sets the RFC 822 Sender header field.

Parameters:
address - the sender 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
MessagingException
Since:
JavaMail 1.3

getRecipients

public Address[] getRecipients(Message.RecipientType type)
                        throws MessagingException
Returns the recipients of the given type.

Specified by:
getRecipients in class Message
Parameters:
type - the recipient type
Throws:
MessagingException

getAllRecipients

public Address[] getAllRecipients()
                           throws MessagingException
Returns all the recipients. This returns the TO, CC, BCC, and NEWSGROUPS recipients.

Overrides:
getAllRecipients in class Message
Throws:
MessagingException

setRecipients

public void setRecipients(Message.RecipientType type,
                          Address[] addresses)
                   throws MessagingException
Sets the recipients of the given type.

Specified by:
setRecipients in class Message
Parameters:
type - the recipient type
addresses - the addresses, or null to remove recipients of this type
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException

setRecipients

public void setRecipients(Message.RecipientType type,
                          String addresses)
                   throws MessagingException
Sets the recipients of the given type.

Parameters:
type - the recipient type
addresses - the addresses, or null to remove recpients of this type
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException

addRecipients

public void addRecipients(Message.RecipientType type,
                          Address[] addresses)
                   throws MessagingException
Adds the given addresses to the recipients of the specified type.

Specified by:
addRecipients in class Message
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
MessagingException

addRecipients

public void addRecipients(Message.RecipientType type,
                          String addresses)
                   throws MessagingException
Adds the given addresses to the recipients 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
MessagingException

getReplyTo

public Address[] getReplyTo()
                     throws MessagingException
Returns the value of the RFC 822 Reply-To header field. If the header is absent, the value of the getFrom method is returned.

Overrides:
getReplyTo in class Message
Throws:
MessagingException

setReplyTo

public void setReplyTo(Address[] addresses)
                throws MessagingException
Sets the RFC 822 Reply-To header field.

Overrides:
setReplyTo in class Message
Parameters:
addresses - the addresses, or null to remove this header
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException

getSubject

public String getSubject()
                  throws MessagingException
Returns the value of the Subject header field.

If the subject is encoded as per RFC 2047, it is decoded and converted into Unicode.

Specified by:
getSubject in class Message
Throws:
MessagingException

setSubject

public void setSubject(String subject)
                throws MessagingException
Sets the Subject header field.

If the subject contains non US-ASCII characters, it will be encoded using the platform default charset.

Specified by:
setSubject in class 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
MessagingException

setSubject

public void setSubject(String subject,
                       String charset)
                throws MessagingException
Sets the Subject header field.

If the subject contains non US-ASCII characters, it will be encoded using the specified charset.

Parameters:
subject - the subject
charset - the charset used for any encoding
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException

getSentDate

public Date getSentDate()
                 throws MessagingException
Returns the value of the RFC 822 Date field. This is the date on which this message was sent.

Specified by:
getSentDate in class Message
Throws:
MessagingException

setSentDate

public void setSentDate(Date date)
                 throws MessagingException
Sets the RFC 822 Date header field.

Specified by:
setSentDate in class Message
Parameters:
date - the sent date, or null to remove this header
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException

getReceivedDate

public Date getReceivedDate()
                     throws MessagingException
Returns the date on which this message was received. This returns null if the received date cannot be obtained.

Specified by:
getReceivedDate in class Message
Throws:
MessagingException

getSize

public int getSize()
            throws MessagingException
Returns the size of the content of this message in bytes, or -1 if the size cannot be determined.

Note that this number may not be an exact measure, but if not -1, it will be suitable for display to the user.

Specified by:
getSize in interface Part
Throws:
MessagingException

getLineCount

public int getLineCount()
                 throws MessagingException
Returns the number of lines in the content of this message, or -1 if this number cannot be determined.

Note that this number may not be an exact measure, but if not -1, it will be suitable for display to the user.

Specified by:
getLineCount in interface Part
Throws:
MessagingException

getContentType

public String getContentType()
                      throws MessagingException
Returns the value of the RFC 822 Content-Type header field, or "text/plain" if the header is not available.

Specified by:
getContentType in interface Part
Throws:
MessagingException

isMimeType

public boolean isMimeType(String mimeType)
                   throws MessagingException
Indicates whether this message is of the specified MIME type.

If the subtype of mimeType is the special character '*', the subtype is ignored during the comparison.

Specified by:
isMimeType in interface Part
Throws:
MessagingException
See Also:
MimeBodyPart.isMimeType(java.lang.String)

getDisposition

public String getDisposition()
                      throws MessagingException
Returns the value of the RFC 822 Content-Disposition header field, or null if the header is not available.

Specified by:
getDisposition in interface Part
Throws:
MessagingException
See Also:
MimeBodyPart.getDisposition()

setDisposition

public void setDisposition(String disposition)
                    throws MessagingException
Sets the Content-Disposition header field of this message.

Specified by:
setDisposition in interface Part
Parameters:
disposition - the disposition value to set, or null to remove
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException
See Also:
MimeBodyPart.setDisposition(java.lang.String)

getEncoding

public String getEncoding()
                   throws MessagingException
Returns the value of the Content-Transfer-Encoding header field.

Specified by:
getEncoding in interface MimePart
Throws:
MessagingException
See Also:
MimeBodyPart.getEncoding()

getContentID

public String getContentID()
                    throws MessagingException
Returns the value of the Content-ID header field.

Specified by:
getContentID in interface MimePart
Throws:
MessagingException
See Also:
MimeBodyPart.getContentID()

setContentID

public void setContentID(String cid)
                  throws MessagingException
Sets the Content-ID header field 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
MessagingException

getContentMD5

public String getContentMD5()
                     throws MessagingException
Returns the value of the Content-MD5 header field.

Specified by:
getContentMD5 in interface MimePart
Throws:
MessagingException
See Also:
MimeBodyPart.getContentMD5()

setContentMD5

public void setContentMD5(String md5)
                   throws MessagingException
Sets the Content-MD5 header field of this message.

Specified by:
setContentMD5 in interface MimePart
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException
See Also:
MimeBodyPart.setContentMD5(java.lang.String)

getDescription

public String getDescription()
                      throws MessagingException
Returns the Content-Description header field of this message.

If the Content-Description field is encoded as per RFC 2047, it is decoded and converted into Unicode.

Specified by:
getDescription in interface Part
Throws:
MessagingException
See Also:
MimeBodyPart.getDescription()

setDescription

public void setDescription(String description)
                    throws MessagingException
Sets the Content-Description header field for this message.

If the description contains non US-ASCII characters, it will be encoded using the platform default charset.

Specified by:
setDescription in interface Part
Parameters:
description - the content description
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException
See Also:
MimeBodyPart.setDescription(java.lang.String)

setDescription

public void setDescription(String description,
                           String charset)
                    throws MessagingException
Sets the Content-Description header field for this message.

If the description contains non US-ASCII characters, it will be encoded using the specified charset.

Parameters:
description - the content description
charset - the charset used for any encoding
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException
See Also:
MimeBodyPart.setDescription(java.lang.String)

getContentLanguage

public String[] getContentLanguage()
                            throws MessagingException
Returns the languages specified in the Content-Language header field of this message, as defined by RFC 1766. This method returns null if this header is not available.

Specified by:
getContentLanguage in interface MimePart
Throws:
MessagingException
See Also:
MimeBodyPart.getContentLanguage()

setContentLanguage

public void setContentLanguage(String[] languages)
                        throws MessagingException
Sets the Content-Language header of this message.

Specified by:
setContentLanguage in interface MimePart
Parameters:
languages - the array of language tags
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException
See Also:
MimeBodyPart.setContentLanguage(java.lang.String[])

getMessageID

public String getMessageID()
                    throws MessagingException
Returns the value of the Message-ID header field.

Throws:
MessagingException

getFileName

public String getFileName()
                   throws MessagingException
Returns the filename associated with this message.

This method returns the value of the "filename" parameter from the Content-Disposition header field of this message. If the latter is not available, it returns the value of the "name" parameter from the Content-Type header field.

Specified by:
getFileName in interface Part
Throws:
MessagingException
See Also:
MimeBodyPart.getFileName()

setFileName

public void setFileName(String filename)
                 throws MessagingException
Sets the filename associated with this part.

Specified by:
setFileName in interface Part
Parameters:
filename - the filename to associate with this part
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException
See Also:
MimeBodyPart.setFileName(java.lang.String)

getInputStream

public InputStream getInputStream()
                           throws IOException,
                                  MessagingException
Returns a decoded input stream for this message's content.

Specified by:
getInputStream in interface Part
Throws:
IOException - if an error occurs in the data handler layer
MessagingException
See Also:
MimeBodyPart.getInputStream()

getContentStream

protected InputStream getContentStream()
                                throws MessagingException
Returns the unencoded bytes of the content.

Throws:
MessagingException
See Also:
MimeBodyPart.getContentStream()

getRawInputStream

public InputStream getRawInputStream()
                              throws MessagingException
Returns the unencoded bytes of the content without applying any content transfer encoding.

Throws:
MessagingException
See Also:
MimeBodyPart.getRawInputStream()

getDataHandler

public DataHandler getDataHandler()
                           throws MessagingException
Returns a data handler for accessing this message's content.

Specified by:
getDataHandler in interface Part
Throws:
MessagingException

getContent

public Object getContent()
                  throws IOException,
                         MessagingException
Returns this message's content as a Java object.

Specified by:
getContent in interface Part
Throws:
IOException - if an error occurred in the data handler layer
MessagingException

setDataHandler

public void setDataHandler(DataHandler datahandler)
                    throws MessagingException
Sets the content of this part using the specified data handler.

Specified by:
setDataHandler in interface Part
Parameters:
datahandler - the data handler for the content
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException
See Also:
MimeBodyPart.setDataHandler(javax.activation.DataHandler)

setContent

public void setContent(Object o,
                       String type)
                throws MessagingException
Sets the content of this message using the specified Java object and MIME type. Note that a data content handler for the MIME type must be installed and accept objects of the type given.

Specified by:
setContent in interface Part
Parameters:
o - the content object
type - the MIME type of the object
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException
See Also:
MimeBodyPart.setContent(java.lang.Object, java.lang.String)

setText

public void setText(String text)
             throws MessagingException
Sets the content of this message using the specified text, and with a MIME type of "text/plain".

If the string contains non US-ASCII characters, it will be encoded using the platform default charset.

Specified by:
setText in interface MimePart
Specified by:
setText in interface Part
Parameters:
text - the text content
Throws:
IllegalWriteException - if the underlying implementation does not support modification
MessagingException
See Also:
MimeBodyPart.setText(String)

setText

public void setText(String text,
                    String charset)
             throws MessagingException
Sets the content of this message using the specified text, and with a MIME type of "text/plain".

If the string contains non US-ASCII characters, it will be encoded using the specified charset.

Specified by:
setText in interface MimePart
Parameters:
text - the text content
charset - the charset used for any encoding
Throws:
MessagingException
See Also:
MimeBodyPart.setText(String,String)

setText

public void setText(String text,
                    String charset,
                    String subtype)
             throws MessagingException
Sets the content of this message using the specified text, and with a text MIME type of the specified subtype.

If the string contains non US-ASCII characters, it will be encoded using the specified charset.

Specified by:
setText in interface MimePart
Parameters:
text - the text content
charset - the charset used for any encoding
subtype - the MIME text subtype (e.g. "plain", "html")
Throws:
MessagingException
Since:
JavaMail 1.4
See Also:
MimeBodyPart.setText(String,String,String)

setContent

public void setContent(Multipart mp)
                throws MessagingException
Sets the content of this message to be the specified multipart.

Specified by:
setContent in interface Part
Parameters:
mp - the multipart content
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException
See Also:
MimeBodyPart.setContent(Multipart)

reply

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

Specified by:
reply in class Message
Parameters:
replyToAll - the reply should be sent to all the recipients of this message
Throws:
MessagingException

writeTo

public void writeTo(OutputStream os)
             throws IOException,
                    MessagingException
Writes this message to the specified stream in RFC 822 format.

Specified by:
writeTo in interface Part
Throws:
IOException - if an error occurs writing to the stream or in the data handler layer
MessagingException - if an error occurs fetching the data to be written

writeTo

public void writeTo(OutputStream os,
                    String[] ignoreList)
             throws IOException,
                    MessagingException
Writes this message to the specified stream in RFC 822 format, without the specified headers.

Throws:
IOException - if an error occurs writing to the stream or in the data handler layer
MessagingException

getHeader

public String[] getHeader(String name)
                   throws MessagingException
Returns all the values for the specified header name. Note that headers may be encoded as per RFC 2047 if they contain non-US-ASCII characters: these should be decoded.

Specified by:
getHeader in interface Part
Parameters:
name - the header name
Throws:
MessagingException

getHeader

public String getHeader(String name,
                        String delimiter)
                 throws MessagingException
Returns all the values for the specified header name as a single string, with headers separated by the given delimiter. If the delimiter is null, only the first header is returned.

Specified by:
getHeader in interface MimePart
Parameters:
name - the header name
delimiter - the delimiter
Throws:
MessagingException

setHeader

public void setHeader(String name,
                      String value)
               throws MessagingException
Sets the specified header.

Specified by:
setHeader in interface Part
Parameters:
name - the header name
value - the header value
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException

addHeader

public void addHeader(String name,
                      String value)
               throws MessagingException
Adds the specified header.

Specified by:
addHeader in interface Part
Parameters:
name - the header name
value - the header value
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException

removeHeader

public void removeHeader(String name)
                  throws MessagingException
Removes all headers with the specified name.

Specified by:
removeHeader in interface Part
Parameters:
name - the header name
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException

getAllHeaders

public Enumeration getAllHeaders()
                          throws MessagingException
Returns all the headers.

Specified by:
getAllHeaders in interface Part
Returns:
an Enumeration of Header objects
Throws:
MessagingException

getMatchingHeaders

public Enumeration getMatchingHeaders(String[] names)
                               throws MessagingException
Returns all the headers with any of the given names.

Specified by:
getMatchingHeaders in interface Part
Parameters:
names - the header names to match
Returns:
an Enumeration of Header objects
Throws:
MessagingException

getNonMatchingHeaders

public Enumeration getNonMatchingHeaders(String[] names)
                                  throws MessagingException
Returns all the headers without any of the given names.

Specified by:
getNonMatchingHeaders in interface Part
Parameters:
names - the header names to ignore
Returns:
an Enumeration of Header objects
Throws:
MessagingException

addHeaderLine

public void addHeaderLine(String line)
                   throws MessagingException
Adds an RFC 822 header-line to this message.

Specified by:
addHeaderLine in interface MimePart
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException

getAllHeaderLines

public Enumeration getAllHeaderLines()
                              throws MessagingException
Returns all the header-lines.

Specified by:
getAllHeaderLines in interface MimePart
Returns:
an Enumeration of Strings
Throws:
MessagingException

getMatchingHeaderLines

public Enumeration getMatchingHeaderLines(String[] names)
                                   throws MessagingException
Returns all the header-lines with any of the given names.

Specified by:
getMatchingHeaderLines in interface MimePart
Returns:
an Enumeration of Strings
Throws:
MessagingException

getNonMatchingHeaderLines

public Enumeration getNonMatchingHeaderLines(String[] names)
                                      throws MessagingException
Returns all the header-lines without any of the given names.

Specified by:
getNonMatchingHeaderLines in interface MimePart
Returns:
an Enumeration of Strings
Throws:
MessagingException

getFlags

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

Specified by:
getFlags in class Message
Throws:
MessagingException

isSet

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

Overrides:
isSet in class Message
Parameters:
flag - the flag
Throws:
MessagingException

setFlags

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

Specified by:
setFlags in class Message
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
MessagingException

saveChanges

public void saveChanges()
                 throws MessagingException
Saves any changes to this message. Header fields in the message are updated appropriately to be consistent with the message contents.

Specified by:
saveChanges in class 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
MessagingException

updateHeaders

protected void updateHeaders()
                      throws MessagingException
Updates the headers of this part, based on the content.

Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder
MessagingException
See Also:
MimeBodyPart.updateHeaders()

createInternetHeaders

protected InternetHeaders createInternetHeaders(InputStream is)
                                         throws MessagingException
Creates the headers from the given input stream.

Parameters:
is - the input stream to read the headers from
Throws:
MessagingException

updateMessageId

protected void updateMessageId()
                        throws MessagingException
Updates the Message-ID header. This method is called by updateHeaders, and should set the Message-Id header to a suitably unique value if overridden.

Throws:
MessagingException
Since:
JavaMail 1.4

createMimeMessage

protected MimeMessage createMimeMessage(Session session)
                                 throws MessagingException
Creates a new MIME message. Used by the reply method to determine the MimeMessage subclass, if any, to use.

Throws:
MessagingException
Since:
JavaMail 1.4


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