javax.mail.internet

Class MimeMessage

public class MimeMessage extends Message implements MimePart

Nested Class Summary
static classMimeMessage.RecipientType
Extends RecipientType to support addition recipient types.
Field Summary
protected byte[]content
This message's content (unless sourced from a SharedInputStream).
protected InputStreamcontentStream
If the data for this message was supplied by a SharedInputStream then this is another such stream representing the content of this message; if this field is non-null, then content will be null.
protected DataHandlerdh
The DataHandler for this Message's content.
protected Flagsflags
This message's flags.
protected InternetHeadersheaders
This message's headers.
protected booleanmodified
Flag indicating that the message has been modified; set to true when an empty message is created or when saveChanges is called.
protected booleansaved
Flag indicating that the message has been saved.
Constructor Summary
MimeMessage(Session session)
Create a new MimeMessage.
MimeMessage(Session session, InputStream in)
Create a MimeMessage by reading an parsing the data from the supplied stream.
MimeMessage(MimeMessage message)
Copy a MimeMessage.
protected MimeMessage(Folder folder, int number)
Create an new MimeMessage in the supplied Folder and message number.
protected MimeMessage(Folder folder, InputStream in, int number)
Create a MimeMessage by reading an parsing the data from the supplied stream.
protected MimeMessage(Folder folder, InternetHeaders headers, byte[] content, int number)
Create a MimeMessage with the supplied headers and content.
Method Summary
voidaddFrom(Address[] addresses)
voidaddHeader(String name, String value)
voidaddHeaderLine(String line)
voidaddRecipients(Message.RecipientType type, Address[] address)
voidaddRecipients(Message.RecipientType type, String address)
protected InternetHeaderscreateInternetHeaders(InputStream in)
EnumerationgetAllHeaderLines()
EnumerationgetAllHeaders()
Address[]getAllRecipients()
ObjectgetContent()
StringgetContentID()
String[]getContentLanguage()
StringgetContentMD5()
protected InputStreamgetContentStream()
StringgetContentType()
DataHandlergetDataHandler()
StringgetDescription()
StringgetDisposition()
StringgetEncoding()
StringgetFileName()
FlagsgetFlags()
Address[]getFrom()
String[]getHeader(String name)
StringgetHeader(String name, String delimiter)
InputStreamgetInputStream()
intgetLineCount()
EnumerationgetMatchingHeaderLines(String[] names)
EnumerationgetMatchingHeaders(String[] names)
StringgetMessageID()
EnumerationgetNonMatchingHeaderLines(String[] names)
EnumerationgetNonMatchingHeaders(String[] names)
InputStreamgetRawInputStream()
DategetReceivedDate()
Address[]getRecipients(Message.RecipientType type)
Address[]getReplyTo()
AddressgetSender()
Return the "Sender" header as an address.
DategetSentDate()
intgetSize()
StringgetSubject()
booleanisMimeType(String type)
booleanisSet(Flags.Flag flag)
protected voidparse(InputStream in)
Parse the supplied stream and initialize headers and content appropriately.
voidremoveHeader(String name)
Messagereply(boolean replyToAll)
voidsaveChanges()
voidsetContent(Object content, String type)
voidsetContent(Multipart part)
voidsetContentID(String cid)
voidsetContentLanguage(String[] languages)
voidsetContentMD5(String md5)
voidsetDataHandler(DataHandler handler)
voidsetDescription(String description)
voidsetDescription(String description, String charset)
voidsetDisposition(String disposition)
voidsetFileName(String name)
voidsetFlags(Flags flags, boolean set)
voidsetFrom(Address address)
voidsetFrom()
Set the "From" header using the value returned by getLocalAddress.
voidsetHeader(String name, String value)
voidsetRecipients(Message.RecipientType type, Address[] addresses)
voidsetRecipients(Message.RecipientType type, String address)
voidsetReplyTo(Address[] address)
voidsetSender(Address address)
Set the "Sender" header.
voidsetSentDate(Date sent)
voidsetSubject(String subject)
voidsetSubject(String subject, String charset)
voidsetText(String text)
voidsetText(String text, String charset)
protected voidupdateHeaders()
voidwriteTo(OutputStream out)
voidwriteTo(OutputStream out, String[] ignoreHeaders)

Field Detail

content

protected byte[] content
This message's content (unless sourced from a SharedInputStream).

contentStream

protected InputStream contentStream
If the data for this message was supplied by a SharedInputStream then this is another such stream representing the content of this message; if this field is non-null, then content will be null.

dh

protected DataHandler dh
The DataHandler for this Message's content.

flags

protected Flags flags
This message's flags.

headers

protected InternetHeaders headers
This message's headers.

modified

protected boolean modified
Flag indicating that the message has been modified; set to true when an empty message is created or when saveChanges is called.

saved

protected boolean saved
Flag indicating that the message has been saved.

Constructor Detail

MimeMessage

public MimeMessage(Session session)
Create a new MimeMessage. An empty message is created, with empty headers and empty flags. The modified flag is set.

Parameters: session the session for this message

MimeMessage

public MimeMessage(Session session, InputStream in)
Create a MimeMessage by reading an parsing the data from the supplied stream.

