Skip to content

Commit ad6cfee

Browse files
committed
Merge branch 'v1.1.4_micro' into HEAD
2 parents eb2975c + bf98efc commit ad6cfee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3389
-631
lines changed

CHANGELOG-1.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ CHANGELOG for 1.1.x
33

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

6+
* 1.1.4 (2024-12-19)
7+
* Microsoft Modern App related updates.
8+
* License and support email address updates.
9+
* Code refactoring.
10+
611
* 1.1.3 (2023-06-12)
712
* Update: Dropped dependency on uvdesk/composer-plugin in support of symfony/flex
813

Console/RefreshMailboxCommand.php

Lines changed: 308 additions & 81 deletions
Large diffs are not rendered by default.

Controller/MailboxChannel.php

Lines changed: 341 additions & 85 deletions
Large diffs are not rendered by default.

Controller/MailboxChannelXHR.php

Lines changed: 92 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,69 @@ public function processRawContentMail(Request $request)
3030

3131
if ($rawEmail != false && !empty($rawEmail)) {
3232
$this->mailboxService->processMail($rawEmail);
33-
}else{
33+
} else {
3434
dump("Empty Text file not allow");
35-
}
35+
}
36+
3637
exit(0);
3738
}
39+
40+
public function loadMailboxesXHR(Request $request)
41+
{
42+
$mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations();
43+
44+
$defaultMailbox = $mailboxConfiguration->getDefaultMailbox();
45+
46+
$collection = array_map(function ($mailbox) use ($defaultMailbox) {
47+
return [
48+
'id' => $mailbox->getId(),
49+
'name' => $mailbox->getName(),
50+
'isEnabled' => $mailbox->getIsEnabled(),
51+
];
52+
}, array_values($mailboxConfiguration->getMailboxes()));
53+
54+
return new JsonResponse($collection ?? []);
55+
}
56+
57+
public function removeMailboxConfiguration($id, Request $request)
58+
{
59+
$mailboxService = $this->mailboxService;
60+
$existingMailboxConfiguration = $mailboxService->parseMailboxConfigurations();
61+
62+
foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) {
63+
if ($configuration->getId() == $id) {
64+
$mailbox = $configuration;
65+
66+
break;
67+
}
68+
}
69+
70+
if (empty($mailbox)) {
71+
return new JsonResponse([
72+
'alertClass' => 'danger',
73+
'alertMessage' => "No mailbox found with id '$id'.",
74+
], 404);
75+
}
76+
77+
$mailboxConfiguration = new MailboxConfiguration();
78+
79+
foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) {
80+
if ($configuration->getId() == $id) {
81+
continue;
82+
}
83+
84+
$mailboxConfiguration->addMailbox($configuration);
85+
}
86+
87+
file_put_contents($mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration);
88+
89+
return new JsonResponse([
90+
'alertClass' => 'success',
91+
'alertMessage' => $this->translator->trans('Mailbox configuration removed successfully.'),
92+
]);
93+
}
3894

