Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.mail.Message
javax.mail.internet.MimeMessage
MimeUtility
to ensure that header
values are correctly encoded.
Nested Class Summary | |
static class |
|
Nested classes/interfaces inherited from class javax.mail.Message | |
Message.RecipientType |
Field Summary | |
protected byte[] |
|
protected InputStream |
|
protected DataHandler |
|
protected Flags |
|
protected InternetHeaders |
|
protected boolean |
|
protected boolean |
|
Fields inherited from interface javax.mail.Part | |
ATTACHMENT , INLINE |
Constructor Summary | |
| |
| |
| |
| |
| |
|
Method Summary | |
void | |
void |
|
void |
|
void |
|
void |
|
protected InternetHeaders |
|
protected MimeMessage |
|
Enumeration |
|
Enumeration |
|
Address[] |
|
Object |
|
String |
|
String[] |
|
String |
|
protected InputStream |
|
String |
|
DataHandler |
|
String |
|
String |
|
String |
|
String |
|
Flags |
|
Address[] |
|
String[] |
|
String |
|
InputStream |
|
int |
|
Enumeration |
|
Enumeration |
|
String |
|
Enumeration |
|
Enumeration |
|
InputStream |
|
Date |
|
Address[] |
|
Address[] |
|
Address |
|
Date |
|
int |
|
String |
|
boolean |
|
boolean |
|
protected void |
|
void |
|
Message |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void | |
void |
|
void | |
void |
|
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
protected void |
|
protected void |
|
void |
|
void |
|
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 |
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 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 thewriteTo
method. This field is set to true when an empty message is created or when thesaveChanges
method is called.
protected boolean saved
Indicates whether we do not need to callsaveChanges
on the message. This flag is set to false by the public constructor and set to true by thesaveChanges
method. ThewriteTo
method checks this flag and calls thesaveChanges
method as necessary.
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 folderis
- the message input streammsgnum
- the message number of this message within the folder
protected MimeMessage(Folder folder, int msgnum)
Constructor with a parent folder and message number.
- Parameters:
folder
- the parent foldermsgnum
- the message number
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
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 contextis
- the message input stream
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
public void addFrom(Address[] addresses) throws MessagingException
Adds the specified addresses to From header field.
- Parameters:
addresses
- the senders of this message
public void addHeader(String name, String value) throws MessagingException
Adds the specified header.
- Parameters:
name
- the header namevalue
- the header value
public void addHeaderLine(String line) throws MessagingException
Adds an RFC 822 header-line to this message.
- Specified by:
- addHeaderLine in interface MimePart
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 typeaddresses
- the addresses
public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
Adds the given addresses to the recipients of the specified type.
- Overrides:
- addRecipients in interface Message
- Parameters:
type
- the recipient typeaddresses
- the addresses
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
protected MimeMessage createMimeMessage(Session session) throws MessagingException
Creates a new MIME message. Used by thereply
method to determine the MimeMessage subclass, if any, to use.
- Since:
- JavaMail 1.4
public Enumeration getAllHeaderLines() throws MessagingException
Returns all the header-lines.
- Specified by:
- getAllHeaderLines in interface MimePart
- Returns:
- an Enumeration of Strings
public Enumeration getAllHeaders() throws MessagingException
Returns all the headers.
- Specified by:
- getAllHeaders in interface Part
- Returns:
- an Enumeration of Header objects
public Address[] getAllRecipients() throws MessagingException
Returns all the recipients. This returns the TO, CC, BCC, and NEWSGROUPS recipients.
- Overrides:
- getAllRecipients in interface Message
public Object getContent() throws IOException, MessagingException
Returns this message's content as a Java object.
- Specified by:
- getContent in interface Part
public String getContentID() throws MessagingException
Returns the value of the Content-ID header field.
- Specified by:
- getContentID in interface MimePart
- See Also:
MimeBodyPart.getContentID()
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 returnsnull
if this header is not available.
- Specified by:
- getContentLanguage in interface MimePart
- See Also:
MimeBodyPart.getContentLanguage()
public String getContentMD5() throws MessagingException
Returns the value of the Content-MD5 header field.
- Specified by:
- getContentMD5 in interface MimePart
- See Also:
MimeBodyPart.getContentMD5()
protected InputStream getContentStream() throws MessagingException
Returns the unencoded bytes of the content.
- See Also:
MimeBodyPart.getContentStream()
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
public DataHandler getDataHandler() throws MessagingException
Returns a data handler for accessing this message's content.
- Specified by:
- getDataHandler in interface Part
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
- See Also:
MimeBodyPart.getDescription()
public String getDisposition() throws MessagingException
Returns the value of the RFC 822 Content-Disposition header field, ornull
if the header is not available.
- Specified by:
- getDisposition in interface Part
- See Also:
MimeBodyPart.getDisposition()
public String getEncoding() throws MessagingException
Returns the value of the Content-Transfer-Encoding header field.
- Specified by:
- getEncoding in interface MimePart
- See Also:
MimeBodyPart.getEncoding()
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
- See Also:
MimeBodyPart.getFileName()
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.
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.
- Parameters:
name
- the header name
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 isnull
, only the first header is returned.
- Parameters:
name
- the header namedelimiter
- the delimiter
public InputStream getInputStream() throws IOException, MessagingException
Returns a decoded input stream for this message's content.
- Specified by:
- getInputStream in interface Part
- See Also:
MimeBodyPart.getInputStream()
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
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
public Enumeration getMatchingHeaders(String[] names) throws MessagingException
Returns all the headers with any of the given names.
- Specified by:
- getMatchingHeaders in interface Part
- Returns:
- an Enumeration of Header objects
public String getMessageID() throws MessagingException
Returns the value of the Message-ID header field.
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
public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException
Returns all the headers without any of the given names.
- Specified by:
- getNonMatchingHeaders in interface Part
- Returns:
- an Enumeration of Header objects
public InputStream getRawInputStream() throws MessagingException
Returns the unencoded bytes of the content without applying any content transfer encoding.
- See Also:
MimeBodyPart.getRawInputStream()
public Date getReceivedDate() throws MessagingException
Returns the date on which this message was received. This returns null if the received date cannot be obtained.
- Overrides:
- getReceivedDate in interface Message
public Address[] getRecipients(Message.RecipientType type) throws MessagingException
Returns the recipients of the given type.
- Overrides:
- getRecipients in interface Message
- Parameters:
type
- the recipient type
public Address[] getReplyTo() throws MessagingException
Returns the value of the RFC 822 Reply-To header field. If the header is absent, the value of thegetFrom
method is returned.
- Overrides:
- getReplyTo in interface Message
public Address getSender() throws MessagingException
Returns the value of the RFC 822 Sender header field.
- Since:
- JavaMail 1.3
public Date getSentDate() throws MessagingException
Returns the value of the RFC 822 Date field. This is the date on which this message was sent.
- Overrides:
- getSentDate in interface Message
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.
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.
- Overrides:
- getSubject in interface Message
public boolean isMimeType(String mimeType) throws MessagingException
Indicates whether this message is of the specified MIME type. If the subtype ofmimeType
is the special character '*', the subtype is ignored during the comparison.
- Specified by:
- isMimeType in interface Part
- See Also:
MimeBodyPart.isMimeType(String)
public boolean isSet(Flags.Flag flag) throws MessagingException
Indicates whether the specified flag is set in this message.
- Parameters:
flag
- the flag
protected void parse(InputStream is) throws MessagingException
Parses the given input stream, setting the headers and content fields appropriately. This resets themodified
flag.
- Parameters:
is
- the message input stream
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
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.
- Parameters:
replyToAll
- the reply should be sent to all the recipients of this message
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.
- Overrides:
- saveChanges in interface Message
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 objecttype
- the MIME type of the object
- See Also:
MimeBodyPart.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
- See Also:
MimeBodyPart.setContent(Multipart)
public void setContentID(String cid) throws MessagingException
Sets the Content-ID header field of this message.
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
public void setContentMD5(String md5) throws MessagingException
Sets the Content-MD5 header field of this message.
- Specified by:
- setContentMD5 in interface MimePart
- See Also:
MimeBodyPart.setContentMD5(String)
public void setDataHandler(DataHandler datahandler) throws MessagingException
Sets the content of this part using the specified data handler.
- Specified by:
- setDataHandler in interface Part
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
- See Also:
MimeBodyPart.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 descriptioncharset
- the charset used for any encoding
- See Also:
MimeBodyPart.setDescription
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
- See Also:
MimeBodyPart.setDisposition(String)
public void setFileName(String filename) throws MessagingException
Sets the filename associated with this part.
- Specified by:
- setFileName in interface Part
- See Also:
MimeBodyPart.setFileName(String)
public void setFlags(Flags flag, boolean set) throws MessagingException
Sets the flags for this message.
public void setFrom() throws MessagingException
Sets the RFC 822 From header field using the value of theInternetAddress.getLocalAddress
method.
public void setFrom(Address address) throws MessagingException
Sets the RFC 822 From header field.
- Parameters:
address
- the sender of this message
public void setHeader(String name, String value) throws MessagingException
Sets the specified header.
- Parameters:
name
- the header namevalue
- the header value
public void setRecipients(Message.RecipientType type, 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
public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
Sets the recipients of the given type.
- Overrides:
- setRecipients in interface Message
- Parameters:
type
- the recipient typeaddresses
- the addresses, or null to remove recipients of this type
public void setReplyTo(Address[] addresses) throws MessagingException
Sets the RFC 822 Reply-To header field.
- Overrides:
- setReplyTo in interface Message
- Parameters:
addresses
- the addresses, ornull
to remove this header
public void setSender(Address address) throws MessagingException
Sets the RFC 822 Sender header field.
- Parameters:
address
- the sender of this message
- Since:
- JavaMail 1.3
public void setSentDate(Date date) throws MessagingException
Sets the RFC 822 Date header field.
- Overrides:
- setSentDate in interface Message
- Parameters:
date
- the sent date, ornull
to remove this header
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.
- Overrides:
- setSubject in interface Message
- Parameters:
subject
- the subject
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 subjectcharset
- the charset used for any encoding
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.
- Parameters:
text
- the text content
- See Also:
MimeBodyPart.setText(String)
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.
- Parameters:
text
- the text contentcharset
- the charset used for any encoding
- See Also:
MimeBodyPart.setText(String,String)
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.
- Parameters:
text
- the text contentcharset
- the charset used for any encodingsubtype
- the MIME text subtype (e.g. "plain", "html")
- Since:
- JavaMail 1.4
protected void updateHeaders() throws MessagingException
Updates the headers of this part, based on the content.
- See Also:
MimeBodyPart.updateHeaders()
protected void updateMessageId() throws MessagingException
Updates the Message-ID header. This method is called byupdateHeaders
, and should set the Message-Id header to a suitably unique value if overridden.
- Since:
- JavaMail 1.4
public void writeTo(OutputStream os) throws IOException, MessagingException
Writes this message to the specified stream in RFC 822 format.
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.