org.apache.james.core
Class MimeMessageWrapper

java.lang.Object
  |
  +--javax.mail.Message
        |
        +--javax.mail.internet.MimeMessage
              |
              +--org.apache.james.core.MimeMessageWrapper
All Implemented Interfaces:
Disposable, MimePart, Part

public class MimeMessageWrapper
extends MimeMessage
implements Disposable

This object wraps a MimeMessage, only loading the underlying MimeMessage object when needed. Also tracks if changes were made to reduce unnecessary saves.


Field Summary
 
Fields inherited from class javax.mail.internet.MimeMessage
content, contentStream, dh, flags, headers, modified, saved
 
Fields inherited from class javax.mail.Message
expunged, folder, msgnum, session
 
Fields inherited from interface javax.mail.Part
ATTACHMENT, INLINE
 
Constructor Summary
MimeMessageWrapper(MimeMessageSource source)
          A constructor that instantiates a MimeMessageWrapper based on a MimeMessageSource
 
Method Summary
 void addFrom(Address[] addresses)
           
 void addHeader(String name, String value)
           
 void addHeaderLine(String line)
           
 void addRecipients(Message.RecipientType type, Address[] addresses)
           
 void addRecipients(Message.RecipientType type, String addresses)
           
 void dispose()
           
 Enumeration getAllHeaderLines()
           
 Enumeration getAllHeaders()
           
 Address[] getAllRecipients()
           
 Object getContent()
           
 String getContentID()
           
 String[] getContentLanguage()
           
 String getContentMD5()
           
 String getContentType()
           
 DataHandler getDataHandler()
           
 String getDescription()
           
 String getDisposition()
           
 String getEncoding()
           
 String getFileName()
           
 Flags getFlags()
           
 Address[] getFrom()
          Various reader methods
 String[] getHeader(String name)
           
 String getHeader(String name, String delimiter)
           
 InputStream getInputStream()
           
 int getLineCount()
          Corrects JavaMail 1.1 version which always returns -1.
 Enumeration getMatchingHeaderLines(String[] names)
           
 Enumeration getMatchingHeaders(String[] names)
           
 String getMessageID()
           
 long getMessageSize()
          Returns size of message, ie headers and content.
 Enumeration getNonMatchingHeaderLines(String[] names)
           
 Enumeration getNonMatchingHeaders(String[] names)
           
 InputStream getRawInputStream()
           
 Date getReceivedDate()
          We do not attempt to define the received date, although in theory this is the last most date in the Received: headers.
 Address[] getRecipients(Message.RecipientType type)
           
 Address[] getReplyTo()
           
 Date getSentDate()
           
 int getSize()
          This is the MimeMessage implementation - this should return ONLY the body, not the entire message (should not count headers).
 String getSourceId()
          Returns the source ID of the MimeMessageSource that is supplying this with data.
 String getSubject()
           
 boolean isMimeType(String mimeType)
           
 boolean isModified()
          Get whether the message has been modified.
 boolean isSet(Flags.Flag flag)
           
 void removeHeader(String name)
           
 Message reply(boolean replyToAll)
           
 void saveChanges()
           
 void setContent(Multipart mp)
           
 void setContent(Object o, String type)
           
 void setContentID(String cid)
           
 void setContentLanguage(String[] languages)
           
 void setContentMD5(String md5)
           
 void setDataHandler(DataHandler dh)
           
 void setDescription(String description)
           
 void setDescription(String description, String charset)
           
 void setDisposition(String disposition)
           
 void setFileName(String filename)
           
 void setFlags(Flags flag, boolean set)
           
 void setFrom()
           
 void setFrom(Address address)
           
 void setHeader(String name, String value)
           
 void setRecipients(Message.RecipientType type, Address[] addresses)
           
 void setRecipients(Message.RecipientType type, String addresses)
           
 void setReplyTo(Address[] addresses)
           
 void setSentDate(Date d)
           
 void setSubject(String subject)
           
 void setSubject(String subject, String charset)
           
 void setText(String text)
           
 void setText(String text, String charset)
           
 void writeContentTo(OutputStream outs)
          Writes content only, ie not headers, to the specified OutputStream.
static void writeTo(MimeMessage message, OutputStream headerOs, OutputStream bodyOs)
          Convenience method to take any MimeMessage and write the headers and body to two different output streams
