com.knowgate.hipermail
Class DBMimeMessage

java.lang.Object
  extended byjavax.mail.Message
      extended byjavax.mail.internet.MimeMessage
          extended bycom.knowgate.hipermail.DBMimeMessage
All Implemented Interfaces:
javax.mail.internet.MimePart, javax.mail.Part

public class DBMimeMessage
extends javax.mail.internet.MimeMessage
implements javax.mail.internet.MimePart, javax.mail.Part

MIME messages stored at database BLOB columns or MBOX files

Version:
2.2

Nested Class Summary
 
Nested classes inherited from class javax.mail.internet.MimeMessage
javax.mail.internet.MimeMessage.RecipientType
 
Field Summary
static short ClassId
           
 
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
DBMimeMessage(javax.mail.Folder oFldr, DBMimeMessage oMsg)
          Create DBMimeMessage from another DBMimeMessage
DBMimeMessage(javax.mail.Folder oFldr, java.io.InputStream oInStrm)
          Create DBMimeMessage from an InputStream, set folder and assign a new GUID
DBMimeMessage(javax.mail.Folder oFldr, javax.mail.internet.MimeMessage oMsg)
          Create DBMimeMessage from a MimeMessage, set folder and assign a new GUID
DBMimeMessage(javax.mail.Folder oFldr, java.lang.String sMsgGuid)
          Create empty message at the given folder
DBMimeMessage(javax.mail.internet.MimeMessage oMsg)
          Create DBMimeMessage from a MimeMessage and assign a new GUID
DBMimeMessage(javax.mail.Session oMailSession)
          Create an empty message
DBMimeMessage(javax.mail.Session oMailSession, java.io.InputStream oInStrm)
          Create DBMimeMessage from an InputStream and assign a new GUID
 
Method Summary
 com.sun.mail.smtp.SMTPMessage composeFinalMessage(javax.mail.Session oMailSession, java.lang.String sSubject, java.lang.String sBody, java.lang.String sId, java.lang.String sContentType)
          Create an SMTPMessage object from given components
static void delete(JDCConnection oConn, java.lang.String sFolderId, java.lang.String sMimeMsgId)
          Delete message from database
 javax.mail.Address[] getAllRecipients()
          Get message recipients
 javax.mail.internet.MimePart getBody()
           
 java.lang.String getContentType()
           
 javax.mail.Flags getFlags()
          Get message flags
 javax.mail.Folder getFolder()
          Get message folder
 DBInetAddr getFromRecipient()
           
static java.lang.String getGuidFromId(JDCConnection oConn, java.lang.String sMsgId)
           
 javax.mail.internet.MimePart getMessageBody()
           
 java.lang.String getMessageGuid()
          Get message GUID
 javax.mail.Multipart getParts()
          Get message parts as an array of DBMimePart objects
 javax.mail.Address[] getRecipients(javax.mail.Message.RecipientType cTpRecipient)
          Get recipients of a particular type
 java.util.Date getSentDate()
           
 java.lang.String getSubject()
           
 java.lang.String getText()
           
 void getText(java.lang.StringBuffer oBuffer)
          Get message body text into a StringBuffer
 void getTextPlain(java.lang.StringBuffer oBuffer)
           
 void saveChanges()
           
 void setFlag(javax.mail.Flags.Flag oFlg, boolean bFlg)
           
 void setFolder(javax.mail.Folder oFldr)
          Set message folder
 void setMessageGuid(java.lang.String sId)
          Set message GUID
static java.lang.String source(javax.mail.internet.MimeMessage oMsg, java.lang.String sEncoding)
           
 java.lang.String tagBodyHtml()
           
 java.lang.String tagBodyPlain()
           
 void writeTo(java.io.OutputStream oOutStrm)
           
 
Methods inherited from class javax.mail.internet.MimeMessage
addFrom, addHeader, addHeaderLine, addRecipients, addRecipients, createInternetHeaders, getAllHeaderLines, getAllHeaders, getContent, getContentID, getContentLanguage, getContentMD5, getContentStream, getDataHandler, getDescription, getDisposition, getEncoding, getFileName, getFrom, getHeader, getHeader, getInputStream, getLineCount, getMatchingHeaderLines, getMatchingHeaders, getMessageID, getNonMatchingHeaderLines, getNonMatchingHeaders, getRawInputStream, getReceivedDate, getReplyTo, getSize, isMimeType, isSet, parse, removeHeader, reply, setContent, setContent, setContentID, setContentLanguage, setContentMD5, setDataHandler, setDescription, setDescription, setDisposition, setFileName, setFlags, setFrom, setFrom, setHeader, setRecipients, setRecipients, setReplyTo, setSentDate, setSubject, setSubject, setText, setText, updateHeaders, writeTo
 
Methods inherited from class javax.mail.Message
addRecipient, getMessageNumber, isExpunged, match, setExpunged, setMessageNumber, setRecipient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.mail.internet.MimePart
addHeaderLine, getAllHeaderLines, getContentID, getContentLanguage, getContentMD5, getEncoding, getHeader, getMatchingHeaderLines, getNonMatchingHeaderLines, setContentLanguage, setContentMD5, setText, setText
 
