From 0efcc82e0d80669476f94605fbb3b61c7a8485b7 Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Fri, 21 Aug 2020 10:58:35 +0530 Subject: [PATCH 01/12] controller depreciation update --- Controller/MailboxChannel.php | 4 ++-- Controller/MailboxChannelXHR.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Controller/MailboxChannel.php b/Controller/MailboxChannel.php index f0ecfd7..fbc394e 100644 --- a/Controller/MailboxChannel.php +++ b/Controller/MailboxChannel.php @@ -6,11 +6,11 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\RedirectResponse; use Webkul\UVDesk\MailboxBundle\Utils\Mailbox\Mailbox; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Webkul\UVDesk\MailboxBundle\Utils\MailboxConfiguration; use Webkul\UVDesk\MailboxBundle\Utils\Imap\Configuration as ImapConfiguration; -class MailboxChannel extends Controller +class MailboxChannel extends AbstractController { public function loadMailboxes() { diff --git a/Controller/MailboxChannelXHR.php b/Controller/MailboxChannelXHR.php index 5f54ed0..5ceefd8 100644 --- a/Controller/MailboxChannelXHR.php +++ b/Controller/MailboxChannelXHR.php @@ -5,10 +5,10 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Webkul\UVDesk\MailboxBundle\Utils\MailboxConfiguration; -class MailboxChannelXHR extends Controller +class MailboxChannelXHR extends AbstractController { public function processMailXHR(Request $request) { From d49c4051e404f5fa1ca7b84e589411bf61cef1ba Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Fri, 4 Sep 2020 18:44:52 +0530 Subject: [PATCH 02/12] controller updates --- Controller/MailboxChannel.php | 19 +++++++++++++++---- Controller/MailboxChannelXHR.php | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Controller/MailboxChannel.php b/Controller/MailboxChannel.php index fbc394e..577b7e7 100644 --- a/Controller/MailboxChannel.php +++ b/Controller/MailboxChannel.php @@ -9,9 +9,20 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Webkul\UVDesk\MailboxBundle\Utils\MailboxConfiguration; use Webkul\UVDesk\MailboxBundle\Utils\Imap\Configuration as ImapConfiguration; +use Webkul\UVDesk\MailboxBundle\Services\MailboxService; +use Symfony\Component\Translation\TranslatorInterface; class MailboxChannel extends AbstractController { + private $mailboxService; + private $translator; + + public function __construct(MailboxService $mailboxService, TranslatorInterface $translator) + { + $this->mailboxService = $mailboxService; + $this->translator = $translator; + } + public function loadMailboxes() { return $this->render('@UVDeskMailbox//listConfigurations.html.twig'); @@ -42,7 +53,7 @@ public function createMailboxConfiguration(Request $request) } if (!empty($imapConfiguration) && !empty($swiftmailerConfiguration)) { - $mailboxService = $this->get('uvdesk.mailbox'); + $mailboxService = $this->mailboxService; $mailboxConfiguration = $mailboxService->parseMailboxConfigurations(); ($mailbox = new Mailbox(!empty($params['id']) ? $params['id'] : null)) @@ -55,7 +66,7 @@ public function createMailboxConfiguration(Request $request) file_put_contents($mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); - $this->addFlash('success', $this->get('translator')->trans('Mailbox successfully created.')); + $this->addFlash('success', $this->translator->trans('Mailbox successfully created.')); return new RedirectResponse($this->generateUrl('helpdesk_member_mailbox_settings')); } } @@ -67,7 +78,7 @@ public function createMailboxConfiguration(Request $request) public function updateMailboxConfiguration($id, Request $request) { - $mailboxService = $this->get('uvdesk.mailbox'); + $mailboxService = $this->mailboxService; $existingMailboxConfiguration = $mailboxService->parseMailboxConfigurations(); $swiftmailerConfigurationCollection = $this->get('swiftmailer.service')->parseSwiftMailerConfigurations(); @@ -129,7 +140,7 @@ public function updateMailboxConfiguration($id, Request $request) file_put_contents($mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); - $this->addFlash('success', $this->get('translator')->trans('Mailbox successfully updated.')); + $this->addFlash('success', $this->translator->trans('Mailbox successfully updated.')); return new RedirectResponse($this->generateUrl('helpdesk_member_mailbox_settings')); } diff --git a/Controller/MailboxChannelXHR.php b/Controller/MailboxChannelXHR.php index 5ceefd8..ca27089 100644 --- a/Controller/MailboxChannelXHR.php +++ b/Controller/MailboxChannelXHR.php @@ -7,9 +7,20 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Webkul\UVDesk\MailboxBundle\Utils\MailboxConfiguration; +use Webkul\UVDesk\MailboxBundle\Services\MailboxService; +use Symfony\Component\Translation\TranslatorInterface; class MailboxChannelXHR extends AbstractController { + private $mailboxService; + private $translator; + + public function __construct(MailboxService $mailboxService, TranslatorInterface $translator) + { + $this->mailboxService = $mailboxService; + $this->translator = $translator; + } + public function processMailXHR(Request $request) { // Return HTTP_OK Response @@ -17,7 +28,7 @@ public function processMailXHR(Request $request) $response->send(); if ("POST" == $request->getMethod() && null != $request->get('email')) { - $this->get('uvdesk.mailbox')->processMail($request->get('email')); + $this->mailboxService->processMail($request->get('email')); } exit(0); @@ -31,14 +42,14 @@ public function loadMailboxesXHR(Request $request) 'name' => $mailbox->getName(), 'isEnabled' => $mailbox->getIsEnabled(), ]; - }, $this->get('uvdesk.mailbox')->parseMailboxConfigurations()->getMailboxes()); + }, $this->mailboxService->parseMailboxConfigurations()->getMailboxes()); return new JsonResponse($collection ?? []); } public function removeMailboxConfiguration($id, Request $request) { - $mailboxService = $this->get('uvdesk.mailbox'); + $mailboxService = $this->mailboxService; $existingMailboxConfiguration = $mailboxService->parseMailboxConfigurations(); foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) { @@ -70,7 +81,7 @@ public function removeMailboxConfiguration($id, Request $request) return new JsonResponse([ 'alertClass' => 'success', - 'alertMessage' => $this->get('translator')->trans('Mailbox configuration removed successfully.'), + 'alertMessage' => $this->translator->trans('Mailbox configuration removed successfully.'), ]); } } From 11e9b5b38b1112ca20f8bd105f18c03e12311ee0 Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Thu, 15 Oct 2020 14:54:10 +0530 Subject: [PATCH 03/12] updates --- Controller/MailboxChannel.php | 9 ++++++--- EventListener/Swiftmailer.php | 16 +++++++++++----- Services/MailboxService.php | 7 +++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Controller/MailboxChannel.php b/Controller/MailboxChannel.php index 577b7e7..3dff997 100644 --- a/Controller/MailboxChannel.php +++ b/Controller/MailboxChannel.php @@ -11,16 +11,19 @@ use Webkul\UVDesk\MailboxBundle\Utils\Imap\Configuration as ImapConfiguration; use Webkul\UVDesk\MailboxBundle\Services\MailboxService; use Symfony\Component\Translation\TranslatorInterface; +use Webkul\UVDesk\CoreFrameworkBundle\SwiftMailer\SwiftMailer as SwiftMailerService; class MailboxChannel extends AbstractController { private $mailboxService; private $translator; + private $swiftMailer; - public function __construct(MailboxService $mailboxService, TranslatorInterface $translator) + public function __construct(MailboxService $mailboxService, TranslatorInterface $translator, SwiftMailerService $swiftMailer) { $this->mailboxService = $mailboxService; $this->translator = $translator; + $this->swiftMailer = $swiftMailer; } public function loadMailboxes() @@ -30,7 +33,7 @@ public function loadMailboxes() public function createMailboxConfiguration(Request $request) { - $swiftmailerConfigurationCollection = $this->get('swiftmailer.service')->parseSwiftMailerConfigurations(); + $swiftmailerConfigurationCollection = $this->swiftMailer->parseSwiftMailerConfigurations(); if ($request->getMethod() == 'POST') { $params = $request->request->all(); @@ -80,7 +83,7 @@ public function updateMailboxConfiguration($id, Request $request) { $mailboxService = $this->mailboxService; $existingMailboxConfiguration = $mailboxService->parseMailboxConfigurations(); - $swiftmailerConfigurationCollection = $this->get('swiftmailer.service')->parseSwiftMailerConfigurations(); + $swiftmailerConfigurationCollection = $this->swiftMailer->parseSwiftMailerConfigurations(); foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) { if ($configuration->getId() == $id) { diff --git a/EventListener/Swiftmailer.php b/EventListener/Swiftmailer.php index e038554..86a719b 100644 --- a/EventListener/Swiftmailer.php +++ b/EventListener/Swiftmailer.php @@ -7,16 +7,22 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Webkul\UVDesk\CoreFrameworkBundle\SwiftMailer\Event\ConfigurationRemovedEvent; use Webkul\UVDesk\CoreFrameworkBundle\SwiftMailer\Event\ConfigurationUpdatedEvent; +use Webkul\UVDesk\CoreFrameworkBundle\SwiftMailer\SwiftMailer as SwiftMailerService; +use Webkul\UVDesk\MailboxBundle\Services\MailboxService; class Swiftmailer { protected $container; protected $requestStack; + protected $swiftMailer; + private $mailboxService; - public final function __construct(ContainerInterface $container, RequestStack $requestStack) + public final function __construct(ContainerInterface $container, RequestStack $requestStack, SwiftMailerService $swiftMailer, MailboxService $mailboxService) { $this->container = $container; $this->requestStack = $requestStack; + $this->swiftMailer = $swiftMailer; + $this->mailboxService = $mailboxService; } public function onSwiftMailerConfigurationUpdated(ConfigurationUpdatedEvent $event) @@ -32,7 +38,7 @@ public function onSwiftMailerConfigurationUpdated(ConfigurationUpdatedEvent $eve return; } - $mailboxConfiguration = $this->container->get('uvdesk.mailbox')->parseMailboxConfigurations(true); + $mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations(true); foreach ($mailboxConfiguration->getMailboxes() as $existingMailbox) { if ($existingMailbox->getSwiftmailerConfiguration()->getId() == $existingConfiguration->getId()) { @@ -50,7 +56,7 @@ public function onSwiftMailerConfigurationUpdated(ConfigurationUpdatedEvent $eve } if (true === $isUpdateRequiredFlag) { - file_put_contents($this->container->get('uvdesk.mailbox')->getPathToConfigurationFile(), (string) $mailboxConfiguration); + file_put_contents($this->mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); } return; @@ -60,7 +66,7 @@ public function onSwiftMailerConfigurationRemoved(ConfigurationRemovedEvent $eve { $isUpdateRequiredFlag = false; $configuration = $event->getSwiftMailerConfiguration(); - $mailboxConfiguration = $this->container->get('uvdesk.mailbox')->parseMailboxConfigurations(); + $mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations(); foreach ($mailboxConfiguration->getMailboxes() as $existingMailbox) { if (null != $existingMailbox->getSwiftmailerConfiguration() && $existingMailbox->getSwiftmailerConfiguration()->getId() == $configuration->getId()) { @@ -77,7 +83,7 @@ public function onSwiftMailerConfigurationRemoved(ConfigurationRemovedEvent $eve } if (true === $isUpdateRequiredFlag) { - file_put_contents($this->container->get('uvdesk.mailbox')->getPathToConfigurationFile(), (string) $mailboxConfiguration); + file_put_contents($this->mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); } return; diff --git a/Services/MailboxService.php b/Services/MailboxService.php index e11021d..1c287cd 100644 --- a/Services/MailboxService.php +++ b/Services/MailboxService.php @@ -21,6 +21,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents; use Webkul\UVDesk\MailboxBundle\Utils\Imap\Configuration as ImapConfiguration; +use Webkul\UVDesk\CoreFrameworkBundle\SwiftMailer\SwiftMailer as SwiftMailerService; class MailboxService { @@ -31,12 +32,14 @@ class MailboxService private $requestStack; private $entityManager; private $mailboxCollection = []; + private $swiftMailer; - public function __construct(ContainerInterface $container, RequestStack $requestStack, EntityManagerInterface $entityManager) + public function __construct(ContainerInterface $container, RequestStack $requestStack, EntityManagerInterface $entityManager, SwiftMailerService $swiftMailer) { $this->container = $container; $this->requestStack = $requestStack; $this->entityManager = $entityManager; + $this->swiftMailer = $swiftMailer; } public function getPathToConfigurationFile() @@ -60,7 +63,7 @@ public function parseMailboxConfigurations(bool $ignoreInvalidAttributes = false // Read configurations from package config. $mailboxConfiguration = new MailboxConfiguration(); - $swiftmailerService = $this->container->get('swiftmailer.service'); + $swiftmailerService = $this->swiftMailer; $swiftmailerConfigurations = $swiftmailerService->parseSwiftMailerConfigurations(); foreach (Yaml::parse(file_get_contents($path))['uvdesk_mailbox']['mailboxes'] ?? [] as $id => $params) { From 41cb8414cc814f04c09a38b438e3342eede79c60 Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Mon, 19 Oct 2020 19:39:30 +0530 Subject: [PATCH 04/12] admin access add for mailbox --- Controller/MailboxChannel.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Controller/MailboxChannel.php b/Controller/MailboxChannel.php index 3dff997..b563a8d 100644 --- a/Controller/MailboxChannel.php +++ b/Controller/MailboxChannel.php @@ -12,15 +12,18 @@ use Webkul\UVDesk\MailboxBundle\Services\MailboxService; use Symfony\Component\Translation\TranslatorInterface; use Webkul\UVDesk\CoreFrameworkBundle\SwiftMailer\SwiftMailer as SwiftMailerService; +use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService; class MailboxChannel extends AbstractController { private $mailboxService; private $translator; private $swiftMailer; + private $userService; - public function __construct(MailboxService $mailboxService, TranslatorInterface $translator, SwiftMailerService $swiftMailer) + public function __construct(UserService $userService, MailboxService $mailboxService, TranslatorInterface $translator, SwiftMailerService $swiftMailer) { + $this->userService = $userService; $this->mailboxService = $mailboxService; $this->translator = $translator; $this->swiftMailer = $swiftMailer; @@ -28,11 +31,19 @@ public function __construct(MailboxService $mailboxService, TranslatorInterface public function loadMailboxes() { + if (!$this->userService->isAccessAuthorized('ROLE_ADMIN')) { + return $this->redirect($this->generateUrl('helpdesk_member_dashboard')); + } + return $this->render('@UVDeskMailbox//listConfigurations.html.twig'); } public function createMailboxConfiguration(Request $request) { + if (!$this->userService->isAccessAuthorized('ROLE_ADMIN')) { + return $this->redirect($this->generateUrl('helpdesk_member_dashboard')); + } + $swiftmailerConfigurationCollection = $this->swiftMailer->parseSwiftMailerConfigurations(); if ($request->getMethod() == 'POST') { @@ -81,6 +92,10 @@ public function createMailboxConfiguration(Request $request) public function updateMailboxConfiguration($id, Request $request) { + if (!$this->userService->isAccessAuthorized('ROLE_ADMIN')) { + return $this->redirect($this->generateUrl('helpdesk_member_dashboard')); + } + $mailboxService = $this->mailboxService; $existingMailboxConfiguration = $mailboxService->parseMailboxConfigurations(); $swiftmailerConfigurationCollection = $this->swiftMailer->parseSwiftMailerConfigurations(); From b31251027692716a64d7e2a3627f3309b4e4b930 Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Thu, 12 Nov 2020 11:47:15 +0530 Subject: [PATCH 05/12] email validation update --- Resources/views/manageConfigurations.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/views/manageConfigurations.html.twig b/Resources/views/manageConfigurations.html.twig index 6cb83b7..937cd69 100644 --- a/Resources/views/manageConfigurations.html.twig +++ b/Resources/views/manageConfigurations.html.twig @@ -237,7 +237,7 @@ msg: 'Please specify a valid email address.' }, { - pattern: /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/, + pattern: /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, msg: 'Please specify a valid email address.' } ], From 66e796185fdc017352c73cb9da50954620917721 Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Wed, 27 Jan 2021 16:44:19 +0530 Subject: [PATCH 06/12] added permission for serch bar --- UIComponents/Dashboard/Search/Mailbox.php | 5 +++++ UIComponents/Dashboard/Search/SwiftMailer.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/UIComponents/Dashboard/Search/Mailbox.php b/UIComponents/Dashboard/Search/Mailbox.php index ccb2e22..26ae9d4 100644 --- a/UIComponents/Dashboard/Search/Mailbox.php +++ b/UIComponents/Dashboard/Search/Mailbox.php @@ -30,6 +30,11 @@ public static function getRouteName() : string return 'helpdesk_member_mailbox_settings'; } + public static function getRoles() : array + { + return ['ROLE_ADMIN']; + } + public function getChildrenRoutes() : array { return []; diff --git a/UIComponents/Dashboard/Search/SwiftMailer.php b/UIComponents/Dashboard/Search/SwiftMailer.php index 48960a0..2395576 100644 --- a/UIComponents/Dashboard/Search/SwiftMailer.php +++ b/UIComponents/Dashboard/Search/SwiftMailer.php @@ -30,6 +30,11 @@ public static function getRouteName() : string return 'helpdesk_member_swiftmailer_settings'; } + public static function getRoles() : array + { + return ['ROLE_ADMIN']; + } + public function getChildrenRoutes() : array { return []; From f5ef18284efbf762ef6630d28779752cd1fd4801 Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Tue, 2 Mar 2021 19:04:00 +0530 Subject: [PATCH 07/12] lowercase the mailbox email to resolve issue if email address reply to exist with uppercase email --- Services/MailboxService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Services/MailboxService.php b/Services/MailboxService.php index 1c287cd..f6784b0 100644 --- a/Services/MailboxService.php +++ b/Services/MailboxService.php @@ -304,6 +304,7 @@ public function processMail($rawEmail) } // Process Mail - References + $addresses['to'][0] = strtolower($addresses['to'][0]); $mailData['replyTo'] = $addresses['to']; $mailData['messageId'] = $parser->getHeader('message-id') ?: null; $mailData['inReplyTo'] = htmlspecialchars_decode($parser->getHeader('in-reply-to')); From be967da28a37ec1084a67761b7b982038c01cbcd Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Mon, 22 Mar 2021 20:36:19 +0530 Subject: [PATCH 08/12] forwording ticket create issue fix and trailing issue update --- Services/MailboxService.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Services/MailboxService.php b/Services/MailboxService.php index f6784b0..8eb6bf7 100644 --- a/Services/MailboxService.php +++ b/Services/MailboxService.php @@ -266,7 +266,7 @@ public function processMail($rawEmail) $from = $this->parseAddress('from') ?: $this->parseAddress('sender'); $addresses = [ 'from' => $this->getEmailAddress($from), - 'to' => $this->parseAddress('to'), + 'to' => !empty($this->parseAddress('to')) ? $this->parseAddress('to') : $this->parseAddress('X-Forwarded-To'), 'cc' => $this->parseAddress('cc'), 'delivered-to' => $this->parseAddress('delivered-to'), ]; @@ -311,10 +311,14 @@ public function processMail($rawEmail) $mailData['referenceIds'] = htmlspecialchars_decode($parser->getHeader('references')); $mailData['cc'] = array_filter(explode(',', $parser->getHeader('cc'))) ?: []; $mailData['bcc'] = array_filter(explode(',', $parser->getHeader('bcc'))) ?: []; + + // User Identity + $from = $this->entityManager->getRepository(User::class)->findOneByEmail($addresses['from']); + $userinstance = $this->entityManager->getRepository(UserInstance::class)->findOneByUser( $from); // Process Mail - User Details $mailData['source'] = 'email'; - $mailData['createdBy'] = 'customer'; + $mailData['createdBy'] = ($userinstance->getSupportRole()->getId() == 4) ? 'customer' : 'agent'; $mailData['role'] = 'ROLE_CUSTOMER'; $mailData['from'] = $addresses['from']; $mailData['name'] = trim(current(explode('@', $from[0]['display']))); From 867f68bdd7eb44815acbfd7194bf6017cab61832 Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Tue, 23 Mar 2021 14:50:47 +0530 Subject: [PATCH 09/12] updates --- Services/MailboxService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Services/MailboxService.php b/Services/MailboxService.php index 8eb6bf7..b2c4152 100644 --- a/Services/MailboxService.php +++ b/Services/MailboxService.php @@ -266,7 +266,7 @@ public function processMail($rawEmail) $from = $this->parseAddress('from') ?: $this->parseAddress('sender'); $addresses = [ 'from' => $this->getEmailAddress($from), - 'to' => !empty($this->parseAddress('to')) ? $this->parseAddress('to') : $this->parseAddress('X-Forwarded-To'), + 'to' => empty($this->parseAddress('X-Forwarded-To')) ? $this->parseAddress('to') : $this->parseAddress('X-Forwarded-To'), 'cc' => $this->parseAddress('cc'), 'delivered-to' => $this->parseAddress('delivered-to'), ]; @@ -313,9 +313,9 @@ public function processMail($rawEmail) $mailData['bcc'] = array_filter(explode(',', $parser->getHeader('bcc'))) ?: []; // User Identity - $from = $this->entityManager->getRepository(User::class)->findOneByEmail($addresses['from']); - $userinstance = $this->entityManager->getRepository(UserInstance::class)->findOneByUser( $from); - + $fromEmail = $this->entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($addresses['from']); + $userinstance = $this->entityManager->getRepository('UVDeskCoreFrameworkBundle:UserInstance')->findOneByUser($fromEmail); + // Process Mail - User Details $mailData['source'] = 'email'; $mailData['createdBy'] = ($userinstance->getSupportRole()->getId() == 4) ? 'customer' : 'agent'; From a2cabef78f1933dc00725395d59bee46ba0bd1fa Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Tue, 30 Mar 2021 17:26:03 +0530 Subject: [PATCH 10/12] updates --- Services/MailboxService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Services/MailboxService.php b/Services/MailboxService.php index b2c4152..976d1f3 100644 --- a/Services/MailboxService.php +++ b/Services/MailboxService.php @@ -318,7 +318,7 @@ public function processMail($rawEmail) // Process Mail - User Details $mailData['source'] = 'email'; - $mailData['createdBy'] = ($userinstance->getSupportRole()->getId() == 4) ? 'customer' : 'agent'; + $mailData['createdBy'] = ($userinstance && $userinstance->getSupportRole()->getId() == 4) ? 'customer' : 'agent'; $mailData['role'] = 'ROLE_CUSTOMER'; $mailData['from'] = $addresses['from']; $mailData['name'] = trim(current(explode('@', $from[0]['display']))); From 3c2b04516d57876a9252e4869a735856eb5d1cce Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Wed, 31 Mar 2021 15:51:33 +0530 Subject: [PATCH 11/12] updates --- Services/MailboxService.php | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/Services/MailboxService.php b/Services/MailboxService.php index 976d1f3..cf7e9c6 100644 --- a/Services/MailboxService.php +++ b/Services/MailboxService.php @@ -312,13 +312,9 @@ public function processMail($rawEmail) $mailData['cc'] = array_filter(explode(',', $parser->getHeader('cc'))) ?: []; $mailData['bcc'] = array_filter(explode(',', $parser->getHeader('bcc'))) ?: []; - // User Identity - $fromEmail = $this->entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($addresses['from']); - $userinstance = $this->entityManager->getRepository('UVDeskCoreFrameworkBundle:UserInstance')->findOneByUser($fromEmail); - // Process Mail - User Details $mailData['source'] = 'email'; - $mailData['createdBy'] = ($userinstance && $userinstance->getSupportRole()->getId() == 4) ? 'customer' : 'agent'; + $mailData['createdBy'] = 'customer'; $mailData['role'] = 'ROLE_CUSTOMER'; $mailData['from'] = $addresses['from']; $mailData['name'] = trim(current(explode('@', $from[0]['display']))); @@ -386,6 +382,7 @@ public function processMail($rawEmail) if (!empty($user) && null != $user->getAgentInstance()) { $mailData['user'] = $user; + $mailData['createdBy'] = 'agent'; $userDetails = $user->getAgentInstance()->getPartialDetails(); } else { // Add user as a ticket collaborator @@ -422,17 +419,19 @@ public function processMail($rawEmail) $mailData['fullname'] = $userDetails['name']; $thread = $this->container->get('ticket.service')->createThread($ticket, $mailData); - - if ($thread->getCreatedBy() == 'customer') { - $event = new GenericEvent(CoreWorkflowEvents\Ticket\CustomerReply::getId(), [ - 'entity' => $ticket, - ]); - } else { - $event = new GenericEvent(CoreWorkflowEvents\Ticket\AgentReply::getId(), [ - 'entity' => $ticket, - ]); + + if($thread->getThreadType() == 'reply') { + if ($thread->getCreatedBy() == 'customer') { + $event = new GenericEvent(CoreWorkflowEvents\Ticket\CustomerReply::getId(), [ + 'entity' => $ticket, + ]); + } else { + $event = new GenericEvent(CoreWorkflowEvents\Ticket\AgentReply::getId(), [ + 'entity' => $ticket, + ]); + } } - + // Trigger thread reply event $this->container->get('event_dispatcher')->dispatch('uvdesk.automation.workflow.execute', $event); } From 5f69080b314dd754c5388c7211570e088094b738 Mon Sep 17 00:00:00 2001 From: Sanjeev Papnoi Date: Thu, 1 Apr 2021 14:55:50 +0530 Subject: [PATCH 12/12] condition removed for same subject with same customer prevent removed --- Services/MailboxService.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Services/MailboxService.php b/Services/MailboxService.php index cf7e9c6..5b1fd65 100644 --- a/Services/MailboxService.php +++ b/Services/MailboxService.php @@ -348,11 +348,12 @@ public function processMail($rawEmail) $mailData['threadType'] = 'create'; $mailData['referenceIds'] = $mailData['messageId']; - $ticketSubjectRefrenceExist = $this->searchticketSubjectRefrence($mailData['from'], $mailData['subject']); + // @Todo For same subject with same customer check + // $ticketSubjectRefrenceExist = $this->searchticketSubjectRefrence($mailData['from'], $mailData['subject']); - if(!empty($ticketSubjectRefrenceExist)) { - return; - } + // if(!empty($ticketSubjectRefrenceExist)) { + // return; + // } $thread = $this->container->get('ticket.service')->createTicket($mailData);