org.alfresco.repo.imap
Class ImapServiceImpl

java.lang.Object
  extended by org.alfresco.repo.imap.ImapServiceImpl
All Implemented Interfaces:
ImapService, NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnDeleteChildAssociationPolicy, AssociationPolicy, Policy

public class ImapServiceImpl
extends java.lang.Object
implements ImapService, NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnDeleteChildAssociationPolicy

Since:
3.2

Nested Class Summary
static class ImapServiceImpl.ImapServiceBootstrap
          Bootstrap initialization bean for the service implementation.
 
Nested classes/interfaces inherited from interface org.alfresco.repo.imap.ImapService
ImapService.EmailBodyFormat
 
Nested classes/interfaces inherited from interface org.alfresco.repo.policy.Policy
Policy.Arg
 
Field Summary
 
Fields inherited from interface org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy
QNAME
 
Fields inherited from interface org.alfresco.repo.node.NodeServicePolicies.OnDeleteChildAssociationPolicy
QNAME
 
Fields inherited from interface org.alfresco.repo.policy.Policy
NAMESPACE
 
Constructor Summary
ImapServiceImpl()
           
 
Method Summary
 void beforeDeleteNode(org.alfresco.service.cmr.repository.NodeRef nodeRef)
           
protected  void bindBeahaviour()
           
 AlfrescoImapFolder createMailbox(AlfrescoImapUser user, java.lang.String mailboxName)
          Returns a reference to a newly created mailbox.
 void deleteMailbox(AlfrescoImapUser user, java.lang.String mailboxName)
          Deletes an existing MailBox.
 org.alfresco.service.cmr.repository.NodeRef extractAttachments(org.alfresco.service.cmr.repository.NodeRef parentFolder, org.alfresco.service.cmr.repository.NodeRef messageFile, javax.mail.internet.MimeMessage originalMessage)
          Extract attachments from a MimeMessage Puts the attachments into a subfolder below the parent folder.
 java.lang.String getAlfrescoServerUID()
          This method should returns a unique identifier of Alfresco server.
 java.lang.String getDefaultEmailBodyTemplate(ImapService.EmailBodyFormat type)
          Returns a template for email body.
 java.lang.String getDefaultFromAddress()
           
 java.lang.String getDefaultToAddress()
           
 FileFolderService getFileFolderService()
           
 javax.mail.Flags getFlags(FileInfo messageInfo)
          Return flags that belong to the specified imap folder.
 AlfrescoImapFolder getFolder(AlfrescoImapUser user, java.lang.String mailboxName)
          Returns a reference to an existing Mailbox.
 org.alfresco.repo.cache.SimpleCache getFoldersCache()
           
 boolean getImapServerEnabled()
          Determines whether the IMAP server is enabled.
 org.alfresco.service.cmr.repository.NodeRef getMailboxRootRef(java.lang.String mailboxName, java.lang.String userName)
          Get root reference for the specified mailbox
 java.lang.String getRepositoryTemplatePath()
           
 java.lang.String getShareApplicationContextUrl()
           
 java.lang.String getWebApplicationContextUrl()
           
 void init()
           
 boolean isNodeInSitesLibrary(org.alfresco.service.cmr.repository.NodeRef nodeRef)
          Return true if provided nodeRef is in Sites/.../documentlibrary
 java.util.List listMailboxes(AlfrescoImapUser user, java.lang.String mailboxPattern)
          Returns an collection of mailboxes.
 java.util.List listSubscribedMailboxes(AlfrescoImapUser user, java.lang.String mailboxPattern)
          Returns an collection of subscribed mailboxes.
 void onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef childAssocRef, boolean isNewNode)
          Called after a node child association has been created.
 void onDeleteChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef childAssocRef)
          Called after a node child association has been deleted.
 void renameMailbox(AlfrescoImapUser user, java.lang.String oldMailboxName, java.lang.String newMailboxName)
          Renames an existing mailbox.
 java.util.List searchMails(org.alfresco.service.cmr.repository.NodeRef contextNodeRef, AlfrescoImapConst.ImapViewMode viewMode)
          Search for emails in specified folder depending on view mode.
 void setDefaultFromAddress(java.lang.String defaultFromAddress)
           
 void setDefaultToAddress(java.lang.String defaultToAddress)
           
 void setExtractAttachmentsEnabled(boolean extractAttachmentsEnabled)
           
 void setFileFolderService(FileFolderService fileFolderService)
           
 void setFlag(FileInfo messageInfo, javax.mail.Flags.Flag flag, boolean value)
          Set flags to the specified imapFolder.
 void setFlags(FileInfo messageInfo, javax.mail.Flags flags, boolean value)
          Set flags to the specified imapFolder.
 void setFoldersCache(org.alfresco.repo.cache.SimpleCache foldersCache)
           
 void setIgnoreExtractionFolders(RepositoryFolderConfigBean[] ignoreExtractionFolders)
           
 void setImapConfigMountPoints(ImapConfigMountPointsBean[] imapConfigMountPointsBeans)
           
 void setImapHome(RepositoryFolderConfigBean imapHomeConfigBean)
           
 void setImapServerEnabled(boolean enabled)
           
 void setMimetypeService(org.alfresco.service.cmr.repository.MimetypeService mimetypeService)
           
 void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)
           
 void setPermissionService(org.alfresco.service.cmr.security.PermissionService permissionService)
           
 void setPolicyFilter(BehaviourFilter policyFilter)
           
 void setRepositoryTemplatePath(java.lang.String repositoryTemplatePath)
           
 void setServiceRegistry(ServiceRegistry serviceRegistry)
           
 void setSysAdminParams(SysAdminParams sysAdminParams)
           
 void shutdown()
           
 void startup()
           
 void subscribe(AlfrescoImapUser user, java.lang.String mailbox)
          Subscribes a user to a mailbox.
 void unsubscribe(AlfrescoImapUser user, java.lang.String mailbox)
          Unsubscribes from a given mailbox.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImapServiceImpl

