<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

    <bean id="imapServiceBootstrap" class="org.alfresco.repo.imap.ImapServiceImpl$ImapServiceBootstrap">
        <property name="service">
            <ref bean="imapService"/>
        </property>
        <property name="imapServerEnabled">
            <value>${imap.server.enabled}</value>
        </property>
    </bean>

    <bean id="imapServer" class="org.alfresco.repo.imap.AlfrescoImapServer">
        <property name="sysAdminParams">
            <ref bean="sysAdminParams" />
        </property>
        <property name="port">
            <value>${imap.server.port}</value>
        </property>
        <property name="imapServerEnabled">
            <value>${imap.server.enabled}</value>
        </property>
        <property name="imapHostManager">
            <ref local="imapHostManager" />
        </property>
        <property name="imapUserManager">
            <ref local="imapUserManager" />
        </property>
    </bean>
    

    <bean id="imapResourceBundles" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
        <property name="resourceBundles">
            <list>
                <value>alfresco.messages.imap-service</value>
            </list>
        </property>
    </bean>
    
    <bean id="imapContentPolicy" class="org.alfresco.repo.imap.ImapContentPolicy" init-method="init">
        <property name="actionService">
            <ref bean="actionService"/>
        </property>       
        <property name="policyComponent">
            <ref bean="policyComponent"/>
        </property>
    </bean>
    
    <!--The configurable list of mount points -->
    <bean id="imap.config.server.mountPoints" class="org.springframework.beans.factory.config.ListFactoryBean" >
        <!-- Uses ImapConfigMountPointsBean with:
            mountPointName (e.g. Repository_virtual')
            modeName (e.g. 'VIRTUAL', 'ARCHIVE' or 'MIXED')
            store (e.g. '${spaces.store}')
            rootPath (e.g. '/${spaces.company_home.childname})
            folderPath (optional e.g. Projects/T1)
        -->
    </bean>

    <!--The configurable list of folders that ignore attachment extraction -->
    <bean id="imap.config.ignore.extraction" class="org.springframework.beans.factory.config.ListFactoryBean">
        <!-- Uses RepositoryPathConfigBean with:
            store (e.g. '${spaces.store}')
            rootPath (e.g. '/${spaces.company_home.childname})
            folderPath (optional e.g. Projects/T1)
        -->
    </bean>
    
    <!-- The IMAP home, which has to be a sub-folder -->
    <bean id="imap.config.home" class="org.alfresco.util.config.RepositoryFolderConfigBean">
        <property name="store">
            <value>${imap.config.home.store}</value>
        </property>
        <property name="rootPath">
            <value>${imap.config.home.rootPath}</value>
        </property>
        <property name="folderPath">
            <value>${imap.config.home.folderPath}</value>
        </property>
    </bean>
    
    <bean id="ImapService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager">
            <ref bean="transactionManager"/>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="search*">${server.transaction.mode.readOnly}</prop>
                <prop key="getFolder">${server.transaction.mode.default}</prop>
                <prop key="getFlags">${server.transaction.mode.default}</prop>
                <prop key="get*">${server.transaction.mode.readOnly}</prop>
                <prop key="*">${server.transaction.mode.default}</prop>
            </props>
        </property>
    </bean>
    

    <bean id="imapService" class="org.alfresco.repo.imap.ImapServiceImpl" init-method="init">
        <property name="sysAdminParams">
            <ref bean="sysAdminParams" />
        </property>
        <property name="fileFolderService">
            <ref bean="FileFolderService"/>
        </property>
        <property name="nodeService">
            <ref bean="NodeService"/>
        </property>
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
        
        <property name="imapConfigMountPoints">
            <ref bean="imap.config.server.mountPoints" />
        </property>
        <property name="ignoreExtractionFolders">
            <ref bean="imap.config.ignore.extraction" />
        </property>
        <property name="imapHome">
            <ref bean="imap.config.home" />
        </property>
        <property name="defaultFromAddress">
            <value>${imap.mail.from.default}</value>
        </property>
        <property name="repositoryTemplatePath">
            <value>${spaces.store}/${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.imapConfig.childname}/${spaces.imap_templates.childname}</value>
        </property>
        <property name="extractAttachmentsEnabled">
            <value>${imap.server.attachments.extraction.enabled}</value>
        </property>
    </bean>
    
    <!-- Public Imap Service -->
    
    <bean id="ImapService" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces">
            <list>
                <value>org.alfresco.repo.imap.ImapService</value>
            </list>
        </property>
        <property name="target">
            <ref bean="imapService"/>
        </property>
        <property name="interceptorNames">
            <list>
                <idref local="ImapService_transaction"/>
            </list>
        </property>
    </bean>
    

    <bean id="imapHostManager" class="org.alfresco.repo.imap.AlfrescoImapHostManager">
        <property name="imapService">
            <ref bean="ImapService" /> 
        </property>
        <property name="transactionService">
            <ref bean="transactionService" /> 
        </property>
    </bean>

    <bean id="imapUserManager" class="org.alfresco.repo.imap.AlfrescoImapUserManager">
        <property name="authenticationService" ref="AuthenticationService" />
        <property name="personService" ref="PersonService" />
        <property name="nodeService" ref="NodeService" />
    </bean>
</beans>
