Skip to content

Commit

Permalink
Merge branch 'v1.1.4_micro' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
papnoisanjeev committed Dec 19, 2024
2 parents eb2975c + bf98efc commit ad6cfee
Show file tree
Hide file tree
Showing 52 changed files with 3,389 additions and 631 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-1.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ CHANGELOG for 1.1.x

This changelog references any relevant changes introduced in 1.1 minor versions.

* 1.1.4 (2024-12-19)
* Microsoft Modern App related updates.
* License and support email address updates.
* Code refactoring.

* 1.1.3 (2023-06-12)
* Update: Dropped dependency on uvdesk/composer-plugin in support of symfony/flex

Expand Down
389 changes: 308 additions & 81 deletions Console/RefreshMailboxCommand.php

Large diffs are not rendered by default.

426 changes: 341 additions & 85 deletions Controller/MailboxChannel.php

Large diffs are not rendered by default.

135 changes: 92 additions & 43 deletions Controller/MailboxChannelXHR.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,69 @@ public function processRawContentMail(Request $request)

if ($rawEmail != false && !empty($rawEmail)) {
$this->mailboxService->processMail($rawEmail);
}else{
} else {
dump("Empty Text file not allow");
}
}

exit(0);
}

public function loadMailboxesXHR(Request $request)
{
$mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations();

$defaultMailbox = $mailboxConfiguration->getDefaultMailbox();

$collection = array_map(function ($mailbox) use ($defaultMailbox) {
return [
'id' => $mailbox->getId(),
'name' => $mailbox->getName(),
'isEnabled' => $mailbox->getIsEnabled(),
];
}, array_values($mailboxConfiguration->getMailboxes()));

return new JsonResponse($collection ?? []);
}

public function removeMailboxConfiguration($id, Request $request)
{
$mailboxService = $this->mailboxService;
$existingMailboxConfiguration = $mailboxService->parseMailboxConfigurations();

foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) {
if ($configuration->getId() == $id) {
$mailbox = $configuration;

break;
}
}

if (empty($mailbox)) {
return new JsonResponse([
'alertClass' => 'danger',
'alertMessage' => "No mailbox found with id '$id'.",
], 404);
}

$mailboxConfiguration = new MailboxConfiguration();

foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) {
if ($configuration->getId() == $id) {
continue;
}

$mailboxConfiguration->addMailbox($configuration);
}

file_put_contents($mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration);

return new JsonResponse([
'alertClass' => 'success',
'alertMessage' => $this->translator->trans('Mailbox configuration removed successfully.'),
]);
}

public function processMailXHR(Request $request)
public function processMailXHR(Request $request, MailboxService $mailboxService)
{
if ("POST" != $request->getMethod()) {
return new JsonResponse([
Expand All @@ -51,7 +107,7 @@ public function processMailXHR(Request $request)
}

try {
$processedThread = $this->mailboxService->processMail($request->get('email'));
$processedThread = $mailboxService->processMail($request->get('email'));
} catch (\Exception $e) {
return new JsonResponse([
'success' => false,
Expand All @@ -66,7 +122,7 @@ public function processMailXHR(Request $request)
}

if (!empty($processedThread['content']['ticket']) && !empty($processedThread['content']['thread'])) {
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['thread'] . "]</comment>";
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['ticket'] . "]</comment>";
} else if (!empty($processedThread['content']['ticket'])) {
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "]</comment>";
}
Expand All @@ -76,56 +132,49 @@ public function processMailXHR(Request $request)
'message' => $responseMessage,
]);
}

public function loadMailboxesXHR(Request $request)
{
$collection = array_map(function ($mailbox) {
return [
'id' => $mailbox->getId(),
'name' => $mailbox->getName(),
'isEnabled' => $mailbox->getIsEnabled(),
'isDeleted' => $mailbox->getIsDeleted() ? $mailbox->getIsDeleted() : false,
];
}, $this->mailboxService->parseMailboxConfigurations()->getMailboxes());

return new JsonResponse($collection ?? []);
}

public function removeMailboxConfiguration($id, Request $request)
public function processOutlookMailXHR(Request $request, MailboxService $mailboxService)
{
$mailboxService = $this->mailboxService;
$existingMailboxConfiguration = $mailboxService->parseMailboxConfigurations();

foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) {
if ($configuration->getId() == $id) {
$mailbox = $configuration;

break;
}
if ("POST" != $request->getMethod()) {
return new JsonResponse([
'success' => false,
'message' => 'Request not supported.'
], 500);
} else if (null == $request->get('email')) {
return new JsonResponse([
'success' => false,
'message' => 'Missing required email data in request content.'
], 500);
}

if (empty($mailbox)) {
try {
$processedThread = $mailboxService->processOutlookMail($request->get('email'));
} catch (\Exception $e) {
return new JsonResponse([
'alertClass' => 'danger',
'alertMessage' => "No mailbox found with id '$id'.",
], 404);
'success' => false,
'message' => $e->getMessage(),
'params' => $request->get('email')
], 500);
}

$mailboxConfiguration = new MailboxConfiguration();

foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) {
if ($configuration->getId() == $id) {
continue;
}
$responseMessage = $processedThread['message'];

$mailboxConfiguration->addMailbox($configuration);
if (! empty($processedThread['content']['from'])) {
$responseMessage = "Received email from <info>" . $processedThread['content']['from']. "</info>. " . $responseMessage;
}

file_put_contents($mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration);
if (
! empty($processedThread['content']['ticket'])
&& !empty($processedThread['content']['thread'])
) {
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['ticket'] . "]</comment>";
} else if (! empty($processedThread['content']['ticket'])) {
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "]</comment>";
}

return new JsonResponse([
'alertClass' => 'success',
'alertMessage' => $this->translator->trans('Mailbox configuration removed successfully.'),
'success' => true,
'message' => $responseMessage,
]);
}
}
31 changes: 24 additions & 7 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,41 @@ public function getConfigTreeBuilder()
->node('enable_delimiter', 'boolean')->defaultValue(false)->end()
->end()
->end()
->node('default_mailbox', 'scalar')->defaultValue(null)->end()
->node('mailboxes', 'array')
->arrayPrototype()
->children()
->node('name', 'scalar')->cannotBeEmpty()->end()
->node('enabled', 'boolean')->defaultFalse()->end()
->node('deleted', 'boolean')->defaultFalse()->end()
->node('smtp_server', 'array')
->children()
->node('mailer_id', 'scalar')->defaultValue('default')->end()
->end()
->end()
->node('enabled', 'boolean')->defaultTrue()->end()
->node('disable_outbound_emails', 'boolean')->defaultFalse()->end()
->node('use_strict_mode', 'boolean')->defaultFalse()->end()
->node('imap_server', 'array')
->children()
->node('host', 'scalar')->cannotBeEmpty()->end()
->node('username', 'scalar')->cannotBeEmpty()->end()
->node('client', 'scalar')->end()
->node('password', 'scalar')->end()
->node('type', 'scalar')->end()
->end()
->end()
->node('smtp_swift_mailer_server', 'array')
->children()
->node('mailer_id', 'scalar')->defaultValue(null)
->end()
->end()
->end()
->node('smtp_server', 'array')
->children()
->node('host', 'scalar')->cannotBeEmpty()->end()
->node('port', 'scalar')->end()
->node('username', 'scalar')->cannotBeEmpty()->end()
->node('client', 'scalar')->end()
->node('password', 'scalar')->end()
->node('type', 'scalar')->end()
->node('sender_address', 'scalar')->defaultValue(null)
->end()
->end()
->end()
->end()
->end()
->end()
Expand Down
82 changes: 82 additions & 0 deletions EventListener/Mailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Webkul\UVDesk\MailboxBundle\EventListener;

