javax.mail.internet

Class MimeMessage

Implemented Interfaces:
MimePart, Part

public class MimeMessage
extends Message
implements MimePart

Nested Class Summary

static class
MimeMessage.RecipientType
Extends Message.RecipientType to support addition recipient types.

Nested classes/interfaces inherited from class javax.mail.Message

Message.RecipientType

Field Summary

protected byte[]
content
This message's content (unless sourced from a SharedInputStream).
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.
protected DataHandler
dh
The DataHandler for this Message's content.
protected Flags
flags
This message's flags.
protected InternetHeaders
headers
This message's headers.
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.
protected boolean
saved
Flag indicating that the message has been saved.

Fields inherited from class javax.mail.Message

expunged, folder, msgnum, session

Fields inherited from interface javax.mail.Part

ATTACHMENT, INLINE

Constructor Summary

MimeMessage(Folder folder, InputStream in, int number)
Create a MimeMessage by reading an parsing the data from the supplied stream.
MimeMessage(Folder folder, int number)
Create an new MimeMessage in the supplied Folder and message number.
MimeMessage(Folder folder, InternetHeaders headers, byte[] content, int number)
Create a MimeMessage with the supplied headers and content.
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.

Method Summary

void
addFrom(Address[] addresses)
void
addHeader(String name, String value)
void
addHeaderLine(String line)
void
addRecipients(Message.RecipientType type, String address)
void
addRecipients(Message.RecipientType type, Address[] address)
protected InternetHeaders
createInternetHeaders(InputStream in)
Enumeration
getAllHeaderLines()
Enumeration
getAllHeaders()
Address[]
getAllRecipients()
Object
getContent()
String
getContentID()
String[]
getContentLanguage()
String
getContentMD5()
protected InputStream
getContentStream()
String
getContentType()
DataHandler
getDataHandler()
String
getDescription()
String
getDisposition()
String
getEncoding()
String
getFileName()
Flags
getFlags()
Address[]
getFrom()
String[]
getHeader(String name)
String
getHeader(String name, String delimiter)
InputStream
getInputStream()
int
getLineCount()
Enumeration
getMatchingHeaderLines(String[] names)
Enumeration
getMatchingHeaders(String[] names)
String
getMessageID()
Enumeration
getNonMatchingHeaderLines(String[] names)
Enumeration
getNonMatchingHeaders(String[] names)
InputStream
getRawInputStream()
Date
getReceivedDate()
Address[]
getRecipients(Message.RecipientType type)
Address[]
getReplyTo()
Address
getSender()
Return the "Sender" header as an address.
Date
getSentDate()
int
getSize()
String
getSubject()
boolean
isMimeType(String type)
boolean
isSet(Flags.Flag flag)
protected void
parse(InputStream in)
Parse the supplied stream and initialize headers and content appropriately.
void
removeHeader(String name)
Message
reply(boolean replyToAll)
void
saveChanges()
void
setContent(Object content, String type)
void
setContent(Multipart part)
void
setContentID(String cid)
void
setContentLanguage(String[] languages)
void
setContentMD5(String md5)
void
setDataHandler(DataHandler handler)
void
setDescription(String description)
void
setDescription(String description, String charset)
void
setDisposition(String disposition)
void
setFileName(String name)
void
setFlags(Flags flags, boolean set)
void
setFrom()
Set the "From" header using the value returned by InternetAddress.getLocalAddress(Session).
void
setFrom(Address address)
void
setHeader(String name, String value)
void
setRecipients(Message.RecipientType type, String address)
void
setRecipients(Message.RecipientType type, Address[] addresses)
void
setReplyTo(Address[] address)
void
setSender(Address address)
Set the "Sender" header.
void
setSentDate(Date sent)
void
setSubject(String subject)
void
setSubject(String subject, String charset)
void
setText(String text)
void
setText(String text, String charset)
protected void
updateHeaders()
void
writeTo(OutputStream out)
void
writeTo(OutputStream out, String[] ignoreHeaders)

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

Field Details

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

saved

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

Constructor Details

MimeMessage