public ImapServiceImpl()
Method Detail

setSysAdminParams

public void setSysAdminParams(SysAdminParams sysAdminParams)

setFoldersCache

public void setFoldersCache(org.alfresco.repo.cache.SimpleCache foldersCache)

getFoldersCache

public org.alfresco.repo.cache.SimpleCache getFoldersCache()

getFileFolderService

public FileFolderService getFileFolderService()

setFileFolderService

public void setFileFolderService(FileFolderService fileFolderService)

setMimetypeService

public void setMimetypeService(org.alfresco.service.cmr.repository.MimetypeService mimetypeService)

setNodeService

public void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)

setPermissionService

public void setPermissionService(org.alfresco.service.cmr.security.PermissionService permissionService)

setServiceRegistry

public void setServiceRegistry(ServiceRegistry serviceRegistry)

setPolicyFilter

public void setPolicyFilter(BehaviourFilter policyFilter)

setImapHome

public void setImapHome(RepositoryFolderConfigBean imapHomeConfigBean)

getDefaultFromAddress

public java.lang.String getDefaultFromAddress()
Specified by:
getDefaultFromAddress in interface ImapService
Returns:
Default From addreses

setDefaultFromAddress

public void setDefaultFromAddress(java.lang.String defaultFromAddress)

getDefaultToAddress

public java.lang.String getDefaultToAddress()
Specified by:
getDefaultToAddress in interface ImapService
Returns:
Default To addreses

setDefaultToAddress

public void setDefaultToAddress(java.lang.String defaultToAddress)

getWebApplicationContextUrl

public java.lang.String getWebApplicationContextUrl()
Specified by:
getWebApplicationContextUrl in interface ImapService
Returns:
Web application context url (e.g. http://localhost:8080/alfresco)

getShareApplicationContextUrl

public java.lang.String getShareApplicationContextUrl()
Specified by:
getShareApplicationContextUrl in interface ImapService
Returns:
Web application context url for share (e.g. http://localhost:8080/share)

getRepositoryTemplatePath

public java.lang.String getRepositoryTemplatePath()
Specified by:
getRepositoryTemplatePath in interface ImapService
Returns:
Path to the folder containing templates, that will be used for generating body of message in VIRTUAL and MIXED views.

setRepositoryTemplatePath

public void setRepositoryTemplatePath(java.lang.String repositoryTemplatePath)

setImapConfigMountPoints

public void setImapConfigMountPoints(ImapConfigMountPointsBean[] imapConfigMountPointsBeans)

setIgnoreExtractionFolders

public void setIgnoreExtractionFolders(RepositoryFolderConfigBean[] ignoreExtractionFolders)

setExtractAttachmentsEnabled

public void setExtractAttachmentsEnabled(boolean extractAttachmentsEnabled)

setImapServerEnabled

public void setImapServerEnabled(boolean enabled)

getImapServerEnabled

public boolean getImapServerEnabled()
Description copied from interface: ImapService
Determines whether the IMAP server is enabled.

Specified by:
getImapServerEnabled in interface ImapService
Returns:
true if enabled

init

public void init()

startup

public void startup()

shutdown

public void shutdown()

bindBeahaviour

protected void bindBeahaviour()

listSubscribedMailboxes

public java.util.List listSubscribedMailboxes(AlfrescoImapUser user,
                                              java.lang.String mailboxPattern)
Description copied from interface: ImapService
Returns an collection of subscribed mailboxes. This method serves LSUB command of the IMAP protocol.

Specified by:
listSubscribedMailboxes in interface ImapService
Parameters:
user - User making the request
mailboxPattern - String name of a mailbox encoded in MUTF-7, possible including a wildcard.
Returns:
Collection of mailboxes matching the pattern.

listMailboxes

public java.util.List listMailboxes(AlfrescoImapUser user,
                                    java.lang.String mailboxPattern)
Description copied from interface: ImapService
Returns an collection of mailboxes. This method serves LIST command of the IMAP protocol.

Specified by:
listMailboxes in interface ImapService
Parameters:
user - User making the request
mailboxPattern - String name of a mailbox encoded in MUTF-7, possible including a wildcard.
Returns:
Collection of mailboxes matching the pattern.

createMailbox

public AlfrescoImapFolder createMailbox(AlfrescoImapUser user,
                                        java.lang.String mailboxName)
Description copied from interface: ImapService
Returns a reference to a newly created mailbox. The request should specify a mailbox that does not already exist on this server, that could exist on this server and that the user has rights to create. This method serves CREATE command of the IMAP protocol.

Specified by:
createMailbox in interface ImapService
Parameters:
user - User making the request.
mailboxName - String name of the target encoded in MUTF-7,
Returns:
an Mailbox reference.

deleteMailbox

public void deleteMailbox(AlfrescoImapUser user,
                          java.lang.String mailboxName)
Description copied from interface: ImapService
Deletes an existing MailBox. Specified mailbox must already exist on this server, and the user must have rights to delete it. This method serves DELETE command of the IMAP protocol.

Specified by:
deleteMailbox in interface ImapService
Parameters:
user - User making the request.
mailboxName - String name of the target encoded in MUTF-7,

renameMailbox

public void renameMailbox(AlfrescoImapUser user,
                          java.lang.String oldMailboxName,
                          java.lang.String newMailboxName)
Description copied from interface: ImapService
Renames an existing mailbox. The specified mailbox must already exist, the requested name must not exist already but must be able to be created and the user must have rights to delete the existing mailbox and create a mailbox with the new name. Any inferior hierarchical names must also be renamed. If INBOX is renamed, the contents of INBOX are transferred to a new mailbox with the new name, but INBOX is not deleted. If INBOX has inferior mailbox these are not renamed. This method serves RENAME command of the IMAP protocol.

Specified by:
renameMailbox in interface ImapService
Parameters:
user - User making the request.
oldMailboxName - String name of the existing folder encoded in MUTF-7,
newMailboxName - String target new name encoded in MUTF-7,

getFolder

public AlfrescoImapFolder getFolder(AlfrescoImapUser user,
                                    java.lang.String mailboxName)
Description copied from interface: ImapService
Returns a reference to an existing Mailbox. The requested mailbox must already exists on this server and the requesting user must have at least lookup rights.

It is also can be used by to obtain hierarchy delimiter by the LIST command:

C: 2 list "" ""

S: * LIST () "." ""

S: 2 OK LIST completed.

Specified by:
getFolder in interface ImapService
Parameters:
user - User making the request.
mailboxName - String name of the target encoded in MUTF-7,.
Returns:
an Mailbox reference.

searchMails

public java.util.List searchMails(org.alfresco.service.cmr.repository.NodeRef contextNodeRef,
                                  AlfrescoImapConst.ImapViewMode viewMode)
Search for emails in specified folder depending on view mode. Shallow list of files

Specified by:
searchMails in interface ImapService
Parameters:
contextNodeRef - context folder for search
viewMode - context folder view mode
Returns:
list of emails that context folder contains.

subscribe

public void subscribe(AlfrescoImapUser user,
                      java.lang.String mailbox)
Description copied from interface: ImapService
Subscribes a user to a mailbox. The mailbox must exist locally and the user must have rights to modify it.

This method serves SUBSCRIBE command of the IMAP protocol.

Specified by:
subscribe in interface ImapService
Parameters:
user - User making the request
mailbox - String representation of a mailbox name encoded in MUTF-7,.

unsubscribe

public void unsubscribe(AlfrescoImapUser user,
                        java.lang.String mailbox)
Description copied from interface: ImapService
Unsubscribes from a given mailbox.

This method serves UNSUBSCRIBE command of the IMAP protocol.

Specified by:
unsubscribe in interface ImapService
Parameters:
user - User making the request
mailbox - String representation of a mailbox name encoded in MUTF-7,.

getFlags

public javax.mail.Flags getFlags(FileInfo messageInfo)
Return flags that belong to the specified imap folder.

Specified by:
getFlags in interface ImapService
Parameters:
messageInfo - imap folder info.
Returns:
flags.

setFlags

public void setFlags(FileInfo messageInfo,
                     javax.mail.Flags flags,
                     boolean value)
Set flags to the specified imapFolder.

Specified by:
setFlags in interface ImapService
Parameters:
messageInfo - FileInfo of imap Folder.
flags - flags to set.
value - value to set.

setFlag

public void setFlag(FileInfo messageInfo,
                    javax.mail.Flags.Flag flag,
                    boolean value)
Set flags to the specified imapFolder.

Specified by:
setFlag in interface ImapService
Parameters:
messageInfo - FileInfo of imap Folder
flag - flag to set.
value - value value to set.

getMailboxRootRef

public org.alfresco.service.cmr.repository.NodeRef getMailboxRootRef(java.lang.String mailboxName,
                                                                     java.lang.String userName)
Get root reference for the specified mailbox

Specified by:
getMailboxRootRef in interface ImapService
Parameters:
mailboxName - mailbox name in IMAP client.
userName -
Returns:
root reference for the specified mailbox

getDefaultEmailBodyTemplate

public java.lang.String getDefaultEmailBodyTemplate(ImapService.EmailBodyFormat type)
Description copied from interface: ImapService
Returns a template for email body. It is either classpath path or NodeRef.toString(). This method trying to find a template on the path in the repository first e.g. "Data Dictionary > IMAP Templates >". This path should be set as the property of the "imapHelper" bean. In this case it returns NodeRef.toString() of the template. If there are no template in the repository it returns a default template on the classpath.

Specified by:
getDefaultEmailBodyTemplate in interface ImapService
Returns:

getAlfrescoServerUID

public java.lang.String getAlfrescoServerUID()
This method should returns a unique identifier of Alfresco server. The possible UID may be calculated based on IP address, Server port, MAC address, Web Application context. This UID should be parseable into initial components. This necessary for the implementation of the following case: If the message being copied (e.g. drag-and-drop) between two different Alfresco accounts in the IMAP client, we must unambiguously identify from which Alfresco server this message being copied. The message itself does not contain content data, so we must download it from the initial server (e.g. using download content servlet) and save it into destination repository.

Returns:
String representation of unique identifier of Alfresco server

onCreateChildAssociation

public void onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef childAssocRef,
                                     boolean isNewNode)
Description copied from interface: NodeServicePolicies.OnCreateChildAssociationPolicy
Called after a node child association has been created.

Specified by:
onCreateChildAssociation in interface NodeServicePolicies.OnCreateChildAssociationPolicy
Parameters:
childAssocRef - the child association that has been created
isNewNode - true if the node is new or false if the node is being linked in

onDeleteChildAssociation

public void onDeleteChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef childAssocRef)
Description copied from interface: NodeServicePolicies.OnDeleteChildAssociationPolicy
Called after a node child association has been deleted.

Specified by:
onDeleteChildAssociation in interface NodeServicePolicies.OnDeleteChildAssociationPolicy
Parameters:
childAssocRef - the child association that has been deleted

beforeDeleteNode

public void beforeDeleteNode(org.alfresco.service.cmr.repository.NodeRef nodeRef)

isNodeInSitesLibrary

public boolean isNodeInSitesLibrary(org.alfresco.service.cmr.repository.NodeRef nodeRef)
Return true if provided nodeRef is in Sites/.../documentlibrary

Specified by:
isNodeInSitesLibrary in interface ImapService
Parameters:
nodeRef - nodeRef
Returns:
true if provided node belongs to sites.

extractAttachments

public org.alfresco.service.cmr.repository.NodeRef extractAttachments(org.alfresco.service.cmr.repository.NodeRef parentFolder,
                                                                      org.alfresco.service.cmr.repository.NodeRef messageFile,
                                                                      javax.mail.internet.MimeMessage originalMessage)
                                                               throws java.io.IOException,
                                                                      javax.mail.MessagingException
Extract attachments from a MimeMessage Puts the attachments into a subfolder below the parent folder.

Specified by:
extractAttachments in interface ImapService
messageFile - the node ref of the message.
Returns:
the node ref of the folder containing the attachments or null if there are no attachments.
Throws:
java.io.IOException
javax.mail.MessagingException


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.