Parameters: session the session for this message in the stream to load from

Throws: MessagingException if there is a problem reading or parsing the stream

MimeMessage

public MimeMessage(MimeMessage message)
Copy a MimeMessage.

Parameters: message the message to copy

Throws: MessagingException is there was a problem copying the message

MimeMessage

protected MimeMessage(Folder folder, int number)
Create an new MimeMessage in the supplied Folder and message number.

Parameters: folder the Folder that contains the new message number the message number of the new message

MimeMessage

protected MimeMessage(Folder folder, InputStream in, int number)
Create a MimeMessage by reading an parsing the data from the supplied stream.

Parameters: folder the folder for this message in the stream to load from number the message number of the new message

Throws: MessagingException if there is a problem reading or parsing the stream

MimeMessage

protected MimeMessage(Folder folder, InternetHeaders headers, byte[] content, int number)
Create a MimeMessage with the supplied headers and content.

Parameters: folder the folder for this message headers the headers for the new message content the content of the new message number the message number of the new message

Throws: MessagingException if there is a problem reading or parsing the stream

Method Detail

addFrom

public void addFrom(Address[] addresses)

addHeader

public void addHeader(String name, String value)

addHeaderLine

public void addHeaderLine(String line)

addRecipients

public void addRecipients(Message.RecipientType type, Address[] address)

addRecipients

public void addRecipients(Message.RecipientType type, String address)

createInternetHeaders

protected InternetHeaders createInternetHeaders(InputStream in)

getAllHeaderLines

public Enumeration getAllHeaderLines()

getAllHeaders

public Enumeration getAllHeaders()

getAllRecipients

public Address[] getAllRecipients()

getContent

public Object getContent()

getContentID

public String getContentID()

getContentLanguage

public String[] getContentLanguage()

getContentMD5

public String getContentMD5()

getContentStream

protected InputStream getContentStream()

getContentType

public String getContentType()

getDataHandler

public DataHandler getDataHandler()

getDescription

public String getDescription()

getDisposition

public String getDisposition()

getEncoding

public String getEncoding()

getFileName

public String getFileName()

getFlags

public Flags getFlags()

getFrom

public Address[] getFrom()

getHeader

public String[] getHeader(String name)

getHeader

public String getHeader(String name, String delimiter)

getInputStream

public InputStream getInputStream()

getLineCount

public int getLineCount()

getMatchingHeaderLines

public Enumeration getMatchingHeaderLines(String[] names)

getMatchingHeaders

public Enumeration getMatchingHeaders(String[] names)

getMessageID

public String getMessageID()

getNonMatchingHeaderLines

public Enumeration getNonMatchingHeaderLines(String[] names)

getNonMatchingHeaders

public Enumeration getNonMatchingHeaders(String[] names)

getRawInputStream

public InputStream getRawInputStream()

getReceivedDate

public Date getReceivedDate()

getRecipients

public Address[] getRecipients(Message.RecipientType type)

getReplyTo

public Address[] getReplyTo()

getSender

public Address getSender()
Return the "Sender" header as an address.

Returns: the "Sender" header as an address, or null if not present

Throws: MessagingException if there was a problem parsing the header

getSentDate

public Date getSentDate()

getSize

public int getSize()

getSubject

public String getSubject()

isMimeType

public boolean isMimeType(String type)

isSet

public boolean isSet(Flags.Flag flag)

parse

protected void parse(InputStream in)
Parse the supplied stream and initialize headers and content appropriately.

Parameters: in the stream to read

Throws: MessagingException if there was a problem parsing the stream

removeHeader

public void removeHeader(String name)

reply

public Message reply(boolean replyToAll)

saveChanges

public void saveChanges()

setContent

public void setContent(Object content, String type)

setContent

public void setContent(Multipart part)

setContentID

public void setContentID(String cid)

setContentLanguage

public void setContentLanguage(String[] languages)

setContentMD5

public void setContentMD5(String md5)

setDataHandler

public void setDataHandler(DataHandler handler)

setDescription

public void setDescription(String description)

setDescription

public void setDescription(String description, String charset)

setDisposition

public void setDisposition(String disposition)

setFileName

public void setFileName(String name)

setFlags

public void setFlags(Flags flags, boolean set)

setFrom

public void setFrom(Address address)

setFrom

public void setFrom()
Set the "From" header using the value returned by getLocalAddress.

Throws: MessagingException if there was a problem setting the header

setHeader

public void setHeader(String name, String value)

setRecipients

public void setRecipients(Message.RecipientType type, Address[] addresses)

setRecipients

public void setRecipients(Message.RecipientType type, String address)

setReplyTo

public void setReplyTo(Address[] address)

setSender

public void setSender(Address address)
Set the "Sender" header.

Parameters: address the new Sender address

Throws: MessagingException if there was a problem setting the header

setSentDate

public void setSentDate(Date sent)

setSubject

public void setSubject(String subject)

setSubject

public void setSubject(String subject, String charset)

setText

public void setText(String text)

setText

public void setText(String text, String charset)

updateHeaders

protected void updateHeaders()

writeTo

public void writeTo(OutputStream out)

writeTo

public void writeTo(OutputStream out, String[] ignoreHeaders)