static void writeTo(MimeMessage message, OutputStream headerOs, OutputStream bodyOs, String[] ignoreList)
          Convenience method to take any MimeMessage and write the headers and body to two different output streams, with an ignore list
 void writeTo(OutputStream os)
          Rewritten for optimization purposes
 void writeTo(OutputStream headerOs, OutputStream bodyOs)
          Write
 void writeTo(OutputStream headerOs, OutputStream bodyOs, String[] ignoreList)
           
 void writeTo(OutputStream os, String[] ignoreList)
          Rewritten for optimization purposes
 
Methods inherited from class javax.mail.internet.MimeMessage
createInternetHeaders, getContentStream, parse, updateHeaders
 
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
 

Constructor Detail

MimeMessageWrapper

public MimeMessageWrapper(MimeMessageSource source)
A constructor that instantiates a MimeMessageWrapper based on a MimeMessageSource

Parameters:
source - the MimeMessageSource
Method Detail

getSourceId

public String getSourceId()
Returns the source ID of the MimeMessageSource that is supplying this with data.

See Also:
MimeMessageSource

isModified

public boolean isModified()
Get whether the message has been modified.

Returns:
whether the message has been modified

writeTo

public void writeTo(OutputStream os)
             throws IOException,
                    MessagingException
Rewritten for optimization purposes

Specified by:
writeTo in interface Part
Overrides:
writeTo in class MimeMessage
IOException
MessagingException

writeTo

public void writeTo(OutputStream os,
                    String[] ignoreList)
             throws IOException,
                    MessagingException
Rewritten for optimization purposes

Overrides:
writeTo in class MimeMessage
IOException
MessagingException

writeTo

public void writeTo(OutputStream headerOs,
                    OutputStream bodyOs)
             throws IOException,
                    MessagingException
Write

IOException
MessagingException

writeTo

public void writeTo(OutputStream headerOs,
                    OutputStream bodyOs,
                    String[] ignoreList)
             throws IOException,
                    MessagingException
IOException
MessagingException

writeTo

public static void writeTo(MimeMessage message,
                           OutputStream headerOs,
                           OutputStream bodyOs)
                    throws IOException,
                           MessagingException
Convenience method to take any MimeMessage and write the headers and body to two different output streams

IOException
MessagingException

writeTo

public static void writeTo(MimeMessage message,
                           OutputStream headerOs,
                           OutputStream bodyOs,
                           String[] ignoreList)
                    throws IOException,
                           MessagingException
Convenience method to take any MimeMessage and write the headers and body to two different output streams, with an ignore list

IOException
MessagingException

getFrom

public Address[] getFrom()
                  throws MessagingException
Various reader methods

Overrides:
getFrom in class MimeMessage
MessagingException

getRecipients

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

getAllRecipients

public Address[] getAllRecipients()
                           throws MessagingException
Overrides:
getAllRecipients in class MimeMessage
MessagingException

getReplyTo

public Address[] getReplyTo()
                     throws MessagingException
Overrides:
getReplyTo in class MimeMessage
MessagingException

getSubject

public String getSubject()
                  throws MessagingException
Overrides:
getSubject in class MimeMessage
MessagingException

getSentDate

public Date getSentDate()
                 throws MessagingException
Overrides:
getSentDate in class MimeMessage
MessagingException

getReceivedDate

public Date getReceivedDate()
                     throws MessagingException
We do not attempt to define the received date, although in theory this is the last most date in the Received: headers. For now we return null, which means we are not implementing it.

Overrides:
getReceivedDate in class MimeMessage
MessagingException

getSize

public int getSize()
            throws MessagingException
This is the MimeMessage implementation - this should return ONLY the body, not the entire message (should not count headers). Will have to parse the message.

Specified by:
getSize in interface Part
Overrides:
getSize in class MimeMessage
MessagingException

getLineCount

public int getLineCount()
                 throws MessagingException
Corrects JavaMail 1.1 version which always returns -1. Only corrected for content less than 5000 bytes, to avoid memory hogging.

Specified by:
getLineCount in interface Part
Overrides:
getLineCount in class MimeMessage
MessagingException

getMessageSize

public long getMessageSize()
                    throws MessagingException
Returns size of message, ie headers and content. Current implementation actually returns number of characters in headers plus number of bytes in the internal content byte array.

MessagingException

getContentType

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

isMimeType

public boolean isMimeType(String mimeType)
                   throws MessagingException
Specified by:
isMimeType in interface Part
Overrides:
isMimeType in class MimeMessage
MessagingException

getDisposition

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

getEncoding

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

getContentID

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

getContentMD5

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

getDescription

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

getContentLanguage

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