Methods inherited from interface javax.mail.Part
addHeader, getAllHeaders, getContent, getDataHandler, getDescription, getDisposition, getFileName, getHeader, getInputStream, getLineCount, getMatchingHeaders, getNonMatchingHeaders, getSize, isMimeType, removeHeader, setContent, setContent, setDataHandler, setDescription, setDisposition, setFileName, setHeader
 

Field Detail

ClassId

public static final short ClassId
See Also:
Constant Field Values
Constructor Detail

DBMimeMessage

public DBMimeMessage(javax.mail.Session oMailSession)
Create an empty message

Parameters:
oMailSession -

DBMimeMessage

public DBMimeMessage(javax.mail.internet.MimeMessage oMsg)
              throws javax.mail.MessagingException
Create DBMimeMessage from a MimeMessage and assign a new GUID

Parameters:
oMsg - MimeMessage
Throws:
javax.mail.MessagingException

DBMimeMessage

public DBMimeMessage(javax.mail.Session oMailSession,
                     java.io.InputStream oInStrm)
              throws javax.mail.MessagingException
Create DBMimeMessage from an InputStream and assign a new GUID

Parameters:
oMailSession - Session
oInStrm - InputStream
Throws:
javax.mail.MessagingException

DBMimeMessage

public DBMimeMessage(javax.mail.Folder oFldr,
                     java.io.InputStream oInStrm)
              throws javax.mail.MessagingException,
                     java.lang.ClassCastException
Create DBMimeMessage from an InputStream, set folder and assign a new GUID

Parameters:
oInStrm - InputStream
Throws:
javax.mail.MessagingException
java.lang.ClassCastException

DBMimeMessage

public DBMimeMessage(javax.mail.Folder oFldr,
                     javax.mail.internet.MimeMessage oMsg)
              throws javax.mail.MessagingException
Create DBMimeMessage from a MimeMessage, set folder and assign a new GUID

Parameters:
oFldr - Folder
Throws:
javax.mail.MessagingException

DBMimeMessage

public DBMimeMessage(javax.mail.Folder oFldr,
                     DBMimeMessage oMsg)
              throws javax.mail.MessagingException

Create DBMimeMessage from another DBMimeMessage

GUID of this message is set to be the same as that of oMsg

Parameters:
oFldr - Folder
Throws:
javax.mail.MessagingException

DBMimeMessage

public DBMimeMessage(javax.mail.Folder oFldr,
                     java.lang.String sMsgGuid)
              throws javax.mail.MessagingException
Create empty message at the given folder

Parameters:
oFldr - Folder
sMsgGuid - String Message GUID
Throws:
javax.mail.MessagingException
Method Detail

getFolder

public javax.mail.Folder getFolder()
Get message folder

Returns:
Folder

setFolder

public void setFolder(javax.mail.Folder oFldr)
Set message folder

Parameters:
oFldr - Folder

getMessageGuid

public java.lang.String getMessageGuid()

Get message GUID

If message had no previous GUID then a new one is assigned

Returns:
String

setMessageGuid

public void setMessageGuid(java.lang.String sId)
Set message GUID

Parameters:
sId - String

getFlags

public javax.mail.Flags getFlags()
                          throws javax.mail.MessagingException

Get message flags

Message flags are readed from k_mime_msgs table at the database

Returns:
Flags
Throws:
javax.mail.MessagingException

getAllRecipients

public javax.mail.Address[] getAllRecipients()
                                      throws javax.mail.MessagingException,
                                             java.lang.NullPointerException,
                                             java.lang.IllegalArgumentException

Get message recipients

This method read recipients from a message stored at k_inet_addrs table or if message is not already stored at k_inet_addrs then it delegates behaviour to parent class MimMessage.getAllRecipients()

Returns:
If this message is stored at the database then this method returns an array of DBInetAddr objects. If this message has not been stored yet then this method returns an array of javax.mail.internet.InternetAddress objects
Throws:
javax.mail.MessagingException
java.lang.NullPointerException
java.lang.IllegalArgumentException

getRecipients

public javax.mail.Address[] getRecipients(javax.mail.Message.RecipientType cTpRecipient)
                                   throws javax.mail.MessagingException

Get recipients of a particular type

This method first calls getAllRecipients() and then filters retrieved recipients by their type.

Parameters:
cTpRecipient - javax.mail.Message.RecipientType
Returns:
Address[]
Throws:
javax.mail.MessagingException

getFromRecipient

public DBInetAddr getFromRecipient()
                            throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

getContentType

public java.lang.String getContentType()
                                throws javax.mail.MessagingException
Specified by:
getContentType in interface javax.mail.Part
Throws:
javax.mail.MessagingException

getSentDate

public java.util.Date getSentDate()
                           throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

getSubject

public java.lang.String getSubject()
                            throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

getMessageBody

