com.sun.mail.mbox
Class MboxMessage

java.lang.Object
  extended by javax.mail.Message
      extended by javax.mail.internet.MimeMessage
          extended by com.sun.mail.mbox.MboxMessage
All Implemented Interfaces:
javax.mail.internet.MimePart, javax.mail.Part

public class MboxMessage
extends javax.mail.internet.MimeMessage

This class represents an RFC822 style email message that resides in a file.


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.mail.internet.MimeMessage
javax.mail.internet.MimeMessage.RecipientType
 
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
MboxMessage(MboxFolder folder, javax.mail.internet.InternetHeaders hdrs, byte[] content, int msgno, java.lang.String unix_from, boolean writable)
          Construct an MboxMessage using the given InternetHeaders object and byte array contents.
MboxMessage(javax.mail.Session session, java.io.InputStream is)
          Construct an MboxMessage from the InputStream.
 
Method Summary
protected  java.io.InputStream getContentStream()
          Produce the raw bytes of the content.
 java.lang.String getContentType()
          Return the content type, mapping from SunV3 types to MIME types as necessary.
 javax.activation.DataHandler getDataHandler()
          Return a DataHandler for this Message's content.
 javax.mail.Address[] getFrom()
          Returns the "From" attribute.
 int getLineCount()
          Return the number of lines for the content of this message.
 java.util.Date getReceivedDate()
          Get the date this message was received, from the UNIX From line.
 javax.mail.internet.InternetAddress getUnixFrom()
          Returns the address from the UNIX "From" line.
 void saveChanges()
          Save any changes made to this message.
 void setFlags(javax.mail.Flags newFlags, boolean set)
          Set the specified flags on this message to the specified value.
protected  void setMessageNumber(int msgno)
          Set the Message number for this Message.
protected  void updateHeaders()
          Called by the saveChanges method to actually update the MIME headers.
 void writeToFile(java.io.OutputStream os)
          Put out a byte stream suitable for saving to a file.
 
Methods inherited from class javax.mail.internet.MimeMessage
addFrom, addHeader, addHeaderLine, addRecipients, addRecipients, createInternetHeaders, createMimeMessage, getAllHeaderLines, getAllHeaders, getAllRecipients, getContent, getContentID, getContentLanguage, getContentMD5, getDescription, getDisposition, getEncoding, getFileName, getFlags, getHeader, getHeader, getInputStream, getMatchingHeaderLines, getMatchingHeaders, getMessageID, getNonMatchingHeaderLines, getNonMatchingHeaders, getRawInputStream, getRecipients, getReplyTo, getSender, getSentDate, getSize, getSubject, isMimeType, isSet, parse, removeHeader, reply, setContent, setContent, setContentID, setContentLanguage, setContentMD5, setDataHandler, setDescription, setDescription, setDisposition, setFileName, setFrom, setFrom, setHeader, setRecipients, setRecipients, setReplyTo, setSender, setSentDate, setSubject, setSubject, setText, setText, setText, updateMessageID, writeTo, writeTo
 
Methods inherited from class javax.mail.Message
addRecipient, getFolder, getMessageNumber, isExpunged, match, setExpunged, setFlag, setRecipient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MboxMessage

public MboxMessage(javax.mail.Session session,
                   java.io.InputStream is)
            throws javax.mail.MessagingException,
                   java.io.IOException
Construct an MboxMessage from the InputStream.

Throws:
javax.mail.MessagingException
java.io.IOException

MboxMessage

public MboxMessage(MboxFolder folder,
                   javax.mail.internet.InternetHeaders hdrs,
                   byte[] content,
                   int msgno,
                   java.lang.String unix_from,
                   boolean writable)
            throws javax.mail.MessagingException
Construct an MboxMessage using the given InternetHeaders object and byte array contents.

Throws:
javax.mail.MessagingException
Method Detail

getFrom

public javax.mail.Address[] getFrom()
                             throws javax.mail.MessagingException
Returns the "From" attribute. The "From" attribute contains the identity of the person(s) who wished this message to be sent.

If our superclass doesn't have a value, we return the address from the UNIX From line.

