Skip to content

Commit

Permalink
Refactor and changelog updates
Browse files Browse the repository at this point in the history
  • Loading branch information
papnoisanjeev committed Dec 4, 2024
1 parent 7ec912c commit 02728bc
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 61 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-1.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ CHANGELOG for 1.1.x

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

* 1.1.4
* Microsoft Modern App related updates.
* License and support email address updates.

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

Expand Down
57 changes: 42 additions & 15 deletions Console/RefreshMailboxCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
} else {
$microsoftAccount = $this->entityManager->getRepository(MicrosoftAccount::class)->findOneBy([
'email' => $imapConfiguration->getUsername(),
'email' => $imapConfiguration->getUsername(),
'microsoftApp' => $microsoftApp,
]);

Expand Down Expand Up @@ -174,8 +174,7 @@ public function refreshMailbox($server_host, $server_username, $server_password,
$output->writeln("\n <bg=black;fg=bright-white>API</> <options=underscore>" . $this->endpoint . "</>\n");

$counter = 1;
try{

try {
foreach ($emailCollection as $id => $messageNumber) {
$output->writeln(" - <comment>Processing email</comment> <info>$counter</info> <comment>of</comment> <info>$emailCount</info>:");

Expand All @@ -187,15 +186,15 @@ public function refreshMailbox($server_host, $server_username, $server_password,
$output->writeln("\n <bg=green;fg=bright-white;options=bold>200</> " . $response['message'] . "\n");
}

if(isset($response['error'])) {
if (isset($response['error'])) {
$output->writeln("\n <bg=red;fg=white;options=bold>ERROR</> <fg=red> ". $response['message'] ."</>\n");
}

$counter++;
}

$output->writeln(" - <info>Mailbox refreshed successfully!</info>");
}catch(\Exception $e){
} catch (\Exception $e) {
$msg = $e->getMessage();
$output->writeln(" - <comment>$msg</comment>");
}
Expand All @@ -214,7 +213,7 @@ public function refreshOutlookMailbox($microsoftApp, $microsoftAccount, \DateTim
$filters = [
'ReceivedDateTime' => [
'operation' => '>',
'value' => $timeSpan,
'value' => $timeSpan,
],
];

Expand All @@ -235,7 +234,10 @@ public function refreshOutlookMailbox($microsoftApp, $microsoftAccount, \DateTim
$response = $nextLink ? MicrosoftGraph\Me::getMessagesWithNextLink($nextLink, $credentials['access_token']) : MicrosoftGraph\Me::messages($credentials['access_token'], $mailboxFolderId, $filters);

if (! empty($response['error'])) {
if (! empty($response['error']['code']) && $response['error']['code'] == 'InvalidAuthenticationToken') {
if (
! empty($response['error']['code'])
&& $response['error']['code'] == 'InvalidAuthenticationToken'
) {
$tokenResponse = $this->microsoftIntegration->refreshAccessToken($microsoftApp, $credentials['refresh_token']);

if (! empty($tokenResponse['access_token'])) {
Expand Down Expand Up @@ -311,11 +313,14 @@ public function refreshOutlookMailbox($microsoftApp, $microsoftAccount, \DateTim

list($response, $responseCode) = $this->parseOutlookInboundEmail($detailedMessage, $output);

if ($response['message'] && !isset($response['error'])) {
if (
$response['message']
&& !isset($response['error'])
) {
$output->writeln("\n <bg=green;fg=bright-white;options=bold>200</> " . $response['message'] . "\n");
}

if(isset($response['error'])) {
if (isset($response['error'])) {
$output->writeln("\n <bg=red;fg=white;options=bold>ERROR</> <fg=red> ". $response['message'] ."</>\n");
}

Expand Down Expand Up @@ -373,13 +378,24 @@ public function parseInboundEmail($message, $output)
$processedThread = $this->mailboxService->processMail($message);
$responseMessage = $processedThread['message'];

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

if ((isset($processedThread['content']['ticket']) && !empty($processedThread['content']['ticket'])) && (isset($processedThread['content']['thread']) && !empty($processedThread['content']['thread']))) {
if (
(isset($processedThread['content']['ticket'])
&& !empty($processedThread['content']['ticket']))
&& (isset($processedThread['content']['thread'])
&& !empty($processedThread['content']['thread']))
) {
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['ticket'] . "]</comment>";
} else if (isset($processedThread['content']['ticket']) && !empty($processedThread['content']['ticket'])) {
} else if (
isset($processedThread['content']['ticket'])
&& !empty($processedThread['content']['ticket'])
) {
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "]</comment>";
}

Expand All @@ -405,13 +421,24 @@ public function parseOutlookInboundEmail($detailedMessage, $output)
$processedThread = $this->mailboxService->processOutlookMail($detailedMessage);
$responseMessage = $processedThread['message'];

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

if ((isset($processedThread['content']['ticket']) && !empty($processedThread['content']['ticket'])) && (isset($processedThread['content']['thread']) && !empty($processedThread['content']['thread']))) {
if (
(isset($processedThread['content']['ticket'])
&& !empty($processedThread['content']['ticket']))
&& (isset($processedThread['content']['thread'])
&& !empty($processedThread['content']['thread']))
) {
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['ticket'] . "]</comment>";
} else if (isset($processedThread['content']['ticket']) && !empty($processedThread['content']['ticket'])) {
} else if (
isset($processedThread['content']['ticket'])
&& !empty($processedThread['content']['ticket'])
) {
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "]</comment>";
}

Expand Down
33 changes: 18 additions & 15 deletions Controller/MailboxChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MailboxChannel extends AbstractController
{
public function loadMailboxes(UserService $userService)
{
if (!$userService->isAccessAuthorized('ROLE_ADMIN')) {
if (! $userService->isAccessAuthorized('ROLE_ADMIN')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

Expand All @@ -31,7 +31,7 @@ public function loadMailboxes(UserService $userService)

public function createMailboxConfiguration(Request $request, EntityManagerInterface $entityManager, UserService $userService, MailboxService $mailboxService, TranslatorInterface $translator, SwiftMailerService $swiftMailer)
{
if (!$userService->isAccessAuthorized('ROLE_ADMIN')) {
if (! $userService->isAccessAuthorized('ROLE_ADMIN')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

Expand All @@ -40,15 +40,15 @@ public function createMailboxConfiguration(Request $request, EntityManagerInterf

$microsoftAppCollection = array_map(function ($microsoftApp) {
return [
'id' => $microsoftApp->getId(),
'id' => $microsoftApp->getId(),
'name' => $microsoftApp->getName(),
];
}, $microsoftAppCollection);

$microsoftAccountCollection = array_map(function ($microsoftAccount) {
return [
'id' => $microsoftAccount->getId(),
'name' => $microsoftAccount->getName(),
'id' => $microsoftAccount->getId(),
'name' => $microsoftAccount->getName(),
'email' => $microsoftAccount->getEmail(),
];
}, $microsoftAccountCollection);
Expand All @@ -74,7 +74,7 @@ public function createMailboxConfiguration(Request $request, EntityManagerInterf
$this->addFlash('warning', 'No configuration details were found for the provided microsoft account.');

return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAccountCollection' => $microsoftAccountCollection,
]);
}
Expand All @@ -90,7 +90,7 @@ public function createMailboxConfiguration(Request $request, EntityManagerInterf
$this->addFlash('warning', 'The resolved IMAP configuration is not configured for any valid available app.');

return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAccountCollection' => $microsoftAccountCollection,
]);
}
Expand Down Expand Up @@ -156,7 +156,10 @@ public function createMailboxConfiguration(Request $request, EntityManagerInterf
}
}

if (empty($imapConfiguration) && empty($smtpConfiguration)) {
if (
empty($imapConfiguration)
&& empty($smtpConfiguration)
) {
$this->addFlash('warning', 'Invalid mailbox details provided. Mailbox needs to have at least IMAP or SMTP settings defined.');
} else {
$mailboxConfiguration = $mailboxService->parseMailboxConfigurations();
Expand All @@ -178,27 +181,27 @@ public function createMailboxConfiguration(Request $request, EntityManagerInterf
->setIsEmailDeliveryDisabled(!empty($params['isEmailDeliveryDisabled']) && 'on' == $params['isEmailDeliveryDisabled'] ? true : false)
;

if (!empty($imapConfiguration)) {
if (! empty($imapConfiguration)) {
$mailbox
->setImapConfiguration($imapConfiguration)
;
}

if (!empty($smtpConfiguration)) {
if (! empty($smtpConfiguration)) {
$mailbox
->setSmtpConfiguration($smtpConfiguration)
;
}

if (!empty($swiftmailerConfiguration)) {
if (! empty($swiftmailerConfiguration)) {
$mailbox
->setSwiftMailerConfiguration($swiftmailerConfiguration);
;
}

$mailboxConfiguration->addMailbox($mailbox);

if (!empty($params['isDefault']) && 'on' == $params['isDefault']) {
if (! empty($params['isDefault']) && 'on' == $params['isDefault']) {
$mailboxConfiguration
->setDefaultMailbox($mailbox)
;
Expand Down Expand Up @@ -238,15 +241,15 @@ public function updateMailboxConfiguration($id, Request $request, EntityManagerI

$microsoftAppCollection = array_map(function ($microsoftApp) {
return [
'id' => $microsoftApp->getId(),
'id' => $microsoftApp->getId(),
'name' => $microsoftApp->getName(),
];
}, $microsoftAppCollection);

$microsoftAccountCollection = array_map(function ($microsoftAccount) {
return [
'id' => $microsoftAccount->getId(),
'name' => $microsoftAccount->getName(),
'id' => $microsoftAccount->getId(),
'name' => $microsoftAccount->getName(),
'email' => $microsoftAccount->getEmail(),
];
}, $microsoftAccountCollection);
Expand Down
Loading

0 comments on commit 02728bc

Please sign in to comment.