org.apache.james.core
Class MimeMessageCopyOnWriteProxy

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

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

This object wraps a "possibly shared" MimeMessage tracking copies and automatically cloning it (if shared) when a write operation is invoked.


Nested Class Summary
protected static class MimeMessageCopyOnWriteProxy.MessageReferenceTracker
          Used internally to track the reference count It is important that this is static otherwise it will keep a reference to the parent object.
 
Nested classes inherited from class javax.mail.internet.MimeMessage
MimeMessage.RecipientType
 
Field Summary
protected  MimeMessageCopyOnWriteProxy.MessageReferenceTracker refCount
           
 
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
MimeMessageCopyOnWriteProxy(MimeMessage original)
           
MimeMessageCopyOnWriteProxy(MimeMessageSource original)
           
 
Method Summary
 void addFrom(Address[] addresses)
           
 void addHeader(String name, String value)
           
 void addHeaderLine(String line)
           
 void addRecipient(MimeMessage.RecipientType arg0, Address arg1)
           
 void addRecipients(Message.RecipientType type, Address[] addresses)
           
 void addRecipients(Message.RecipientType type, String addresses)
           
 void dispose()
           
 boolean equals(Object arg0)
           
protected  void finalize()
           
 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()
           
 Folder getFolder()
           
 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()
           
 int getMessageNumber()
           
 long getMessageSize()
           
 Enumeration getNonMatchingHeaderLines(String[] names)
           
 Enumeration getNonMatchingHeaders(String[] names)
           
 InputStream getRawInputStream()
           
 Date getReceivedDate()
           
 Address[] getRecipients(Message.RecipientType type)
           
 Address[] getReplyTo()
           
 Address getSender()
           
 Date getSentDate()
           
 int getSize()
           
 String getSubject()
           
 MimeMessage getWrappedMessage()
           
protected  MimeMessage getWrappedMessageForWriting()
          Check the number of references over the MimeMessage and clone it if needed before returning the reference
 int hashCode()
           
 boolean isExpunged()
           
 boolean isMimeType(String mimeType)
           
 boolean isSet(Flags.Flag flag)
           
 boolean match(SearchTerm arg0)
           
 void removeHeader(String name)
           
 Message reply(boolean replyToAll)
          This does not need a writable message
 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 setFlag(Flags.Flag arg0, boolean arg1)
           
 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 setSender(Address arg0)
           
 void setSentDate(Date d)
           
 void setSubject(String subject)
           
 void setSubject(String subject, String charset)
           
 void setText(String text)
           
 void setText(String text, String charset)
           
 String toString()
           
 void writeTo(OutputStream os)
          Rewritten for optimization purposes
 void writeTo(OutputStream os, String[] ignoreList)
          Rewritten for optimization purposes
 
Methods inherited from class javax.mail.internet.MimeMessage
createInternetHeaders, createMimeMessage, getContentStream, parse, setText, updateHeaders, updateMessageID
 
Methods inherited from class javax.mail.Message
addRecipient, setExpunged, setMessageNumber, setRecipient
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

refCount

protected MimeMessageCopyOnWriteProxy.MessageReferenceTracker refCount
Constructor Detail

MimeMessageCopyOnWriteProxy

public MimeMessageCopyOnWriteProxy(MimeMessage original)
                            throws MessagingException
Parameters:
original - MimeMessageWrapper
Throws:
MessagingException

MimeMessageCopyOnWriteProxy

public MimeMessageCopyOnWriteProxy(MimeMessageSource original)
                            throws MessagingException
Parameters:
original - MimeMessageSource
Throws:
MessagingException
Method Detail

getWrappedMessageForWriting

protected MimeMessage getWrappedMessageForWriting()
                                           throws MessagingException
Check the number of references over the MimeMessage and clone it if needed before returning the reference

Throws:
MessagingException - exception

getWrappedMessage

public MimeMessage getWrappedMessage()
Returns:

dispose

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

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

getFrom

public Address[] getFrom()
                  throws MessagingException
Throws:
MessagingException
See Also:
Message.getFrom()

