services:
    oro_email.entity.cache.warmer:
        class: Oro\Bundle\EmailBundle\Cache\EntityCacheWarmer
        arguments:
            - '@oro_email.email.owner.provider.storage'
            - '%oro_email.entity.cache_dir%'
            - '%oro_email.entity.cache_namespace%'
            - '%oro_email.entity.proxy_name_template%'
            - '@kernel'
        tags:
            - { name: kernel.cache_warmer, priority: 30 }
            - { name: oro_entity_extend.warmer }

    oro_email.email.cache.manager:
        class: Oro\Bundle\EmailBundle\Cache\EmailCacheManager
        public: true
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@event_dispatcher'
            - '@oro_email.email_body_synchronizer'

    Oro\Bundle\EmailBundle\Cache\EmailCacheManager:
        alias: 'oro_email.email.cache.manager'

    oro_email.email_holder_helper:
        class: Oro\Bundle\EmailBundle\Tools\EmailHolderHelper
        arguments:
            - '@oro_entity_config.provider.extend'

    oro_email.email.address.helper:
        class: Oro\Bundle\EmailBundle\Tools\EmailAddressHelper
        public: true

    oro_email.email_body_loader_selector:
        class: Oro\Bundle\EmailBundle\Provider\EmailBodyLoaderSelector
        arguments:
            - !tagged_iterator oro_email.email_body_loader

    oro_email.email_flag_manager_loader_selector:
        class: Oro\Bundle\EmailBundle\Provider\EmailFlagManagerLoaderSelector
        arguments:
            - !tagged_iterator oro_email.email_flag_manager_loader

    oro_email.email.address.manager:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailAddressManager
        arguments:
            - '%oro_email.entity.cache_namespace%'
            - '%oro_email.entity.proxy_name_template%'
            - '@doctrine'

    oro_email.email.owner.provider.storage:
        class: Oro\Bundle\EmailBundle\Entity\Provider\EmailOwnerProviderStorage

    oro_email.email.owner.provider:
        class: Oro\Bundle\EmailBundle\Entity\Provider\EmailOwnerProvider
        arguments:
            - '@oro_email.email.owner.provider.storage'

    oro_email.email.owner.manager:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailOwnerManager
        arguments:
            - '@oro_email.email.owner.provider.storage'
            - '@oro_email.email.address.manager'

    oro_email.email.address.association_metadata_listener:
        class: Oro\Bundle\EmailBundle\EventListener\EmailAddressAssociationMetadataListener
        arguments:
            - '@oro_email.email.address.manager'
        tags:
            - { name: doctrine.event_listener, event: loadClassMetadata }

    oro_email.email.model.builder.helper:
        class: Oro\Bundle\EmailBundle\Builder\Helper\EmailModelBuilderHelper
        arguments:
            - '@oro_entity.routing_helper'
            - '@oro_email.email.address.helper'
            - '@oro_entity.entity_name_resolver'
            - '@oro_security.token_accessor'
            - '@oro_email.email.address.manager'
            - '@doctrine.orm.entity_manager'
            - '@oro_email.email.cache.manager'
            - '@twig'
            - '@oro_email.mailbox.manager'

    oro_email.email.entity.builder:
        class: Oro\Bundle\EmailBundle\Builder\EmailEntityBuilder
        shared: false
        arguments:
            - '@oro_email.email.entity.batch_processor'
            - '@oro_email.email.address.manager'
            - '@oro_email.email.address.helper'
            - '@doctrine'
            - '@logger'

    oro_email.email.model.builder:
        class: Oro\Bundle\EmailBundle\Builder\EmailModelBuilder
        public: true
        arguments:
            - '@oro_email.email.model.builder.helper'
            - '@doctrine.orm.entity_manager'
            - '@oro_config.user'
            - '@oro_email.activity_list.provider'
            - '@oro_email.provider.email_attachment_provider'
            - '@oro_email.form.factory'
            - '@request_stack'
            - '@oro_ui.html_tag_helper'
            - '@oro_attachment.provider.file_constraints'

    Oro\Bundle\EmailBundle\Builder\EmailModelBuilder:
        alias: 'oro_email.email.model.builder'

    oro_email.email_websocket.processor:
        class: Oro\Bundle\EmailBundle\Model\WebSocket\WebSocketSendProcessor
        arguments:
            - '@oro_sync.websocket_client'
            - '@oro_sync.client.connection_checker'

    oro_email.event_listener.email_user_listener:
        class: Oro\Bundle\EmailBundle\EventListener\EmailUserListener
        arguments:
            - '@Psr\Container\ContainerInterface'
        tags:
            - { name: doctrine.event_listener, event: onFlush, priority: 1 }
            - { name: doctrine.event_listener, event: postFlush, priority: 1 }
            - { name: container.service_subscriber, id: oro_email.email_websocket.processor }

    oro_email.delete_handler.email_user:
        class: Oro\Bundle\EmailBundle\Handler\EmailUserDeleteHandler
        parent: oro_entity.delete_handler
        tags:
            - { name: oro_entity.delete_handler, entity: Oro\Bundle\EmailBundle\Entity\EmailUser }

    oro_email.delete_handler_extension.email_user:
        class: Oro\Bundle\EmailBundle\Handler\EmailUserDeleteHandlerExtension
        parent: oro_entity.delete_handler_extension
        tags:
            - { name: oro_entity.delete_handler_extension, entity: Oro\Bundle\EmailBundle\Entity\EmailUser }

    oro_email.delete_handler.email_thread:
        class: Oro\Bundle\EmailBundle\Handler\EmailThreadActivityEntityDeleteHandler
        public: true
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_activity.activity_entity_delete_handler'

    oro_email.email.entity.batch_processor:
        class: Oro\Bundle\EmailBundle\Builder\EmailEntityBatchProcessor
        shared: false
        arguments:
            - '@oro_email.email.address.manager'
            - '@oro_email.email.owner.provider'
            - '@event_dispatcher'

    oro_email.listener.entity_listener:
        class: Oro\Bundle\EmailBundle\EventListener\EntityListener
        arguments:
            - '@oro_message_queue.client.message_producer'
            - '@Psr\Container\ContainerInterface'
        tags:
            - { name: doctrine.event_listener, event: onFlush }
            - { name: doctrine.event_listener, event: postFlush }
            - { name: doctrine.event_listener, event: postRemove }
            - { name: container.service_subscriber, id: oro_email.email.owner.manager }
            - { name: container.service_subscriber, id: oro_email.email.thread.manager }
            - { name: container.service_subscriber, id: oro_email.email.activity.manager }
            - { name: container.service_subscriber, id: oro_email.model.email_activity_updates }
            - { name: container.service_subscriber, id: oro_email.email.address.manager }
            - { name: container.service_subscriber, id: oro_email.email_address_visibility.manager }

    oro_email.listener.auto_response_listener:
        class: Oro\Bundle\EmailBundle\EventListener\AutoResponseListener
        arguments:
            - '@Psr\Container\ContainerInterface'
        tags:
            - { name: doctrine.event_listener, event: onFlush }
            - { name: doctrine.event_listener, event: postFlush }
            - { name: oro_featuretogle.feature, feature: email }
            - { name: container.service_subscriber }
            - { name: container.service_subscriber, id: oro_email.autoresponserule_manager }

    oro_email.async.auto_response:
        class: 'Oro\Bundle\EmailBundle\Async\AutoResponseMessageProcessor'
        arguments:
            - '@doctrine'
            - '@oro_email.autoresponserule_manager'
            - '@oro_message_queue.job.runner'
            - '@logger'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.async.auto_responses:
        class: 'Oro\Bundle\EmailBundle\Async\AutoResponsesMessageProcessor'
        arguments:
            - '@oro_message_queue.client.message_producer'
            - '@oro_message_queue.job.runner'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.async.add_email_associations:
        class: 'Oro\Bundle\EmailBundle\Async\AddEmailAssociationsMessageProcessor'
        arguments:
            - '@oro_message_queue.client.message_producer'
            - '@oro_message_queue.job.runner'
            - '@logger'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.async.add_email_association:
        class: 'Oro\Bundle\EmailBundle\Async\AddEmailAssociationMessageProcessor'
        arguments:
            - '@oro_email.async.manager.association_manager'
            - '@oro_message_queue.job.runner'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.async.update_email_associations:
        class: 'Oro\Bundle\EmailBundle\Async\UpdateEmailAssociationsMessageProcessor'
        arguments:
            - '@oro_email.async.manager.association_manager'
            - '@oro_message_queue.job.runner'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.async.update_email_owner_association:
        class: 'Oro\Bundle\EmailBundle\Async\UpdateEmailOwnerAssociationMessageProcessor'
        arguments:
            - '@oro_email.async.manager.association_manager'
            - '@oro_message_queue.job.runner'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.async.update_email_owner_associations:
        class: 'Oro\Bundle\EmailBundle\Async\UpdateEmailOwnerAssociationsMessageProcessor'
        arguments:
            - '@oro_message_queue.client.message_producer'
            - '@oro_message_queue.job.runner'
            - '@logger'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.async.sync_email_seen_flag:
        class: 'Oro\Bundle\EmailBundle\Async\SyncEmailSeenFlagMessageProcessor'
        arguments:
            - '@doctrine'
            - '@oro_email.email.flag.manager'
            - '@logger'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.async.purge_email_attachments:
        class: 'Oro\Bundle\EmailBundle\Async\PurgeEmailAttachmentsMessageProcessor'
        arguments:
            - '@doctrine'
            - '@oro_message_queue.client.message_producer'
            - '@oro_message_queue.job.runner'
            - '@oro_config.global'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.async.purge_email_attachments_by_ids:
        class: 'Oro\Bundle\EmailBundle\Async\PurgeEmailAttachmentsByIdsMessageProcessor'
        arguments:
            - '@doctrine'
            - '@oro_message_queue.job.runner'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.async.recalculate_email_visibility:
        class: Oro\Bundle\EmailBundle\Async\RecalculateEmailVisibilityProcessor
        arguments:
            - '@doctrine'
            - '@oro_message_queue.job.runner'
            - '@oro_message_queue.client.message_producer'
        tags:
            - { name: oro_message_queue.client.message_processor }

    oro_email.async.recalculate_email_visibility_chunk:
        class: Oro\Bundle\EmailBundle\Async\RecalculateEmailVisibilityChunkProcessor
        arguments:
            - '@doctrine'
            - '@oro_email.email_address_visibility.manager'
            - '@oro_activity_list.provider.chain'
            - '@oro_message_queue.job.runner'
        tags:
            - { name: oro_message_queue.client.message_processor }

    oro_email.async.update_visibilities:
        class: Oro\Bundle\EmailBundle\Async\UpdateVisibilitiesProcessor
        arguments:
            - '@doctrine'
            - '@oro_message_queue.client.message_producer'
            - '@oro_message_queue.job.runner'
        tags:
            - { name: oro_message_queue.client.message_processor }

    oro_email.async.update_visibilities_for_organization:
        class: Oro\Bundle\EmailBundle\Async\UpdateVisibilitiesForOrganizationProcessor
        arguments:
            - '@oro_email.email_address_visibility.manager'
            - '@oro_message_queue.client.message_producer'
            - '@oro_message_queue.job.runner'
        tags:
            - { name: oro_message_queue.client.message_processor }

    oro_email.async.update_email_visibilities_for_organization:
        class: Oro\Bundle\EmailBundle\Async\UpdateEmailVisibilitiesForOrganizationProcessor
        arguments:
            - '@doctrine'
            - '@oro_message_queue.client.message_producer'
            - '@oro_message_queue.job.runner'
        tags:
            - { name: oro_message_queue.client.message_processor }

    oro_email.async.update_email_visibilities_for_organization_chunk:
        class: Oro\Bundle\EmailBundle\Async\UpdateEmailVisibilitiesForOrganizationChunkProcessor
        arguments:
            - '@doctrine'
            - '@oro_email.email_address_visibility.manager'
            - '@oro_message_queue.job.runner'
        tags:
            - { name: oro_message_queue.client.message_processor }

    oro_email.manager.autoresponserule.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\EmailBundle\Entity\AutoResponseRule'
            - '@doctrine.orm.entity_manager'

    oro_email.autoresponserule_manager:
        class: Oro\Bundle\EmailBundle\Manager\AutoResponseManager
        arguments:
            - '@doctrine'
            - '@oro_email.email.model.builder'
            - '@oro_email.sender.email_model_sender'
            - '@oro_email.email_renderer'
            - '@logger'
            - '@translator'
            - '%oro_locale.language%'

    oro_email.manager.email.api:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\EmailBundle\Entity\Email'
            - '@doctrine.orm.entity_manager'
            - '@oro_email.datagrid_query_factory'

    oro_email.manager.email_origin.api:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailOriginApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\EmailBundle\Entity\EmailOrigin'
            - '@doctrine.orm.entity_manager'

    oro_email.sender.email_model_sender:
        class: Oro\Bundle\EmailBundle\Sender\EmailModelSender
        arguments:
            - '@mailer'
            - '@oro_email.embedded_images.handler.email_model'
            - '@oro_email.sender.email_factory'
            - '@oro_email.builder.email_user_from_email_model_builder'
            - '@event_dispatcher'
        calls:
            - [setEmailEntityListener, ['@oro_email.listener.entity_listener']]

    oro_email.builder.email_user_from_email_model_builder:
        class: Oro\Bundle\EmailBundle\Builder\EmailUserFromEmailModelBuilder
        shared: false
        arguments:
            - '@doctrine'
            - '@oro_email.email.entity.builder'
            - '@oro_email.tools.email_origin_helper'
            - '@oro_email.provider.parent_message_id'
            - '@oro_email.email.activity.manager'

    oro_email.sender.email_factory:
        class: Oro\Bundle\EmailBundle\Sender\EmailFactory
        arguments:
            - '@oro_email.provider.parent_message_id'
            - '@oro_email.email.address.helper'

    oro_email.embedded_images.extractor:
        class: Oro\Bundle\EmailBundle\EmbeddedImages\EmbeddedImagesExtractor
        arguments:
            - '@mime_types'

    oro_email.embedded_images.handler.email_model:
        class: Oro\Bundle\EmailBundle\EmbeddedImages\EmbeddedImagesInEmailModelHandler
        arguments:
            - '@oro_email.embedded_images.extractor'
            - '@oro_email.email.entity.builder'
            - '@oro_email.form.factory'

    oro_email.embedded_images.handler.symfony_email:
        class: Oro\Bundle\EmailBundle\EmbeddedImages\EmbeddedImagesInSymfonyEmailHandler
        arguments:
            - '@oro_email.embedded_images.extractor'

    oro_email.provider.parent_message_id:
        class: Oro\Bundle\EmailBundle\Provider\ParentMessageIdProvider
        arguments:
            - '@doctrine'

    oro_email.manager.emailtemplate.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\EmailBundle\Entity\EmailTemplate'
            - '@doctrine.orm.entity_manager'

    oro_email.cache:
          parent: oro.data.cache
          tags:
              - { name: 'cache.pool', namespace: 'oro_email' }

    oro_email.listener.config_listener:
        class: Oro\Bundle\EmailBundle\EventListener\EntityConfigListener
        arguments:
            - '@oro_email.email_renderer_configuration'
        tags:
            - { name: kernel.event_listener, event: oro.entity_config.pre_flush, method: preFlush }

    Oro\Bundle\EmailBundle\Provider\EmailRenderer:
        alias: oro_email.email_renderer

    oro_email.email_renderer:
        class: Oro\Bundle\EmailBundle\Provider\EmailRenderer
        public: true
        arguments:
            - '@oro_email.twig.email_environment'
            - '@oro_email.email_renderer_configuration'
            - '@oro_email.emailtemplate.variable_processor'
            - '@translator'
            - '@Doctrine\Inflector\Inflector'
            - '@oro_ui.html_tag_helper'
        calls:
            - [addSystemVariableDefaultFilter, ['userSignature', 'oro_html_sanitize']]
        lazy: true

    oro_email.email_renderer_configuration:
        class: Oro\Bundle\EntityBundle\Twig\Sandbox\TemplateRendererConfigProvider
        arguments:
            - '@oro_email.emailtemplate.variable_provider'
            - '@oro_email.cache'
            - 'oro_email.available_in_template_fields'

    oro_email.twig.email_security_policy:
        class: Twig\Sandbox\SecurityPolicy
        arguments:
            # tags
            - [ 'app', 'for', 'if', 'apply', 'set' ]
            # filters
            - [ 'default', 'date', 'escape', 'format', 'length', 'lower', 'nl2br', 'number_format', 'title', 'trim', 'upper', 'oro_html_sanitize', 'slice', 'spaceless' ]
            # methods
            - []
            # properties
            - []
            # functions
            - [ '_entity_var', 'date' ]

    oro_email.twig.email_sandbox:
        class: Twig\Extension\SandboxExtension
        arguments:
            - '@oro_email.twig.email_security_policy'
            - true # use sandbox globally in instance

    oro_email.twig.string_loader:
        class: Twig\Loader\ArrayLoader

    oro_email.twig.email_environment:
        class: Twig\Environment
        arguments:
            - '@oro_email.twig.string_loader'
            - { strict_variables: true }
        calls:
            - [addExtension, ['@oro_email.twig.email_sandbox']]

    oro_email.emailtemplate.variable_provider:
        class: Oro\Bundle\EntityBundle\Twig\Sandbox\VariablesProvider
        public: true
        arguments:
            # All arguments are set by Oro\Bundle\EmailBundle\DependencyInjection\Compiler\EmailTemplateVariablesPass
            - ~ # providers
            - [] # names of system variables providers
            - [] # names of entity variables providers

    Oro\Bundle\EntityBundle\Twig\Sandbox\VariablesProvider:
        alias: oro_email.emailtemplate.variable_provider

    oro_email.emailtemplate.variable_provider.entity:
        class: Oro\Bundle\EmailBundle\Provider\EntityVariablesProvider
        arguments:
            - '@translator'
            - '@oro_entity_config.config_manager'
            - '@doctrine'
            - '@oro_ui.formatter'
            - '@Doctrine\Inflector\Inflector'
        tags:
            - { name: oro_email.emailtemplate.variable_provider, scope: entity }

    oro_email.emailtemplate.variable_provider.entity_routes:
        class: Oro\Bundle\EmailBundle\Provider\EntityRouteVariablesProvider
        arguments:
            - '@translator'
            - '@oro_entity_config.config_manager'
            - '@oro_config.user'
        tags:
            - { name: oro_email.emailtemplate.variable_provider, scope: entity }

    oro_email.emailtemplate.variable_provider.system:
        class: Oro\Bundle\EmailBundle\Provider\SystemVariablesProvider
        arguments:
            - '@translator'
            - '@oro_config.user'
            - '@oro_locale.formatter.date_time'
        tags:
            - { name: oro_email.emailtemplate.variable_provider, scope: system }

    oro_email.emailtemplate.variable_provider.user:
        class: Oro\Bundle\EmailBundle\Provider\LoggedUserVariablesProvider
        arguments:
            - '@translator'
            - '@oro_security.token_accessor'
            - '@oro_entity.entity_name_resolver'
            - '@oro_config.user'
            - '@oro_ui.html_tag_helper'
        tags:
            - { name: oro_email.emailtemplate.variable_provider, scope: system }

    oro_email.validator.email_template_syntax:
        class: Oro\Bundle\EmailBundle\Validator\Constraints\EmailTemplateSyntaxValidator
        arguments:
            - '@oro_email.email_renderer'
            - '@oro_locale.manager.localization'
            - '@oro_entity_config.provider.entity'
            - '@translator'
        tags:
            - { name: validator.constraint_validator }

    oro_email.validator.email_address_validator:
        class: Oro\Bundle\EmailBundle\Validator\Constraints\EmailAddressValidator
        arguments:
            - '@oro_email.email.address.helper'
        tags:
            - { name: validator.constraint_validator }

    oro_email.validator.email_recipients:
        class: Oro\Bundle\EmailBundle\Validator\Constraints\EmailRecipientsValidator
        tags:
            - { name: validator.constraint_validator }

    oro_email.validator.mailbox_origin:
        class: Oro\Bundle\EmailBundle\Validator\Constraints\MailboxOriginValidator
        arguments:
            - '@translator'
        tags:
            - { name: validator.constraint_validator }

    oro_email.validator.not_empty_email_template_translation_subject:
        class: Oro\Bundle\EmailBundle\Validator\Constraints\NotEmptyEmailTemplateTranslationSubjectValidator
        tags:
            - { name: validator.constraint_validator }

    oro_email.datagrid_query_factory:
        class: Oro\Bundle\EmailBundle\Datagrid\EmailQueryFactory
        arguments:
            - '@oro_email.email.owner.provider.storage'
            - '@oro_entity.entity_name_resolver'
            - '@oro_email.mailbox.manager'
            - '@oro_security.token_accessor'
            - '@form.factory'
            - '@oro_filter.filter_utility'

    oro_email.emailtemplate.datagrid_view_list:
        class: Oro\Bundle\EmailBundle\Datagrid\EmailTemplatesViewList
        public: true
        arguments:
            - '@translator'

    oro_email.emailfolder.datagrid_view_list:
        class: Oro\Bundle\EmailBundle\Datagrid\EmailFolderViewList
        public: true
        arguments:
            - '@translator'
            - '@oro_email.mailbox_choice_list'

    oro_email.emailseen.datagrid_view_list:
        class: Oro\Bundle\EmailBundle\Datagrid\EmailSeenViewList
        public: true
        arguments:
            - '@translator'
            - '@oro_email.mailbox_choice_list'

    oro_email.emailtemplate.datagrid_helper:
        class: Oro\Bundle\EmailBundle\Datagrid\EmailTemplateGridHelper
        public: true
        arguments:
            - '@oro_entity.entity_provider'
            - '@translator'

    oro_email_filter.filter_origin_folder:
        class: Oro\Bundle\EmailBundle\Filter\ChoiceOriginFolderFilter
        arguments:
            - '@form.factory'
            - '@oro_filter.filter_utility'
        tags:
            - { name: oro_filter.extension.orm_filter.filter, type: multiselect-originfolder }

    oro_email_filter.filter_massage_type:
        class: Oro\Bundle\EmailBundle\Filter\ChoiceMessageTypeFilter
        arguments:
            - '@form.factory'
            - '@oro_filter.filter_utility'
            - '@oro_email.email.owner.provider.storage'
        tags:
            - { name: oro_filter.extension.orm_filter.filter, type: multiselect-messagetype }

    oro_email_filter.filter_email_string:
        class: Oro\Bundle\EmailBundle\Filter\EmailStringFilter
        arguments:
            - '@form.factory'
            - '@oro_filter.filter_utility'
            - '@oro_email.email.owner.provider.storage'
        tags:
            - { name: oro_filter.extension.orm_filter.filter, type: email-string }

    oro_email.workflow.action.send_email:
        class: Oro\Bundle\EmailBundle\Workflow\Action\SendEmail
        arguments:
            - '@oro_action.expression.context_accessor'
            - '@validator'
            - '@oro_email.email.address.helper'
            - '@oro_entity.entity_name_resolver'
            - '@oro_email.sender.email_model_sender'
            - '@oro_email.tools.email_origin_helper'
        calls:
            - [setLogger, ['@logger']]
        tags:
            - { name: oro_action.action, alias: send_email }

    oro_email.workflow.action.send_email_template:
        class: Oro\Bundle\EmailBundle\Workflow\Action\SendEmailTemplate
        arguments:
            - '@oro_action.expression.context_accessor'
            - '@validator'
            - '@oro_email.email.address.helper'
            - '@oro_entity.entity_name_resolver'
            - '@oro_email.sender.aggregated_email_templates'
        calls:
            - [setLogger, ['@logger']]
        tags:
            - { name: oro_action.action, alias: send_email_template }

    oro_email.workflow.action.schedule_send_email_template:
        class: Oro\Bundle\EmailBundle\Workflow\Action\ScheduleSendEmailTemplate
        arguments:
            - '@oro_action.expression.context_accessor'
            - '@validator'
            - '@oro_email.email.address.helper'
            - '@oro_entity.entity_name_resolver'
            - '@oro_entity.doctrine_helper'
            - '@oro_message_queue.client.message_producer'
        calls:
            - [setLogger, ['@logger']]
        tags:
            - { name: oro_action.action, alias: schedule_send_email_template }

    oro_email.helper.datagrid.emails:
        class: Oro\Bundle\EmailBundle\Datagrid\EmailGridHelper
        public: true
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_email.email_synchronization_manager'
            - '@oro_activity.manager'
            - 'Oro\Bundle\UserBundle\Entity\User'

    Oro\Bundle\EmailBundle\Datagrid\EmailGridHelper:
        alias: 'oro_email.helper.datagrid.emails'

    oro_email.email_grid_result_helper:
        class: Oro\Bundle\EmailBundle\Datagrid\EmailGridResultHelper
        arguments:
            - '@doctrine'
            - '@oro_email.email.owner.provider.storage'
            - '@oro_email.email_grid_mailbox_name_helper'
            - '@oro_email.email.address.manager'

    oro_email.email_grid_mailbox_name_helper:
        class: Oro\Bundle\EmailBundle\Datagrid\MailboxNameHelper
        arguments:
            - '@translator'

    oro_email.listener.datagrid.email:
        class: Oro\Bundle\EmailBundle\EventListener\Datagrid\EmailGridListener
        arguments:
            - '@oro_email.datagrid_query_factory'
            - '@oro_filter.provider.state.filters'
            - '@oro_config.manager'
            - '@oro_email.email_grid_result_helper'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.after.base-email-grid, method: onBuildAfter }
            - { name: kernel.event_listener, event: oro_datagrid.orm_datasource.result.before_query.base-email-grid, method: onResultBeforeQuery, priority: -255 }
            - { name: kernel.event_listener, event: oro_datagrid.orm_datasource.result.after.base-email-grid, method: onResultAfter }

    oro_email.listener.datagrid.activity:
        class: Oro\Bundle\EmailBundle\EventListener\Datagrid\ActivityGridListener
        arguments:
            - '@oro_email.helper.datagrid.emails'
            - '@oro_entity.routing_helper'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.after.activity-email-grid, method: onBuildAfter }

    oro_email.listener.datagrid.recent_emails:
        class: Oro\Bundle\EmailBundle\EventListener\Datagrid\RecentEmailGridListener
        arguments:
            - '@oro_email.helper.datagrid.emails'
            - '@oro_email.datagrid_query_factory'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.after.dashboard-recent-emails-grid, method: onBuildAfter }

    oro_email.listener.datagrid.recent_emails.incoming:
        class: Oro\Bundle\EmailBundle\EventListener\Datagrid\IncomingEmailGridListener
        arguments:
            - '@oro_email.datagrid_query_factory'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.after.dashboard-recent-emails-inbox-grid, method: onBuildAfter }
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.after.dashboard-recent-emails-new-grid, method: onBuildAfter }

    oro_email.listener.datagrid.recent_emails.outgoing:
        class: Oro\Bundle\EmailBundle\EventListener\Datagrid\OutgoingEmailGridListener
        arguments:
            - '@oro_email.email_grid_result_helper'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.orm_datasource.result.after.dashboard-recent-emails-sent-grid, method: onResultAfter }

    oro_email.email_synchronization_manager:
        class: Oro\Bundle\EmailBundle\Sync\EmailSynchronizationManager
        public: true
        arguments:
            - '@service_container'

    Oro\Bundle\EmailBundle\Sync\EmailSynchronizationManager:
        alias: 'oro_email.email_synchronization_manager'

    oro_email.known_email_address_checker_factory:
        class: Oro\Bundle\EmailBundle\Sync\KnownEmailAddressCheckerFactory
        shared: false
        arguments:
            - '@doctrine'
            - '@oro_email.email.address.manager'
            - '@oro_email.email.address.helper'
            - '@oro_email.email.owner.provider.storage'
            - '%oro_email.email_sync_exclusions%'

    oro_email.public_email_owner_provider:
        class: Oro\Bundle\EmailBundle\Entity\Provider\PublicEmailOwnerProvider
        arguments:
            - '%oro_email.public_email_owners%'

    oro_email.email_address_visibility.manager:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailAddressVisibilityManager
        arguments:
            - '@oro_email.email.owner.provider'
            - '@doctrine'
            - '@oro_message_queue.client.message_producer'
            - '@oro_email.public_email_owner_provider'

    oro_email.email.activity.manager:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailActivityManager
        arguments:
            - '@oro_activity.manager'
            - '@oro_email.activity_list.provider'
            - '@oro_email.email.thread.provider'
            - '@security.token_storage'
            - '@oro_security.owner.entity_owner_accessor.link'
            - "@=service('doctrine').getManagerForClass('OroEmailBundle:Email')"

    oro_email.email.thread.provider:
        class: Oro\Bundle\EmailBundle\Entity\Provider\EmailThreadProvider
        public: true

    Oro\Bundle\EmailBundle\Entity\Provider\EmailThreadProvider:
        alias: 'oro_email.email.thread.provider'

    oro_email.email.thread.manager:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailThreadManager
        arguments:
            - '@oro_email.email.thread.provider'
            - "@=service('doctrine').getManagerForClass('OroEmailBundle:EmailThread')"

    oro_email.email.manager:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailManager
        public: true
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@oro_email.email.thread.manager'
            - '@oro_email.email.thread.provider'
            - '@oro_security.token_accessor'
            - '@oro_email.mailbox.manager'

    Oro\Bundle\EmailBundle\Entity\Manager\EmailManager:
        alias: 'oro_email.email.manager'

    oro_email.twig.extension.email:
        class: Oro\Bundle\EmailBundle\Twig\EmailExtension
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_email.listener.search_listener:
          class: Oro\Bundle\EmailBundle\EventListener\SearchListener
          tags:
              - { name: kernel.event_listener, event: oro_search.prepare_entity_map, method: prepareEntityMapEvent, priority: 10 }

    oro_email.activity_list.provider:
        class: Oro\Bundle\EmailBundle\Provider\EmailActivityListProvider
        arguments:
           - '@oro_entity.doctrine_helper'
           - '@oro_entity.entity_name_resolver'
           - '@router'
           - '@oro_entity_config.config_manager'
           - '@oro_email.email.thread.provider'
           - '@oro_ui.html_tag_helper'
           - '@security.authorization_checker'
           - '@oro_security.token_accessor'
           - '@oro_email.mailbox.process_storage'
           - '@oro_activity.association_helper'
           - '@oro_comment.association_helper'
        tags:
           - { name: oro_activity_list.provider, class: Oro\Bundle\EmailBundle\Entity\Email, acl_class: Oro\Bundle\EmailBundle\Entity\EmailUser, priority: 30 }
           - { name: oro_featuretogle.feature, feature: email }

    oro_email.related_emails.provider:
        class: Oro\Bundle\EmailBundle\Provider\RelatedEmailsProvider
        arguments:
            - '@security.authorization_checker'
            - '@oro_security.token_accessor'
            - '@oro_email.provider.email_recipients.helper'
            - '@oro_entity.entity_field_provider'
            - '@oro_email.email_attribute.provider'

    oro_email.email_attribute.provider:
        class: Oro\Bundle\EmailBundle\Provider\EmailAttributeProvider
        arguments:
            - '@doctrine'
            - '@oro_entity_config.config_manager'
            - '@oro_locale.formatter.name'
            - '@oro_email.email.address.helper'

    oro_email.email_recipients.provider:
        class: Oro\Bundle\EmailBundle\Provider\EmailRecipientsProvider
        public: true
        arguments:
            - '@translator'
            - '@oro_email.provider.email_recipients.helper'

    Oro\Bundle\EmailBundle\Provider\EmailRecipientsProvider:
        alias: 'oro_email.email_recipients.provider'

    oro_email.recent_email_recipients.provider:
        class: Oro\Bundle\EmailBundle\Provider\RecentEmailRecipientsProvider
        arguments:
            - '@oro_security.token_accessor'
            - '@oro_email.related_emails.provider'
            - '@oro_security.acl_helper'
            - '@doctrine'
            - '@oro_email.email.owner.provider'
            - '@oro_email.provider.email_recipients.helper'
        tags:
            - { name: oro_email.recipients_provider }

    oro_email.context_email_recipients.provider:
        class: Oro\Bundle\EmailBundle\Provider\ContextEmailRecipientsProvider
        arguments:
            - '@oro_email.related_emails.provider'
        tags:
            - { name: oro_email.recipients_provider, priority: 10 }

    oro_email.provider.emailowners.provider:
        class: Oro\Bundle\EmailBundle\Provider\EmailOwnersProvider
        arguments:
            - '@oro_activity_list.provider.chain'
            - '@oro_email.email.owner.provider.storage'
            - '@doctrine'

    oro_email.provider.email_recipients.helper:
        class: Oro\Bundle\EmailBundle\Provider\EmailRecipientsHelper
        public: true
        arguments:
            - '@oro_security.acl_helper'
            - '@oro_locale.dql.formatter.name'
            - '@oro_locale.formatter.name'
            - '@oro_entity_config.config_manager'
            - '@translator'
            - '@oro_email.email.owner.provider'
            - '@doctrine'
            - '@oro_email.email.address.helper'
            - '@oro_search.index'
            - '@property_accessor'

    Oro\Bundle\EmailBundle\Provider\EmailRecipientsHelper:
        alias: 'oro_email.provider.email_recipients.helper'

    oro_email.manager.email_attachment_manager:
        class: Oro\Bundle\EmailBundle\Manager\EmailAttachmentManager
        public: true
        arguments:
            - '@oro_attachment.file_manager'
            - '@doctrine'
            - '@router'
            - '@oro_attachment.validator.file_config_validator'
            - '@oro_attachment.association_helper'

    Oro\Bundle\EmailBundle\Manager\EmailAttachmentManager:
        alias: 'oro_email.manager.email_attachment_manager'

    oro_email.listener.email_body_add_listener:
        class: Oro\Bundle\EmailBundle\EventListener\EmailBodyAddListener
        arguments:
            - '@oro_email.manager.email_attachment_manager'
            - '@oro_entity_config.provider.attachment'
            - '@oro_email.activity_list.provider'
            - '@security.authorization_checker'
            - '@security.token_storage'
            - '@oro_activity_list.provider.chain'
            - '@doctrine.orm.entity_manager'
        tags:
            - { name: kernel.event_listener, event: oro_email.email_body_added, method: linkToScope, priority: 10 }
            - { name: kernel.event_listener, event: oro_email.email_body_added, method: updateActivityDescription, priority: 20 }

    oro_email.listener.replace_embedded_attachments_listener:
        class: Oro\Bundle\EmailBundle\EventListener\ReplaceEmbeddedAttachmentsListener
        tags:
            - { name: kernel.event_listener, event: oro_email.email_body_loaded, method: replace }

    oro_email.provider.email_attachment_provider:
        class: Oro\Bundle\EmailBundle\Provider\EmailAttachmentProvider
        arguments:
            - '@oro_email.email.thread.provider'
            - '@doctrine'
            - '@oro_attachment.provider.attachment'
            - '@oro_email.email_attachment_transformer'

    oro_email.email_attachment_transformer:
        class: Oro\Bundle\EmailBundle\Tools\EmailAttachmentTransformer
        arguments:
            - '@oro_email.form.factory'
            - '@oro_attachment.file_manager'
            - '@oro_attachment.manager'
            - '@oro_email.manager.email_attachment_manager'

    oro_email.email_importance_transformer:
        class: Oro\Bundle\EmailBundle\Form\DataTransformer\EmailImportanceApiTransformer
        public: true

    oro_email.email_body_type_transformer:
        class: Oro\Bundle\EmailBundle\Form\DataTransformer\EmailBodyTypeApiTransformer
        public: true

    oro_email.acl.voter.email_voter:
        class: Oro\Bundle\EmailBundle\Acl\Voter\EmailVoter
        arguments:
            - '@security.authorization_checker'
            - '@Psr\Container\ContainerInterface'
        tags:
            - { name: security.voter }
            - { name: container.service_subscriber, id: oro_email.mailbox.manager }

    oro_email.acl.voter.acl_voter:
        class: Oro\Bundle\EmailBundle\Acl\Voter\AclVoter
        decorates: oro_security.acl.voter.basic_permissions
        arguments:
            - '@.inner'

    oro_email.acl.access_rule.email_user:
        class: Oro\Bundle\EmailBundle\Acl\AccessRule\EmailUserAccessRule
        public: false
        arguments:
            - '@oro_security.orm.ownership_sql_walker_builder'
        tags:
            - { name: oro_security.access_rule, entityClass: Oro\Bundle\EmailBundle\Entity\EmailUser, permission: VIEW }

    oro_email.acl.search.acl_helper_condition:
        class: Oro\Bundle\EmailBundle\Acl\Search\SearchAclHelperCondition
        arguments:
            - '@oro_security.orm.ownership_sql_walker_builder'
        tags:
            - { name: oro_security.acl_helper.condition }

    oro_email.entity_alias_provider:
        class: Oro\Bundle\EmailBundle\Provider\EmailEntityAliasProvider
        arguments:
            - '@oro_email.email.address.manager'
        tags:
            - { name: oro_entity.alias_provider }

    oro_email.manager.email_activity.api:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailActivityApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\EmailBundle\Entity\Email'
            - '@doctrine.orm.entity_manager'
            - '@oro_activity.manager'
            - '@security.token_storage'

    oro_email.manager.email_activity_entity.api:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailActivityEntityApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\EmailBundle\Entity\Email'
            - '@doctrine.orm.entity_manager'
            - '@oro_activity.manager'
            - '@security.token_storage'

    oro_email.manager.email_activity_search.api:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailActivitySearchApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\EmailBundle\Entity\Email'
            - '@doctrine.orm.entity_manager'
            - '@oro_activity.manager'
            - '@oro_search.index'
            - '@oro_entity.entity_name_resolver'

    oro_email.manager.email_thread_activity_context.api:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailThreadActivityContextApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@oro_entity_config.config_manager'
            - '@router'
            - '@oro_entity.entity_alias_resolver'
            - '@oro_entity.entity_name_resolver'
            - '@oro_featuretoggle.checker.feature_checker'
            - '@security.authorization_checker'
            - '@oro_activity.manager'

    oro_email.manager.email_activity_suggestion.api:
        class: Oro\Bundle\EmailBundle\Entity\Manager\EmailActivitySuggestionApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\EmailBundle\Entity\Email'
            - '@doctrine.orm.entity_manager'
            - '@oro_activity.manager'
            - '@oro_search.index'
            - '@oro_entity.entity_name_resolver'
        calls:
            - [setTokenStorage, ['@security.token_storage']]

    oro_email.email.flag.manager:
        class: Oro\Bundle\EmailBundle\Manager\EmailFlagManager
        arguments:
            - '@oro_email.email_flag_manager_loader_selector'
            - '@doctrine.orm.entity_manager'
        calls:
            - [setLogger, ['@logger']]

    oro_email.internal_email.flag_manager_loader:
        class: Oro\Bundle\EmailBundle\Provider\InternalEmailFlagManagerLoader
        tags:
            - { name: oro_email.email_flag_manager_loader }

    oro_email.manager.notification:
        class: Oro\Bundle\EmailBundle\Manager\EmailNotificationManager
        public: true
        arguments:
            - '@doctrine'
            - '@oro_ui.html_tag_helper'
            - '@router'
            - '@oro_entity_config.config_manager'
            - '@oro_security.acl_helper'

    Oro\Bundle\EmailBundle\Manager\EmailNotificationManager:
        alias: 'oro_email.manager.notification'
        public: true

    Oro\Bundle\EmailBundle\Datagrid\OriginFolderFilterProvider:
        alias: oro_email.datagrid.origin_folder.provider

    oro_email.datagrid.origin_folder.provider:
        class: Oro\Bundle\EmailBundle\Datagrid\OriginFolderFilterProvider
        public: true
        arguments:
            - '@doctrine'
            - '@oro_security.token_accessor'
            - '@oro_email.email_grid_mailbox_name_helper'

    oro_email.mailbox.process_storage:
        class: Oro\Bundle\EmailBundle\Mailbox\MailboxProcessStorage
        arguments:
            - '@oro_featuretoggle.checker.feature_checker'

    oro_email.mailbox_email_owner_provider:
        class: Oro\Bundle\EmailBundle\Entity\Provider\MailboxEmailOwnerProvider
        tags:
            - { name: oro_email.owner.provider, order: 2 }

    oro_email.mailbox_choice_list:
        class: Oro\Bundle\EmailBundle\Datagrid\MailboxChoiceList
        public: true
        arguments:
            - '@oro_security.token_accessor'
            - '@oro_email.mailbox.manager'
            - '@oro_email.email_grid_mailbox_name_helper'

    oro_email.mailbox.manager.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\EmailBundle\Entity\Mailbox'
            - '@doctrine.orm.entity_manager'

    oro_email.mailbox.entity_name_provider:
        class: Oro\Bundle\EmailBundle\Provider\MailboxEntityNameProvider
        arguments:
            - '@translator'
        tags:
            - { name: oro_entity.name_provider, priority: 100}

    oro_email.email_user.provider.email_user_entity_name_provider:
        class: Oro\Bundle\EmailBundle\Provider\EmailUserEntityNameProvider
        tags:
            - { name: oro_entity.name_provider, priority: 100 }

    oro_email.email_body_entity_name_provider:
        class: Oro\Bundle\EmailBundle\Provider\EmailBodyEntityNameProvider
        tags:
            - { name: oro_entity.name_provider, priority: 100 }

    oro_email.listener.mailbox_process_trigger_listener:
        class: Oro\Bundle\EmailBundle\EventListener\MailboxProcessTriggerListener
        arguments:
            - '@Psr\Container\ContainerInterface'
        tags:
            - { name: doctrine.event_listener, event: onFlush }
            - { name: doctrine.event_listener, event: postFlush }
            - { name: oro_featuretogle.feature, feature: email }
            - { name: container.service_subscriber }
            - { name: container.service_subscriber, id: oro_email.mailbox.process_storage }
            - { name: container.service_subscriber, id: oro_workflow.process.process_handler }

    oro_email.autocomplete.mailbox_user_search_handler:
        class: Oro\Bundle\EmailBundle\Autocomplete\MailboxUserSearchHandler
        public: true
        parent: oro_user.autocomplete.user.organization_search_handler

    oro_email.listener.mailbox.authorization:
        class: Oro\Bundle\EmailBundle\EventListener\MailboxAuthorizationListener
        arguments:
            - '@doctrine'
            - '@security.authorization_checker'
            - '@oro_security.token_accessor'
        tags:
            - { name: kernel.event_listener, event: kernel.controller, method: onKernelController }

    oro_email.listener.datagrid.mailbox_grid:
        class: Oro\Bundle\EmailBundle\EventListener\Datagrid\MailboxGridListener
        arguments:
            - '@doctrine'
            - '@oro_security.acl_helper'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.pre.base-mailboxes-grid, method: onPreBuild }
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.after.base-mailboxes-grid, method: onBuildAfter }
            - { name: oro_featuretogle.feature, feature: email }

    oro_email.mailbox.manager:
        class: Oro\Bundle\EmailBundle\Entity\Manager\MailboxManager
        public: true
        arguments:
            - '@doctrine'

    Oro\Bundle\EmailBundle\Entity\Manager\MailboxManager:
        alias: 'oro_email.mailbox.manager'

    oro_email.workflow.condition.instanceof:
        class: Oro\Bundle\EmailBundle\Model\Condition\IsInstanceOf
        tags:
            - { name: oro_action.condition, alias: instanceof }

    oro_email.workflow.condition.has_count:
        class: Oro\Bundle\EmailBundle\Model\Condition\HasCount
        tags:
            - { name: oro_action.condition, alias: has_count }

    oro_email.workflow.action.parse_first_name:
        class: Oro\Bundle\EmailBundle\Model\Action\ParseFirstNameFromEmailAddress
        arguments:
            - '@oro_action.expression.context_accessor'
            - '@oro_email.email.address.helper'
        tags:
            - { name: oro_action.action, alias: parse_first_name_from_email_address }

    oro_email.workflow.action.parse_last_name:
        class: Oro\Bundle\EmailBundle\Model\Action\ParseLastNameFromEmailAddress
        arguments:
            - '@oro_action.expression.context_accessor'
            - '@oro_email.email.address.helper'
        tags:
            - { name: oro_action.action, alias: parse_last_name_from_email_address }

    oro_email.workflow.action.request_mailboxes:
        class: Oro\Bundle\EmailBundle\Model\Action\RequestMailboxes
        arguments:
            - '@oro_action.expression.context_accessor'
            - '@doctrine'
            - '@oro_email.mailbox.process_storage'
        tags:
            - { name: oro_action.action, alias: request_mailboxes|find_mailboxes }

    oro_email.workflow.action.strip_html_tags:
        class: Oro\Bundle\EmailBundle\Model\Action\StripHtmlTags
        arguments:
            - '@oro_action.expression.context_accessor'
            - '@oro_ui.html_tag_helper'
        tags:
            - { name: oro_action.action, alias: strip_html_tags }

    oro_email.workflow.action.add_activity_target:
        class: Oro\Bundle\EmailBundle\Model\Action\AddActivityTarget
        arguments:
            - '@oro_action.expression.context_accessor'
            - '@oro_email.email.activity.manager'
            - '@oro_activity_list.provider.chain'
            - '@doctrine.orm.entity_manager'
        tags:
            - { name: oro_action.action, alias: add_email_activity_target }

    oro_email.placeholder.send_email.filter:
        class: Oro\Bundle\EmailBundle\Placeholder\SendEmailPlaceholderFilter
        public: true
        arguments:
            - '@oro_activity.manager'

    oro_email.tools.email_origin_helper:
        class: Oro\Bundle\EmailBundle\Tools\EmailOriginHelper
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_security.token_accessor'
            - '@oro_email.email.owner.provider'
            - '@oro_email.email.address.helper'

    oro_email.listener.search_aliases_listener:
        class: Oro\Bundle\EmailBundle\EventListener\SearchAliasesListener
        tags:
            - { name: kernel.event_listener, event: oro_activity.search_aliases, method: addEmailAliasEvent }

    oro_email.listener.prepare_result_item_listener:
        class: Oro\Bundle\EmailBundle\EventListener\PrepareResultItemListener
        arguments:
            - '@router'
            - '@doctrine'
        tags:
            - { name: kernel.event_listener, event: oro_search.prepare_result_item, method: prepareResultItem }

    oro_email.listener.prepare_context_title_listener:
        class: Oro\Bundle\EmailBundle\EventListener\PrepareContextTitleListener
        arguments:
            - '@router'
            - '@doctrine'
        tags:
            - { name: kernel.event_listener, event: oro_activity.context_title, method: prepareContextTitle }

    oro_email.listener.activity_list_pre_query_build_listener:
        class: Oro\Bundle\EmailBundle\EventListener\ActivityListPreQueryBuildListener
        arguments:
            - '@oro_entity.doctrine_helper'
        tags:
            - { name: kernel.event_listener, event: oro_activity_list.activity_list_pre_query_build, method: prepareIdsForEmailThreadEvent }
            - { name: oro_featuretogle.feature, feature: email }

    oro_email.email_body_synchronizer:
        class: Oro\Bundle\EmailBundle\Sync\EmailBodySynchronizer
        arguments:
            - '@oro_email.email_body_loader_selector'
            - '@doctrine'
            - '@event_dispatcher'
            - '@oro_email.email_notification_alert_manager'
        calls:
            - [setLogger, ['@logger']]

    oro_email.model.email_activity_updates:
        class: Oro\Bundle\EmailBundle\Model\EmailActivityUpdates
        arguments:
            - '@oro_email.provider.emailowners.provider'

    oro_email.async.manager.association_manager:
        class: Oro\Bundle\EmailBundle\Async\Manager\AssociationManager
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_email.email.activity.manager'
            - '@oro_email.provider.emailowners.provider'
            - '@oro_email.email.manager'
            - '@oro_message_queue.client.message_producer'

    oro_email.async.upgrade_email_body_processor:
        class: Oro\Bundle\EmailBundle\Migrations\Schema\v1_29\UpgradeEmailBodyMessageProcessor
        arguments:
            - '@oro_message_queue.message_producer'
            - '@oro_entity.orm.native_query_executor_helper'
            - '@logger'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.provider.smtp_settings:
        class: Oro\Bundle\EmailBundle\Provider\SmtpSettingsProvider
        arguments:
            - '@oro_config.manager'
            - '@oro_security.encoder.default'
            - '@oro_distribution.handler.application_status'

    Oro\Bundle\EmailBundle\Provider\SmtpSettingsProvider:
        alias: oro_email.provider.smtp_settings

    oro_email.listener.datagrid.user_email_grid_listener:
        class: Oro\Bundle\EmailBundle\EventListener\Datagrid\UserEmailGridListener
        arguments:
            - '@oro_email.datagrid_query_factory'
        tags:
          - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.after.user-email-grid, method: onBuildAfter }
          - { name: oro_featuretogle.feature, feature: email }

    oro_email.emailtemplate.variable_processor:
        class: Oro\Bundle\EntityBundle\Twig\Sandbox\VariableProcessorRegistry
        arguments:
            - ~ # service locator

    oro_email.emailtemplate.variable_processor.entity_routes:
        class: Oro\Bundle\EmailBundle\Processor\EntityRouteVariableProcessor
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_email.provider.url_provider'
            - '@logger'
        tags:
            - { name: oro_email.emailtemplate.variable_processor, alias: entity_routes }

    oro_email.migration.demo_data_fixtures_listener.email_associations:
        parent: oro_platform.event_listener.demo_data_fixtures_listener.abstract
        class: Oro\Bundle\EmailBundle\EventListener\EmailAssociationsDemoDataFixturesListener
        arguments:
            - '@oro_email.async.manager.association_manager'
            - '@doctrine'
            - '@oro_email.email_address_visibility.manager'
        calls:
            # this listener is disabled to prevent a lot of UpdateEmailAssociations messages
            - [disableListener, ['oro_email.listener.entity_listener']]
        tags:
            - { name: kernel.event_listener, event: oro_migration.data_fixtures.pre_load, method: onPreLoad }
            - { name: kernel.event_listener, event: oro_migration.data_fixtures.post_load, method: onPostLoad }

    oro_email.topic.event:
        class: Oro\Bundle\SyncBundle\Topic\SecuredTopic
        arguments:
            - 'oro_email.event'
            - '@gos_web_socket.client.manipulator'
        tags:
            - { name: gos_web_socket.topic }

    oro_email.acl.voter.email_template_voter:
        class: Oro\Bundle\EmailBundle\Acl\Voter\EmailTemplateVoter
        arguments:
            - '@oro_entity.doctrine_helper'
        calls:
            - [setClassName, ['Oro\Bundle\EmailBundle\Entity\EmailTemplate']]
        tags:
            - { name: security.voter }

    oro_email.manager.template_email:
        class: Oro\Bundle\EmailBundle\Manager\EmailTemplateManager
        public: true
        arguments:
            - '@mailer'
            - '@oro_email.embedded_images.handler.symfony_email'
            - '@oro_email.provider.localized_template'
        calls:
            - [setLogger, ['@logger']]

    oro_email.entity_name_provider:
        class: 'Oro\Bundle\EmailBundle\Provider\EmailEntityNameProvider'
        arguments:
            - '@property_accessor'
        tags:
            - { name: oro_entity.name_provider, priority: -80 }

    oro_email.provider.localized_template:
        class: 'Oro\Bundle\EmailBundle\Provider\LocalizedTemplateProvider'
        arguments:
            - '@oro_locale.provider.preferred_localization_provider'
            - '@oro_email.provider.email_template_content_provider'

    Oro\Bundle\EmailBundle\Provider\EmailTemplateContentProvider:
        alias: oro_email.provider.email_template_content_provider

    oro_email.provider.email_template_content_provider:
        class: 'Oro\Bundle\EmailBundle\Provider\EmailTemplateContentProvider'
        public: true
        arguments:
            - '@doctrine'
            - '@oro_email.email_renderer'
            - '@property_accessor'
            - '@logger'
            - '@stof_doctrine_extensions.listener.translatable'
            - '@translator'

    oro_email.provider.url_provider:
        class: 'Oro\Bundle\EmailBundle\Provider\UrlProvider'
        arguments:
            - '@oro_config.manager'
            - '@router'

    oro_email.form.handler.user_email_config:
         class: 'Oro\Bundle\EmailBundle\Form\Handler\UserEmailConfigHandler'
         public: true
         arguments:
             - '@doctrine.orm.entity_manager'

    oro_email.validator.connection_configuration.smtp:
        class: Oro\Bundle\EmailBundle\Validator\Constraints\SmtpConnectionConfigurationValidator
        arguments:
            - '@oro_email.mailer.checker.smtp_settings'
            - '@oro_email.smtp_settings_factory'
            - '@oro_security.encoder.default'
        tags:
            - { name: validator.constraint_validator }

    oro_email.smtp_settings_factory:
        class: 'Oro\Bundle\EmailBundle\Form\Model\SmtpSettingsFactory'
        arguments:
            - '@oro_security.encoder.default'

    oro_email.sender.aggregated_email_templates:
        class: 'Oro\Bundle\EmailBundle\Tools\AggregatedEmailTemplatesSender'
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_email.provider.localized_template'
            - '@oro_email.tools.email_origin_helper'
            - '@oro_email.sender.email_model_sender'
            - '@oro_security.owner.entity_owner_accessor'
        calls:
            - [setLogger, ['@logger']]

    oro_email.async.send_email_template:
        class: 'Oro\Bundle\EmailBundle\Async\SendEmailTemplateProcessor'
        arguments:
            - '@doctrine'
            - '@oro_email.sender.aggregated_email_templates'
        calls:
            - [setLogger, ['@logger']]
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_email.email_notification_alert_manager:
        class: Oro\Bundle\EmailBundle\Sync\NotificationAlertManager
        public: true
        arguments:
            - 'EmailSync'
            - 'email'
            - '@doctrine'
            - '@oro_security.token_accessor'
            - '@logger'

    oro_email.event_listener.notification_alerts_listener:
        class: Oro\Bundle\EmailBundle\EventListener\NotificationAlertsListener
        arguments:
            - '@router'
            - '@session'
            - '@translator'
            - '@oro_email.email_notification_alert_manager'
            - '@oro_email.mailbox.manager'
            - '@oro_security.token_accessor'
        tags:
            - { name: kernel.event_listener, event: kernel.request, method: onRequest }

    Oro\Bundle\EmailBundle\EntityConfig\EmailFieldConfiguration:
        tags:
            - oro_entity_config.validation.entity_config

    Oro\Bundle\EmailBundle\EntityConfig\AttachmentEntityConfiguration:
        tags:
            - oro_entity_config.validation.entity_config

    oro_email.listener.update_visibility_for_new_email_user:
        class: Oro\Bundle\EmailBundle\EventListener\UpdateVisibilityForNewEmailUserListener
        arguments:
            - '@oro_email.email_address_visibility.manager'
        tags:
            - { name: kernel.event_listener, event: oro_email.email_user_added, method: onEmailUserAdded }

    oro_email.virtual_relation_provider.email_user:
        class: Oro\Bundle\EmailBundle\Provider\EmailUserVirtualRelationsProvider
        arguments:
            - '@oro_entity_extend.association_manager'
            - '@oro_entity_config.provider.entity'
        tags:
            - { name: oro_entity.virtual_relation_provider, priority: -150 }

    oro_email.email_template_entity_provider:
        class: Oro\Bundle\EmailBundle\Provider\EmailTemplateEntityProvider
        parent: oro_entity.entity_provider.abstract
        lazy: true

    oro_email.twig.email_security_policy_decorator:
        decorates: oro_email.twig.email_security_policy
        class: Oro\Bundle\EmailBundle\Twig\EmailSecurityPolicyDecorator
        arguments:
            - '@.inner'

    oro_email.event_listener.default_email_user_owner:
        class: Oro\Bundle\EmailBundle\EventListener\DefaultEmailUserOwnerListener
        arguments:
            - '@oro_user.provider.default_user'
        tags:
            - { name: doctrine.event_listener, event: prePersist, priority: -5 }

    oro_email.event_listener.system_config.default_email_user_owner:
        class: Oro\Bundle\UserBundle\EventListener\DefaultUserSystemConfigListener
        arguments:
            - '@oro_user.provider.default_user'
            - '@doctrine'
            - 'oro_email.default_email_owner'
        tags:
            - { name: kernel.event_listener, event: oro_config.settings_form_preset, method: onFormPreSetData }
            - { name: kernel.event_listener, event: oro_config.settings_before_save, method: onSettingsSaveBefore }
