/**
  * @dataProvider inapplicableEmailsProvider
  */
 public function testGetApplicableRulesDoesNotReturnTheRule(Email $email)
 {
     $mailbox = new Mailbox();
     $mailbox->setAutoResponseRules(new ArrayCollection([$this->getAutoResponseRule()]));
     $rules = $this->autoResponseManager->getApplicableRules($mailbox, $email);
     $this->assertEquals(0, $rules->count());
 }
 /**
  * @Route("/connection/check", name="oro_imap_connection_check", methods={"POST"})
  */
 public function checkAction(Request $request)
 {
     $responseCode = Codes::HTTP_BAD_REQUEST;
     $data = null;
     $id = $request->get('id', false);
     if (false !== $id) {
         $data = $this->getDoctrine()->getRepository('OroImapBundle:UserEmailOrigin')->find($id);
     }
     $form = $this->createForm('oro_imap_configuration', null, ['csrf_protection' => false]);
     $form->setData($data);
     $form->submit($request);
     /** @var UserEmailOrigin $origin */
     $origin = $form->getData();
     if ($form->isValid() && null !== $origin) {
         $response = [];
         $password = $this->get('oro_security.encoder.mcrypt')->decryptData($origin->getPassword());
         if ($origin->getImapHost() !== null) {
             $response['imap'] = [];
             $config = new ImapConfig($origin->getImapHost(), $origin->getImapPort(), $origin->getImapEncryption(), $origin->getUser(), $password);
             try {
                 $connector = $this->get('oro_imap.connector.factory')->createImapConnector($config);
                 $this->manager = new ImapEmailFolderManager($connector, $this->getDoctrine()->getManager(), $origin);
                 $emailFolders = $this->manager->getFolders();
                 $origin->setFolders($emailFolders);
                 if ($request->get('for_entity', 'user') === 'user') {
                     $user = new User();
                     $user->setImapConfiguration($origin);
                     $userForm = $this->get('oro_user.form.user');
                     $userForm->setData($user);
                     $response['imap']['folders'] = $this->renderView('OroImapBundle:Connection:check.html.twig', ['form' => $userForm->createView()]);
                 } elseif ($request->get('for_entity', 'user') === 'mailbox') {
                     $mailbox = new Mailbox();
                     $mailbox->setOrigin($origin);
                     $mailboxForm = $this->createForm('oro_email_mailbox');
                     $mailboxForm->setData($mailbox);
                     $response['imap']['folders'] = $this->renderView('OroImapBundle:Connection:checkMailbox.html.twig', ['form' => $mailboxForm->createView()]);
                 }
             } catch (\Exception $e) {
                 $response['imap']['error'] = $e->getMessage();
             }
         }
         if ($origin->getSmtpHost() !== null) {
             $response['smtp'] = [];
             try {
                 $mailer = $this->get('oro_email.direct_mailer');
                 $transport = $mailer->getTransport();
                 $transport->setHost($origin->getSmtpHost());
                 $transport->setPort($origin->getSmtpPort());
                 $transport->setEncryption($origin->getSmtpEncryption());
                 $transport->setUsername($origin->getUser());
                 $transport->setPassword($password);
                 $transport->start();
             } catch (\Exception $e) {
                 $response['smtp']['error'] = $e->getMessage();
             }
         }
         return new JsonResponse($response);
     }
     return new Response('', $responseCode);
 }
 /**
  * {@inheritdoc}
  */
 public function isEnabled(Mailbox $mailbox = null)
 {
     if ($mailbox === null || null === ($organization = $mailbox->getOrganization())) {
         $organization = $this->securityLink->getService()->getOrganization();
     }
     $qb = $this->getChannelRepository()->createQueryBuilder('c');
     return (bool) $qb->select('COUNT(c.id)')->join('c.entities', 'e')->andWhere('e.name = :name')->andWhere('c.status = :status')->andWhere('c.owner = :owner')->setParameter('name', static::LEAD_CLASS)->setParameter('status', Channel::STATUS_ACTIVE)->setParameter('owner', $organization)->getQuery()->getSingleScalarResult();
 }
Example #4
0
 /**
  * @param bool $skipOrigin
  * @param string $accessToken
  * @param string $accountType
  *
  * @dataProvider setDataProviderAccountType
  */
 public function testGetAccountType($skipOrigin, $accessToken, $accountType)
 {
     $mailbox = new Mailbox();
     $mailbox->setOrigin($this->origin);
     if ($skipOrigin) {
         $mailbox->setOrigin(null);
         $this->assertEmpty($mailbox->getImapAccountType());
     } else {
         $this->origin->expects($this->any())->method('getAccessToken')->willReturn($accessToken);
         $this->assertEquals($accountType, $mailbox->getImapAccountType()->getAccountType());
     }
 }
Example #5
0
 /**
  * Configures user field so it searches only within mailboxes' organization.
  *
  * @param FormInterface $form
  * @param Mailbox       $data
  */
 protected function configureUserField(FormInterface $form, Mailbox $data)
 {
     if (!$data->getOrganization()) {
         return;
     }
     FormUtils::replaceField($form, 'authorizedUsers', ['configs' => ['route_name' => 'oro_email_mailbox_users_search', 'route_parameters' => ['organizationId' => $data->getOrganization()->getId()], 'multiple' => true, 'width' => '400px', 'placeholder' => 'oro.user.form.choose_user', 'allowClear' => true, 'result_template_twig' => 'OroUserBundle:User:Autocomplete/result.html.twig', 'selection_template_twig' => 'OroUserBundle:User:Autocomplete/selection.html.twig']]);
 }
Example #6
0
 public function __construct($id = null)
 {
     parent::__construct();
     $this->id = $id;
 }
 /**
  * @param MailBox $mailbox
  * @param Email $email
  *
  * @return AutoResponseRule[]|Collection
  */
 public function getApplicableRules(Mailbox $mailbox, Email $email)
 {
     return $mailbox->getAutoResponseRules()->filter(function (AutoResponseRule $rule) use($email) {
         return $rule->isActive() && $this->isExprApplicable($email, $this->createRuleExpr($rule, $email)) && $rule->getCreatedAt() < $email->getSentAt();
     });
 }
Example #8
0
 /**
  * @Route(
  *      "/mailbox/create/{organization_id}",
  *      name="oro_email_mailbox_create",
  *      defaults={"organization_id"=null}
  * )
  * @ParamConverter(
  *      "organization",
  *      class="OroOrganizationBundle:Organization",
  *      isOptional=true,
  *      options={"id"="organization_id"}
  * )
  * @Template("OroEmailBundle:Configuration/Mailbox:update.html.twig")
  *
  * @param Request      $request
  * @param Organization $organization
  *
  * @return array
  */
 public function createAction(Request $request, Organization $organization = null)
 {
     $data = new Mailbox();
     if ($organization != null) {
         $data->setOrganization($organization);
     } else {
         $data->setOrganization($this->get('oro_security.security_facade')->getOrganization());
     }
     return $this->update($data, $request);
 }