getRecipients

public Address[] getRecipients(Message.RecipientType type)
                        throws MessagingException
Throws:
MessagingException
See Also:
Message.getRecipients(javax.mail.Message.RecipientType)

getAllRecipients

public Address[] getAllRecipients()
                           throws MessagingException
Throws:
MessagingException
See Also:
Message.getAllRecipients()

getReplyTo

public Address[] getReplyTo()
                     throws MessagingException
Throws:
MessagingException
See Also:
Message.getReplyTo()

getSubject

public String getSubject()
                  throws MessagingException
Throws:
MessagingException
See Also:
Message.getSubject()

getSentDate

public Date getSentDate()
                 throws MessagingException
Throws:
MessagingException
See Also:
Message.getSentDate()

getReceivedDate

public Date getReceivedDate()
                     throws MessagingException
Throws:
MessagingException
See Also:
Message.getReceivedDate()

getSize

public int getSize()
            throws MessagingException
Specified by:
getSize in interface Part
Throws:
MessagingException
See Also:
Part.getSize()

getLineCount

public int getLineCount()
                 throws MessagingException
Specified by:
getLineCount in interface Part
Throws:
MessagingException
See Also:
Part.getLineCount()

getContentType

public String getContentType()
                      throws MessagingException
Specified by:
getContentType in interface Part
Throws:
MessagingException
See Also:
Part.getContentType()

isMimeType

public boolean isMimeType(String mimeType)
                   throws MessagingException
Specified by:
isMimeType in interface Part
Throws:
MessagingException
See Also:
Part.isMimeType(java.lang.String)

getDisposition

public String getDisposition()
                      throws MessagingException
Specified by:
getDisposition in interface Part
Throws:
MessagingException
See Also:
Part.getDisposition()

getEncoding

public String getEncoding()
                   throws MessagingException
Specified by:
getEncoding in interface MimePart
Throws:
MessagingException
See Also:
MimePart.getEncoding()

getContentID

public String getContentID()
                    throws MessagingException
Specified by:
getContentID in interface MimePart
Throws:
MessagingException
See Also:
MimePart.getContentID()

getContentMD5

public String getContentMD5()
                     throws MessagingException
Specified by:
getContentMD5 in interface MimePart
Throws:
MessagingException
See Also:
MimePart.getContentMD5()

getDescription

public String getDescription()
                      throws MessagingException
Specified by:
getDescription in interface Part
Throws:
MessagingException
See Also:
Part.getDescription()

getContentLanguage

public String[] getContentLanguage()
                            throws MessagingException
Specified by:
getContentLanguage in interface MimePart
Throws:
MessagingException
See Also:
MimePart.getContentLanguage()

getMessageID

public String getMessageID()
                    throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.getMessageID()

getFileName

public String getFileName()
                   throws MessagingException
Specified by:
getFileName in interface Part
Throws:
MessagingException
See Also:
Part.getFileName()

getInputStream

public InputStream getInputStream()
                           throws IOException,
                                  MessagingException
Specified by:
getInputStream in interface Part
Throws:
IOException
MessagingException
See Also:
Part.getInputStream()

getDataHandler

public DataHandler getDataHandler()
                           throws MessagingException
Specified by:
getDataHandler in interface Part
Throws:
MessagingException
See Also:
Part.getDataHandler()

getContent

public Object getContent()
                  throws IOException,
                         MessagingException
Specified by:
getContent in interface Part
Throws:
IOException
MessagingException
See Also:
Part.getContent()

getHeader

public String[] getHeader(String name)
                   throws MessagingException
Specified by:
getHeader in interface Part
Throws:
MessagingException
See Also:
Part.getHeader(java.lang.String)

getHeader

public String getHeader(String name,
                        String delimiter)
                 throws MessagingException
Specified by:
getHeader in interface MimePart
Throws:
MessagingException
See Also:
MimePart.getHeader(java.lang.String, java.lang.String)

getAllHeaders

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

getMatchingHeaders

public Enumeration getMatchingHeaders(String[] names)
                               throws MessagingException