Overrides:
getFrom in class javax.mail.internet.MimeMessage
Returns:
array of Address objects
Throws:
javax.mail.MessagingException
See Also:
MimeMessage.headers

getUnixFrom

public javax.mail.internet.InternetAddress getUnixFrom()
                                                throws javax.mail.MessagingException
Returns the address from the UNIX "From" line.

Returns:
UNIX From address
Throws:
javax.mail.MessagingException

getReceivedDate

public java.util.Date getReceivedDate()
                               throws javax.mail.MessagingException
Get the date this message was received, from the UNIX From line.

Overrides:
getReceivedDate in class javax.mail.internet.MimeMessage
Returns:
the date this message was received
Throws:
javax.mail.MessagingException

getLineCount

public int getLineCount()
                 throws javax.mail.MessagingException
Return the number of lines for the content of this message. Return -1 if this number cannot be determined.

Note that this number may not be an exact measure of the content length and may or may not account for any transfer encoding of the content.

This implementation returns -1.

Specified by:
getLineCount in interface javax.mail.Part
Overrides:
getLineCount in class javax.mail.internet.MimeMessage
Returns:
number of lines in the content.
Throws:
javax.mail.MessagingException

setFlags

public void setFlags(javax.mail.Flags newFlags,
                     boolean set)
              throws javax.mail.MessagingException
Set the specified flags on this message to the specified value.

Overrides:
setFlags in class javax.mail.internet.MimeMessage
Parameters:
flags - the flags to be set
set - the value to be set
Throws:
javax.mail.MessagingException
See Also:
MessageChangedEvent

getContentType

public java.lang.String getContentType()
                                throws javax.mail.MessagingException
Return the content type, mapping from SunV3 types to MIME types as necessary.

Specified by:
getContentType in interface javax.mail.Part
Overrides:
getContentType in class javax.mail.internet.MimeMessage
Returns:
The ContentType of this part
Throws:
javax.mail.MessagingException
See Also:
DataHandler

getContentStream

protected java.io.InputStream getContentStream()
                                        throws javax.mail.MessagingException
Produce the raw bytes of the content. This method is used during parsing, to create a DataHandler object for the content. Subclasses that can provide a separate input stream for just the message content might want to override this method.

This implementation just returns a ByteArrayInputStream constructed out of the content byte array.

Overrides:
getContentStream in class javax.mail.internet.MimeMessage
Throws:
javax.mail.MessagingException
See Also:
MimeMessage.content

getDataHandler

public javax.activation.DataHandler getDataHandler()
                                            throws javax.mail.MessagingException
Return a DataHandler for this Message's content. If this is a SunV3 multipart message, handle it specially.

Specified by:
getDataHandler in interface javax.mail.Part
Overrides:
getDataHandler in class javax.mail.internet.MimeMessage
Returns:
DataHandler for the content
Throws:
javax.mail.MessagingException

setMessageNumber

protected void setMessageNumber(int msgno)
Description copied from class: javax.mail.Message
Set the Message number for this Message. This method is invoked only by the implementation classes.

Overrides:
setMessageNumber in class javax.mail.Message

updateHeaders

protected void updateHeaders()
                      throws javax.mail.MessagingException
Description copied from class: javax.mail.internet.MimeMessage
Called by the saveChanges method to actually update the MIME headers. The implementation here sets the Content-Transfer-Encoding header (if needed and not already set), the MIME-Version header and the Message-ID header. Also, if the content of this message is a MimeMultipart, it's updateHeaders method is called.

Overrides:
updateHeaders in class javax.mail.internet.MimeMessage
Throws:
javax.mail.IllegalWriteException - if the underlying implementation does not support modification
javax.mail.MessagingException

saveChanges

public void saveChanges()
                 throws javax.mail.MessagingException
Save any changes made to this message.

Overrides:
saveChanges in class javax.mail.internet.MimeMessage
Throws:
javax.mail.MessagingException

writeToFile

public void writeToFile(java.io.OutputStream os)
                 throws java.io.IOException
Put out a byte stream suitable for saving to a file. XXX - ultimately implement "ignore headers" here?

Throws:
java.io.IOException