@@ -104,22 +105,28 @@
{# IMAP Settings #}
-
{{ 'Incoming Mail (IMAP) Server'|trans }}
-
{{ 'Configure your imap settings which will be used to fetch emails from your mailbox.'|trans }}
+
{{ 'Incoming Mail'|trans }}
+
{{ 'Manage how you wish to retrieve and process emails from your mailbox.'|trans }}
@@ -169,10 +197,44 @@
{% block footer %}
{{ parent() }}
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
{% endblock %}
diff --git a/Services/MailboxService.php b/Services/MailboxService.php
index 2090f0c..08bbe66 100644
--- a/Services/MailboxService.php
+++ b/Services/MailboxService.php
@@ -9,7 +9,6 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RequestStack;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
-use Symfony\Component\EventDispatcher\GenericEvent;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\Thread;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\Website;
@@ -20,6 +19,8 @@
use Webkul\UVDesk\MailboxBundle\Utils\MailboxConfiguration;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents;
+use Webkul\UVDesk\MailboxBundle\Utils\IMAP;
+use Webkul\UVDesk\MailboxBundle\Utils\SMTP;
use Webkul\UVDesk\MailboxBundle\Utils\Imap\Configuration as ImapConfiguration;
use Webkul\UVDesk\CoreFrameworkBundle\SwiftMailer\SwiftMailer as SwiftMailerService;
use Webkul\UVDesk\MailboxBundle\Workflow\Events as MaibloxWorkflowEvents;
@@ -28,6 +29,10 @@ class MailboxService
{
const PATH_TO_CONFIG = '/config/packages/uvdesk_mailbox.yaml';
+ private $parser;
+ private $container;
+ private $requestStack;
+ private $entityManager;
private $mailboxCollection = [];
public function __construct(ContainerInterface $container, RequestStack $requestStack, EntityManagerInterface $entityManager, SwiftMailerService $swiftMailer)
@@ -46,6 +51,7 @@ public function getPathToConfigurationFile()
public function createConfiguration($params)
{
$configuration = new MailboxConfigurations\MailboxConfiguration($params);
+
return $configuration ?? null;
}
@@ -53,41 +59,105 @@ public function parseMailboxConfigurations(bool $ignoreInvalidAttributes = false
{
$path = $this->getPathToConfigurationFile();
- if (!file_exists($path)) {
+ if (! file_exists($path)) {
throw new \Exception("File '$path' not found.");
}
// Read configurations from package config.
$mailboxConfiguration = new MailboxConfiguration();
- $swiftmailerService = $this->swiftMailer;
- $swiftmailerConfigurations = $swiftmailerService->parseSwiftMailerConfigurations();
foreach (Yaml::parse(file_get_contents($path))['uvdesk_mailbox']['mailboxes'] ?? [] as $id => $params) {
// Swiftmailer Configuration
- $swiftmailerConfiguration = null;
+
+ $swiftMailerConfigurations = $this->swiftMailer->parseSwiftMailerConfigurations() ?? null;
- foreach ($swiftmailerConfigurations as $configuration) {
- if ($configuration->getId() == $params['smtp_server']['mailer_id']) {
- $swiftmailerConfiguration = $configuration;
- break;
+ if (isset($params['smtp_swift_mailer_server'])) {
+ foreach ($swiftMailerConfigurations as $configuration) {
+ if ($configuration->getId() == $params['smtp_swift_mailer_server']['mailer_id']) {
+ $swiftMailerConfiguration = $configuration;
+ break;
+ }
}
}
-
+
// IMAP Configuration
- ($imapConfiguration = ImapConfiguration::guessTransportDefinition($params['imap_server']['host']))
- ->setUsername($params['imap_server']['username'])
- ->setPassword($params['imap_server']['password']);
+ $imapConfiguration = null;
+
+ if (! empty($params['imap_server'])) {
+ $imapConfiguration = IMAP\Configuration::guessTransportDefinition($params['imap_server']);
+
+ if ($imapConfiguration instanceof IMAP\Transport\AppTransportConfigurationInterface) {
+ $imapConfiguration
+ ->setClient($params['imap_server']['client'])
+ ->setUsername($params['imap_server']['username'])
+ ;
+ } else if ($imapConfiguration instanceof IMAP\Transport\SimpleTransportConfigurationInterface) {
+ $imapConfiguration
+ ->setUsername($params['imap_server']['username'])
+ ;
+ } else {
+ $imapConfiguration
+ ->setUsername($params['imap_server']['username'])
+ ->setPassword($params['imap_server']['password'])
+ ;
+ }
+ }
+
+ // SMTP Configuration
+ $smtpConfiguration = null;
+
+ if (
+ ! empty($params['smtp_server'])
+ && !isset($params['smtp_server']['mailer_id'])
+ ) {
+ $smtpConfiguration = SMTP\Configuration::guessTransportDefinition($params['smtp_server']);
+
+ if ($smtpConfiguration instanceof SMTP\Transport\AppTransportConfigurationInterface) {
+ $smtpConfiguration
+ ->setClient($params['smtp_server']['client'])
+ ->setUsername($params['smtp_server']['username'])
+ ;
+ } else if ($smtpConfiguration instanceof SMTP\Transport\ResolvedTransportConfigurationInterface) {
+ $smtpConfiguration
+ ->setUsername($params['smtp_server']['username'])
+ ->setPassword($params['smtp_server']['password'])
+ ;
+ } else {
+ $smtpConfiguration
+ ->setHost($params['smtp_server']['host'])
+ ->setPort($params['smtp_server']['port'])
+ ->setUsername($params['smtp_server']['username'])
+ ->setPassword($params['smtp_server']['password'])
+ ;
+
+ if (! empty($params['smtp_server']['sender_address'])) {
+ $smtpConfiguration
+ ->setSenderAddress($params['smtp_server']['sender_address'])
+ ;
+ }
+ }
+ }
// Mailbox Configuration
($mailbox = new Mailbox($id))
->setName($params['name'])
- ->setIsEnabled($params['enabled'])
- ->setIsDeleted(empty($params['deleted']) ? false : $params['deleted'])
- ->setImapConfiguration($imapConfiguration);
+ ->setIsEnabled($params['enabled']);
+
+ if (! empty($imapConfiguration)) {
+ $mailbox
+ ->setImapConfiguration($imapConfiguration)
+ ;
+ }
+
+ if (! empty($smtpConfiguration)) {
+ $mailbox
+ ->setSmtpConfiguration($smtpConfiguration)
+ ;
+ }
- if (!empty($swiftmailerConfiguration)) {
- $mailbox->setSwiftMailerConfiguration($swiftmailerConfiguration);
- } else if (!empty($params['smtp_server']['mailer_id']) && true === $ignoreInvalidAttributes) {
+ if (! empty($swiftMailerConfiguration)) {
+ $mailbox->setSwiftMailerConfiguration($swiftMailerConfiguration);
+ } else if (! empty($params['smtp_server']['mailer_id']) && true === $ignoreInvalidAttributes) {
$mailbox->setSwiftMailerConfiguration($swiftmailerService->createConfiguration('smtp', $params['smtp_server']['mailer_id']));
}
@@ -97,6 +167,15 @@ public function parseMailboxConfigurations(bool $ignoreInvalidAttributes = false
return $mailboxConfiguration;
}
+ private function getParser()
+ {
+ if (empty($this->parser)) {
+ $this->parser = new EmailParser();
+ }
+
+ return $this->parser;
+ }
+
private function getLoadedEmailContentParser($emailContents = null, $cacheContent = true): ?EmailParser
{
if (empty($emailContents)) {
@@ -160,6 +239,24 @@ public function getEmailAddresses($collection)
return count($filteredCollection) == 1 ? $filteredCollection[0] : $filteredCollection;
}
+ public function parseAddress($type)
+ {
+ $addresses = mailparse_rfc822_parse_addresses($this->getParser()->getHeader($type));
+
+ return $addresses ?: false;
+ }
+
+ public function getEmailAddress($addresses)
+ {
+ foreach ((array) $addresses as $address) {
+ if (filter_var($address['address'], FILTER_VALIDATE_EMAIL)) {
+ return $address['address'];
+ }
+ }
+
+ return null;
+ }
+
public function getMailboxByEmail($email)
{
foreach ($this->getRegisteredMailboxes() as $registeredMailbox) {
@@ -171,10 +268,24 @@ public function getMailboxByEmail($email)
throw new \Exception("No mailbox found for email '$email'");
}
- private function searchticketSubjectRefrence($senderEmail, $messageSubject) {
+ public function getMailboxByToEmail($email)
+ {
+ foreach ($this->getRegisteredMailboxes() as $registeredMailbox) {
+ if (strtolower($email) === strtolower($registeredMailbox['imap_server']['username'])) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private function searchTicketSubjectReference($senderEmail, $messageSubject) {
// Search Criteria: Find ticket based on subject
- if (!empty($senderEmail) && !empty($messageSubject)) {
+ if (
+ ! empty($senderEmail)
+ && ! empty($messageSubject)
+ ) {
$threadRepository = $this->entityManager->getRepository(Thread::class);
$ticket = $threadRepository->findTicketBySubject($senderEmail, $messageSubject);
@@ -205,29 +316,36 @@ private function searchExistingTickets(array $criterias = [])
// Search Criteria 1: Find ticket by unique message id
$ticket = $ticketRepository->findOneByReferenceIds($criteriaValue);
- if (!empty($ticket)) {
+ if (! empty($ticket)) {
return $ticket;
} else {
$thread = $threadRepository->findOneByMessageId($criteriaValue);
- if (!empty($thread)) {
+ if (! empty($thread)) {
return $thread->getTicket();
}
}
+
+ break;
+ case 'outlookConversationId':
+ // Search Criteria 1: Find ticket by unique message id
+ $ticket = $ticketRepository->findOneByOutlookConversationId($criteriaValue);
+
+ if (! empty($ticket)) {
+ return $ticket;
+ }
+
break;
case 'inReplyTo':
// Search Criteria 2: Find ticket based on in-reply-to reference id
+ $ticket = $this->entityManager->getRepository(Thread::class)->findThreadByRefrenceId($criteriaValue);
- $repository = $this->entityManager->getRepository(Thread::class);
- $ticket = $repository->findThreadByRefrenceId($criteriaValue);
-
-
- if (!empty($ticket)) {
+ if (! empty($ticket)) {
return $ticket;
} else {
$thread = $threadRepository->findOneByMessageId($criteriaValue);
- if (!empty($thread)) {
+ if (! empty($thread)) {
return $thread->getTicket();
}
}
@@ -241,7 +359,7 @@ private function searchExistingTickets(array $criterias = [])
foreach ($referenceIds as $messageId) {
$thread = $threadRepository->findOneByMessageId($messageId);
- if (!empty($thread)) {
+ if (! empty($thread)) {
return $thread->getTicket();
}
}
@@ -253,187 +371,414 @@ private function searchExistingTickets(array $criterias = [])
return null;
}
-
- private function prepareResolvedEmailHeaders(EmailParser $emailParser): array
- {
- // Email headers with all sender/recipients details
- $emailHeaders = [
- 'from' => $emailParser->getHeader('from') != false ? $emailParser->getHeader('from') : null,
- 'reply-to' => $emailParser->getHeader('reply-to') != false ? $emailParser->getHeader('reply-to') : null,
- 'to' => $emailParser->getHeader('to') != false ? $emailParser->getHeader('to') : null,
- 'cc' => $emailParser->getHeader('cc') != false ? $emailParser->getHeader('cc') : null,
- 'bcc' => $emailParser->getHeader('bcc') != false ? $emailParser->getHeader('bcc') : null,
- 'x-forwarded-to' => $emailParser->getHeader('x-forwarded-to') != false ? $emailParser->getHeader('x-forwarded-to') : null,
- 'delivered-to' => $emailParser->getHeader('delivered-to') != false ? $emailParser->getHeader('delivered-to') : null,
- ];
-
- // If 'from' header is empty, use 'sender' header if provided instead
- if (empty($emailHeaders['from']) && $emailParser->getHeader('sender') != false) {
- $emailHeaders['from'] = $emailParser->getHeader('sender');
- }
-
- // Resolve & map only email addresses from email headers
- $resolvedEmailHeaders = [];
-
- foreach ($emailHeaders as $headerName => $headerContent) {
- $resolvedEmailHeaders[$headerName] = null;
-
- if (!empty($headerContent)) {
- $parsedEmailAddresses = mailparse_rfc822_parse_addresses($headerContent);
-
- $emailHeaders[$headerName] = $parsedEmailAddresses;
- $resolvedEmailHeaders[$headerName] = $this->getEmailAddresses($parsedEmailAddresses);
- }
- }
-
- return [$emailHeaders, $resolvedEmailHeaders];
- }
- public function processMail($emailContents)
+ public function processMail($rawEmail)
{
- $emailParser = $this->getLoadedEmailContentParser($emailContents);
-
- list($emailHeaders, $resolvedEmailHeaders) = $this->prepareResolvedEmailHeaders($emailParser);
+ $mailData = [];
+ $parser = $this->getParser();
+ $parser->setText($rawEmail);
+
+ $from = $this->parseAddress('from') ?: $this->parseAddress('sender');
+ $addresses = [
+ 'from' => $this->getEmailAddress($from),
+ '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'),
+ ];
- // Skip email processing if email is an auto-forwarded message to prevent infinite loop.
- if (empty($resolvedEmailHeaders['from'])) {
- // Skip email processing if no to-emails are specified
+ if (empty($addresses['from'])) {
return [
- 'message' => "No sender email addresses were found while processing contents of email.",
+ 'message' => "No 'from' email address was found while processing contents of email.",
'content' => [],
];
- } else if (empty($resolvedEmailHeaders['to']) && empty($resolvedEmailHeaders['delivered-to']) && empty($resolvedEmailHeaders['cc'])) {
- // Skip email processing if no recipient emails are specified
- return [
- 'message' => "No recipient email addresses were found while processing contents of email.",
- 'content' => [
- 'from' => !empty($resolvedEmailHeaders['from']) ? $resolvedEmailHeaders['from'] : null,
- ],
- ];
} else {
- // Skip email if it is auto-generated to prevent looping of emails
- if ($emailParser->getHeader('precedence') || $emailParser->getHeader('x-autoreply') || $emailParser->getHeader('x-autorespond') || 'auto-replied' == $emailParser->getHeader('auto-submitted')) {
+ if (! empty($addresses['delivered-to'])) {
+ $addresses['to'] = array_map(function($address) {
+ return $address['address'];
+ }, $addresses['delivered-to']);
+ } else if (! empty($addresses['to'])) {
+ $addresses['to'] = array_map(function($address) {
+ return $address['address'];
+ }, $addresses['to']);
+ } else if (! empty($addresses['cc'])) {
+ $addresses['to'] = array_map(function($address) {
+ return $address['address'];
+ }, $addresses['cc']);
+ }
+
+ // Skip email processing if no to-emails are specified
+ if (empty($addresses['to'])) {
return [
- 'message' => "Received an auto-forwarded email which can lead to possible infinite loop of email exchanges. Skipping email from further processing.",
+ 'message' => "No 'to' email addresses were found in the email.",
'content' => [
- 'from' => $resolvedEmailHeaders['from'] ?? null,
+ 'from' => ! empty($addresses['from']) ? $addresses['from'] : null,
],
];
}
- $website = $this->entityManager->getRepository(Website::class)->findOneByCode('knowledgebase');
-
- // Skip email if sender email address is in block list
- if ($this->container->get('ticket.service')->isEmailBlocked($resolvedEmailHeaders['from'], $website)) {
+ // Skip email processing if email is an auto-forwarded message to prevent infinite loop.
+ if ($parser->getHeader('precedence') || $parser->getHeader('x-autoreply') || $parser->getHeader('x-autorespond') || 'auto-replied' == $parser->getHeader('auto-submitted')) {
return [
- 'message' => "Received email where the sender email address is present in the block list. Skipping this email from further processing.",
+ 'message' => "Received an auto-forwarded email which can lead to possible infinite loop of email exchanges. Skipping email from further processing.",
'content' => [
- 'from' => $resolvedEmailHeaders['from'],
+ 'from' => ! empty($addresses['from']) ? $addresses['from'] : null,
],
];
}
- // Check for self-referencing
- // 1. Skip email processing if a mailbox is configured by the sender's address
+ // Check for self-referencing. Skip email processing if a mailbox is configured by the sender's address.
try {
- $this->getMailboxByEmail($resolvedEmailHeaders['from']);
+ $this->getMailboxByEmail($addresses['from']);
return [
'message' => "Received a self-referencing email where the sender email address matches one of the configured mailbox address. Skipping email from further processing.",
'content' => [
- 'from' => $resolvedEmailHeaders['from'],
+ 'from' => !empty($addresses['from']) ? $addresses['from'] : null,
],
];
- } catch (\Exception $e) { /* No mailboxes found */ }
+ } catch (\Exception $e) {
+ // An exception being thrown means no mailboxes were found from the recipient's address. Continue processing.
+ }
+ }
- // 2. Skip email processing if a mailbox is configured by the reply-to email address
- try {
- if (!empty($resolvedEmailHeaders['reply-to'])) {
- $this->getMailboxByEmail($resolvedEmailHeaders['reply-to']);
-
- return [
- 'message' => "Received a self-referencing email where the reply-to email address matches one of the configured mailbox address. Skipping email from further processing.",
- 'content' => [
- 'from' => $resolvedEmailHeaders['reply-to'],
- ],
- ];
- }
- } catch (\Exception $e) { /* No mailboxes found */ }
+ $mailData['replyTo'] = '';
+
+ foreach ($addresses['to'] as $mailboxEmail){
+ if ($this->getMailboxByToEmail(strtolower($mailboxEmail))) {
+ $mailData['replyTo'] = $mailboxEmail;
+ }
}
- // Trigger email recieved event
- $event = new MaibloxWorkflowEvents\Email\EmailRecieved();
- $event
- ->setEmailHeaders($emailHeaders)
- ->setResolvedEmailHeaders($resolvedEmailHeaders)
- ;
+ // Process Mail - References
+ $addresses['to'][0] = isset($mailData['replyTo']) ? strtolower($mailData['replyTo']) : strtolower($addresses['to'][0]);
+ $mailData['replyTo'] = $addresses['to'];
+ $mailData['messageId'] = $parser->getHeader('message-id') ?: null;
+ $mailData['inReplyTo'] = htmlspecialchars_decode($parser->getHeader('in-reply-to'));
+ $mailData['referenceIds'] = htmlspecialchars_decode($parser->getHeader('references'));
+ $mailData['cc'] = array_filter(explode(',', $parser->getHeader('cc'))) ?: [];
+ $mailData['bcc'] = array_filter(explode(',', $parser->getHeader('bcc'))) ?: [];
+
+ // Process Mail - User Details
+ $mailData['source'] = 'email';
+ $mailData['createdBy'] = 'customer';
+ $mailData['role'] = 'ROLE_CUSTOMER';
+ $mailData['from'] = $addresses['from'];
+ $mailData['name'] = trim(current(explode('@', $from[0]['display'])));
+
+ // Process Mail - Content
+ try {
+ $htmlFilter = new HTMLFilter();
+ $mailData['subject'] = $parser->getHeader('subject');
+ $mailData['message'] = autolink($htmlFilter->addClassEmailReplyQuote($parser->getMessageBody('htmlEmbedded')));
+ $mailData['attachments'] = $parser->getAttachments();
+ } catch(\Exception $e) {
+ return [
+ 'error' => true,
+ 'message' => $e->getMessage(),
+ ];
+ }
+
+ if (! $mailData['message']) {
+ $mailData['message'] = autolink($htmlFilter->addClassEmailReplyQuote($parser->getMessageBody('text')));
+ }
- $this->container->get('event_dispatcher')->dispatch($event, 'uvdesk.automation.workflow.execute');
+ $website = $this->entityManager->getRepository(Website::class)->findOneByCode('knowledgebase');
+
+ if (! empty($mailData['from']) && $this->container->get('ticket.service')->isEmailBlocked($mailData['from'], $website)) {
+ return [
+ 'message' => "Received email where the sender email address is present in the block list. Skipping this email from further processing.",
+ 'content' => [
+ 'from' => !empty($mailData['from']) ? $mailData['from'] : null,
+ ],
+ ];
+ }
- $emailHeaders = $event->getEmailHeaders();
- $resolvedEmailHeaders = $event->getResolvedEmailHeaders();
+ // Search for any existing tickets
+ $ticket = $this->searchExistingTickets([
+ 'messageId' => $mailData['messageId'],
+ 'inReplyTo' => $mailData['inReplyTo'],
+ 'referenceIds' => $mailData['referenceIds'],
+ 'from' => $mailData['from'],
+ 'subject' => $mailData['subject'],
+ ]);
- $senderEmailAddress = $resolvedEmailHeaders['from'];
- $senderName = trim(current(explode('@', $emailHeaders['from'][0]['display'])));
+ if (empty($ticket)) {
+ $mailData['threadType'] = 'create';
+ $mailData['referenceIds'] = $mailData['messageId'];
- $mailboxEmail = null;
-
- $mailboxEmailCandidates = array_merge((array) $resolvedEmailHeaders['to'], (array) $resolvedEmailHeaders['delivered-to'], (array) $resolvedEmailHeaders['cc']);
- $mailboxEmailCandidates = array_values(array_unique(array_filter($mailboxEmailCandidates)));
+ // @Todo For same subject with same customer check
+ // $ticketSubjectReferenceExist = $this->searchTicketSubjectReference($mailData['from'], $mailData['subject']);
- foreach ($mailboxEmailCandidates as $emailAddress) {
- try {
- $mailbox = $this->getMailboxByEmail($emailAddress);
+ // if (!empty($ticketSubjectReferenceExist)) {
+ // return;
+ // }
+
+ $thread = $this->container->get('ticket.service')->createTicket($mailData);
- if (!empty($mailbox)) {
- $mailboxEmail = $emailAddress;
+ // Trigger ticket created event
+ $event = new CoreWorkflowEvents\Ticket\Create();
+ $event
+ ->setTicket($thread->getTicket())
+ ;
- break;
+ $this->container->get('event_dispatcher')->dispatch($event, 'uvdesk.automation.workflow.execute');
+ } else if (false === $ticket->getIsTrashed() && strtolower($ticket->getStatus()->getCode()) != 'spam' && !empty($mailData['inReplyTo'])) {
+ $mailData['threadType'] = 'reply';
+ $thread = $this->entityManager->getRepository(Thread::class)->findOneByMessageId($mailData['messageId']);
+ $ticketRef = $this->entityManager->getRepository(Ticket::class)->findById($ticket->getId());
+ $referenceIds = explode(' ', $ticketRef[0]->getReferenceIds());
+
+ if (!empty($thread)) {
+ // Thread with the same message id exists skip process.
+ return [
+ 'message' => "The contents of this email has already been processed.",
+ 'content' => [
+ 'from' => ! empty($mailData['from']) ? $mailData['from'] : null,
+ 'thread' => $thread->getId(),
+ 'ticket' => $ticket->getId(),
+ ],
+ ];
+ }
+
+ if (in_array($mailData['messageId'], $referenceIds)) {
+ // Thread with the same message id exists skip process.
+ return [
+ 'message' => "The contents of this email has already been processed.",
+ 'content' => [
+ 'from' => !empty($mailData['from']) ? $mailData['from'] : null,
+ ],
+ ];
+ }
+
+ if (
+ $ticket->getCustomer()
+ && $ticket->getCustomer()->getEmail() == $mailData['from']
+ ) {
+ // Reply from customer
+ $user = $ticket->getCustomer();
+
+ $mailData['user'] = $user;
+ $userDetails = $user->getCustomerInstance()->getPartialDetails();
+ } else if ($this->entityManager->getRepository(Ticket::class)->isTicketCollaborator($ticket, $mailData['from'])) {
+ // Reply from collaborator
+ $user = $this->entityManager->getRepository(User::class)->findOneByEmail($mailData['from']);
+
+ $mailData['user'] = $user;
+ $mailData['createdBy'] = 'collaborator';
+ $userDetails = $user->getCustomerInstance()->getPartialDetails();
+ } else {
+ $user = $this->entityManager->getRepository(User::class)->findOneByEmail($mailData['from']);
+
+ if (
+ ! empty($user)
+ && null != $user->getAgentInstance()
+ ) {
+ $mailData['user'] = $user;
+ $mailData['createdBy'] = 'agent';
+ $userDetails = $user->getAgentInstance()->getPartialDetails();
+ } else {
+ // Add user as a ticket collaborator
+ if (empty($user)) {
+ // Create a new user instance with customer support role
+ $role = $this->entityManager->getRepository(SupportRole::class)->findOneByCode('ROLE_CUSTOMER');
+
+ $user = $this->container->get('user.service')->createUserInstance($mailData['from'], $mailData['name'], $role, [
+ 'source' => 'email',
+ 'active' => true
+ ]);
+ }
+
+ $mailData['user'] = $user;
+ $userDetails = $user->getCustomerInstance()->getPartialDetails();
+
+ if (false == $this->entityManager->getRepository(Ticket::class)->isTicketCollaborator($ticket, $mailData['from'])) {
+ $ticket->addCollaborator($user);
+
+ $this->entityManager->persist($ticket);
+ $this->entityManager->flush();
+
+ $ticket->lastCollaborator = $user;
+
+ $event = new CoreWorkflowEvents\Ticket\Collaborator();
+ $event
+ ->setTicket($ticket)
+ ;
+
+ $this->container->get('event_dispatcher')->dispatch($event, 'uvdesk.automation.workflow.execute');
+ }
+ }
+ }
+
+ $mailData['fullname'] = $userDetails['name'];
+
+ $thread = $this->container->get('ticket.service')->createThread($ticket, $mailData);
+
+ if ($thread->getThreadType() == 'reply') {
+ if ($thread->getCreatedBy() == 'customer') {
+ $event = new CoreWorkflowEvents\Ticket\CustomerReply();
+ $event
+ ->setTicket($ticket)
+ ;
+ } else if ($thread->getCreatedBy() == 'collaborator') {
+ $event = new CoreWorkflowEvents\Ticket\CollaboratorReply();
+ $event
+ ->setTicket($ticket)
+ ;
+ } else {
+ $event = new CoreWorkflowEvents\Ticket\AgentReply();
+ $event
+ ->setTicket($ticket)
+ ;
}
- } catch (\Exception $e) { /* No mailboxes found */ }
+ }
+
+ // Trigger thread reply event
+ $this->container->get('event_dispatcher')->dispatch($event, 'uvdesk.automation.workflow.execute');
+ } else if (false === $ticket->getIsTrashed() && strtolower($ticket->getStatus()->getCode()) != 'spam' && empty($mailData['inReplyTo'])) {
+ return [
+ 'message' => "The contents of this email has already been processed.",
+ 'content' => [
+ 'from' => ! empty($mailData['from']) ? $mailData['from'] : null,
+ 'thread' => ! empty($thread) ? $thread->getId() : null,
+ 'ticket' => ! empty($ticket) ? $ticket->getId() : null,
+ ],
+ ];
}
- // Process Mail - References
- $mailData = [
- 'name' => $senderName,
- 'from' => $senderEmailAddress,
- 'role' => 'ROLE_CUSTOMER',
- 'source' => 'email',
- 'createdBy' => 'customer',
- 'mailboxEmail' => $mailboxEmail,
- 'cc' => $resolvedEmailHeaders['cc'] ?? [],
- 'bcc' => $resolvedEmailHeaders['bcc'] ?? [],
- 'messageId' => $emailParser->getHeader('message-id') != false ? $emailParser->getHeader('message-id') : null,
- 'inReplyTo' => $emailParser->getHeader('in-reply-to') != false ? htmlspecialchars_decode($emailParser->getHeader('in-reply-to')) : null,
- 'referenceIds' => $emailParser->getHeader('references') != false ? htmlspecialchars_decode($emailParser->getHeader('references')) : null,
- 'subject' => $emailParser->getHeader('subject') != false ? $emailParser->getHeader('subject') : null,
- 'text' => $emailParser->getMessageBody('text'),
- 'htmlEmbedded' => $emailParser->getMessageBody('htmlEmbedded'),
- 'attachments' => $emailParser->getAttachments(),
+ return [
+ 'message' => "Inbound email processed successfully.",
+ 'content' => [
+ 'from' => ! empty($mailData['from']) ? $mailData['from'] : null,
+ 'thread' => ! empty($thread) ? $thread->getId() : null,
+ 'ticket' => ! empty($ticket) ? $ticket->getId() : null,
+ ],
];
+ }
- // Format message content
- $htmlFilter = new HTMLFilter();
+ public function processOutlookMail(array $outlookEmail)
+ {
+ $mailData = [];
+ $senderName = null;
+ $senderAddress = null;
+
+ if (! empty($outlookEmail['from']['emailAddress']['address'])) {
+ $senderName = $outlookEmail['from']['emailAddress']['name'];
+ $senderAddress = $outlookEmail['from']['emailAddress']['address'];
+ } else if (! empty($outlookEmail['sender']['emailAddress']['address'])) {
+ $senderName = $outlookEmail['sender']['emailAddress']['name'];
+ $senderAddress = $outlookEmail['sender']['emailAddress']['address'];
+ } else {
+ return [
+ 'message' => "No 'from' email address was found while processing contents of email.",
+ 'content' => [],
+ ];
+ }
- $mailData['text'] = autolink($htmlFilter->addClassEmailReplyQuote($mailData['text']));
- $mailData['htmlEmbedded'] = autolink($htmlFilter->addClassEmailReplyQuote($mailData['htmlEmbedded']));
+ $toRecipients = array_map(function ($recipient) { return $recipient['emailAddress']['address']; }, $outlookEmail['toRecipients']);
+ $ccRecipients = array_map(function ($recipient) { return $recipient['emailAddress']['address']; }, $outlookEmail['ccRecipients'] ?? []);
+ $bccRecipients = array_map(function ($recipient) { return $recipient['emailAddress']['address']; }, $outlookEmail['bccRecipients'] ?? []);
+
+ $addresses = [
+ 'from' => $senderAddress,
+ 'to' => $toRecipients,
+ 'cc' => $ccRecipients,
+ ];
- $mailData['message'] = !empty($mailData['htmlEmbedded']) ? $mailData['htmlEmbedded'] : $mailData['text'];
+ // Skip email processing if no to-emails are specified
+ if (empty($addresses['to'])) {
+ return [
+ 'message' => "No 'to' email addresses were found in the email.",
+ 'content' => [
+ 'from' => $senderAddress ?? null,
+ ],
+ ];
+ }
+
+ // Check for self-referencing. Skip email processing if a mailbox is configured by the sender's address.
+ try {
+ $this->getMailboxByEmail($senderAddress);
+
+ return [
+ 'message' => "Received a self-referencing email where the sender email address matches one of the configured mailbox address. Skipping email from further processing.",
+ 'content' => [
+ 'from' => $senderAddress ?? null,
+ ],
+ ];
+ } catch (\Exception $e) {
+ // An exception being thrown means no mailboxes were found from the recipient's address. Continue processing.
+ }
+
+ // Process Mail - References
+ // $addresses['to'][0] = isset($mailData['replyTo']) ? strtolower($mailData['replyTo']) : strtolower($addresses['to'][0]);
+ $mailData['replyTo'] = $addresses['to'];
+
+ $mailData['messageId'] = $outlookEmail['internetMessageId'];
+ $mailData['outlookConversationId'] = $outlookEmail['conversationId'];
+ $mailData['inReplyTo'] = $outlookEmail['conversationId'];
+ // $mailData['inReplyTo'] = htmlspecialchars_decode($parser->getHeader('in-reply-to'));
+ $mailData['referenceIds'] = '';
+ // $mailData['referenceIds'] = htmlspecialchars_decode($parser->getHeader('references'));
+ $mailData['cc'] = $ccRecipients;
+ $mailData['bcc'] = $bccRecipients;
+
+ // Process Mail - User Details
+ $mailData['source'] = 'email';
+ $mailData['createdBy'] = 'customer';
+ $mailData['role'] = 'ROLE_CUSTOMER';
+ $mailData['from'] = $senderAddress;
+ $mailData['name'] = trim($senderName);
+
+ // Process Mail - Content
+ $htmlFilter = new HTMLFilter();
+ $mailData['subject'] = $outlookEmail['subject'];
+ $mailData['message'] = autolink($htmlFilter->addClassEmailReplyQuote($outlookEmail['body']['content']));
+
+ $mailData['attachments'] = [];
+ $mailData['attachmentContent'] = isset($outlookEmail['outlookAttachments']) ? $outlookEmail['outlookAttachments'] : [];
+
+ $website = $this->entityManager->getRepository(Website::class)->findOneByCode('knowledgebase');
+ if (
+ ! empty($mailData['from'])
+ && $this->container->get('ticket.service')->isEmailBlocked($mailData['from'], $website)
+ ) {
+ return [
+ 'message' => "Received email where the sender email address is present in the block list. Skipping this email from further processing.",
+ 'content' => [
+ 'from' => !empty($mailData['from']) ? $mailData['from'] : null,
+ ],
+ ];
+ }
+
+ // return [
+ // 'outlookConversationId' => $mailData['outlookConversationId'],
+ // 'message' => "No 'to' email addresses were found in the email.",
+ // 'content' => [
+ // 'outlookConversationId' => $mailData['outlookConversationId'],
+ // ],
+ // ];
+
// Search for any existing tickets
$ticket = $this->searchExistingTickets([
- 'messageId' => $mailData['messageId'],
- 'inReplyTo' => $mailData['inReplyTo'],
- 'referenceIds' => $mailData['referenceIds'],
- 'from' => $mailData['from'],
- 'subject' => $mailData['subject'],
+ 'messageId' => $mailData['messageId'],
+ 'inReplyTo' => $mailData['inReplyTo'],
+ 'referenceIds' => $mailData['referenceIds'],
+ 'from' => $mailData['from'],
+ 'subject' => $mailData['subject'],
+ 'outlookConversationId' => $mailData['outlookConversationId'],
]);
if (empty($ticket)) {
$mailData['threadType'] = 'create';
$mailData['referenceIds'] = $mailData['messageId'];
- // @TODO: Concatenate two tickets for same customer with same subject depending on settings
+ // @Todo For same subject with same customer check
+ // $ticketSubjectReferenceExist = $this->searchTicketSubjectReference($mailData['from'], $mailData['subject']);
+
+ // if(!empty($ticketSubjectReferenceExist)) {
+ // return;
+ // }
+
$thread = $this->container->get('ticket.service')->createTicket($mailData);
// Trigger ticket created event
@@ -443,18 +788,22 @@ public function processMail($emailContents)
;
$this->container->get('event_dispatcher')->dispatch($event, 'uvdesk.automation.workflow.execute');
- } else if (false === $ticket->getIsTrashed() && strtolower($ticket->getStatus()->getCode()) != 'spam' && !empty($mailData['inReplyTo'])) {
- $ticketRef = $this->entityManager->getRepository(Ticket::class)->findById($ticket->getId());
+ } else if (
+ false === $ticket->getIsTrashed()
+ && strtolower($ticket->getStatus()->getCode()) != 'spam'
+ && ! empty($mailData['inReplyTo'])
+ ) {
+ $mailData['threadType'] = 'reply';
$thread = $this->entityManager->getRepository(Thread::class)->findOneByMessageId($mailData['messageId']);
-
+ $ticketRef = $this->entityManager->getRepository(Ticket::class)->findById($ticket->getId());
$referenceIds = explode(' ', $ticketRef[0]->getReferenceIds());
- if (!empty($thread)) {
+ if (! empty($thread)) {
// Thread with the same message id exists skip process.
return [
- 'message' => "The contents of this email has already been processed.",
+ 'message' => "The contents of this email has already been processed 1.",
'content' => [
- 'from' => !empty($mailData['from']) ? $mailData['from'] : null,
+ 'from' => ! empty($mailData['from']) ? $mailData['from'] : null,
'thread' => $thread->getId(),
'ticket' => $ticket->getId(),
],
@@ -464,7 +813,7 @@ public function processMail($emailContents)
if (in_array($mailData['messageId'], $referenceIds)) {
// Thread with the same message id exists skip process.
return [
- 'message' => "The contents of this email has already been processed.",
+ 'message' => "The contents of this email has already been processed 2.",
'content' => [
'from' => !empty($mailData['from']) ? $mailData['from'] : null,
],
@@ -486,8 +835,7 @@ public function processMail($emailContents)
$userDetails = $user->getCustomerInstance()->getPartialDetails();
} else {
$user = $this->entityManager->getRepository(User::class)->findOneByEmail($mailData['from']);
-
- if (!empty($user) && null != $user->getAgentInstance()) {
+ if (! empty($user) && null != $user->getAgentInstance()) {
$mailData['user'] = $user;
$mailData['createdBy'] = 'agent';
$userDetails = $user->getAgentInstance()->getPartialDetails();
@@ -524,7 +872,6 @@ public function processMail($emailContents)
}
}
- $mailData['threadType'] = 'reply';
$mailData['fullname'] = $userDetails['name'];
$thread = $this->container->get('ticket.service')->createThread($ticket, $mailData);
@@ -552,22 +899,22 @@ public function processMail($emailContents)
$this->container->get('event_dispatcher')->dispatch($event, 'uvdesk.automation.workflow.execute');
} else if (false === $ticket->getIsTrashed() && strtolower($ticket->getStatus()->getCode()) != 'spam' && empty($mailData['inReplyTo'])) {
return [
- 'message' => "The contents of this email has already been processed.",
+ 'message' => "The contents of this email has already been processed 3.",
'content' => [
- 'from' => !empty($mailData['from']) ? $mailData['from'] : null,
- 'thread' => !empty($thread) ? $thread->getId() : null,
- 'ticket' => !empty($ticket) ? $ticket->getId() : null,
+ 'from' => ! empty($mailData['from']) ? $mailData['from'] : null,
+ 'thread' => ! empty($thread) ? $thread->getId() : null,
+ 'ticket' => ! empty($ticket) ? $ticket->getId() : null,
],
];
}
return [
- 'message' => "Inbound email processsed successfully.",
+ 'message' => "Inbound email processed successfully.",
'content' => [
- 'from' => !empty($mailData['from']) ? $mailData['from'] : null,
- 'thread' => !empty($thread) ? $thread->getId() : null,
- 'ticket' => !empty($ticket) ? $ticket->getId() : null,
- ],
+ 'from' => ! empty($mailData['from']) ? $mailData['from'] : null,
+ 'thread' => ! empty($thread) ? $thread->getId() : null,
+ 'ticket' => ! empty($ticket) ? $ticket->getId() : null,
+ ],
];
}
-}
+}
\ No newline at end of file
diff --git a/Templates/Default.yaml b/Templates/Default.yaml
new file mode 100644
index 0000000..1982ca9
--- /dev/null
+++ b/Templates/Default.yaml
@@ -0,0 +1,39 @@
+uvdesk_mailbox:
+ emails: ~
+ # Often Reply emails like from gmail contains extra and redundant previous mail data.
+ # This data can be removed by adding delimiter i.e. specific line before each reply.
+ # delimiter: '<-- Please add content above this line -->'
+ # enable_delimiter: true
+
+ # Specify id of the mailbox you want to use as default for sending emails when no other "configured" mailbox is found.
+ # Applies to all emails sent through the system & in cases of tickets where the original source mailbox of the created
+ # ticket is no longer available.
+ default_mailbox: ~
+
+ # Configure your mailboxes here
+ mailboxes: ~
+ # mailbox_id:
+ # name: 'Mailbox'
+ # enabled: true
+ # disable_outbound_emails: false
+ # use_strict_mode: false
+
+ # # Incoming email settings
+ # # IMAP settings to use for fetching emails from mailbox
+ # imap_server:
+ # host: ~
+ # username: ~
+ # password: ~
+
+ # # Outgoing email settings
+ # # SMTP settings to use for sending emails from mailbox
+ # smtp_server:
+ # host: ~
+ # port: ~
+ # username: ~
+ # password: ~
+ # sender_address: ~
+ #
+ # # For app transport method
+ # type: ~
+ # client: ~
diff --git a/Templates/Mailbox/IMAP/AppConfiguration.php b/Templates/Mailbox/IMAP/AppConfiguration.php
new file mode 100644
index 0000000..eb26fe4
--- /dev/null
+++ b/Templates/Mailbox/IMAP/AppConfiguration.php
@@ -0,0 +1,9 @@
+
\ No newline at end of file
diff --git a/Templates/Mailbox/IMAP/DefaultConfiguration.php b/Templates/Mailbox/IMAP/DefaultConfiguration.php
new file mode 100644
index 0000000..22b3e60
--- /dev/null
+++ b/Templates/Mailbox/IMAP/DefaultConfiguration.php
@@ -0,0 +1,10 @@
+
\ No newline at end of file
diff --git a/Templates/Mailbox/IMAP/SimpleConfiguration.php b/Templates/Mailbox/IMAP/SimpleConfiguration.php
new file mode 100644
index 0000000..a7b9b20
--- /dev/null
+++ b/Templates/Mailbox/IMAP/SimpleConfiguration.php
@@ -0,0 +1,8 @@
+
\ No newline at end of file
diff --git a/Templates/Mailbox/Mailbox.php b/Templates/Mailbox/Mailbox.php
new file mode 100644
index 0000000..343c8cf
--- /dev/null
+++ b/Templates/Mailbox/Mailbox.php
@@ -0,0 +1,77 @@
+'
+ # enable_delimiter: true
+
+ # Specify id of the mailbox you want to use as default for sending emails when no other "configured" mailbox is found.
+ # Applies to all emails sent through the system & in cases of tickets where the original source mailbox of the created
+ # ticket is no longer available.
+TEMPLATE;
+
+if ($this->getDefaultMailbox() == null) {
+ $template .= <<
$this->getDefaultMailbox() ? $this->getDefaultMailbox()->getId() : null,
+ '[[ MAILBOXES ]]' => $mailboxes,
+]);
+
+?>
\ No newline at end of file
diff --git a/Templates/Mailbox/MailboxSettings.php b/Templates/Mailbox/MailboxSettings.php
new file mode 100644
index 0000000..4bbb1c1
--- /dev/null
+++ b/Templates/Mailbox/MailboxSettings.php
@@ -0,0 +1,53 @@
+ $this->getId(),
+ '[[ name ]]' => $this->getName(),
+ '[[ disable_outbound_emails ]]' => $this->getIsEmailDeliveryDisabled() ? 'true' : 'false',
+ '[[ status ]]' => $this->getIsEnabled() ? 'true' : 'false',
+ '[[ use_strict_mode ]]' => $this->getIsStrictModeEnabled() ? 'true' : 'false',
+ '[[ smtp_settings ]]' => $smtpTemplate,
+ '[[ imap_settings ]]' => $imapTemplate,
+ '[[ swift_mailer_settings ]]' => $swiftMailerTemplate,
+]);
+
+?>
\ No newline at end of file
diff --git a/Templates/Mailbox/SMTP/AppConfiguration.php b/Templates/Mailbox/SMTP/AppConfiguration.php
new file mode 100644
index 0000000..d6022b5
--- /dev/null
+++ b/Templates/Mailbox/SMTP/AppConfiguration.php
@@ -0,0 +1,21 @@
+ $smtpConfiguration->getClient(),
+ '[[ username ]]' => $smtpConfiguration->getUsername(),
+ '[[ type ]]' => $smtpConfiguration->getType(),
+]);
+
+?>
\ No newline at end of file
diff --git a/Templates/Mailbox/SMTP/DefaultConfiguration.php b/Templates/Mailbox/SMTP/DefaultConfiguration.php
new file mode 100644
index 0000000..bdb5745
--- /dev/null
+++ b/Templates/Mailbox/SMTP/DefaultConfiguration.php
@@ -0,0 +1,31 @@
+getSenderAddress() != null) {
+ $template .= << $smtpConfiguration->getHost(),
+ '[[ username ]]' => $smtpConfiguration->getUsername(),
+ '[[ password ]]' => $smtpConfiguration->getPassword(),
+ '[[ port ]]' => $smtpConfiguration->getPort(),
+ '[[ sender_address ]]' => method_exists($smtpConfiguration, 'getSenderAddress') ? $smtpConfiguration->getSenderAddress() : null,
+]);
+
+?>
\ No newline at end of file
diff --git a/Templates/Mailbox/SwiftMailerSettings.php b/Templates/Mailbox/SwiftMailerSettings.php
new file mode 100644
index 0000000..7382d17
--- /dev/null
+++ b/Templates/Mailbox/SwiftMailerSettings.php
@@ -0,0 +1,11 @@
+
\ No newline at end of file
diff --git a/Templates/PackageConfigurations/Mailbox.php b/Templates/PackageConfigurations/Mailbox.php
deleted file mode 100644
index 13f87f5..0000000
--- a/Templates/PackageConfigurations/Mailbox.php
+++ /dev/null
@@ -1,24 +0,0 @@
-
\ No newline at end of file
diff --git a/Templates/PackageConfigurations/Template.php b/Templates/PackageConfigurations/Template.php
deleted file mode 100644
index d8ff0a6..0000000
--- a/Templates/PackageConfigurations/Template.php
+++ /dev/null
@@ -1,16 +0,0 @@
-'
- # enable_delimiter: true
-
- # Configure your mailboxes here
- mailboxes:
-[[ MAILBOXES ]]
-TEMPLATE;
-
-?>
\ No newline at end of file
diff --git a/Templates/config.yaml b/Templates/config.yaml
deleted file mode 100644
index 8f5bcfe..0000000
--- a/Templates/config.yaml
+++ /dev/null
@@ -1,24 +0,0 @@
-uvdesk_mailbox:
- emails: ~
- # Often Reply emails like from gmail contains extra and redundant previous mail data.
- # This data can be removed by adding delimiter i.e. specific line before each reply.
- # delimiter: '<-- Please add content above this line -->'
- # enable_delimiter: true
-
- # Configure your mailboxes here
- mailboxes: ~
- # default:
- # name: 'Sample Mailbox'
- # enabled: true
-
- # # [SMTP] Outgoing mail server
- # # Swiftmailer smtp mailer to use for sending emails through on behalf of this mailbox
- # smtp_server:
- # mailer_id: ~
-
- # # [IMAP] Incoming mail server
- # # IMAP configurations to use for fetching emails from mailbox
- # imap_server:
- # host: ~
- # username: ~
- # password: ~
diff --git a/Utils/IMAP/Configuration.php b/Utils/IMAP/Configuration.php
new file mode 100644
index 0000000..2195a8e
--- /dev/null
+++ b/Utils/IMAP/Configuration.php
@@ -0,0 +1,107 @@
+isInstantiable() && $reflectionClass->implementsInterface(TransportConfigurationInterface::class)) {
+ self::$reflectedDefinitions[] = $reflectionClass;
+ }
+ } catch (\ReflectionException $exception) {
+ continue;
+ } catch (\RuntimeException $exception) {
+ continue;
+ }
+ }
+ }
+
+ return self::$reflectedDefinitions;
+ }
+
+ public static function getSupportedTransportTypes(): array
+ {
+ return array_map(function ($reflectionClass) {
+ return $reflectionClass->getName()::getCode();
+ }, self::getAvailableDefinitions());
+ }
+
+ public static function guessTransportDefinition(array $params): TransportConfigurationInterface
+ {
+ foreach (self::getAvailableDefinitions() as $reflectedImapDefinition) {
+ // Use default configuration only when no other transport type matches the provided configs
+ if (true === $reflectedImapDefinition->implementsInterface(DefaultTransportConfigurationInterface::class)) {
+ $defaultConfigurationReflection = $reflectedImapDefinition;
+
+ continue;
+ }
+
+ $imapInstance = $reflectedImapDefinition->newInstance();
+
+ if ($imapInstance instanceof AppTransportConfigurationInterface || $imapInstance instanceof SimpleTransportConfigurationInterface) {
+ if (empty($params['host'])) {
+ return $imapInstance;
+ }
+ } else if (!empty($params['host']) && $imapInstance->getHost() == $params['host']) {
+ return $imapInstance;
+ }
+ }
+
+ if (!empty($defaultConfigurationReflection)) {
+ return $defaultConfigurationReflection->newInstance($params['host']);
+ }
+
+ throw new \Exception('No matching imap definition found for host address "' . $params['host'] . '".');
+ }
+
+ public static function createTransportDefinition($transportCode, $host = null): TransportConfigurationInterface
+ {
+ if (false == in_array($transportCode, self::getSupportedTransportTypes(), true)) {
+ throw new \Exception('No imap definition found for transport type "' . $transportCode . '".');
+ }
+
+ foreach (self::getAvailableDefinitions() as $reflectedImapDefinition) {
+ if ($reflectedImapDefinition->getName()::getCode() !== $transportCode) {
+ continue;
+ }
+
+ if (true === $reflectedImapDefinition->implementsInterface(DefaultTransportConfigurationInterface::class)) {
+ return $reflectedImapDefinition->newInstance($host);
+ }
+
+ return $reflectedImapDefinition->newInstance();
+ }
+ }
+}
diff --git a/Utils/IMAP/Transport/AppTransportConfigurationInterface.php b/Utils/IMAP/Transport/AppTransportConfigurationInterface.php
new file mode 100644
index 0000000..d9997ad
--- /dev/null
+++ b/Utils/IMAP/Transport/AppTransportConfigurationInterface.php
@@ -0,0 +1,18 @@
+username = $username;
+
+ return $this;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ public function setPassword($password)
+ {
+ $this->password = $password;
+
+ return $this;
+ }
+
+ public function getPassword()
+ {
+ return $this->password;
+ }
+}
diff --git a/Utils/IMAP/Transport/Type/IMAP.php b/Utils/IMAP/Transport/Type/IMAP.php
new file mode 100644
index 0000000..974c78e
--- /dev/null
+++ b/Utils/IMAP/Transport/Type/IMAP.php
@@ -0,0 +1,69 @@
+setHost($host);
+
+ return $this;
+ }
+
+ public static function getCode()
+ {
+ return self::CODE;
+ }
+
+ public static function getName()
+ {
+ return self::NAME;
+ }
+
+ public function setHost($host)
+ {
+ $this->host = $host;
+
+ return $this;
+ }
+
+ public function getHost()
+ {
+ return $this->host;
+ }
+
+ public function setUsername($username)
+ {
+ $this->username = $username;
+
+ return $this;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ public function setPassword($password)
+ {
+ $this->password = $password;
+
+ return $this;
+ }
+
+ public function getPassword()
+ {
+ return $this->password;
+ }
+}
diff --git a/Utils/IMAP/Transport/Type/Outlook.php b/Utils/IMAP/Transport/Type/Outlook.php
new file mode 100644
index 0000000..794a594
--- /dev/null
+++ b/Utils/IMAP/Transport/Type/Outlook.php
@@ -0,0 +1,55 @@
+username = $username;
+
+ return $this;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ public function setPassword($password)
+ {
+ $this->password = $password;
+
+ return $this;
+ }
+
+ public function getPassword()
+ {
+ return $this->password;
+ }
+}
diff --git a/Utils/IMAP/Transport/Type/OutlookModernAuth.php b/Utils/IMAP/Transport/Type/OutlookModernAuth.php
new file mode 100644
index 0000000..40c2abb
--- /dev/null
+++ b/Utils/IMAP/Transport/Type/OutlookModernAuth.php
@@ -0,0 +1,49 @@
+client = $client;
+
+ return $this;
+ }
+
+ public function getClient()
+ {
+ return $this->client;
+ }
+
+ public function setUsername($username)
+ {
+ $this->username = $username;
+
+ return $this;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+}
diff --git a/Utils/IMAP/Transport/Type/Webhook.php b/Utils/IMAP/Transport/Type/Webhook.php
new file mode 100644
index 0000000..d428265
--- /dev/null
+++ b/Utils/IMAP/Transport/Type/Webhook.php
@@ -0,0 +1,36 @@
+username = $username;
+
+ return $this;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+}
diff --git a/Utils/IMAP/Transport/Type/Yahoo.php b/Utils/IMAP/Transport/Type/Yahoo.php
new file mode 100644
index 0000000..947ba13
--- /dev/null
+++ b/Utils/IMAP/Transport/Type/Yahoo.php
@@ -0,0 +1,55 @@
+username = $username;
+
+ return $this;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ public function setPassword($password)
+ {
+ $this->password = $password;
+
+ return $this;
+ }
+
+ public function getPassword()
+ {
+ return $this->password;
+ }
+}
diff --git a/Utils/Imap/Configuration.php b/Utils/Imap/Configuration.php
index ba8ab85..8c233e4 100644
--- a/Utils/Imap/Configuration.php
+++ b/Utils/Imap/Configuration.php
@@ -65,7 +65,7 @@ public static function guessTransportDefinition($host) : ConfigurationInterface
}
}
- if (!empty($customConfigurationReflection)) {
+ if (! empty($customConfigurationReflection)) {
return $customConfigurationReflection->newInstance($host);
}
diff --git a/Utils/Mailbox/Mailbox.php b/Utils/Mailbox/Mailbox.php
index 1befa83..ae1f999 100644
--- a/Utils/Mailbox/Mailbox.php
+++ b/Utils/Mailbox/Mailbox.php
@@ -3,24 +3,36 @@
namespace Webkul\UVDesk\MailboxBundle\Utils\Mailbox;
use Webkul\UVDesk\CoreFrameworkBundle\Utils\TokenGenerator;
-use Webkul\UVDesk\MailboxBundle\Utils\Imap\ConfigurationInterface as ImapConfiguration;
+use Webkul\UVDesk\MailboxBundle\Utils\IMAP;
+use Webkul\UVDesk\MailboxBundle\Utils\SMTP;
use Webkul\UVDesk\CoreFrameworkBundle\Utils\SwiftMailer\BaseConfiguration as SwiftMailerConfiguration;
class Mailbox
{
CONST TOKEN_RANGE = '12345';
- const TEMPLATE = __DIR__ . "/../../Templates/PackageConfigurations/Mailbox.php";
+
+ const IMAP_APP_CONFIGURATION_TEMPLATE = __DIR__ . "/../../Templates/Mailbox/IMAP/AppConfiguration.php";
+ const IMAP_DEFAULT_CONFIGURATION_TEMPLATE = __DIR__ . "/../../Templates/Mailbox/IMAP/DefaultConfiguration.php";
+ const IMAP_SIMPLE_CONFIGURATION_TEMPLATE = __DIR__ . "/../../Templates/Mailbox/IMAP/SimpleConfiguration.php";
+
+ const SMTP_APP_CONFIGURATION_TEMPLATE = __DIR__ . "/../../Templates/Mailbox/SMTP/AppConfiguration.php";
+ const SMTP_DEFAULT_CONFIGURATION_TEMPLATE = __DIR__ . "/../../Templates/Mailbox/SMTP/DefaultConfiguration.php";
+
+ const MAILBOX_CONFIGURATION_TEMPLATE = __DIR__ . "/../../Templates/Mailbox/MailboxSettings.php";
+ const SWIFT_MAILER_CONFIGURATION_TEMPLATE = __DIR__ . "/../../Templates/Mailbox/SwiftMailerSettings.php";
private $id = null;
private $name = null;
- private $isEnabled = false;
- private $isDeleted = false;
+ private $isEnabled = true;
+ private $isEmailDeliveryDisabled = false;
+ private $isStrictModeEnabled = false;
private $imapConfiguration = null;
- private $swiftmailerConfiguration = null;
+ private $smtpConfiguration = null;
+ private $swiftMailerConfiguration = null;
public function __construct($id = null)
{
- $this->id = $id;
+ $this->setId($id ?? sprintf("mailbox_%s", TokenGenerator::generateToken(4, self::TOKEN_RANGE)));
}
private function setId($id)
@@ -57,62 +69,115 @@ public function getIsEnabled() : bool
return $this->isEnabled;
}
- public function getIsDeleted() : bool
+ public function setIsEmailDeliveryDisabled(bool $isEmailDeliveryDisabled)
{
- return $this->isDeleted;
+ $this->isEmailDeliveryDisabled = $isEmailDeliveryDisabled;
+
+ return $this;
}
- public function setIsDeleted(bool $isDeleted)
+ public function getIsEmailDeliveryDisabled() : bool
{
- $this->isDeleted = $isDeleted;
+ return $this->isEmailDeliveryDisabled;
+ }
+
+ public function setIsStrictModeEnabled($isStrictModeEnabled)
+ {
+ $this->isStrictModeEnabled = $isStrictModeEnabled;
return $this;
}
+ public function getIsStrictModeEnabled()
+ {
+ return $this->isStrictModeEnabled;
+ }
- public function setImapConfiguration(ImapConfiguration $imapConfiguration)
+ public function setImapConfiguration(IMAP\Transport\TransportConfigurationInterface $imapConfiguration)
{
$this->imapConfiguration = $imapConfiguration;
return $this;
}
- public function getImapConfiguration() : ?ImapConfiguration
+ public function getImapConfiguration() : ?IMAP\Transport\TransportConfigurationInterface
{
return $this->imapConfiguration;
}
- public function setSwiftMailerConfiguration(SwiftMailerConfiguration $swiftmailerConfiguration)
+ public function setSmtpConfiguration(SMTP\Transport\TransportConfigurationInterface $smtpConfiguration)
{
- $this->swiftmailerConfiguration = $swiftmailerConfiguration;
+ $this->smtpConfiguration = $smtpConfiguration;
+
+ return $this;
+ }
+
+ public function getSmtpConfiguration() : ?SMTP\Transport\TransportConfigurationInterface
+ {
+ return $this->smtpConfiguration;
+ }
+
+ public function setSwiftMailerConfiguration(SwiftMailerConfiguration $swiftMailerConfiguration)
+ {
+ $this->swiftMailerConfiguration = $swiftMailerConfiguration;
return $this;
}
public function getSwiftMailerConfiguration() : ?SwiftMailerConfiguration
{
- return $this->swiftmailerConfiguration;
+ return $this->swiftMailerConfiguration;
}
public function __toString()
{
- if (null == $this->getId()) {
- // Set random id
- $this->setId(sprintf("mailbox_%s", TokenGenerator::generateToken(4, self::TOKEN_RANGE)));
+ $imapConfiguration = $this->getImapConfiguration();
+ $smtpConfiguration = $this->getSmtpConfiguration();
+ $swiftMailerConfiguration = $this->getSwiftMailerConfiguration();
+
+ $imapTemplate = '';
+
+ if (! empty($imapConfiguration)) {
+ if ($imapConfiguration instanceof IMAP\Transport\AppTransportConfigurationInterface) {
+ $imapTemplate = strtr(require self::IMAP_APP_CONFIGURATION_TEMPLATE, [
+ '[[ imap_client ]]' => $imapConfiguration->getClient(),
+ '[[ imap_username ]]' => $imapConfiguration->getUsername(),
+ ]);
+ } else if ($imapConfiguration instanceof IMAP\Transport\SimpleTransportConfigurationInterface) {
+ $imapTemplate = strtr(require self::IMAP_SIMPLE_CONFIGURATION_TEMPLATE, [
+ '[[ imap_username ]]' => $imapConfiguration->getUsername(),
+ ]);
+ } else {
+ $imapTemplate = strtr(require self::IMAP_DEFAULT_CONFIGURATION_TEMPLATE, [
+ '[[ imap_host ]]' => $imapConfiguration->getHost(),
+ '[[ imap_username ]]' => $imapConfiguration->getUsername(),
+ '[[ imap_password ]]' => $imapConfiguration->getPassword(),
+ ]);
+ }
}
- $imapConfiguration = $this->getImapConfiguration();
- $swiftmailerConfiguration = $this->getSwiftMailerConfiguration();
-
- return strtr(require self::TEMPLATE, [
- '[[ id ]]' => $this->getId(),
- '[[ name ]]' => $this->getName(),
- '[[ status ]]' => $this->getIsEnabled() ? 'true' : 'false',
- '[[ delete_status ]]' => $this->getIsDeleted() ? 'true' : 'false',
- '[[ swiftmailer_id ]]' => $swiftmailerConfiguration ? $swiftmailerConfiguration->getId() : '~',
- '[[ imap_host ]]' => $imapConfiguration->getHost(),
- '[[ imap_username ]]' => $imapConfiguration->getUsername(),
- '[[ imap_password ]]' => $imapConfiguration->getPassword(),
- ]);
+ $smtpTemplate = '';
+
+ if (!empty($smtpConfiguration)) {
+ if ($smtpConfiguration instanceof SMTP\Transport\AppTransportConfigurationInterface) {
+ $smtpTemplate = strtr(require self::SMTP_APP_CONFIGURATION_TEMPLATE, [
+ '[[ client ]]' => $smtpConfiguration->getClient(),
+ '[[ username ]]' => $smtpConfiguration->getUsername(),
+ '[[ type ]]' => $smtpConfiguration->getType(),
+ ]);
+ } else {
+ $smtpTemplate = (require self::SMTP_DEFAULT_CONFIGURATION_TEMPLATE);
+ }
+ }
+
+ $swiftMailerTemplate = '';
+
+ if (! empty($swiftMailerConfiguration)) {
+ $swiftMailerTemplate = strtr(require self::SWIFT_MAILER_CONFIGURATION_TEMPLATE, [
+ '[[ swiftMailer_id ]]' => $swiftMailerConfiguration->getId(),
+ ]);
+ }
+
+ return require self::MAILBOX_CONFIGURATION_TEMPLATE;
}
}
diff --git a/Utils/MailboxConfiguration.php b/Utils/MailboxConfiguration.php
index 6b103ce..59db683 100644
--- a/Utils/MailboxConfiguration.php
+++ b/Utils/MailboxConfiguration.php
@@ -3,66 +3,135 @@
namespace Webkul\UVDesk\MailboxBundle\Utils;
use Webkul\UVDesk\MailboxBundle\Utils\Mailbox\Mailbox;
+use Webkul\UVDesk\MailboxBundle\Utils\IMAP;
final class MailboxConfiguration
{
- const DEFAULT_TEMPLATE = __DIR__ . "/../Templates/config.yaml";
- const CONFIGURATION_TEMPLATE = __DIR__ . "/../Templates/PackageConfigurations/Template.php";
+ const DEFAULT_TEMPLATE = __DIR__ . "/../Templates/Default.yaml";
+ const CONFIGURATION_TEMPLATE = __DIR__ . "/../Templates/Mailbox/Mailbox.php";
private $collection = [];
+ private $defaultMailbox = null;
+
+ public function __construct($defaultMailbox = null)
+ {
+ $this->defaultMailbox = $defaultMailbox;
+ }
public function addMailbox(Mailbox $mailbox)
{
- if (preg_match('/"/', $mailbox->getImapConfiguration()->getHost())) {
- $mailbox->getImapConfiguration()->setHost(trim($mailbox->getImapConfiguration()->getHost(), '"'));
- }
+ $imapConfiguration = $mailbox->getImapConfiguration();
+
+ if (
+ ! empty($imapConfiguration)
+ && !$imapConfiguration instanceof IMAP\Transport\AppTransportConfigurationInterface
+ && !$imapConfiguration instanceof IMAP\Transport\SimpleTransportConfigurationInterface
+ ) {
+ if (preg_match('/"/', $imapConfiguration->getHost())) {
+ $imapConfiguration->setHost(trim($imapConfiguration->getHost(), '"'));
+ }
+
+ if (preg_match("/'/", $imapConfiguration->getHost())) {
+ $imapConfiguration->setHost(trim($imapConfiguration->getHost(), "'"));
+ }
- if (preg_match("/'/", $mailbox->getImapConfiguration()->getHost())) {
- $mailbox->getImapConfiguration()->setHost(trim($mailbox->getImapConfiguration()->getHost(), "'"));
+ $mailbox->setImapConfiguration($imapConfiguration);
}
- $this->collection[] = $mailbox;
+ $this->collection[$mailbox->getId()] = $mailbox;
return $this;
}
public function removeMailbox(Mailbox $mailbox)
{
- if ($mailbox->getId() != null) {
- foreach ($this->collection as $index => $configuration) {
- if ($configuration->getId() == null) {
- continue;
- }
-
- if ($configuration->getId() == $mailbox->getId()) {
- unset($this->collection[$index]);
- break;
- }
- }
+ if ($mailbox->getId() != null && !empty($this->collection[$mailbox->getId()])) {
+ unset($this->collection[$mailbox->getId()]);
}
- $this->collection = array_values($this->collection);
-
return $this;
}
- public function getMailboxes() : array
+ public function getMailboxes(): array
{
return $this->collection;
}
+ public function getDefaultMailbox(): ?Mailbox
+ {
+ if (
+ ! empty($this->defaultMailbox)
+ && !empty($this->collection[$this->defaultMailbox])
+ ) {
+ return $this->collection[$this->defaultMailbox];
+ }
+
+ return null;
+ }
+
+ public function setDefaultMailbox(Mailbox $mailbox): self
+ {
+ if ($mailbox->getId() == null) {
+ throw new \Exception("Cannot set the provided mailbox as default mailbox since no mailbox id is available.");
+ } else if (empty($this->collection[$mailbox->getId()])) {
+ throw new \Exception("Cannot set the provided mailbox as default mailbox since it's not part of the collection.");
+ }
+
+ $this->defaultMailbox = $mailbox->getId();
+
+ return $this;
+ }
+
+ public function getMailboxById($mailboxId): ?Mailbox
+ {
+ if (! empty($this->collection[$mailboxId])) {
+ return $this->collection[$mailboxId];
+ }
+
+ return null;
+ }
+
+ public function getMailboxByEmailAddress($mailboxEmail): ?Mailbox
+ {
+ foreach ($this->collection as $mailbox) {
+ $smtpConfiguration = $mailbox->getSmtpConfiguration();
+
+ if (! empty($smtpConfiguration) && $smtpConfiguration->getUsername() == $mailboxEmail) {
+ return $mailbox;
+ }
+ }
+
+ return null;
+ }
+
+ public function getIncomingMailboxByEmailAddress($mailboxEmail): ?Mailbox
+ {
+ foreach ($this->collection as $mailbox) {
+ $imapConfiguration = $mailbox->getImapConfiguration();
+
+ if (! empty($imapConfiguration) && $imapConfiguration->getUsername() == $mailboxEmail) {
+ return $mailbox;
+ }
+ }
+
+ return null;
+ }
+
+ public function getOutgoingMailboxByEmailAddress($mailboxEmail): ?Mailbox
+ {
+ return $this->getMailboxByEmailAddress($mailboxEmail);
+ }
+
public function __toString()
{
- if (!empty($this->collection)) {
- $stream = array_reduce($this->collection, function($stream, $mailbox) {
- return $stream . (string) $mailbox;
+ if (! empty($this->collection)) {
+ $mailboxes = array_reduce($this->collection, function($mailboxes, $mailbox) {
+ return $mailboxes . (string) $mailbox;
}, '');
-
- return strtr(require self::CONFIGURATION_TEMPLATE, [
- '[[ MAILBOXES ]]' => $stream,
- ]);
+
+ return require self::CONFIGURATION_TEMPLATE;
}
return file_get_contents(self::DEFAULT_TEMPLATE);
}
-}
+}
\ No newline at end of file
diff --git a/Utils/SMTP/Configuration.php b/Utils/SMTP/Configuration.php
new file mode 100644
index 0000000..648f1d3
--- /dev/null
+++ b/Utils/SMTP/Configuration.php
@@ -0,0 +1,106 @@
+isInstantiable() && $reflectionClass->implementsInterface(TransportConfigurationInterface::class)) {
+ self::$reflectedDefinitions[] = $reflectionClass;
+ }
+ } catch (\ReflectionException $exception) {
+ continue;
+ } catch (\RuntimeException $exception) {
+ continue;
+ }
+ }
+ }
+
+ return self::$reflectedDefinitions;
+ }
+
+ public static function getSupportedTransportTypes() : array
+ {
+ return array_map(function ($reflectionClass) {
+ return $reflectionClass->getName()::getCode();
+ }, self::getAvailableDefinitions());
+ }
+
+ public static function guessTransportDefinition(array $params): TransportConfigurationInterface
+ {
+ foreach (self::getAvailableDefinitions() as $reflectedSmtpDefinition) {
+ // Use default configuration only when no other transport type matches the provided configs
+ if (true === $reflectedSmtpDefinition->implementsInterface(DefaultTransportConfigurationInterface::class)) {
+ $defaultConfigurationReflection = $reflectedSmtpDefinition;
+
+ continue;
+ }
+
+ $smtpInstance = $reflectedSmtpDefinition->newInstance();
+
+ if ($smtpInstance instanceof AppTransportConfigurationInterface) {
+ if (empty($params['host']) && !empty($params['type']) && $smtpInstance->getType() == $params['type']) {
+ return $smtpInstance;
+ }
+ } else if (!empty($params['host']) && $smtpInstance->getHost() == $params['host']) {
+ return $smtpInstance;
+ }
+ }
+
+ if (!empty($defaultConfigurationReflection)) {
+ return $defaultConfigurationReflection->newInstance();
+ }
+
+ throw new \Exception('No matching smtp definition found for host address "' . $params['host'] . '".');
+ }
+
+ public static function createTransportDefinition($transportCode, $host = null): TransportConfigurationInterface
+ {
+ if (false == in_array($transportCode, self::getSupportedTransportTypes(), true)) {
+ throw new \Exception('No smtp definition found for transport type "' . $transportCode . '".');
+ }
+
+ foreach (self::getAvailableDefinitions() as $reflectionClass) {
+ if ($reflectionClass->getName()::getCode() !== $transportCode) {
+ continue;
+ }
+
+ // if (true === $reflectedSmtpDefinition->implementsInterface(DefaultTransportConfigurationInterface::class)) {
+ // return $reflectedSmtpDefinition->newInstance($host);
+ // }
+
+ return $reflectionClass->newInstance();
+ }
+ }
+}
diff --git a/Utils/SMTP/Transport/AppTransportConfigurationInterface.php b/Utils/SMTP/Transport/AppTransportConfigurationInterface.php
new file mode 100644
index 0000000..5f3f57a
--- /dev/null
+++ b/Utils/SMTP/Transport/AppTransportConfigurationInterface.php
@@ -0,0 +1,16 @@
+username = $username;
+
+ return $this;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ public function setPassword($password)
+ {
+ $this->password = $password;
+
+ return $this;
+ }
+
+ public function getPassword()
+ {
+ return $this->password;
+ }
+}
diff --git a/Utils/SMTP/Transport/Type/Outlook.php b/Utils/SMTP/Transport/Type/Outlook.php
new file mode 100644
index 0000000..3046a40
--- /dev/null
+++ b/Utils/SMTP/Transport/Type/Outlook.php
@@ -0,0 +1,61 @@
+username = $username;
+
+ return $this;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ public function setPassword($password)
+ {
+ $this->password = $password;
+
+ return $this;
+ }
+
+ public function getPassword()
+ {
+ return $this->password;
+ }
+}
diff --git a/Utils/SMTP/Transport/Type/OutlookModernAuth.php b/Utils/SMTP/Transport/Type/OutlookModernAuth.php
new file mode 100644
index 0000000..524e249
--- /dev/null
+++ b/Utils/SMTP/Transport/Type/OutlookModernAuth.php
@@ -0,0 +1,53 @@
+client;
+ }
+
+ public function setClient($client)
+ {
+ $this->client = $client;
+
+ return $this;
+ }
+
+ public function setUsername($username)
+ {
+ $this->username = $username;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+}
diff --git a/Utils/SMTP/Transport/Type/SMTP.php b/Utils/SMTP/Transport/Type/SMTP.php
new file mode 100644
index 0000000..f1ce9ec
--- /dev/null
+++ b/Utils/SMTP/Transport/Type/SMTP.php
@@ -0,0 +1,88 @@
+host = $host;
+
+ return $this;
+ }
+
+ public function getHost()
+ {
+ return $this->host;
+ }
+
+ public function setPort($port)
+ {
+ $this->port = $port;
+
+ return $this;
+ }
+
+ public function getPort()
+ {
+ return $this->port;
+ }
+
+ public function setUsername($username)
+ {
+ $this->username = $username;
+
+ return $this;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ public function setPassword($password)
+ {
+ $this->password = $password;
+
+ return $this;
+ }
+
+ public function getPassword()
+ {
+ return $this->password;
+ }
+
+ public function setSenderAddress($senderAddress)
+ {
+ $this->senderAddress = $senderAddress;
+
+ return $this;
+ }
+
+ public function getSenderAddress()
+ {
+ return $this->senderAddress;
+ }
+}
diff --git a/Utils/SMTP/Transport/Type/Yahoo.php b/Utils/SMTP/Transport/Type/Yahoo.php
new file mode 100644
index 0000000..a245fee
--- /dev/null
+++ b/Utils/SMTP/Transport/Type/Yahoo.php
@@ -0,0 +1,61 @@
+username = $username;
+
+ return $this;
+ }
+
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ public function setPassword($password)
+ {
+ $this->password = $password;
+
+ return $this;
+ }
+
+ public function getPassword()
+ {
+ return $this->password;
+ }
+}
diff --git a/Workflow/Actions/Email/FromEmail.php b/Workflow/Actions/Email/FromEmail.php
index 52cf857..185075b 100644
--- a/Workflow/Actions/Email/FromEmail.php
+++ b/Workflow/Actions/Email/FromEmail.php
@@ -35,18 +35,18 @@ public static function getOptions(ContainerInterface $container)
$emailTemplateCollection = array_map(function ($emailTemplate) {
return [
- 'id' => $emailTemplate->getId(),
+ 'id' => $emailTemplate->getId(),
'name' => $emailTemplate->getName(),
];
}, $entityManager->getRepository(EmailTemplates::class)->findAll());
return [
[
- 'id' => 'use_same_address',
+ 'id' => 'use_same_address',
'name' => "Use original email address",
],
[
- 'id' => 'use_reply_to_address',
+ 'id' => 'use_reply_to_address',
'name' => "Use reply-to email address as customer email address",
]
];
@@ -54,7 +54,7 @@ public static function getOptions(ContainerInterface $container)
public static function applyAction(ContainerInterface $container, Event $event, $value = null)
{
- if (!$event instanceof EmailActivity) {
+ if (! $event instanceof EmailActivity) {
return;
}
@@ -63,7 +63,10 @@ public static function applyAction(ContainerInterface $container, Event $event,
switch ($value) {
case 'use_reply_to_address':
- if (!empty($resolvedEmailHeaders['from']) && !empty($resolvedEmailHeaders['reply-to'])) {
+ if (
+ ! empty($resolvedEmailHeaders['from'])
+ && !empty($resolvedEmailHeaders['reply-to'])
+ ) {
$emailHeaders['from'] = $emailHeaders['reply-to'];
$resolvedEmailHeaders['from'] = $resolvedEmailHeaders['reply-to'];
}
diff --git a/composer.json b/composer.json
index f387a21..1cffbcb 100644
--- a/composer.json
+++ b/composer.json
@@ -5,8 +5,8 @@
"license": "MIT",
"authors": [
{
- "name": "akshay kumar",
- "email": "akshay.kumar758@webkul.com"
+ "name": "UVdesk Support",
+ "email": "support@uvdesk.com"
}
],
"require": {