Specified by:
getMatchingHeaders in interface Part
Throws:
MessagingException
See Also:
Part.getMatchingHeaders(java.lang.String[])

getNonMatchingHeaders

public Enumeration getNonMatchingHeaders(String[] names)
                                  throws MessagingException
Specified by:
getNonMatchingHeaders in interface Part
Throws:
MessagingException
See Also:
Part.getNonMatchingHeaders(java.lang.String[])

getAllHeaderLines

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

getMatchingHeaderLines

public Enumeration getMatchingHeaderLines(String[] names)
                                   throws MessagingException
Specified by:
getMatchingHeaderLines in interface MimePart
Throws:
MessagingException
See Also:
MimePart.getMatchingHeaderLines(java.lang.String[])

getNonMatchingHeaderLines

public Enumeration getNonMatchingHeaderLines(String[] names)
                                      throws MessagingException
Specified by:
getNonMatchingHeaderLines in interface MimePart
Throws:
MessagingException
See Also:
MimePart.getNonMatchingHeaderLines(java.lang.String[])

getFlags

public Flags getFlags()
               throws MessagingException
Throws:
MessagingException
See Also:
Message.getFlags()

isSet

public boolean isSet(Flags.Flag flag)
              throws MessagingException
Throws:
MessagingException
See Also:
Message.isSet(javax.mail.Flags.Flag)

getSender

public Address getSender()
                  throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.getSender()

match

public boolean match(SearchTerm arg0)
              throws MessagingException
Throws:
MessagingException
See Also:
Message.match(javax.mail.search.SearchTerm)

getRawInputStream

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

getFolder

public Folder getFolder()
See Also:
Message.getFolder()

getMessageNumber

public int getMessageNumber()
See Also:
Message.getMessageNumber()

isExpunged

public boolean isExpunged()
See Also:
Message.isExpunged()

equals

public boolean equals(Object arg0)
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
See Also:
Object.hashCode()

toString

public String toString()
See Also:
Object.toString()

setFrom

public void setFrom(Address address)
             throws MessagingException
Throws:
MessagingException
See Also:
Message.setFrom(javax.mail.Address)

setFrom

public void setFrom()
             throws MessagingException
Throws:
MessagingException
See Also:
Message.setFrom()

addFrom

public void addFrom(Address[] addresses)
             throws MessagingException
Throws:
MessagingException
See Also:
Message.addFrom(javax.mail.Address[])

setRecipients

public void setRecipients(Message.RecipientType type,
                          Address[] addresses)
                   throws MessagingException
Throws:
MessagingException
See Also:
Message.setRecipients(javax.mail.Message.RecipientType, javax.mail.Address[])

addRecipients

public void addRecipients(Message.RecipientType type,
                          Address[] addresses)
                   throws MessagingException
Throws:
MessagingException
See Also:
Message.addRecipients(javax.mail.Message.RecipientType, javax.mail.Address[])

setReplyTo

public void setReplyTo(Address[] addresses)
                throws MessagingException
Throws:
MessagingException
See Also:
Message.setReplyTo(javax.mail.Address[])

setSubject

public void setSubject(String subject)
                throws MessagingException
Throws:
MessagingException
See Also:
Message.setSubject(java.lang.String)

setSubject

public void setSubject(String subject,
                       String charset)
                throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.setSubject(java.lang.String, java.lang.String)

setSentDate

public void setSentDate(Date d)
                 throws MessagingException
Throws:
MessagingException
See Also:
Message.setSentDate(java.util.Date)

setDisposition

public void setDisposition(String disposition)
                    throws MessagingException
Specified by:
setDisposition in interface Part
Throws:
MessagingException
See Also:
Part.setDisposition(java.lang.String)

setContentID

public void setContentID(String cid)
                  throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.setContentID(java.lang.String)

setContentMD5

public void setContentMD5(String md5)
                   throws MessagingException
Specified by:
setContentMD5 in interface MimePart
Throws:
MessagingException
See Also:
MimePart.setContentMD5(java.lang.String)

setDescription