public javax.mail.internet.MimePart getMessageBody()
                                            throws javax.mail.internet.ParseException,
                                                   javax.mail.MessagingException,
                                                   java.io.IOException
Throws:
javax.mail.internet.ParseException
javax.mail.MessagingException
java.io.IOException

setFlag

public void setFlag(javax.mail.Flags.Flag oFlg,
                    boolean bFlg)
             throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

saveChanges

public void saveChanges()
                 throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

getParts

public javax.mail.Multipart getParts()
                              throws javax.mail.MessagingException,
                                     java.io.IOException,
                                     java.lang.NullPointerException
Get message parts as an array of DBMimePart objects

Returns:
DBMimeMultiPart if this message folder is of type DBFolder or another type of Object if this message folder is another subclass of javax.mail.Folder such as POP3Folder.
Throws:
javax.mail.MessagingException
java.io.IOException
java.lang.NullPointerException - If this message Folder is null

getBody

public javax.mail.internet.MimePart getBody()
                                     throws javax.mail.internet.ParseException,
                                            javax.mail.MessagingException,
                                            java.io.IOException
Throws:
javax.mail.internet.ParseException
javax.mail.MessagingException
java.io.IOException

getText

public void getText(java.lang.StringBuffer oBuffer)
             throws javax.mail.MessagingException,
                    java.io.IOException,
                    java.lang.ClassCastException
Get message body text into a StringBuffer

Parameters:
oBuffer - StringBuffer
Throws:
javax.mail.MessagingException
java.io.IOException
java.lang.ClassCastException

getText

public java.lang.String getText()
                         throws javax.mail.MessagingException,
                                java.io.IOException
Throws:
javax.mail.MessagingException
java.io.IOException

getTextPlain

public void getTextPlain(java.lang.StringBuffer oBuffer)
                  throws javax.mail.MessagingException,
                         java.io.IOException
Throws:
javax.mail.MessagingException
java.io.IOException

writeTo

public void writeTo(java.io.OutputStream oOutStrm)
             throws java.io.IOException,
                    javax.mail.FolderClosedException,
                    javax.mail.MessagingException
Specified by:
writeTo in interface javax.mail.Part
Throws:
java.io.IOException
javax.mail.FolderClosedException
javax.mail.MessagingException

tagBodyHtml

public java.lang.String tagBodyHtml()
                             throws java.io.IOException,
                                    javax.mail.MessagingException
Throws:
java.io.IOException
javax.mail.MessagingException

tagBodyPlain

public java.lang.String tagBodyPlain()
                              throws java.io.IOException,
                                     javax.mail.MessagingException
Throws:
java.io.IOException
javax.mail.MessagingException

composeFinalMessage

public com.sun.mail.smtp.SMTPMessage composeFinalMessage(javax.mail.Session oMailSession,
                                                         java.lang.String sSubject,
                                                         java.lang.String sBody,
                                                         java.lang.String sId,
                                                         java.lang.String sContentType)
                                                  throws java.io.IOException,
                                                         javax.mail.MessagingException,
                                                         java.lang.IllegalArgumentException,
                                                         java.lang.SecurityException

Create an SMTPMessage object from given components

Depending on what is inside, message structure is as follows :
Format/AttachmentsNoYes
plaintext/plainmultipart/mixed [text/plain, {attachment}]
html without imagesmultipart/alternative [text/plain, text/html]multipart/mixed [multipart/alternative [text/plain, text/html], {attachment}]
html with imagesmultipart/alternative [text/plain, multipart/related[text/html, {image}]]multipart/mixed [multipart/alternative [text/plain, multipart/related[text/html, {image}]], {attachment}]

Parameters:
oMailSession - Session
sSubject - String Message subject or null
sBody - String Message text body or null
sId - String Contend-ID for message or null
sContentType - String should be either "plain" or "html"
Returns:
SMTPMessage
Throws:
java.io.IOException
javax.mail.MessagingException
java.lang.SecurityException
java.lang.IllegalArgumentException - if sContentType is not "plain" or "html"

delete

public static void delete(JDCConnection oConn,
                          java.lang.String sFolderId,
                          java.lang.String sMimeMsgId)
                   throws java.sql.SQLException,
                          java.io.IOException

Delete message from database

This method calls stored procedure k_sp_del_mime_msg

Parameters:
oConn - JDBC database connection
sFolderId - Folder GUID (k_mime_msgs.gu_category)
sMimeMsgId - Message GUID (k_mime_msgs.gu_mimemsg)
Throws:
java.sql.SQLException
java.io.IOException

source

public static java.lang.String source(javax.mail.internet.MimeMessage oMsg,
                                      java.lang.String sEncoding)
                               throws javax.mail.MessagingException,
                                      java.io.UnsupportedEncodingException,
                                      java.io.IOException
Throws:
javax.mail.MessagingException
java.io.UnsupportedEncodingException
java.io.IOException

getGuidFromId

public static java.lang.String getGuidFromId(JDCConnection oConn,
                                             java.lang.String sMsgId)
                                      throws java.sql.SQLException
Throws:
java.sql.SQLException