protected MimeMessage(Folder folder,
                      InputStream in,
                      int number)
            throws MessagingException
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,
                      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,
                      InternetHeaders headers,
                      byte[] content,
                      int number)
            throws MessagingException
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

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)
            throws MessagingException
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)
            throws MessagingException
Copy a MimeMessage.
Parameters:
message - the message to copy
Throws:
MessagingException - is there was a problem copying the message

Method Details

addFrom

public void addFrom(Address[] addresses)
            throws MessagingException
Overrides:
addFrom in interface Message

addHeader

public void addHeader(String name,
                      String value)
            throws MessagingException
Specified by:
addHeader in interface Part

addHeaderLine

public void addHeaderLine(String line)
            throws MessagingException
Specified by:
addHeaderLine in interface MimePart

addRecipients

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

addRecipients

public void addRecipients(Message.RecipientType type,
                          Address[] address)
            throws MessagingException
Overrides:
addRecipients in interface Message

createInternetHeaders

protected InternetHeaders createInternetHeaders(InputStream in)
            throws MessagingException

getAllHeaderLines

public Enumeration getAllHeaderLines()
            throws MessagingException
Specified by:
getAllHeaderLines in interface MimePart

getAllHeaders

public Enumeration getAllHeaders()
            throws MessagingException
Specified by:
getAllHeaders in interface Part

getAllRecipients

public Address[] getAllRecipients()
            throws MessagingException
Overrides:
getAllRecipients in interface Message

getContent

public Object getContent()
            throws MessagingException,
                   IOException
Specified by:
getContent in interface Part

getContentID

public String getContentID()
            throws MessagingException
Specified by:
getContentID in interface MimePart

getContentLanguage

public String[] getContentLanguage()
            throws MessagingException
Specified by:
getContentLanguage in interface MimePart

getContentMD5

public String getContentMD5()
            throws MessagingException
Specified by:
getContentMD5 in interface MimePart

getContentStream

protected InputStream getContentStream()
            throws MessagingException

getContentType

public String getContentType()
            throws MessagingException
Specified by:
getContentType in interface Part

getDataHandler

public DataHandler getDataHandler()
            throws MessagingException
Specified by:
getDataHandler in interface Part

getDescription

public String getDescription()
            throws MessagingException
Specified by:
getDescription in interface Part

getDisposition

public String getDisposition()
            throws MessagingException
Specified by:
getDisposition in interface Part

getEncoding

public String getEncoding()
            throws MessagingException
Specified by:
getEncoding in interface MimePart

getFileName

public String getFileName()
            throws MessagingException
Specified by:
getFileName in interface Part

getFlags

public Flags getFlags()
            throws MessagingException
Overrides:
getFlags in interface Message

getFrom

public Address[] getFrom()
            throws MessagingException
Overrides:
getFrom in interface Message

getHeader

public String[] getHeader(String name)
            throws MessagingException
Specified by:
getHeader in interface Part

getHeader

public String getHeader(String name,
                        String delimiter)
            throws MessagingException
Specified by:
getHeader in interface MimePart

getInputStream

public InputStream getInputStream()
            throws MessagingException,
                   IOException
Specified by:
getInputStream in interface Part

getLineCount

public int getLineCount()
            throws MessagingException
Specified by:
getLineCount in interface Part

getMatchingHeaderLines

public Enumeration getMatchingHeaderLines(String[] names)
            throws MessagingException
Specified by:
getMatchingHeaderLines in interface MimePart

getMatchingHeaders

public Enumeration getMatchingHeaders(String[] names)
            throws MessagingException
Specified by:
getMatchingHeaders in interface Part

getMessageID

public String getMessageID()
            throws MessagingException

getNonMatchingHeaderLines

public Enumeration getNonMatchingHeaderLines(String[] names)
            throws MessagingException
Specified by:
getNonMatchingHeaderLines in interface MimePart

getNonMatchingHeaders

public Enumeration getNonMatchingHeaders(String[] names)
            throws MessagingException
Specified by:
getNonMatchingHeaders in interface Part

getRawInputStream

