Email Answering System
Version 1.0

com.ninecode.email.util
Class EmailMessage

java.lang.Object
  |
  +--javax.mail.Message
        |
        +--javax.mail.internet.MimeMessage
              |
              +--com.ninecode.email.util.EmailMessage
All Implemented Interfaces:
MimePart, Part

public class EmailMessage
extends MimeMessage

A wrapper for the usual MimeMessage that provides access to the session. Since the RecordFactory is obtained from the ConnectionFactory and not the ManagedConnection (or Connection) which has access to the session, we have to set the session on the message at send time (the interaction has the Connection). Since this was not exposed on MimeMessage, we subclass it and add a zero args constructor and accessors for the session. Users can still treat the messages they receive in the Record as a MimeMessage. This class also provides a utility method and constructor that handle byte arrays of rfc822 encoded data.

Author:
Derrick Oswald

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
EmailMessage()
          Creates a new instance of EmailMessage.
EmailMessage(byte[] data)
          Convert an array of bytes (in RFC 822 format) to an email message.
EmailMessage(InputStream in)
          Create an new instance from a stream.
 
Method Summary
 Session getSession()
          Get the session associated with this message.
static EmailMessage pickle(MimeMessage message)
          Convert a message to internal form (losing the session object within it).
 byte[] rfc822()
          Output the message as an RFC 822 format array of bytes.
static byte[] rfc822(MimeMessage message)
          Output the message as an RFC 822 format array of bytes.
 void setSession(Session session)
          Set the session associated with this message.
 
Methods inherited from class javax.mail.internet.MimeMessage
addFrom, addHeader, addHeaderLine, addRecipients, addRecipients, createInternetHeaders, getAllHeaderLines, getAllHeaders, getAllRecipients, getContent, getContentID, getContentLanguage, getContentMD5, getContentStream, getContentType, getDataHandler, getDescription, getDisposition, getEncoding, getFileName, getFlags, getFrom, getHeader, getHeader, getInputStream, getLineCount, getMatchingHeaderLines, getMatchingHeaders, getMessageID, getNonMatchingHeaderLines, getNonMatchingHeaders, getRawInputStream, getReceivedDate, getRecipients, getReplyTo, getSender, getSentDate, getSize, getSubject, isMimeType, isSet, parse, removeHeader, reply, saveChanges, setContent, setContent, setContentID, setContentLanguage, setContentMD5, setDataHandler, setDescription, setDescription, setDisposition, setFileName, setFlags, setFrom, setFrom, setHeader, setRecipients, setRecipients, setReplyTo, setSender, setSentDate, setSubject, setSubject, setText, setText, updateHeaders, writeTo, writeTo
 
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

EmailMessage

public EmailMessage()
Creates a new instance of EmailMessage. The session in the superclass is set to null, so it's important to set the session prior to sending the message.


EmailMessage

public EmailMessage(InputStream in)
             throws MessagingException
Create an new instance from a stream.

Parameters:
in - The mime input stream to parse.

EmailMessage

public EmailMessage(byte[] data)
             throws MessagingException
Convert an array of bytes (in RFC 822 format) to an email message.

Parameters:
data - The data containing the RFC 822 format data.
Throws:
MessagingException - If an error occurs converting to RFC 822 format.
Method Detail

getSession

public Session getSession()
Get the session associated with this message.

Returns:
The session object.

setSession

public void setSession(Session session)
Set the session associated with this message.

Parameters:
session - The new session object.

rfc822

public byte[] rfc822()
              throws IOException,
                     MessagingException
Output the message as an RFC 822 format array of bytes. Note that, depending on how the message was constructed, it may use a variety of line termination conventions. Generally the output should be sent through an appropriate FilterOutputStream that converts the line terminators to the desired form, either CRLF for MIME compatibility and for use in Internet protocols, or the local platform's line terminator for storage in a local text file.

Returns:
The array of bytes containing the RFC 822 format data.
Throws:
IOException - If an i/o error occurs.
MessagingException - If conversion of the message encounters an error.

rfc822

public static byte[] rfc822(MimeMessage message)
                     throws IOException,
                            MessagingException
Output the message as an RFC 822 format array of bytes. Note that, depending on how the message was constructed, it may use a variety of line termination conventions. Generally the output should be sent through an appropriate FilterOutputStream that converts the line terminators to the desired form, either CRLF for MIME compatibility and for use in Internet protocols, or the local platform's line terminator for storage in a local text file.

Returns:
The array of bytes containing the RFC 822 format data.
Throws:
IOException - If an i/o error occurs.
MessagingException - If conversion of the message encounters an error.

pickle

public static EmailMessage pickle(MimeMessage message)
                           throws IOException,
                                  MessagingException
Convert a message to internal form (losing the session object within it).

Parameters:
message - The message to repackage.
Returns:
The object that is safe to pass back to the user.
Throws:
IOException - If an i/o error occurs (unlikely).
MessagingException - If conversion to or from rfc822 format fails.
See Also:
rfc822()

Email Answering System
Version 1.0

Copyright © 2003 Derrick Oswald. All rights reserved.