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

Since:
3.2
Author:
Dmitry Vaserin, Arseny Kovalchuk, David Ward
  • Constructor Details

    • ImapServiceImpl

      public ImapServiceImpl()
  • Method Details

    • setSysAdminParams

      public void setSysAdminParams(SysAdminParams sysAdminParams)
    • setMessageCache

      public void setMessageCache(SimpleCache<NodeRef,org.alfresco.repo.imap.ImapServiceImpl.CacheItem> messageCache)
    • setFileFolderService

      public void setFileFolderService(FileFolderService fileFolderService)
    • setNodeService

      public void setNodeService(NodeService nodeService)
    • setPermissionService

      public void setPermissionService(PermissionService permissionService)
    • setServiceRegistry

      public void setServiceRegistry(ServiceRegistry serviceRegistry)
    • setPolicyFilter

      public void setPolicyFilter(BehaviourFilter policyFilter)
    • setAttachmentsExtractor

      public void setAttachmentsExtractor(AttachmentsExtractor attachmentsExtractor)
    • setImapHome

      public void setImapHome(RepositoryFolderConfigBean imapHomeConfigBean)
    • setFolderCacheSize

      public void setFolderCacheSize(int folderCacheSize)
    • getDefaultFromAddress

      public String getDefaultFromAddress()
      Specified by:
      getDefaultFromAddress in interface ImapService
      Returns:
      Default From addreses
    • setDefaultFromAddress

      public void setDefaultFromAddress(String defaultFromAddress)
    • getDefaultToAddress

      public String getDefaultToAddress()
      Specified by:
      getDefaultToAddress in interface ImapService
      Returns:
      Default To addreses
    • setDefaultToAddress

      public void setDefaultToAddress(String defaultToAddress)
    • getWebApplicationContextUrl

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

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

      public 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(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)
    • setMessageHeadersToPersist

      public void setMessageHeadersToPersist(List<String> headers)
    • setImapServerShuffleMoveDeleteDelay

      public void setImapServerShuffleMoveDeleteDelay(long imapServerShuffleMoveDeleteDelay)
    • 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()
      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: ImapService
      Gets a cached MIME message for the given file, complete with message body.
      Specified by:
      getMessage in interface ImapService
      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: ImapService
      Creates a MIME message for the given file
      Specified by:
      createImapMessage in interface ImapService
      Parameters:
      fileInfo - imap file info.
      generateBody - Should the message body be generated?
      Returns:
      a message.
      Throws:
      jakarta.mail.MessagingException
    • expungeMessage

      public void expungeMessage(FileInfo fileInfo)
      Description copied from interface: ImapService
      Expunges (deletes) an IMAP message if its flags indicates
      Specified by:
      expungeMessage in interface ImapService
      Parameters:
      fileInfo - imap file info.
    • getOrCreateMailbox

      public AlfrescoImapFolder getOrCreateMailbox(AlfrescoImapUser user, String mailboxName, boolean mayExist, boolean mayCreate)
      Description copied from interface: ImapService
      Returns a reference to a mailbox, either creating a new one or retrieving an existing one.

      mailbox parameter may specify absolute or relative path to a folder. Absolute path uniquely identifies some directory, whereas relative path implies that root folder should be IMAP home directory for the specified user rather than IMAP root (i.e. IMAP mount point). Mailbox will be found or created (mayCreate=true, mayExist=false or ) in user's IMAP home directory if relative path is specified.

      mayExist and 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:
      getOrCreateMailbox in interface ImapService
      Parameters:
      user - User making the request.
      mailboxName - String name of the target.
      mayExist - Is the mailbox allowed to exist already? If false and the mailbox already exists, an error will be thrown
      mayCreate - If the mailbox does not exist, can one be created? If false then an error is thrown if the folder does not exist
      Returns:
      a Mailbox reference
      Throws:
      AlfrescoImapRuntimeException
    • deleteMailbox

      public void deleteMailbox(AlfrescoImapUser user, 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,
    • renameMailbox

      public void renameMailbox(AlfrescoImapUser user, String oldMailboxName, 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
      newMailboxName - 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:
      getFolderStatus in interface ImapService
      Parameters:
      contextNodeRef - context folder for search
      viewMode - context folder view mode
      userName - user name
      Returns:
      list of emails that context folder contains.
    • subscribe

      public void subscribe(AlfrescoImapUser user, 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.
    • unsubscribe

      public void unsubscribe(AlfrescoImapUser user, 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.
    • getFlags

      public jakarta.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, jakarta.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, jakarta.mail.Flags.Flag flag, boolean value)
      Set flags to the specified message.
      Specified by:
      setFlag in interface ImapService
      Parameters:
      messageInfo - FileInfo of imap Folder
      flag - 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:
      listMailboxes in interface ImapService
      Parameters:
      user - User making the request
      mailboxPattern - String name of a mailbox, possible including a wildcard.
      listSubscribed - list only subscribed folders?
      Returns:
      Collection of mailboxes matching the pattern.
    • getUserImapHomeRef

      public NodeRef getUserImapHomeRef(String userName)
      Get the node ref of the user's imap home. Will create it on demand if it does not already exist.
      Specified by:
      getUserImapHomeRef in interface ImapService
      Parameters:
      userName - user name
      Returns:
      user IMAP home reference and create it if it doesn't exist.
    • getDefaultEmailBodyTemplate

      public 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
      Parameters:
      type - one of the possible body types text/html and text/plain
      Returns:
      String
    • getAlfrescoServerUID

      public 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(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(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
    • onUpdateProperties

      public void onUpdateProperties(NodeRef nodeRef, Map<QName,Serializable> before, Map<QName,Serializable> after)
      Description copied from interface: NodeServicePolicies.OnUpdatePropertiesPolicy
      Called after a node's properties have been changed.
      Specified by:
      onUpdateProperties in interface NodeServicePolicies.OnUpdatePropertiesPolicy
      Parameters:
      nodeRef - reference to the updated node
      before - the node's properties before the change
      after - the node's properties after the change
    • onRestoreNode

      public void onRestoreNode(ChildAssociationRef childAssocRef)
      Description copied from interface: NodeServicePolicies.OnRestoreNodePolicy
      Called after an archived node is restored.
      Specified by:
      onRestoreNode in interface NodeServicePolicies.OnRestoreNodePolicy
      Parameters:
      childAssocRef - the newly created child association reference
    • beforeDeleteNode

      public void beforeDeleteNode(NodeRef nodeRef)
      Description copied from interface: NodeServicePolicies.BeforeDeleteNodePolicy
      Called before a node is deleted.
      Specified by:
      beforeDeleteNode in interface NodeServicePolicies.BeforeDeleteNodePolicy
      Parameters:
      nodeRef - the node reference
    • getNodeSiteContainer

      public NodeRef getNodeSiteContainer(NodeRef inputNodeRef)
      Description copied from interface: ImapService
      Get the node's site container if it belongs to Sites.
      Specified by:
      getNodeSiteContainer in interface ImapService
      Parameters:
      inputNodeRef - nodeRef
      Returns:
      nodeRef of the node's site container or null if provided node does not belong to sites.
    • getContentFolderUrl

      public String getContentFolderUrl(NodeRef contentNodeRef)
      Description copied from interface: ImapService
      Get the web URL for the document's parent folder
      Specified by:
      getContentFolderUrl in interface ImapService
      Parameters:
      contentNodeRef - or null if the document is not from site
      Returns:
      url for the content folder
    • setNamespaceService

      public void setNamespaceService(NamespaceService namespaceService)
    • getNamespaceService

      public NamespaceService getNamespaceService()
    • setSearchService

      public void setSearchService(SearchService searchService)
    • getSearchService

      public SearchService getSearchService()
    • extractAttachments

      public void extractAttachments(NodeRef messageRef, jakarta.mail.internet.MimeMessage originalMessage) throws IOException, jakarta.mail.MessagingException
      Description copied from interface: ImapService
      Extract attachments from message.
      Specified by:
      extractAttachments in interface ImapService
      Parameters:
      messageRef - nodeRef that represents message in Alfresco.
      originalMessage - original message in eml format.
      Throws:
      IOException
      jakarta.mail.MessagingException
    • generateUniqueFilename

      public String generateUniqueFilename(NodeRef destFolderNodeRef, String fileName)
      Specified by:
      generateUniqueFilename in interface ImapService
    • persistMessageHeaders

      public void persistMessageHeaders(NodeRef messageRef, jakarta.mail.internet.MimeMessage message)
      Specified by:
      persistMessageHeaders in interface ImapService
    • getPathFromSites

      public String getPathFromSites(NodeRef ref)
      Specified by:
      getPathFromSites in interface ImapService
      Parameters:
      ref - NodeRef
      Returns:
      path for node relatively to site root
    • getPathFromRepo

      public String getPathFromRepo(ChildAssociationRef assocRef)
      Specified by:
      getPathFromRepo in interface ImapService
      Parameters:
      assocRef - an association between the node and it's parent
      Returns:
      path for node relatively to repository