Class MimeMessage
- java.lang.Object
-
- javax.mail.Message
-
- javax.mail.internet.MimeMessage
-
- 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
MimeUtilityto ensure that header values are correctly encoded.- Version:
- 1.4
- Author:
- Chris Burdess
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMimeMessage.RecipientTypeAdditional recipient types specific to internet messages.
-
Field Summary
Fields Modifier and Type Field Description protected byte[]contentThe bytes of the content of this message, if the message can be stored in memory.protected java.io.InputStreamcontentStreamA SharedInputStream containing the byte content of this message, if the message cannot be stored in memory.protected javax.activation.DataHandlerdhThe data handler managing this message's content.protected FlagsflagsThe message flags.protected InternetHeadersheadersThe message headers.protected booleanmodifiedIndicates whether the message has been modified.protected booleansavedIndicates whether we do not need to callsaveChangeson the message.-
Fields inherited from interface javax.mail.Part
ATTACHMENT, INLINE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMimeMessage(Folder folder, int msgnum)Constructor with a parent folder and message number.protectedMimeMessage(Folder folder, java.io.InputStream is, int msgnum)Constructor with a parent folder, message number, and RFC 822 input stream.protectedMimeMessage(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, java.io.InputStream is)Constructor with an input stream contining an RFC 822 message.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFrom(Address[] addresses)Adds the specified addresses to From header field.voidaddHeader(java.lang.String name, java.lang.String value)Adds the specified header.voidaddHeaderLine(java.lang.String line)Adds an RFC 822 header-line to this message.voidaddRecipients(Message.RecipientType type, java.lang.String addresses)Adds the given addresses to the recipients of the specified type.voidaddRecipients(Message.RecipientType type, Address[] addresses)Adds the given addresses to the recipients of the specified type.protected InternetHeaderscreateInternetHeaders(java.io.InputStream is)Creates the headers from the given input stream.protected MimeMessagecreateMimeMessage(Session session)Creates a new MIME message.java.util.EnumerationgetAllHeaderLines()Returns all the header-lines.java.util.EnumerationgetAllHeaders()Returns all the headers.Address[]getAllRecipients()Returns all the recipients.java.lang.ObjectgetContent()Returns this message's content as a Java object.java.lang.StringgetContentID()Returns the value of the Content-ID header field.java.lang.String[]getContentLanguage()Returns the languages specified in the Content-Language header field of this message, as defined by RFC 1766.java.lang.StringgetContentMD5()Returns the value of the Content-MD5 header field.protected java.io.InputStreamgetContentStream()Returns the unencoded bytes of the content.java.lang.StringgetContentType()Returns the value of the RFC 822 Content-Type header field, or "text/plain" if the header is not available.javax.activation.DataHandlergetDataHandler()Returns a data handler for accessing this message's content.java.lang.StringgetDescription()Returns the Content-Description header field of this message.java.lang.StringgetDisposition()Returns the value of the RFC 822 Content-Disposition header field, ornullif the header is not available.java.lang.StringgetEncoding()Returns the value of the Content-Transfer-Encoding header field.java.lang.StringgetFileName()Returns the filename associated with this message.FlagsgetFlags()Returns the flags for this message.Address[]getFrom()Returns the value of the RFC 822 From header field.java.lang.String[]getHeader(java.lang.String name)Returns all the values for the specified header name.java.lang.StringgetHeader(java.lang.String name, java.lang.String delimiter)Returns all the values for the specified header name as a single string, with headers separated by the given delimiter.java.io.InputStreamgetInputStream()Returns a decoded input stream for this message's content.intgetLineCount()Returns the number of lines in the content of this message, or -1 if this number cannot be determined.java.util.EnumerationgetMatchingHeaderLines(java.lang.String[] names)Returns all the header-lines with any of the given names.java.util.EnumerationgetMatchingHeaders(java.lang.String[] names)Returns all the headers with any of the given names.java.lang.StringgetMessageID()Returns the value of the Message-ID header field.java.util.EnumerationgetNonMatchingHeaderLines(java.lang.String[] names)Returns all the header-lines without any of the given names.java.util.EnumerationgetNonMatchingHeaders(java.lang.String[] names)Returns all the headers without any of the given names.java.io.InputStreamgetRawInputStream()Returns the unencoded bytes of the content without applying any content transfer encoding.java.util.DategetReceivedDate()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.AddressgetSender()Returns the value of the RFC 822 Sender header field.java.util.DategetSentDate()Returns the value of the RFC 822 Date field.intgetSize()Returns the size of the content of this message in bytes, or -1 if the size cannot be determined.java.lang.StringgetSubject()Returns the value of the Subject header field.booleanisMimeType(java.lang.String mimeType)Indicates whether this message is of the specified MIME type.booleanisSet(Flags.Flag flag)Indicates whether the specified flag is set in this message.protected voidparse(java.io.InputStream is)Parses the given input stream, setting the headers and content fields appropriately.voidremoveHeader(java.lang.String name)Removes all headers with the specified name.Messagereply(boolean replyToAll)Returns a new message suitable for a reply to this message.voidsaveChanges()Saves any changes to this message.voidsetContent(java.lang.Object o, java.lang.String type)Sets the content of this message using the specified Java object and MIME type.voidsetContent(Multipart mp)Sets the content of this message to be the specified multipart.voidsetContentID(java.lang.String cid)Sets the Content-ID header field of this message.voidsetContentLanguage(java.lang.String[] languages)Sets the Content-Language header of this message.voidsetContentMD5(java.lang.String md5)Sets the Content-MD5 header field of this message.voidsetDataHandler(javax.activation.DataHandler datahandler)Sets the content of this part using the specified data handler.voidsetDescription(java.lang.String description)Sets the Content-Description header field for this message.voidsetDescription(java.lang.String description, java.lang.String charset)Sets the Content-Description header field for this message.voidsetDisposition(java.lang.String disposition)Sets the Content-Disposition header field of this message.voidsetFileName(java.lang.String filename)Sets the filename associated with this part.voidsetFlags(Flags flag, boolean set)Sets the flags for this message.voidsetFrom()Sets the RFC 822 From header field using the value of theInternetAddress.getLocalAddressmethod.voidsetFrom(Address address)Sets the RFC 822 From header field.voidsetHeader(java.lang.String name, java.lang.String value)Sets the specified header.voidsetRecipients(Message.RecipientType type, java.lang.String addresses)Sets the recipients of the given type.voidsetRecipients(Message.RecipientType type, Address[] addresses)Sets the recipients of the given type.voidsetReplyTo(Address[] addresses)Sets the RFC 822 Reply-To header field.voidsetSender(Address address)Sets the RFC 822 Sender header field.voidsetSentDate(java.util.Date date)Sets the RFC 822 Date header field.voidsetSubject(java.lang.String subject)Sets the Subject header field.voidsetSubject(java.lang.String subject, java.lang.String charset)Sets the Subject header field.voidsetText(java.lang.String text)Sets the content of this message using the specified text, and with a MIME type of "text/plain".voidsetText(java.lang.String text, java.lang.String charset)Sets the content of this message using the specified text, and with a MIME type of "text/plain".voidsetText(java.lang.String text, java.lang.String charset, java.lang.String subtype)Sets the content of this message using the specified text, and with a text MIME type of the specified subtype.protected voidupdateHeaders()Updates the headers of this part, based on the content.protected voidupdateMessageId()Updates the Message-ID header.voidwriteTo(java.io.OutputStream os)Writes this message to the specified stream in RFC 822 format.voidwriteTo(java.io.OutputStream os, java.lang.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
-
-
-
-
Field Detail
-
dh
protected javax.activation.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 java.io.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 thewriteTomethod. This field is set to true when an empty message is created or when thesaveChangesmethod is called.
-
saved
protected boolean saved
Indicates whether we do not need to callsaveChangeson the message. This flag is set to false by the public constructor and set to true by thesaveChangesmethod. ThewriteTomethod checks this flag and calls thesaveChangesmethod as necessary.
-
-
Constructor Detail
-
MimeMessage
public MimeMessage(Session session)
Constructor for an empty message.
-
MimeMessage
public MimeMessage(Session session, java.io.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 contextis- 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 foldermsgnum- the message number
-
MimeMessage
protected MimeMessage(Folder folder, java.io.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 folderis- the message input streammsgnum- 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 folderheaders- the headerscontent- the content byte arraymsgnum- the message number of this message within the folder- Throws:
MessagingException
-
-
Method Detail
-
parse
protected void parse(java.io.InputStream is) throws MessagingExceptionParses the given input stream, setting the headers and content fields appropriately. This resets themodifiedflag.- 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:
getFromin classMessage- Throws:
MessagingException
-
setFrom
public void setFrom(Address address) throws MessagingException
Sets the RFC 822 From header field.- Specified by:
setFromin classMessage- Parameters:
address- the sender of this message- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
setFrom
public void setFrom() throws MessagingExceptionSets the RFC 822 From header field using the value of theInternetAddress.getLocalAddressmethod.- Specified by:
setFromin classMessage- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
addFrom
public void addFrom(Address[] addresses) throws MessagingException
Adds the specified addresses to From header field.- Specified by:
addFromin classMessage- Parameters:
addresses- the senders of this message- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
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 valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- Since:
- JavaMail 1.3
-
getRecipients
public Address[] getRecipients(Message.RecipientType type) throws MessagingException
Returns the recipients of the given type.- Specified by:
getRecipientsin classMessage- 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:
getAllRecipientsin classMessage- Throws:
MessagingException
-
setRecipients
public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
Sets the recipients of the given type.- Specified by:
setRecipientsin classMessage- Parameters:
type- the recipient typeaddresses- the addresses, or null to remove recipients of this type- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
setRecipients
public void setRecipients(Message.RecipientType type, java.lang.String addresses) throws MessagingException
Sets the recipients of the given type.- Parameters:
type- the recipient typeaddresses- the addresses, or null to remove recpients of this type- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
addRecipients
public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
Adds the given addresses to the recipients of the specified type.- Specified by:
addRecipientsin classMessage- Parameters:
type- the recipient typeaddresses- the addresses- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
addRecipients
public void addRecipients(Message.RecipientType type, java.lang.String addresses) throws MessagingException
Adds the given addresses to the recipients of the specified type.- Parameters:
type- the recipient typeaddresses- the addresses- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
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 thegetFrommethod is returned.- Overrides:
getReplyToin classMessage- Throws:
MessagingException
-
setReplyTo
public void setReplyTo(Address[] addresses) throws MessagingException
Sets the RFC 822 Reply-To header field.- Overrides:
setReplyToin classMessage- Parameters:
addresses- the addresses, ornullto remove this header- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
getSubject
public java.lang.String getSubject() throws MessagingExceptionReturns 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:
getSubjectin classMessage- Throws:
MessagingException
-
setSubject
public void setSubject(java.lang.String subject) throws MessagingExceptionSets the Subject header field.If the subject contains non US-ASCII characters, it will be encoded using the platform default charset.
- Specified by:
setSubjectin classMessage- Parameters:
subject- the subject- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
setSubject
public void setSubject(java.lang.String subject, java.lang.String charset) throws MessagingExceptionSets the Subject header field.If the subject contains non US-ASCII characters, it will be encoded using the specified charset.
- Parameters:
subject- the subjectcharset- the charset used for any encoding- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
getSentDate
public java.util.Date getSentDate() throws MessagingExceptionReturns the value of the RFC 822 Date field. This is the date on which this message was sent.- Specified by:
getSentDatein classMessage- Throws:
MessagingException
-
setSentDate
public void setSentDate(java.util.Date date) throws MessagingExceptionSets the RFC 822 Date header field.- Specified by:
setSentDatein classMessage- Parameters:
date- the sent date, ornullto remove this header- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
getReceivedDate
public java.util.Date getReceivedDate() throws MessagingExceptionReturns the date on which this message was received. This returns null if the received date cannot be obtained.- Specified by:
getReceivedDatein classMessage- Throws:
MessagingException
-
getSize
public int getSize() throws MessagingExceptionReturns 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:
getSizein interfacePart- Throws:
MessagingException
-
getLineCount
public int getLineCount() throws MessagingExceptionReturns 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:
getLineCountin interfacePart- Throws:
MessagingException
-
getContentType
public java.lang.String getContentType() throws MessagingExceptionReturns the value of the RFC 822 Content-Type header field, or "text/plain" if the header is not available.- Specified by:
getContentTypein interfacePart- Throws:
MessagingException
-
isMimeType
public boolean isMimeType(java.lang.String mimeType) throws MessagingExceptionIndicates whether this message is of the specified MIME type.If the subtype of
mimeTypeis the special character '*', the subtype is ignored during the comparison.- Specified by:
isMimeTypein interfacePart- Throws:
MessagingException- See Also:
MimeBodyPart.isMimeType(java.lang.String)
-
getDisposition
public java.lang.String getDisposition() throws MessagingExceptionReturns the value of the RFC 822 Content-Disposition header field, ornullif the header is not available.- Specified by:
getDispositionin interfacePart- Throws:
MessagingException- See Also:
MimeBodyPart.getDisposition()
-
setDisposition
public void setDisposition(java.lang.String disposition) throws MessagingExceptionSets the Content-Disposition header field of this message.- Specified by:
setDispositionin interfacePart- Parameters:
disposition- the disposition value to set, or null to remove- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- See Also:
MimeBodyPart.setDisposition(java.lang.String)
-
getEncoding
public java.lang.String getEncoding() throws MessagingExceptionReturns the value of the Content-Transfer-Encoding header field.- Specified by:
getEncodingin interfaceMimePart- Throws:
MessagingException- See Also:
MimeBodyPart.getEncoding()
-
getContentID
public java.lang.String getContentID() throws MessagingExceptionReturns the value of the Content-ID header field.- Specified by:
getContentIDin interfaceMimePart- Throws:
MessagingException- See Also:
MimeBodyPart.getContentID()
-
setContentID
public void setContentID(java.lang.String cid) throws MessagingExceptionSets the Content-ID header field of this message.- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
getContentMD5
public java.lang.String getContentMD5() throws MessagingExceptionReturns the value of the Content-MD5 header field.- Specified by:
getContentMD5in interfaceMimePart- Throws:
MessagingException- See Also:
MimeBodyPart.getContentMD5()
-
setContentMD5
public void setContentMD5(java.lang.String md5) throws MessagingExceptionSets the Content-MD5 header field of this message.- Specified by:
setContentMD5in interfaceMimePart- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- See Also:
MimeBodyPart.setContentMD5(java.lang.String)
-
getDescription
public java.lang.String getDescription() throws MessagingExceptionReturns 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:
getDescriptionin interfacePart- Throws:
MessagingException- See Also:
MimeBodyPart.getDescription()
-
setDescription
public void setDescription(java.lang.String description) throws MessagingExceptionSets 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:
setDescriptionin interfacePart- Parameters:
description- the content description- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- See Also:
MimeBodyPart.setDescription(java.lang.String)
-
setDescription
public void setDescription(java.lang.String description, java.lang.String charset) throws MessagingExceptionSets 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 descriptioncharset- the charset used for any encoding- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- See Also:
MimeBodyPart.setDescription(java.lang.String)
-
getContentLanguage
public java.lang.String[] getContentLanguage() throws MessagingExceptionReturns the languages specified in the Content-Language header field of this message, as defined by RFC 1766. This method returnsnullif this header is not available.- Specified by:
getContentLanguagein interfaceMimePart- Throws:
MessagingException- See Also:
MimeBodyPart.getContentLanguage()
-
setContentLanguage
public void setContentLanguage(java.lang.String[] languages) throws MessagingExceptionSets the Content-Language header of this message.- Specified by:
setContentLanguagein interfaceMimePart- Parameters:
languages- the array of language tags- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- See Also:
MimeBodyPart.setContentLanguage(java.lang.String[])
-
getMessageID
public java.lang.String getMessageID() throws MessagingExceptionReturns the value of the Message-ID header field.- Throws:
MessagingException
-
getFileName
public java.lang.String getFileName() throws MessagingExceptionReturns 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:
getFileNamein interfacePart- Throws:
MessagingException- See Also:
MimeBodyPart.getFileName()
-
setFileName
public void setFileName(java.lang.String filename) throws MessagingExceptionSets the filename associated with this part.- Specified by:
setFileNamein interfacePart- Parameters:
filename- the filename to associate with this part- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- See Also:
MimeBodyPart.setFileName(java.lang.String)
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException, MessagingExceptionReturns a decoded input stream for this message's content.- Specified by:
getInputStreamin interfacePart- Throws:
java.io.IOException- if an error occurs in the data handler layerMessagingException- See Also:
MimeBodyPart.getInputStream()
-
getContentStream
protected java.io.InputStream getContentStream() throws MessagingExceptionReturns the unencoded bytes of the content.- Throws:
MessagingException- See Also:
MimeBodyPart.getContentStream()
-
getRawInputStream
public java.io.InputStream getRawInputStream() throws MessagingExceptionReturns the unencoded bytes of the content without applying any content transfer encoding.- Throws:
MessagingException- See Also:
MimeBodyPart.getRawInputStream()
-
getDataHandler
public javax.activation.DataHandler getDataHandler() throws MessagingExceptionReturns a data handler for accessing this message's content.- Specified by:
getDataHandlerin interfacePart- Throws:
MessagingException
-
getContent
public java.lang.Object getContent() throws java.io.IOException, MessagingExceptionReturns this message's content as a Java object.- Specified by:
getContentin interfacePart- Throws:
java.io.IOException- if an error occurred in the data handler layerMessagingException
-
setDataHandler
public void setDataHandler(javax.activation.DataHandler datahandler) throws MessagingExceptionSets the content of this part using the specified data handler.- Specified by:
setDataHandlerin interfacePart- Parameters:
datahandler- the data handler for the content- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- See Also:
MimeBodyPart.setDataHandler(javax.activation.DataHandler)
-
setContent
public void setContent(java.lang.Object o, java.lang.String type) throws MessagingExceptionSets 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:
setContentin interfacePart- Parameters:
o- the content objecttype- the MIME type of the object- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- See Also:
MimeBodyPart.setContent(java.lang.Object, java.lang.String)
-
setText
public void setText(java.lang.String text) throws MessagingExceptionSets 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:
setTextin interfaceMimePart- Specified by:
setTextin interfacePart- Parameters:
text- the text content- Throws:
IllegalWriteException- if the underlying implementation does not support modificationMessagingException- See Also:
MimeBodyPart.setText(String)
-
setText
public void setText(java.lang.String text, java.lang.String charset) throws MessagingExceptionSets 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:
setTextin interfaceMimePart- Parameters:
text- the text contentcharset- the charset used for any encoding- Throws:
MessagingException- See Also:
MimeBodyPart.setText(String,String)
-
setText
public void setText(java.lang.String text, java.lang.String charset, java.lang.String subtype) throws MessagingExceptionSets 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:
setTextin interfaceMimePart- Parameters:
text- the text contentcharset- the charset used for any encodingsubtype- 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:
setContentin interfacePart- Parameters:
mp- the multipart content- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- 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:
replyin classMessage- Parameters:
replyToAll- the reply should be sent to all the recipients of this message- Throws:
MessagingException
-
writeTo
public void writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingExceptionWrites this message to the specified stream in RFC 822 format.- Specified by:
writeToin interfacePart- Throws:
java.io.IOException- if an error occurs writing to the stream or in the data handler layerMessagingException- if an error occurs fetching the data to be written
-
writeTo
public void writeTo(java.io.OutputStream os, java.lang.String[] ignoreList) throws java.io.IOException, MessagingExceptionWrites this message to the specified stream in RFC 822 format, without the specified headers.- Throws:
java.io.IOException- if an error occurs writing to the stream or in the data handler layerMessagingException
-
getHeader
public java.lang.String[] getHeader(java.lang.String name) throws MessagingExceptionReturns 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:
getHeaderin interfacePart- Parameters:
name- the header name- Throws:
MessagingException
-
getHeader
public java.lang.String getHeader(java.lang.String name, java.lang.String delimiter) throws MessagingExceptionReturns all the values for the specified header name as a single string, with headers separated by the given delimiter. If the delimiter isnull, only the first header is returned.- Specified by:
getHeaderin interfaceMimePart- Parameters:
name- the header namedelimiter- the delimiter- Throws:
MessagingException
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value) throws MessagingExceptionSets the specified header.- Specified by:
setHeaderin interfacePart- Parameters:
name- the header namevalue- the header value- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value) throws MessagingExceptionAdds the specified header.- Specified by:
addHeaderin interfacePart- Parameters:
name- the header namevalue- the header value- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
removeHeader
public void removeHeader(java.lang.String name) throws MessagingExceptionRemoves all headers with the specified name.- Specified by:
removeHeaderin interfacePart- Parameters:
name- the header name- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
getAllHeaders
public java.util.Enumeration getAllHeaders() throws MessagingExceptionReturns all the headers.- Specified by:
getAllHeadersin interfacePart- Returns:
- an Enumeration of Header objects
- Throws:
MessagingException
-
getMatchingHeaders
public java.util.Enumeration getMatchingHeaders(java.lang.String[] names) throws MessagingExceptionReturns all the headers with any of the given names.- Specified by:
getMatchingHeadersin interfacePart- Parameters:
names- the header names to match- Returns:
- an Enumeration of Header objects
- Throws:
MessagingException
-
getNonMatchingHeaders
public java.util.Enumeration getNonMatchingHeaders(java.lang.String[] names) throws MessagingExceptionReturns all the headers without any of the given names.- Specified by:
getNonMatchingHeadersin interfacePart- Parameters:
names- the header names to ignore- Returns:
- an Enumeration of Header objects
- Throws:
MessagingException
-
addHeaderLine
public void addHeaderLine(java.lang.String line) throws MessagingExceptionAdds an RFC 822 header-line to this message.- Specified by:
addHeaderLinein interfaceMimePart- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
getAllHeaderLines
public java.util.Enumeration getAllHeaderLines() throws MessagingExceptionReturns all the header-lines.- Specified by:
getAllHeaderLinesin interfaceMimePart- Returns:
- an Enumeration of Strings
- Throws:
MessagingException
-
getMatchingHeaderLines
public java.util.Enumeration getMatchingHeaderLines(java.lang.String[] names) throws MessagingExceptionReturns all the header-lines with any of the given names.- Specified by:
getMatchingHeaderLinesin interfaceMimePart- Returns:
- an Enumeration of Strings
- Throws:
MessagingException
-
getNonMatchingHeaderLines
public java.util.Enumeration getNonMatchingHeaderLines(java.lang.String[] names) throws MessagingExceptionReturns all the header-lines without any of the given names.- Specified by:
getNonMatchingHeaderLinesin interfaceMimePart- Returns:
- an Enumeration of Strings
- Throws:
MessagingException
-
getFlags
public Flags getFlags() throws MessagingException
Returns the flags for this message.- Specified by:
getFlagsin classMessage- Throws:
MessagingException
-
isSet
public boolean isSet(Flags.Flag flag) throws MessagingException
Indicates whether the specified flag is set in this message.- Overrides:
isSetin classMessage- Parameters:
flag- the flag- Throws:
MessagingException
-
setFlags
public void setFlags(Flags flag, boolean set) throws MessagingException
Sets the flags for this message.- Specified by:
setFlagsin classMessage- Parameters:
flag- the flags to be setset- the value to be set- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
saveChanges
public void saveChanges() throws MessagingExceptionSaves any changes to this message. Header fields in the message are updated appropriately to be consistent with the message contents.- Specified by:
saveChangesin classMessage- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException
-
updateHeaders
protected void updateHeaders() throws MessagingExceptionUpdates the headers of this part, based on the content.- Throws:
IllegalWriteException- if the underlying implementation does not support modification of existing valuesjava.lang.IllegalStateException- if this message is obtained from a READ_ONLY folderMessagingException- See Also:
MimeBodyPart.updateHeaders()
-
createInternetHeaders
protected InternetHeaders createInternetHeaders(java.io.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 MessagingExceptionUpdates the Message-ID header. This method is called byupdateHeaders, 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 thereplymethod to determine the MimeMessage subclass, if any, to use.- Throws:
MessagingException- Since:
- JavaMail 1.4
-
-