use Webkul\UVDesk\CoreFrameworkBundle\Mailer\Event\ConfigurationRemovedEvent;
use Webkul\UVDesk\CoreFrameworkBundle\Mailer\Event\ConfigurationUpdatedEvent;
use Webkul\UVDesk\MailboxBundle\Services\MailboxService;
use Webkul\UVDesk\MailboxBundle\Utils\Mailbox\Mailbox;

class Mailer
{
private $mailboxService;

public final function __construct(MailboxService $mailboxService)
{
$this->mailboxService = $mailboxService;
}

public function onMailerConfigurationUpdated(ConfigurationUpdatedEvent $event)
{
$isUpdateRequiredFlag = false;
$updatedConfiguration = $event->getUpdatedMailerConfiguration();
$existingConfiguration = $event->getExistingMailerConfiguration();

if ($updatedConfiguration->getId() == $existingConfiguration->getId()) {
// We only need to update if the mailer configuration's id has changed
// or if it has been disabled.

return;
}

$mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations(true);

foreach ($mailboxConfiguration->getMailboxes() as $existingMailbox) {
if ($existingMailbox->getMailerConfiguration()->getId() == $existingConfiguration->getId()) {
// Disable mailbox and update configuration
$mailbox = new Mailbox($existingMailbox->getId());
$mailbox->setName($existingMailbox->getName())
->setIsEnabled($existingMailbox->getIsEnabled())
->setImapConfiguration($existingMailbox->getImapConfiguration())
->setMailerConfiguration($updatedConfiguration);

$isUpdateRequiredFlag = true;
$mailboxConfiguration->removeMailbox($existingMailbox);
$mailboxConfiguration->addMailbox($mailbox);
}
}

if (true === $isUpdateRequiredFlag) {
file_put_contents($this->mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration);
}

return;
}

public function onMailerConfigurationRemoved(ConfigurationRemovedEvent $event)
{
$isUpdateRequiredFlag = false;
$configuration = $event->getMailerConfiguration();
$mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations();

foreach ($mailboxConfiguration->getMailboxes() as $existingMailbox) {
if (null != $existingMailbox->getMailerConfiguration() && $existingMailbox->getMailerConfiguration()->getId() == $configuration->getId()) {
// Disable mailbox and update configuration
$mailbox = new Mailbox($existingMailbox->getId());
$mailbox->setName($existingMailbox->getName())
->setIsEnabled(false)
->setImapConfiguration($existingMailbox->getImapConfiguration());

$isUpdateRequiredFlag = true;
$mailboxConfiguration->removeMailbox($existingMailbox);
$mailboxConfiguration->addMailbox($mailbox);
}
}

if (true === $isUpdateRequiredFlag) {
file_put_contents($this->mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration);
}

return;
}
}
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

Loading

0 comments on commit ad6cfee

Please sign in to comment.