org.apache.james.core
Class MimeMessageWrapper

java.lang.Object
  extended byjavax.mail.Message
      extended byjavax.mail.internet.MimeMessage
          extended byorg.apache.james.core.MimeMessageWrapper
All Implemented Interfaces:
org.apache.avalon.framework.activity.Disposable, MimePart, Part

public class MimeMessageWrapper
extends MimeMessage
implements org.apache.avalon.framework.activity.Disposable

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


Nested Class Summary
 
Nested classes inherited from class javax.mail.internet.MimeMessage
MimeMessage.RecipientType
 
Field Summary
protected  boolean bodyModified
          This is false until we parse the message
protected  boolean headersModified
          This is false until we parse the message
protected  boolean messageParsed
          This is false until we parse the message
protected  MimeMessageSource source
          Can provide an input stream to the data
 
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(MimeMessage original)
           
MimeMessageWrapper(MimeMessageSource source)
          A constructor that instantiates a MimeMessageWrapper based on a MimeMessageSource
MimeMessageWrapper(Session session, MimeMessageSource source)
          A constructor that instantiates a MimeMessageWrapper based on a MimeMessageSource
 
Method Summary
 void addHeader(String name, String value)
           
 void addHeaderLine(String line)
           
protected  InternetHeaders createInternetHeaders(InputStream is)
          If we already parsed the headers then we simply return the updated ones.
 void dispose()
           
 Enumeration getAllHeaderLines()
           
 Enumeration getAllHeaders()
           
protected  InputStream getContentStream()
           
 String[] getHeader(String name)
          We override all the "headers" access methods to be sure that we loaded the headers
 String getHeader(String name, String delimiter)
           
 int getLineCount()
          Corrects JavaMail 1.1 version which always returns -1.
 Enumeration getMatchingHeaderLines(String[] names)
           
 Enumeration getMatchingHeaders(String[] names)
           
 long getMessageSize()
          Returns size of message, ie headers and content
 Enumeration getNonMatchingHeaderLines(String[] names)
           
 Enumeration getNonMatchingHeaders(String[] names)
           
 InputStream getRawInputStream()
           
 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.
 boolean isModified()
          Get whether the message has been modified.
protected  void loadHeaders()
          Load the message headers from the internal source.
protected  void loadMessage()
          Load the complete MimeMessage from the internal source.
protected  void parse(InputStream is)
           
 void removeHeader(String name)
           
 void setDataHandler(DataHandler arg0)
          The message is changed when working with headers and when altering the content.
 void setHeader(String name, String value)
           
 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
addFrom, addRecipients, addRecipients, createMimeMessage, getAllRecipients, getContent, getContentID, getContentLanguage, getContentMD5, getContentType, getDataHandler, getDescription, getDisposition, getEncoding, getFileName, getFlags, getFrom, getInputStream, getMessageID, getReceivedDate, getRecipients, getReplyTo, getSender, getSentDate, getSubject, isMimeType, isSet, reply, saveChanges, setContent, setContent, setContentID, setContentLanguage, setContentMD5, setDescription, setDescription, setDisposition, setFileName, setFlags, setFrom, setFrom, setRecipients, setRecipients, setReplyTo, setSender, setSentDate, setSubject, setSubject, setText, setText, setText, updateHeaders, updateMessageID
 
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
 

Field Detail

source

protected MimeMessageSource source
Can provide an input stream to the data


messageParsed

protected boolean messageParsed
This is false until we parse the message


headersModified

protected boolean headersModified
This is false until we parse the message


bodyModified

protected boolean bodyModified
This is false until we parse the message

Constructor Detail

MimeMessageWrapper

public MimeMessageWrapper(Session session,
                          MimeMessageSource source)
                   throws MessagingException
A constructor that instantiates a MimeMessageWrapper based on a MimeMessageSource

Parameters:
source - the MimeMessageSource
Throws:
MessagingException

MimeMessageWrapper

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

Parameters:
source - the MimeMessageSource
Throws:
MessagingException
MessagingException

MimeMessageWrapper

public MimeMessageWrapper(MimeMessage original)
                   throws MessagingException
Method Detail

getSourceId

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

See Also:
MimeMessageSource

loadHeaders

protected void loadHeaders()
                    throws MessagingException
Load the message headers from the internal source.

Throws:
MessagingException - if an error is encountered while loading the headers

loadMessage

protected void loadMessage()
                    throws MessagingException
Load the complete MimeMessage from the internal source.

Throws:
MessagingException - if an error is encountered while loading the message

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
Throws:
IOException
MessagingException

writeTo

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

Throws:
IOException
MessagingException

writeTo

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

Throws:
IOException
MessagingException

writeTo

public void writeTo(OutputStream headerOs,
                    OutputStream bodyOs,
                    String[] ignoreList)
             throws IOException,
                    MessagingException
Throws:
IOException
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
Throws:
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
Throws:
MessagingException

getMessageSize

public long getMessageSize()
                    throws MessagingException
Returns size of message, ie headers and content

Throws:
MessagingException

getHeader

public String[] getHeader(String name)
                   throws MessagingException
We override all the "headers" access methods to be sure that we loaded the headers

Specified by:
getHeader in interface Part
Throws:
MessagingException

getHeader

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

getAllHeaders

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

getMatchingHeaders

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

getNonMatchingHeaders

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

getAllHeaderLines

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

getMatchingHeaderLines

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

getNonMatchingHeaderLines

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

setHeader

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

addHeader

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

removeHeader

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

addHeaderLine

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

setDataHandler

public void setDataHandler(DataHandler arg0)
                    throws MessagingException
The message is changed when working with headers and when altering the content. Every method that alter the content will fallback to this one.

Specified by:
setDataHandler in interface Part
Throws:
MessagingException
See Also:
Part.setDataHandler(javax.activation.DataHandler)

dispose

public void dispose()
Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable
See Also:
Disposable.dispose()

parse

protected void parse(InputStream is)
              throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.parse(java.io.InputStream)

createInternetHeaders

protected InternetHeaders createInternetHeaders(InputStream is)
                                         throws MessagingException
If we already parsed the headers then we simply return the updated ones. Otherwise we parse

Throws:
MessagingException
See Also:
MimeMessage.createInternetHeaders(java.io.InputStream)

getContentStream

protected InputStream getContentStream()
                                throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.getContentStream()

getRawInputStream

public InputStream getRawInputStream()
                              throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.getRawInputStream()


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