39-
public function processMailXHR(Request $request)
95+
public function processMailXHR(Request $request, MailboxService $mailboxService)
4096
{
4197
if ("POST" != $request->getMethod()) {
4298
return new JsonResponse([
@@ -51,7 +107,7 @@ public function processMailXHR(Request $request)
51107
}
52108

53109
try {
54-
$processedThread = $this->mailboxService->processMail($request->get('email'));
110+
$processedThread = $mailboxService->processMail($request->get('email'));
55111
} catch (\Exception $e) {
56112
return new JsonResponse([
57113
'success' => false,
@@ -66,7 +122,7 @@ public function processMailXHR(Request $request)
66122
}
67123

68124
if (!empty($processedThread['content']['ticket']) && !empty($processedThread['content']['thread'])) {
69-
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['thread'] . "]</comment>";
125+
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['ticket'] . "]</comment>";
70126
} else if (!empty($processedThread['content']['ticket'])) {
71127
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "]</comment>";
72128
}
@@ -76,56 +132,49 @@ public function processMailXHR(Request $request)
76132
'message' => $responseMessage,
77133
]);
78134
}
79-
80-
public function loadMailboxesXHR(Request $request)
81-
{
82-
$collection = array_map(function ($mailbox) {
83-
return [
84-
'id' => $mailbox->getId(),
85-
'name' => $mailbox->getName(),
86-
'isEnabled' => $mailbox->getIsEnabled(),
87-
'isDeleted' => $mailbox->getIsDeleted() ? $mailbox->getIsDeleted() : false,
88-
];
89-
}, $this->mailboxService->parseMailboxConfigurations()->getMailboxes());
90-
91-
return new JsonResponse($collection ?? []);
92-
}
93135

94-
public function removeMailboxConfiguration($id, Request $request)
136+
public function processOutlookMailXHR(Request $request, MailboxService $mailboxService)
95137
{
96-
$mailboxService = $this->mailboxService;
97-
$existingMailboxConfiguration = $mailboxService->parseMailboxConfigurations();
98-
99-
foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) {
100-
if ($configuration->getId() == $id) {
101-
$mailbox = $configuration;
102-
103-
break;
104-
}
138+
if ("POST" != $request->getMethod()) {
139+
return new JsonResponse([
140+
'success' => false,
141+
'message' => 'Request not supported.'
142+
], 500);
143+
} else if (null == $request->get('email')) {
144+
return new JsonResponse([
145+
'success' => false,
146+
'message' => 'Missing required email data in request content.'
147+
], 500);
105148
}
106149

107-
if (empty($mailbox)) {
150+
try {
151+
$processedThread = $mailboxService->processOutlookMail($request->get('email'));
152+
} catch (\Exception $e) {
108153
return new JsonResponse([
109-
'alertClass' => 'danger',
110-
'alertMessage' => "No mailbox found with id '$id'.",
111-
], 404);
154+
'success' => false,
155+
'message' => $e->getMessage(),
156+
'params' => $request->get('email')
157+
], 500);
112158
}
113159

114-
$mailboxConfiguration = new MailboxConfiguration();
115-
116-
foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) {
117-
if ($configuration->getId() == $id) {
118-
continue;
119-
}
160+
$responseMessage = $processedThread['message'];
120161

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

124-
file_put_contents($mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration);
166+
if (
167+
! empty($processedThread['content']['ticket'])
168+
&& !empty($processedThread['content']['thread'])
169+
) {
170+
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['ticket'] . "]</comment>";
171+
} else if (! empty($processedThread['content']['ticket'])) {
172+
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "]</comment>";
173+
}
125174

126175
return new JsonResponse([
127-
'alertClass' => 'success',
128-
'alertMessage' => $this->translator->trans('Mailbox configuration removed successfully.'),
176+
'success' => true,
177+
'message' => $responseMessage,
129178
]);
130179
}
131180
}

DependencyInjection/Configuration.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,41 @@ public function getConfigTreeBuilder()
1818
->node('enable_delimiter', 'boolean')->defaultValue(false)->end()
1919
->end()
2020
->end()
21+
->node('default_mailbox', 'scalar')->defaultValue(null)->end()
2122
->node('mailboxes', 'array')
2223
->arrayPrototype()
2324
->children()
2425
->node('name', 'scalar')->cannotBeEmpty()->end()
25-
->node('enabled', 'boolean')->defaultFalse()->end()
26-
->node('deleted', 'boolean')->defaultFalse()->end()
27-
->node('smtp_server', 'array')
28-
->children()
29-
->node('mailer_id', 'scalar')->defaultValue('default')->end()
30-
->end()
31-
->end()
26+
->node('enabled', 'boolean')->defaultTrue()->end()
27+
->node('disable_outbound_emails', 'boolean')->defaultFalse()->end()
28+
->node('use_strict_mode', 'boolean')->defaultFalse()->end()
3229
->node('imap_server', 'array')
3330
->children()
3431
->node('host', 'scalar')->cannotBeEmpty()->end()
3532
->node('username', 'scalar')->cannotBeEmpty()->end()
33+
->node('client', 'scalar')->end()
3634
->node('password', 'scalar')->end()
35+
->node('type', 'scalar')->end()
36+
->end()
37+
->end()
38+
->node('smtp_swift_mailer_server', 'array')
39+
->children()
40+
->node('mailer_id', 'scalar')->defaultValue(null)
41+
->end()
3742
->end()
3843
->end()
44+
->node('smtp_server', 'array')
45+
->children()
46+
->node('host', 'scalar')->cannotBeEmpty()->end()
47+
->node('port', 'scalar')->end()
48+
->node('username', 'scalar')->cannotBeEmpty()->end()
49+
->node('client', 'scalar')->end()
50+
->node('password', 'scalar')->end()
51+
->node('type', 'scalar')->end()
52+
->node('sender_address', 'scalar')->defaultValue(null)
53+
->end()
54+
->end()
55+
->end()
3956
->end()
4057
->end()
4158
->end()

