<commit_before><?php

namespace Oro\Bundle\EmailBundle\Mailer;

use Doctrine\ORM\EntityManager;

use Oro\Bundle\EmailBundle\Entity\EmailOrigin;
use Oro\Bundle\EmailBundle\Form\Model\Email;
use Oro\Bundle\EmailBundle\Builder\EmailEntityBuilder;
use Oro\Bundle\EmailBundle\Entity\Util\EmailUtil;
use Oro\Bundle\EmailBundle\Entity\EmailFolder;
use Oro\Bundle\EmailBundle\Entity\InternalEmailOrigin;
use Oro\Bundle\EmailBundle\Entity\Provider\EmailOwnerProvider;
use Oro\Bundle\UserBundle\Entity\User;

class Processor
{
    /** @var EntityManager */
    protected $em;

    /** @var EmailEntityBuilder */
    protected $emailEntityBuilder;

    /** @var \Swift_Mailer */
    protected $mailer;

    /** @var  EmailOwnerProvider */
    protected $emailOwnerProvider;

    /**
     * @param EntityManager      $em
     * @param EmailEntityBuilder $emailEntityBuilder
     * @param \Swift_Mailer      $mailer
     * @param EmailOwnerProvider $emailOwnerProvider
     */
    public function __construct(
        EntityManager $em,
        EmailEntityBuilder $emailEntityBuilder,
        \Swift_Mailer $mailer,
        EmailOwnerProvider $emailOwnerProvider
    ) {
        $this->em                 = $em;
        $this->emailEntityBuilder = $emailEntityBuilder;
        $this->mailer             = $mailer;
        $this->emailOwnerProvider = $emailOwnerProvider;
    }

    /**
     * Process email model sending.
     *
     * @param Email  $model
     * @param string $originName
     * @return \Oro\Bundle\EmailBundle\Entity\Email
     * @throws \Swift_SwiftException
     */
    public function process(Email $model, $originName = InternalEmailOrigin::BAP)
    {
        $this->assertModel($model);
        $messageDate = new \DateTime('now', new \DateTimeZone('UTC'));

        /** @var \Swift_Message $message */
        $message = $this->mailer->createMessage();
        $message->setDate($messageDate->getTimestamp());
        $message->setFrom($this->getAddresses($model->getFrom()));
        $message->setTo($this->getAddresses($model->getTo()));
        $message->setSubject($model->getSubject());
        $message->setBody($model->getBody(), 'text/plain');

        $messageId = $message->generateId();

        if (!$this->mailer->send($message)) {
            throw new \Swift_SwiftException('An email was not delivered.');
        }

        $origin = $this->getEmailOrigin($model->getFrom());
        $this->emailEntityBuilder->setOrigin($origin);

        $email = $this->emailEntityBuilder->email(
            $model->getSubject(),<commit_msg>BAP-4256: Emails demo data. Users' emails are not shown in User view form - CR update<commit_after><?php

namespace Oro\Bundle\EmailBundle\Mailer;

use Doctrine\ORM\EntityManager;

use Oro\Bundle\EmailBundle\Entity\EmailOrigin;
use Oro\Bundle\EmailBundle\Form\Model\Email;
use Oro\Bundle\EmailBundle\Builder\EmailEntityBuilder;
use Oro\Bundle\EmailBundle\Entity\Util\EmailUtil;
use Oro\Bundle\EmailBundle\Entity\EmailFolder;
use Oro\Bundle\EmailBundle\Entity\InternalEmailOrigin;
use Oro\Bundle\EmailBundle\Entity\Provider\EmailOwnerProvider;
use Oro\Bundle\UserBundle\Entity\User;

class Processor
{
    /** @var EntityManager */
    protected $em;

    /** @var EmailEntityBuilder */
    protected $emailEntityBuilder;

    /** @var \Swift_Mailer */
    protected $mailer;

    /** @var  EmailOwnerProvider */
    protected $emailOwnerProvider;

    /**
     * @param EntityManager      $em
     * @param EmailEntityBuilder $emailEntityBuilder
     * @param \Swift_Mailer      $mailer
     * @param EmailOwnerProvider $emailOwnerProvider
     */
    public function __construct(
        EntityManager $em,
        EmailEntityBuilder $emailEntityBuilder,
        \Swift_Mailer $mailer,
        EmailOwnerProvider $emailOwnerProvider
    ) {
        $this->em                 = $em;
        $this->emailEntityBuilder = $emailEntityBuilder;
        $this->mailer             = $mailer;
        $this->emailOwnerProvider = $emailOwnerProvider;
    }

    /**
     * Process email model sending.
     *
     * @param Email  $model
     * @return \Oro\Bundle\EmailBundle\Entity\Email
     * @throws \Swift_SwiftException
     */
    public function process(Email $model)
    {
        $this->assertModel($model);
        $messageDate = new \DateTime('now', new \DateTimeZone('UTC'));

        /** @var \Swift_Message $message */
        $message = $this->mailer->createMessage();
        $message->setDate($messageDate->getTimestamp());
        $message->setFrom($this->getAddresses($model->getFrom()));
        $message->setTo($this->getAddresses($model->getTo()));
        $message->setSubject($model->getSubject());
        $message->setBody($model->getBody(), 'text/plain');

        $messageId = $message->generateId();

        if (!$this->mailer->send($message)) {
            throw new \Swift_SwiftException('An email was not delivered.');
        }

        $origin = $this->getEmailOrigin($model->getFrom());
        $this->emailEntityBuilder->setOrigin($origin);

        $email = $this->emailEntityBuilder->email(
            $model->getSubject(),
{'fraction_non_alphanumeric': 0.13558990412835062, 'fraction_numerical': 0.000782625709254549, 'mean_word_length': 2.941403238242097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5099888', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1439, 'n_words': 256}