getMessageID

public String getMessageID()
                    throws MessagingException
Overrides:
getMessageID in class MimeMessage
MessagingException

getFileName

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

getInputStream

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

getDataHandler

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

getContent

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

getHeader

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

getHeader

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

getAllHeaders

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

getMatchingHeaders

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

getNonMatchingHeaders

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

getAllHeaderLines

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

getMatchingHeaderLines

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

getNonMatchingHeaderLines

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

getFlags

public Flags getFlags()
               throws MessagingException
Overrides:
getFlags in class MimeMessage
MessagingException

isSet

public boolean isSet(Flags.Flag flag)
              throws MessagingException
Overrides:
isSet in class MimeMessage
MessagingException

writeContentTo

public void writeContentTo(OutputStream outs)
                    throws IOException,
                           MessagingException
Writes content only, ie not headers, to the specified OutputStream.

Parameters:
outs - the OutputStream to which the content is written
IOException
MessagingException

setFrom

public void setFrom(Address address)
             throws MessagingException
Overrides:
setFrom in class MimeMessage
MessagingException

setFrom

public void setFrom()
             throws MessagingException
Overrides:
setFrom in class MimeMessage
MessagingException

addFrom

public void addFrom(Address[] addresses)
             throws MessagingException
Overrides:
addFrom in class MimeMessage
MessagingException

setRecipients

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

addRecipients

public void addRecipients(Message.RecipientType type,
                          Address[] addresses)
                   throws MessagingException
Overrides:
addRecipients in class MimeMessage
MessagingException

setReplyTo

public void setReplyTo(Address[] addresses)
                throws MessagingException
Overrides:
setReplyTo in class MimeMessage
MessagingException

setSubject

public void setSubject(String subject)
                throws MessagingException
Overrides:
setSubject in class MimeMessage
MessagingException

setSubject

public void setSubject(String subject,
                       String charset)
                throws MessagingException
Overrides:
setSubject in class MimeMessage
MessagingException

setSentDate

public void setSentDate(Date d)
                 throws MessagingException
Overrides:
setSentDate in class MimeMessage
MessagingException

setDisposition

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

setContentID

public void setContentID(String cid)
                  throws MessagingException
Overrides:
setContentID in class MimeMessage
MessagingException

setContentMD5

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

setDescription

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

setDescription

public void setDescription(String description,
                           String charset)
                    throws MessagingException
Overrides:
setDescription in class MimeMessage
MessagingException

setContentLanguage

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

setFileName

public void setFileName(String filename)
                 throws MessagingException
Specified by:
setFileName in interface Part
Overrides:
setFileName in class MimeMessage
MessagingException

setDataHandler

public void setDataHandler(DataHandler dh)
                    throws MessagingException
Specified by:
setDataHandler in interface Part
Overrides:
setDataHandler in class MimeMessage
MessagingException

setContent

public void setContent(Object o,
                       String type)
                throws MessagingException
Specified by:
setContent in interface Part
Overrides:
setContent in class MimeMessage
MessagingException

setText

public void setText(String text)
             throws MessagingException
Specified by:
setText in interface MimePart
Overrides:
setText in class MimeMessage
MessagingException

setText

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

setContent

public void setContent(Multipart mp)
                throws MessagingException
Specified by:
setContent in interface Part
Overrides:
setContent in class MimeMessage
MessagingException

reply

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

setHeader

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

addHeader

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

removeHeader

public void removeHeader(String name)
                  throws MessagingException
Specified by:
removeHeader in interface Part
Overrides:
removeHeader in class MimeMessage
MessagingException

addHeaderLine

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

setFlags

public void setFlags(Flags flag,
                     boolean set)
              throws MessagingException
Overrides:
setFlags in class MimeMessage
MessagingException

saveChanges

public void saveChanges()
                 throws MessagingException
Overrides:
saveChanges in class MimeMessage
MessagingException

getRawInputStream

public InputStream getRawInputStream()
                              throws MessagingException
Overrides:
getRawInputStream in class MimeMessage
MessagingException

addRecipients

public void addRecipients(Message.RecipientType type,
                          String addresses)
                   throws MessagingException
Overrides:
addRecipients in class MimeMessage
MessagingException

setRecipients

public void setRecipients(Message.RecipientType type,
                          String addresses)
                   throws MessagingException
Overrides:
setRecipients in class MimeMessage
MessagingException

dispose

public void dispose()
Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()


"Copyright © 1999-2002 Apache Jakarta Project. All Rights Reserved."