|
Jive Forums API (5.5.20.2-oracle) Developer Javadocs | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jivesoftware.forum.gateway.JavaMailImporter
public abstract class JavaMailImporter
This class is an abstract JavaMail implementation of the Gateway interface. This class provides all the needed methods to import messages from whatever JavaMail providers are supported.
If a provider such as a NNTP provider needs to do something special when connecting or retrieving messages all it needs to do is re-implement the method in question in a subclass.
Nested Class Summary | |
---|---|
protected class |
JavaMailImporter.InsertCacheItem
Small class to cache insert's so that we can do them all at once and not incur penalties for continuously invalidating the message & thread caches because of constant inserts. |
Nested classes/interfaces inherited from interface com.jivesoftware.forum.gateway.GatewayImporter |
---|
GatewayImporter.Stats |
Field Summary | |
---|---|
protected java.lang.String |
emptySubject
Dummy subject string for inbound messages with no subject |
protected ForumFactory |
factory
|
protected java.util.List |
failedMessageIDs
Used to store a list of message id's that failed to be imported |
protected long |
forumID
The forumID is used instead of an actual forum object since Jive's cache system will orphan the forum object after 6 hours. |
protected java.lang.String |
gatewayMessageId
Used to flag messages in the forum with a message id. |
protected java.lang.String |
gatewayParentId
Used to flag messages in the forum with a parent id. |
static java.lang.String |
MESSAGE_DATE_HEADER
Used to store a messages original date if the date had to be changed such as in the case of a parent with an older child |
protected java.util.Hashtable |
parentMessageIDs
Used to store the parent message id's indexed by message id |
protected boolean |
stopFlag
Flag used to stop an already running import or export. |
static java.lang.String |
SUBJECT_EXTENDED_PROPERTY
Used for storing a hash of a subject as an extended property needed for parent message comparison |
protected boolean |
subjectParentageCheckEnabled
Whether or not to attempt to determine parentage via subject line matching |
protected java.lang.String |
temporaryParentBody
Dummy message string for messages autocreated by this gateway |
Constructor Summary | |
---|---|
JavaMailImporter(ForumFactory factory,
Forum forum,
GatewaySettings settings)
|
Method Summary | |
---|---|
protected void |
addAttachments(ForumMessage forumMessage,
javax.mail.Part part)
Adds attachments from a JavaMail Part object to a forum message object. |
protected void |
addUUencodedAttachments(ForumMessage forumMessage,
java.io.BufferedReader reader)
Search for uuencoded attachments from a reader and attach them to a message. |
protected void |
cleanup()
Called after all imports are done just prior to the folder and the store being closed. |
protected void |
correctMessageDates(java.util.List messages)
Corrects the dates on the provided list of messages. |
long |
getAverageTime()
|
protected boolean |
getBody(java.lang.StringBuffer buf,
javax.mail.Part part)
Retrieve the textual body of the message. |
protected java.util.Date |
getDate(javax.mail.Message message)
Returns the date a message was created or received, or the current date if date parsing fails. |
java.lang.String |
getDefaultCharacterSet()
Returns the character set that will be used to decode inbound messages that have no explicit character set defined. |
java.lang.String |
getEmptySubject()
Returns the string to be used in place of an empty subject. |
long |
getFailedMessageCount()
|
protected javax.mail.Folder |
getFolder(javax.mail.Store store)
Retrieve the JavaMail folder from the provided store object. |
java.lang.String |
getHost()
Get the server host. |
java.util.Date |
getLastImport()
Not implemented throws UnsupportedOperation exception |
java.lang.String |
getMailbox()
Returns the name of the mailbox. |
protected java.lang.String |
getMessageID(javax.mail.Message message)
Retrieve the messageID using the JavaMail provided method. |
long |
getMessagesAdded()
|
protected java.lang.String[] |
getParentMessageID(javax.mail.Message message)
Returns the the parent message id's of a message. |
protected java.lang.String[] |
getParentMessageID(javax.mail.Message message,
java.lang.String header)
Returns the parent ID's of a message as a String [] or null if there are no parents. |
java.lang.String |
getPassword()
Returns the password. |
int |
getPort()
Get the server port. |
abstract java.lang.String |
getProtocol()
Get the protocol. |
java.lang.String |
getReplyPrefixes()
Returns a comma seperated of prefixes that will be stripped from messages when attempting to find a parent message via subject line matching. |
GatewayImporter.Stats |
getStats()
|
protected javax.mail.Store |
getStore(java.util.Date afterDate)
Retrieve the JavaMail store. |
protected java.lang.String |
getSubject(javax.mail.Message message)
Returns the subject of a JavaMail message. |
java.lang.String |
getTemporaryParentBody()
Returns the body that will be used when creating temporary parent messages. |
protected java.io.BufferedReader |
getTextReader(javax.mail.Part part)
Get a reader object for a Part with the character set properly chosen. |
int |
getTimesRan()
|
long |
getTotalMessages()
|
protected long |
getTotalTime()
|
java.lang.String |
getUsername()
Returns the username. |
static void |
handleAttachmentException(AttachmentException e,
ForumMessage forumMessage)
|
void |
importData(java.util.Date afterDate)
Import data from the data source into the specified forum. |
protected void |
importMessages(java.util.List messages)
Import the List of messages into the forum specified. |
boolean |
isAttachmentsEnabled()
True if attachments are enabled, false otherwise. |
boolean |
isDebugEnabled()
True if debug is enabled, false otherwise. |
boolean |
isDeleteEnabled()
Returns true if data will be deleted from the store after being read. |
boolean |
isEmailToUserMappingEnabled()
True if email address -> user mapping is enabled, false otherwise. |
boolean |
isImportHtmlEnabled()
True if if the importation of html email is enabled, false otherwise. |
boolean |
isImporting()
Not implemented throws UnsupportedOperation exception |
protected JavaMailImporter.InsertCacheItem |
isMessageinInsertCache(java.util.List cache,
java.lang.String messageID)
|
protected boolean |
isMessageWithAttachments(javax.mail.Message message)
Utility method to check to see if a Message object contains attachments or not. |
boolean |
isSubjectParentageCheckEnabled()
Returns whether parentage checks will be done using subject line matching or not. |
protected DbForumMessage |
lookupMessageByID(Forum forum,
java.lang.String messageID,
boolean checkDummy)
Utility method to determine if a message exists in the forum already. |
protected ForumMessage |
parseMessage(javax.mail.Message message,
java.util.Date afterDate)
Parse the JavaMail message object and return a ForumMessage object. |
protected void |
processMessagesAndImport(java.util.List messages)
Resolves parentage, corrects dates, sorts, imports, then clears messages. |
protected void |
removeUUencodedAttachments(java.lang.StringBuffer sb,
java.io.BufferedReader reader)
Search for uuencoded attachments from a reader and remove them appending the remaining lines into the provided stringbuffer |
protected void |
resolveParentage(java.util.List messages)
Resolve parentage of messages. |
protected void |
retrieveMessages(javax.mail.Store store,
javax.mail.Folder folder,
java.util.Date afterDate)
Retrieve messages from a JavaMail folder and calls methods to import them into a forum. |
void |
setAttachmentsEnabled(boolean attachmentsEnabled)
Set whether attachments are enabled or not. |
void |
setDebugEnabled(boolean debugEnabled)
Set whether debug is enabled or not. |
void |
setDefaultCharacterSet(java.lang.String defaultCharacterSet)
Sets the character set that will be used to decode inbound messages that have no explicit character set defined. |
void |
setDeleteEnabled(boolean deleteEnabled)
Sets whether data will be deleted from the store after being read. |
void |
setEmailToUserMappingEnabled(boolean emailToUserMappingEnabled)
Sets whether email address -> user mapping is enabled, false otherwise. |
void |
setEmptySubject(java.lang.String emptySubject)
Sets the string to be used in place of an empty subject. |
void |
setFailedMessageCount(long failedMessages)
|
void |
setHost(java.lang.String host)
Set the server host. |
void |
setImportHtmlEnabled(boolean importHtmlEnabled)
Sets whether the importation of html email is enabled. |
void |
setImporting(boolean importing)
Not implemented throws UnsupportedOperation exception |
void |
setMailbox(java.lang.String mailbox)
Sets the name of the mailbox. |
void |
setMessagesAdded(long totalAddedMessages)
|
void |
setPassword(java.lang.String password)
Set the password. |
void |
setPort(int port)
Set the server port. |
void |
setReplyPrefixes(java.lang.String replyPrefixes)
Sets the possible prefixes that will be stripped from messages when attempting to find a parent message via subject line matching. |
void |
setSubjectParentageCheckEnabled(boolean subjectParentageCheckEnabled)
Sets whether parentage checks will be done using subject line matching or not. |
void |
setTemporaryParentBody(java.lang.String temporaryParentBody)
Sets the body that will be used when creating temporary parent messages. |
protected void |
setTimesRan(int timesRan)
|
void |
setTotalMessages(long totalMessages)
|
protected void |
setTotalTime(long totalTime)
|
void |
setUsername(java.lang.String username)
Set the username. |
protected void |
shortTermQueryCacheHack(ResultFilter filter)
Like the name says, it's a hack. |
void |
stop()
Stop a already running import or export. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected boolean stopFlag
protected java.lang.String gatewayMessageId
protected java.lang.String gatewayParentId
protected boolean subjectParentageCheckEnabled
protected java.lang.String temporaryParentBody
protected java.lang.String emptySubject
protected java.util.Hashtable parentMessageIDs
protected java.util.List failedMessageIDs
public static final java.lang.String MESSAGE_DATE_HEADER
public static final java.lang.String SUBJECT_EXTENDED_PROPERTY
protected long forumID
protected ForumFactory factory
Constructor Detail |
---|
public JavaMailImporter(ForumFactory factory, Forum forum, GatewaySettings settings)
Method Detail |
---|
public void importData(java.util.Date afterDate) throws GatewayException
GatewayImporter
importData
in interface GatewayImporter
afterDate
- the oldest cutoff date for data to import.
GatewayException
protected javax.mail.Store getStore(java.util.Date afterDate) throws javax.mail.MessagingException
afterDate
- the date after which messages will be imported.
javax.mail.MessagingException
- if an error occurred establishing the connection.protected javax.mail.Folder getFolder(javax.mail.Store store) throws javax.mail.MessagingException
store
- the JavaMail store.
javax.mail.MessagingException
- if an error occurred establishing the connection.protected void retrieveMessages(javax.mail.Store store, javax.mail.Folder folder, java.util.Date afterDate) throws javax.mail.MessagingException, GatewayException
folder
- a connected JavaMail folder object.afterDate
- the date after which we'll import message.
javax.mail.MessagingException
- if a protocol error occurs retrieving a message.
GatewayException
protected void processMessagesAndImport(java.util.List messages) throws ForumNotFoundException, UnauthorizedException
messages
- a list of ForumMessage objects to import
ForumNotFoundException
UnauthorizedException
protected void resolveParentage(java.util.List messages) throws ForumNotFoundException, UnauthorizedException
We need to go through all the messages and determine parentage from subject if the parent id property isn't already set, which is almost certain in the case of POP3 and sometimes the case with other providers.
messages
- a List of ForumMessage objects.
ForumNotFoundException
UnauthorizedException
protected void correctMessageDates(java.util.List messages) throws ForumNotFoundException, UnauthorizedException
We need to check dates on all the messages to verify that we don't have a child the same age or older than a parent, which Jive was explicitly designed not to handle. Our solution to this problem is to change the child messages' creation date to 1 millisecond later the parent's and store the original date in an extended property. In the case where we are inserting a message that was already created as a dummy parent message, we check to verify that the message is also older than any children it has. If it isn't we correct the current messages' date to be 1 millisecond older than it's oldest child.
messages
- a List of ForumMessage objects.
ForumNotFoundException
UnauthorizedException
protected ForumMessage parseMessage(javax.mail.Message message, java.util.Date afterDate)
message
- the JavaMail Message object.afterDate
- the date we use to check to see if we should import this message or not.
protected void importMessages(java.util.List messages) throws ForumNotFoundException, UnauthorizedException
One of the things we need to do in this method is check to see if this message or it's parent already exist (or doesn't exist) in this forum.
If a parent doesn't exist, we create a dummy message in its place. If a parent does exist, we attach the message to the parent's thread.
If a message already exists in the forum, we first check to see if it's one of the dummy messages we previously created. If so, we modify it. Otherwise, we don't insert the message.
If a message doesn't already exist in the forum and it has no parent(s), we create a new thread with this message as the root message
messages
- a list of messages to import into the forum.
ForumNotFoundException
UnauthorizedException
protected JavaMailImporter.InsertCacheItem isMessageinInsertCache(java.util.List cache, java.lang.String messageID)
protected DbForumMessage lookupMessageByID(Forum forum, java.lang.String messageID, boolean checkDummy)
forum
- [required]messageID
- Message-ID mail header value. Checked against null and empty.checkDummy
- whether to mandate that it is a "dummy" or not.
protected void shortTermQueryCacheHack(ResultFilter filter)
filter
- the filter to apply the hack to.protected boolean isMessageWithAttachments(javax.mail.Message message) throws javax.mail.MessagingException
javax.mail.MessagingException
- If the error occurs parsing the message object.protected void addAttachments(ForumMessage forumMessage, javax.mail.Part part) throws javax.mail.MessagingException, UnauthorizedException
This implementation doesn't attempt to figure out beforehand if an attachment should be added by checking with an attachment manager, rather it just catches any AttachmentException thrown and reports it.
javax.mail.MessagingException
- if the error occurs getting an attachment out of the message.
UnauthorizedException
- if the error occurs adding an attachment to the forumMessage.public static void handleAttachmentException(AttachmentException e, ForumMessage forumMessage) throws UnauthorizedException
UnauthorizedException
protected void addUUencodedAttachments(ForumMessage forumMessage, java.io.BufferedReader reader) throws java.io.IOException, java.lang.IllegalStateException, AttachmentException, UnauthorizedException
forumMessage
- the message to attach the uuencoded attachments to.reader
- the reader to search for uuencoded attachments in.
java.io.IOException
java.lang.IllegalStateException
AttachmentException
UnauthorizedException
protected void removeUUencodedAttachments(java.lang.StringBuffer sb, java.io.BufferedReader reader) throws java.io.IOException
sb
- the StringBuffer to append text lines to.reader
- the reader to search for uuencoded attachments in.
java.io.IOException
protected java.lang.String getSubject(javax.mail.Message message)
message
- the JavaMail message.
protected java.util.Date getDate(javax.mail.Message message) throws javax.mail.MessagingException
If the parsed date is in the future, we return the current date.
message
- a JavaMail message.
javax.mail.MessagingException
- if an error occurred trying to retrieve the date.protected java.lang.String getMessageID(javax.mail.Message message) throws javax.mail.MessagingException
message
- the JavaMail message.
javax.mail.MessagingException
- if an error occurred trying to retrieve the messageID.protected java.lang.String[] getParentMessageID(javax.mail.Message message) throws javax.mail.MessagingException
See RFC 822/2822 for a full explanation. Note that this implementation doesn't handle CFWS, particularly the Comment part. Shoot me. (RFC 2822 Section 3.6.4)
message
- the JavaMail message.
javax.mail.MessagingException
- if something goes wrong.protected java.lang.String[] getParentMessageID(javax.mail.Message message, java.lang.String header) throws javax.mail.MessagingException
message
- the JavaMail message.header
- the header to use to lookup the parent message id.
javax.mail.MessagingException
- if something goes wrong.protected boolean getBody(java.lang.StringBuffer buf, javax.mail.Part part) throws javax.mail.MessagingException, java.io.IOException
buf
- the StringBuffer to append text lines to.part
- the JavaMail message.
javax.mail.MessagingException
- if JavaMail throws an exception.
java.io.IOException
- if JavaMail throws an exception handling mime content.protected java.io.BufferedReader getTextReader(javax.mail.Part part) throws javax.mail.MessagingException
part
- a javax.mail.part object.
javax.mail.MessagingException
- if error occurs reading the part object.protected void cleanup()
public abstract java.lang.String getProtocol()
public int getPort()
public void setPort(int port)
port
- the new port setting.public java.lang.String getHost()
public void setHost(java.lang.String host)
host
- the new host setting.public java.lang.String getUsername()
public void setUsername(java.lang.String username)
username
- the username to use.public java.lang.String getPassword()
public void setPassword(java.lang.String password)
password
- the password to use.public java.lang.String getMailbox()
public void setMailbox(java.lang.String mailbox)
mailbox
- the mailbox to use.public java.lang.String getTemporaryParentBody()
public void setTemporaryParentBody(java.lang.String temporaryParentBody)
On subsequent imports when a real parent message is found, the fake data will be replaced with the correct subject and body.
temporaryParentBody
- the message body that will be used for
temporary fake parent messages.public boolean isDeleteEnabled()
public void setDeleteEnabled(boolean deleteEnabled)
deleteEnabled
- true if data should be deleted from the store after
being read.public boolean isDebugEnabled()
public void setDebugEnabled(boolean debugEnabled)
debugEnabled
- true to debug, false otherwise.public boolean isAttachmentsEnabled()
public void setAttachmentsEnabled(boolean attachmentsEnabled)
attachmentsEnabled
- true if attachments are enabled, false otherwise.public boolean isEmailToUserMappingEnabled()
public void setEmailToUserMappingEnabled(boolean emailToUserMappingEnabled)
emailToUserMappingEnabled
- True if email address -> user mapping is enabled,
false otherwise.public boolean isImportHtmlEnabled()
public void setImportHtmlEnabled(boolean importHtmlEnabled)
importHtmlEnabled
- True if the importation of html email is enabled,
false otherwise.public java.lang.String getDefaultCharacterSet()
public void setDefaultCharacterSet(java.lang.String defaultCharacterSet)
defaultCharacterSet
- the character set that will be used to decode inbound messages
that have no explicit character set defined.public java.lang.String getReplyPrefixes()
public void setReplyPrefixes(java.lang.String replyPrefixes)
replyPrefixes
- an comma seperated string of lowercase prefixespublic boolean isSubjectParentageCheckEnabled()
public void setSubjectParentageCheckEnabled(boolean subjectParentageCheckEnabled)
subjectParentageCheckEnabled
- true if parentage checks will be done using
subject line matching, false otherwise.public void stop()
stop
in interface GatewayImporter
public java.lang.String getEmptySubject()
public void setEmptySubject(java.lang.String emptySubject)
emptySubject
- the string to be used in place of an empty subject.public java.util.Date getLastImport()
getLastImport
in interface GatewayImporter
public int getTimesRan()
protected void setTimesRan(int timesRan)
protected long getTotalTime()
protected void setTotalTime(long totalTime)
public long getAverageTime()
public long getTotalMessages()
public void setTotalMessages(long totalMessages)
public long getMessagesAdded()
public void setMessagesAdded(long totalAddedMessages)
public void setFailedMessageCount(long failedMessages)
public long getFailedMessageCount()
public GatewayImporter.Stats getStats()
getStats
in interface GatewayImporter
public boolean isImporting()
isImporting
in interface GatewayImporter
public void setImporting(boolean importing)
setImporting
in interface GatewayImporter
|
Jive Forums Project Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |