Package org.alfresco.repo.imap
Class ImapServiceImpl
java.lang.Object
org.alfresco.repo.imap.ImapServiceImpl
- All Implemented Interfaces:
ImapService,NodeServicePolicies.BeforeDeleteNodePolicy,NodeServicePolicies.OnCreateChildAssociationPolicy,NodeServicePolicies.OnDeleteChildAssociationPolicy,NodeServicePolicies.OnRestoreNodePolicy,NodeServicePolicies.OnUpdatePropertiesPolicy,AssociationPolicy,ClassPolicy,Policy
public class ImapServiceImpl
extends Object
implements ImapService, NodeServicePolicies.OnRestoreNodePolicy, NodeServicePolicies.OnCreateChildAssociationPolicy, NodeServicePolicies.OnDeleteChildAssociationPolicy, NodeServicePolicies.OnUpdatePropertiesPolicy, NodeServicePolicies.BeforeDeleteNodePolicy
- Since:
- 3.2
- Author:
- Dmitry Vaserin, Arseny Kovalchuk, David Ward
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBootstrap initialization bean for the service implementation.Nested classes/interfaces inherited from interface org.alfresco.repo.imap.ImapService
ImapService.EmailBodyFormat, ImapService.FolderStatusNested classes/interfaces inherited from interface org.alfresco.repo.policy.Policy
Policy.Arg -
Field Summary
Fields inherited from interface org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy
QNAMEFields inherited from interface org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy
QNAMEFields inherited from interface org.alfresco.repo.node.NodeServicePolicies.OnDeleteChildAssociationPolicy
QNAMEFields inherited from interface org.alfresco.repo.node.NodeServicePolicies.OnRestoreNodePolicy
QNAMEFields inherited from interface org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy
ARG_0, ARG_1, ARG_2, QNAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforeDeleteNode(NodeRef nodeRef) Called before a node is deleted.protected voidcom.icegreen.greenmail.store.SimpleStoredMessagecreateImapMessage(FileInfo fileInfo, boolean generateBody) Creates a MIME message for the given filevoiddeleteMailbox(AlfrescoImapUser user, String mailboxName) Deletes an existing MailBox.voidexpungeMessage(FileInfo fileInfo) Expunges (deletes) an IMAP message if its flags indicatesvoidextractAttachments(NodeRef messageRef, jakarta.mail.internet.MimeMessage originalMessage) Extract attachments from message.generateUniqueFilename(NodeRef destFolderNodeRef, String fileName) This method should returns a unique identifier of Alfresco server.getContentFolderUrl(NodeRef contentNodeRef) Get the web URL for the document's parent folderReturns a template for email body.jakarta.mail.FlagsReturn flags that belong to the specified imap folder.getFolderStatus(String userName, NodeRef contextNodeRef, AlfrescoImapConst.ImapViewMode viewMode) Search for emails in specified folder depending on view mode.booleanDetermines whether the IMAP server is enabled.com.icegreen.greenmail.store.SimpleStoredMessagegetMessage(FileInfo mesInfo) Gets a cached MIME message for the given file, complete with message body.getNodeSiteContainer(NodeRef inputNodeRef) Get the node's site container if it belongs to Sites.getOrCreateMailbox(AlfrescoImapUser user, String mailboxName, boolean mayExist, boolean mayCreate) Returns a reference to a mailbox, either creating a new one or retrieving an existing one.
mailboxparameter may specify absolute or relative path to a folder.getPathFromRepo(ChildAssociationRef assocRef) getPathFromSites(NodeRef ref) getUserImapHomeRef(String userName) Get the node ref of the user's imap home.voidinit()listMailboxes(AlfrescoImapUser user, String mailboxPattern, boolean listSubscribed) Depend on listSubscribed param, list Mailboxes or list subscribed MailboxesvoidonCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode) Called after a node child association has been created.voidonDeleteChildAssociation(ChildAssociationRef childAssocRef) Called after a node child association has been deleted.voidonRestoreNode(ChildAssociationRef childAssocRef) Called after an archived node is restored.voidonUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after) Called after a node's properties have been changed.voidpersistMessageHeaders(NodeRef messageRef, jakarta.mail.internet.MimeMessage message) voidrenameMailbox(AlfrescoImapUser user, String oldMailboxName, String newMailboxName) Renames an existing mailbox.voidsetAttachmentsExtractor(AttachmentsExtractor attachmentsExtractor) voidsetDefaultFromAddress(String defaultFromAddress) voidsetDefaultToAddress(String defaultToAddress) voidsetExtractAttachmentsEnabled(boolean extractAttachmentsEnabled) voidsetFileFolderService(FileFolderService fileFolderService) voidSet flags to the specified message.voidSet flags to the specified imapFolder.voidsetFolderCacheSize(int folderCacheSize) voidsetIgnoreExtractionFolders(RepositoryFolderConfigBean[] ignoreExtractionFolders) voidsetImapConfigMountPoints(ImapConfigMountPointsBean[] imapConfigMountPointsBeans) voidsetImapHome(RepositoryFolderConfigBean imapHomeConfigBean) voidsetImapServerEnabled(boolean enabled) voidsetImapServerShuffleMoveDeleteDelay(long imapServerShuffleMoveDeleteDelay) voidsetMessageCache(SimpleCache<NodeRef, org.alfresco.repo.imap.ImapServiceImpl.CacheItem> messageCache) voidsetMessageHeadersToPersist(List<String> headers) voidsetNamespaceService(NamespaceService namespaceService) voidsetNodeService(NodeService nodeService) voidsetPermissionService(PermissionService permissionService) voidsetPolicyFilter(BehaviourFilter policyFilter) voidsetRepositoryTemplatePath(String repositoryTemplatePath) voidsetSearchService(SearchService searchService) voidsetServiceRegistry(ServiceRegistry serviceRegistry) voidsetSysAdminParams(SysAdminParams sysAdminParams) voidshutdown()voidstartup()This method is run as System within a single transaction on startup.protected voidstartupInTxn(boolean force) voidsubscribe(AlfrescoImapUser user, String mailbox) Subscribes a user to a mailbox.voidunsubscribe(AlfrescoImapUser user, String mailbox) Unsubscribes from a given mailbox.
-
Constructor Details
-
ImapServiceImpl
public ImapServiceImpl()
-
-
Method Details
-
setSysAdminParams
-
setMessageCache
public void setMessageCache(SimpleCache<NodeRef, org.alfresco.repo.imap.ImapServiceImpl.CacheItem> messageCache) -
setFileFolderService
-
setNodeService
-
setPermissionService
-
setServiceRegistry
-
setPolicyFilter
-
setAttachmentsExtractor
-
setImapHome
-
setFolderCacheSize
public void setFolderCacheSize(int folderCacheSize) -
getDefaultFromAddress
- Specified by:
getDefaultFromAddressin interfaceImapService- Returns:
- Default From addreses
-
setDefaultFromAddress
-
getDefaultToAddress
- Specified by:
getDefaultToAddressin interfaceImapService- Returns:
- Default To addreses
-
setDefaultToAddress
-
getWebApplicationContextUrl
- Specified by:
getWebApplicationContextUrlin interfaceImapService- Returns:
- Web application context url (e.g. http://localhost:8080/alfresco)
-
getRepositoryTemplatePath
- Specified by:
getRepositoryTemplatePathin interfaceImapService- Returns:
- Path to the folder containing templates, that will be used for generating body of message in VIRTUAL and MIXED views.
-
setRepositoryTemplatePath
-
setImapConfigMountPoints
-
setIgnoreExtractionFolders
-
setExtractAttachmentsEnabled
public void setExtractAttachmentsEnabled(boolean extractAttachmentsEnabled) -
setImapServerEnabled
public void setImapServerEnabled(boolean enabled) -
setMessageHeadersToPersist
-
setImapServerShuffleMoveDeleteDelay
public void setImapServerShuffleMoveDeleteDelay(long imapServerShuffleMoveDeleteDelay) -
getImapServerEnabled
public boolean getImapServerEnabled()Description copied from interface:ImapServiceDetermines whether the IMAP server is enabled.- Specified by:
getImapServerEnabledin interfaceImapService- Returns:
- true if enabled
-
init
public void init() -
startup
public void startup()This method is run as System within a single transaction on startup. -
shutdown
public void shutdown() -
startupInTxn
protected void startupInTxn(boolean force) -
bindBehaviour
protected void bindBehaviour() -
getMessage
public com.icegreen.greenmail.store.SimpleStoredMessage getMessage(FileInfo mesInfo) throws jakarta.mail.MessagingException Description copied from interface:ImapServiceGets a cached MIME message for the given file, complete with message body.- Specified by:
getMessagein interfaceImapService- Parameters:
mesInfo- imap file info.- Returns:
- a message.
- Throws:
jakarta.mail.MessagingException
-
createImapMessage
public com.icegreen.greenmail.store.SimpleStoredMessage createImapMessage(FileInfo fileInfo, boolean generateBody) throws jakarta.mail.MessagingException Description copied from interface:ImapServiceCreates a MIME message for the given file- Specified by:
createImapMessagein interfaceImapService- Parameters:
fileInfo- imap file info.generateBody- Should the message body be generated?- Returns:
- a message.
- Throws:
jakarta.mail.MessagingException
-
expungeMessage
Description copied from interface:ImapServiceExpunges (deletes) an IMAP message if its flags indicates- Specified by:
expungeMessagein interfaceImapService- Parameters:
fileInfo- imap file info.
-
getOrCreateMailbox
public AlfrescoImapFolder getOrCreateMailbox(AlfrescoImapUser user, String mailboxName, boolean mayExist, boolean mayCreate) Description copied from interface:ImapServiceReturns a reference to a mailbox, either creating a new one or retrieving an existing one.
mailboxparameter may specify absolute or relative path to a folder. Absolute path uniquely identifies some directory, whereas relative path implies that root folder should beIMAP homedirectory for the specifieduserrather thanIMAP root(i.e.IMAP mount point). Mailbox will be found or created (mayCreate=true,mayExist=falseor ) inuser'sIMAP homedirectory if relative path is specified.
mayExistand mayCreate parameters' combinations and results:mayCreate=false,mayExist=true- mailbox is found and not created if it doesn't exist. Error is thrown if mailbox doesn't not exist;mayCreate=true,mayExist=true- mailbox is created if it doesn't exist or it is just found in other case. No error is thrown;mayCreate=true,mayExist=false- mailbox is created if it doesn't exist. Error is thrown if it is already created;mayCreate=false,mayExist=false- error is thrown that mailbox cannot be created if doesn't exist. Error is thrown that mailbox should not exist in other case.
It's a very shady combination!
- Specified by:
getOrCreateMailboxin interfaceImapService- Parameters:
user- User making the request.mailboxName- String name of the target.mayExist- Is the mailbox allowed to exist already? Iffalseand the mailbox already exists, an error will be thrownmayCreate- If the mailbox does not exist, can one be created? Iffalsethen an error is thrown if the folder does not exist- Returns:
- a Mailbox reference
- Throws:
AlfrescoImapRuntimeException
-
deleteMailbox
Description copied from interface:ImapServiceDeletes 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:
deleteMailboxin interfaceImapService- Parameters:
user- User making the request.mailboxName- String name of the target,
-
renameMailbox
Description copied from interface:ImapServiceRenames 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:
renameMailboxin interfaceImapService- Parameters:
user- User making the request.oldMailboxName- String name of the existing foldernewMailboxName- String target new name
-
getFolderStatus
public ImapService.FolderStatus getFolderStatus(String userName, NodeRef contextNodeRef, AlfrescoImapConst.ImapViewMode viewMode) Search for emails in specified folder depending on view mode. Shallow list of files- Specified by:
getFolderStatusin interfaceImapService- Parameters:
contextNodeRef- context folder for searchviewMode- context folder view modeuserName- user name- Returns:
- list of emails that context folder contains.
-
subscribe
Description copied from interface:ImapServiceSubscribes 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:
subscribein interfaceImapService- Parameters:
user- User making the requestmailbox- String representation of a mailbox name.
-
unsubscribe
Description copied from interface:ImapServiceUnsubscribes from a given mailbox. This method serves UNSUBSCRIBE command of the IMAP protocol.- Specified by:
unsubscribein interfaceImapService- Parameters:
user- User making the requestmailbox- String representation of a mailbox name.
-
getFlags
Return flags that belong to the specified imap folder.- Specified by:
getFlagsin interfaceImapService- Parameters:
messageInfo- imap folder info.- Returns:
- flags.
-
setFlags
Set flags to the specified imapFolder.- Specified by:
setFlagsin interfaceImapService- Parameters:
messageInfo- FileInfo of imap Folder.flags- flags to set.value- value to set.
-
setFlag
Set flags to the specified message.- Specified by:
setFlagin interfaceImapService- Parameters:
messageInfo- FileInfo of imap Folderflag- flag to set.value- value value to set.
-
listMailboxes
public List<AlfrescoImapFolder> listMailboxes(AlfrescoImapUser user, String mailboxPattern, boolean listSubscribed) Depend on listSubscribed param, list Mailboxes or list subscribed Mailboxes- Specified by:
listMailboxesin interfaceImapService- Parameters:
user- User making the requestmailboxPattern- String name of a mailbox, possible including a wildcard.listSubscribed- list only subscribed folders?- Returns:
- Collection of mailboxes matching the pattern.
-
getUserImapHomeRef
Get the node ref of the user's imap home. Will create it on demand if it does not already exist.- Specified by:
getUserImapHomeRefin interfaceImapService- Parameters:
userName- user name- Returns:
- user IMAP home reference and create it if it doesn't exist.
-
getDefaultEmailBodyTemplate
Description copied from interface:ImapServiceReturns 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 returnsNodeRef.toString()of the template. If there are no template in the repository it returns a default template on the classpath.- Specified by:
getDefaultEmailBodyTemplatein interfaceImapService- Parameters:
type- one of the possible body types text/html and text/plain- Returns:
- 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
Description copied from interface:NodeServicePolicies.OnCreateChildAssociationPolicyCalled after a node child association has been created.- Specified by:
onCreateChildAssociationin interfaceNodeServicePolicies.OnCreateChildAssociationPolicy- Parameters:
childAssocRef- the child association that has been createdisNewNode- true if the node is new or false if the node is being linked in
-
onDeleteChildAssociation
Description copied from interface:NodeServicePolicies.OnDeleteChildAssociationPolicyCalled after a node child association has been deleted.- Specified by:
onDeleteChildAssociationin interfaceNodeServicePolicies.OnDeleteChildAssociationPolicy- Parameters:
childAssocRef- the child association that has been deleted
-
onUpdateProperties
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after) Description copied from interface:NodeServicePolicies.OnUpdatePropertiesPolicyCalled after a node's properties have been changed.- Specified by:
onUpdatePropertiesin interfaceNodeServicePolicies.OnUpdatePropertiesPolicy- Parameters:
nodeRef- reference to the updated nodebefore- the node's properties before the changeafter- the node's properties after the change
-
onRestoreNode
Description copied from interface:NodeServicePolicies.OnRestoreNodePolicyCalled after an archived node is restored.- Specified by:
onRestoreNodein interfaceNodeServicePolicies.OnRestoreNodePolicy- Parameters:
childAssocRef- the newly created child association reference
-
beforeDeleteNode
Description copied from interface:NodeServicePolicies.BeforeDeleteNodePolicyCalled before a node is deleted.- Specified by:
beforeDeleteNodein interfaceNodeServicePolicies.BeforeDeleteNodePolicy- Parameters:
nodeRef- the node reference
-
getNodeSiteContainer
Description copied from interface:ImapServiceGet the node's site container if it belongs to Sites.- Specified by:
getNodeSiteContainerin interfaceImapService- Parameters:
inputNodeRef- nodeRef- Returns:
- nodeRef of the node's site container or null if provided node does not belong to sites.
-
getContentFolderUrl
Description copied from interface:ImapServiceGet the web URL for the document's parent folder- Specified by:
getContentFolderUrlin interfaceImapService- Parameters:
contentNodeRef- or null if the document is not from site- Returns:
- url for the content folder
-
setNamespaceService
-
getNamespaceService
-
setSearchService
-
getSearchService
-
extractAttachments
public void extractAttachments(NodeRef messageRef, jakarta.mail.internet.MimeMessage originalMessage) throws IOException, jakarta.mail.MessagingException Description copied from interface:ImapServiceExtract attachments from message.- Specified by:
extractAttachmentsin interfaceImapService- Parameters:
messageRef- nodeRef that represents message in Alfresco.originalMessage- original message in eml format.- Throws:
IOExceptionjakarta.mail.MessagingException
-
generateUniqueFilename
- Specified by:
generateUniqueFilenamein interfaceImapService
-
persistMessageHeaders
- Specified by:
persistMessageHeadersin interfaceImapService
-
getPathFromSites
- Specified by:
getPathFromSitesin interfaceImapService- Parameters:
ref- NodeRef- Returns:
- path for node relatively to site root
-
getPathFromRepo
- Specified by:
getPathFromRepoin interfaceImapService- Parameters:
assocRef- an association between the node and it's parent- Returns:
- path for node relatively to repository
-