public void setDescription(String description)
                    throws MessagingException
Specified by:
setDescription in interface Part
Throws:
MessagingException
See Also:
Part.setDescription(java.lang.String)

setDescription

public void setDescription(String description,
                           String charset)
                    throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.setDescription(java.lang.String, java.lang.String)

setContentLanguage

public void setContentLanguage(String[] languages)
                        throws MessagingException
Specified by:
setContentLanguage in interface MimePart
Throws:
MessagingException
See Also:
MimePart.setContentLanguage(java.lang.String[])

setFileName

public void setFileName(String filename)
                 throws MessagingException
Specified by:
setFileName in interface Part
Throws:
MessagingException
See Also:
Part.setFileName(java.lang.String)

setDataHandler

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

setContent

public void setContent(Object o,
                       String type)
                throws MessagingException
Specified by:
setContent in interface Part
Throws:
MessagingException
See Also:
Part.setContent(java.lang.Object, java.lang.String)

setText

public void setText(String text)
             throws MessagingException
Specified by:
setText in interface MimePart
Throws:
MessagingException
See Also:
Part.setText(java.lang.String)

setText

public void setText(String text,
                    String charset)
             throws MessagingException
Specified by:
setText in interface MimePart
Throws:
MessagingException
See Also:
MimePart.setText(java.lang.String, java.lang.String)

setContent

public void setContent(Multipart mp)
                throws MessagingException
Specified by:
setContent in interface Part
Throws:
MessagingException
See Also:
Part.setContent(javax.mail.Multipart)

reply

public Message reply(boolean replyToAll)
              throws MessagingException
This does not need a writable message

Throws:
MessagingException
See Also:
Message.reply(boolean)

setHeader

public void setHeader(String name,
                      String value)
               throws MessagingException
Specified by:
setHeader in interface Part
Throws:
MessagingException
See Also:
Part.setHeader(java.lang.String, java.lang.String)

addHeader

public void addHeader(String name,
                      String value)
               throws MessagingException
Specified by:
addHeader in interface Part
Throws:
MessagingException
See Also:
Part.addHeader(java.lang.String, java.lang.String)

removeHeader

public void removeHeader(String name)
                  throws MessagingException
Specified by:
removeHeader in interface Part
Throws:
MessagingException
See Also:
Part.removeHeader(java.lang.String)

addHeaderLine

public void addHeaderLine(String line)
                   throws MessagingException
Specified by:
addHeaderLine in interface MimePart
Throws:
MessagingException
See Also:
MimePart.addHeaderLine(java.lang.String)

setFlags

public void setFlags(Flags flag,
                     boolean set)
              throws MessagingException
Throws:
MessagingException
See Also:
Message.setFlags(javax.mail.Flags, boolean)

saveChanges

public void saveChanges()
                 throws MessagingException
Throws:
MessagingException
See Also:
Message.saveChanges()

addRecipients

public void addRecipients(Message.RecipientType type,
                          String addresses)
                   throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.addRecipients(javax.mail.Message.RecipientType, java.lang.String)

setRecipients

public void setRecipients(Message.RecipientType type,
                          String addresses)
                   throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.setRecipients(javax.mail.Message.RecipientType, java.lang.String)

setSender

public void setSender(Address arg0)
               throws MessagingException
Throws:
MessagingException
See Also:
MimeMessage.setSender(javax.mail.Address)

addRecipient

public void addRecipient(MimeMessage.RecipientType arg0,
                         Address arg1)
                  throws MessagingException
Throws:
MessagingException
See Also:
Message.addRecipient(javax.mail.Message.RecipientType, javax.mail.Address)

setFlag

public void setFlag(Flags.Flag arg0,
                    boolean arg1)
             throws MessagingException
Throws:
MessagingException
See Also:
Message.setFlag(javax.mail.Flags.Flag, boolean)

finalize

protected void finalize()
                 throws Throwable
Throws:
Throwable
See Also:
Object.finalize()

getMessageSize

public long getMessageSize()
                    throws MessagingException
Returns:
the message size
Throws:
MessagingException


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