EventListener/Mailer.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Webkul\UVDesk\MailboxBundle\EventListener;
4+
5+
use Webkul\UVDesk\CoreFrameworkBundle\Mailer\Event\ConfigurationRemovedEvent;
6+
use Webkul\UVDesk\CoreFrameworkBundle\Mailer\Event\ConfigurationUpdatedEvent;
7+
use Webkul\UVDesk\MailboxBundle\Services\MailboxService;
8+
use Webkul\UVDesk\MailboxBundle\Utils\Mailbox\Mailbox;
9+
10+
class Mailer
11+
{
12+
private $mailboxService;
13+
14+
public final function __construct(MailboxService $mailboxService)
15+
{
16+
$this->mailboxService = $mailboxService;
17+
}
18+
19+
public function onMailerConfigurationUpdated(ConfigurationUpdatedEvent $event)
20+
{
21+
$isUpdateRequiredFlag = false;
22+
$updatedConfiguration = $event->getUpdatedMailerConfiguration();
23+
$existingConfiguration = $event->getExistingMailerConfiguration();
24+
25+
if ($updatedConfiguration->getId() == $existingConfiguration->getId()) {
26+
// We only need to update if the mailer configuration's id has changed
27+
// or if it has been disabled.
28+
29+
return;
30+
}
31+
32+
$mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations(true);
33+
34+
foreach ($mailboxConfiguration->getMailboxes() as $existingMailbox) {
35+
if ($existingMailbox->getMailerConfiguration()->getId() == $existingConfiguration->getId()) {
36+
// Disable mailbox and update configuration
37+
$mailbox = new Mailbox($existingMailbox->getId());
38+
$mailbox->setName($existingMailbox->getName())
39+
->setIsEnabled($existingMailbox->getIsEnabled())
40+
->setImapConfiguration($existingMailbox->getImapConfiguration())
41+
->setMailerConfiguration($updatedConfiguration);
42+
43+
$isUpdateRequiredFlag = true;
44+
$mailboxConfiguration->removeMailbox($existingMailbox);
45+
$mailboxConfiguration->addMailbox($mailbox);
46+
}
47+
}
48+
49+
if (true === $isUpdateRequiredFlag) {
50+
file_put_contents($this->mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration);
51+
}
52+
53+
return;
54+
}
55+
56+
public function onMailerConfigurationRemoved(ConfigurationRemovedEvent $event)
57+
{
58+
$isUpdateRequiredFlag = false;
59+
$configuration = $event->getMailerConfiguration();
60+
$mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations();
61+
62+
foreach ($mailboxConfiguration->getMailboxes() as $existingMailbox) {
63+
if (null != $existingMailbox->getMailerConfiguration() && $existingMailbox->getMailerConfiguration()->getId() == $configuration->getId()) {
64+
// Disable mailbox and update configuration
65+
$mailbox = new Mailbox($existingMailbox->getId());
66+
$mailbox->setName($existingMailbox->getName())
67+
->setIsEnabled(false)
68+
->setImapConfiguration($existingMailbox->getImapConfiguration());
69+
70+
$isUpdateRequiredFlag = true;
71+
$mailboxConfiguration->removeMailbox($existingMailbox);
72+
$mailboxConfiguration->addMailbox($mailbox);
73+
}
74+
}
75+
76+
if (true === $isUpdateRequiredFlag) {
77+
file_put_contents($this->mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration);
78+
}
79+
80+
return;
81+
}
82+
}

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)