public InputStream getRawInputStream()
            throws MessagingException

getReceivedDate

public Date getReceivedDate()
            throws MessagingException
Overrides:
getReceivedDate in interface Message

getRecipients

public Address[] getRecipients(Message.RecipientType type)
            throws MessagingException
Overrides:
getRecipients in interface Message

getReplyTo

public Address[] getReplyTo()
            throws MessagingException
Overrides:
getReplyTo in interface Message

getSender

public Address getSender()
            throws MessagingException
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()
            throws MessagingException
Overrides:
getSentDate in interface Message

getSize

public int getSize()
            throws MessagingException
Specified by:
getSize in interface Part

getSubject

public String getSubject()
            throws MessagingException
Overrides:
getSubject in interface Message

isMimeType

public boolean isMimeType(String type)
            throws MessagingException
Specified by:
isMimeType in interface Part

isSet

public boolean isSet(Flags.Flag flag)
            throws MessagingException
Overrides:
isSet in interface Message

parse

protected void parse(InputStream in)
            throws MessagingException
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)
            throws MessagingException
Specified by:
removeHeader in interface Part

reply

public Message reply(boolean replyToAll)
            throws MessagingException
Overrides:
reply in interface Message

saveChanges

public void saveChanges()
            throws MessagingException
Overrides:
saveChanges in interface Message

setContent

public void setContent(Object content,
                       String type)
            throws MessagingException
Specified by:
setContent in interface Part

setContent

public void setContent(Multipart part)
            throws MessagingException
Specified by:
setContent in interface Part

setContentID

public void setContentID(String cid)
            throws MessagingException

setContentLanguage

public void setContentLanguage(String[] languages)
            throws MessagingException
Specified by:
setContentLanguage in interface MimePart

setContentMD5

public void setContentMD5(String md5)
            throws MessagingException
Specified by:
setContentMD5 in interface MimePart

setDataHandler

public void setDataHandler(DataHandler handler)
            throws MessagingException
Specified by:
setDataHandler in interface Part

setDescription

public void setDescription(String description)
            throws MessagingException
Specified by:
setDescription in interface Part

setDescription

public void setDescription(String description,
                           String charset)
            throws MessagingException

setDisposition

public void setDisposition(String disposition)
            throws MessagingException
Specified by:
setDisposition in interface Part

setFileName

public void setFileName(String name)
            throws MessagingException
Specified by:
setFileName in interface Part

setFlags

public void setFlags(Flags flags,
                     boolean set)
            throws MessagingException
Overrides:
setFlags in interface Message

setFrom

public void setFrom()
            throws MessagingException
Set the "From" header using the value returned by InternetAddress.getLocalAddress(Session).
Overrides:
setFrom in interface Message
Throws:
MessagingException - if there was a problem setting the header

setFrom

public void setFrom(Address address)
            throws MessagingException
Overrides:
setFrom in interface Message

setHeader

public void setHeader(String name,
                      String value)
            throws MessagingException
Specified by:
setHeader in interface Part

setRecipients

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

setRecipients

public void setRecipients(Message.RecipientType type,
                          Address[] addresses)
            throws MessagingException
Overrides:
setRecipients in interface Message

setReplyTo

public void setReplyTo(Address[] address)
            throws MessagingException
Overrides:
setReplyTo in interface Message

setSender

public void setSender(Address address)
            throws MessagingException
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)
            throws MessagingException
Overrides:
setSentDate in interface Message

setSubject

public void setSubject(String subject)
            throws MessagingException
Overrides:
setSubject in interface Message

setSubject

public void setSubject(String subject,
                       String charset)
            throws MessagingException

setText

public void setText(String text)
            throws MessagingException
Specified by:
setText in interface MimePart
setText in interface Part

setText

public void setText(String text,
                    String charset)
            throws MessagingException
Specified by:
setText in interface MimePart

updateHeaders

protected void updateHeaders()
            throws MessagingException

writeTo

public void writeTo(OutputStream out)
            throws MessagingException,
                   IOException
Specified by:
writeTo in interface Part

writeTo

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