Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
papnoisanjeev committed Dec 10, 2024
1 parent 02728bc commit efede9c
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 97 deletions.
26 changes: 13 additions & 13 deletions Controller/MailboxChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function createMailboxConfiguration(Request $request, EntityManagerInterf
}, $microsoftAccountCollection);

# load swift mailer configuration
$swiftmailerConfigurationCollection = $swiftMailer->parseSwiftMailerConfigurations();
$swiftMailerConfigurationCollection = $swiftMailer->parseSwiftMailerConfigurations();

if ($request->getMethod() == 'POST') {
$params = $request->request->all();
Expand Down Expand Up @@ -120,7 +120,7 @@ public function createMailboxConfiguration(Request $request, EntityManagerInterf
return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAccountCollection' => $microsoftAccountCollection,
'swiftmailerConfigurations' => $swiftmailerConfigurationCollection,
'swiftmailerConfigurations' => $swiftMailerConfigurationCollection,
]);
}

Expand All @@ -137,7 +137,7 @@ public function createMailboxConfiguration(Request $request, EntityManagerInterf
return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAccountCollection' => $microsoftAccountCollection,
'swiftmailerConfigurations' => $swiftmailerConfigurationCollection,
'swiftmailerConfigurations' => $swiftMailerConfigurationCollection,
]);
}
} else if ($smtpConfiguration instanceof SMTP\Transport\ResolvedTransportConfigurationInterface) {
Expand Down Expand Up @@ -166,7 +166,7 @@ public function createMailboxConfiguration(Request $request, EntityManagerInterf

// Swiftmailer Configuration
if (!empty($params['swiftmailer_id'])) {
foreach ($swiftmailerConfigurationCollection as $configuration) {
foreach ($swiftMailerConfigurationCollection as $configuration) {
if ($configuration->getId() == $params['swiftmailer_id']) {
$swiftmailerConfiguration = $configuration;
break;
Expand Down Expand Up @@ -218,7 +218,7 @@ public function createMailboxConfiguration(Request $request, EntityManagerInterf
return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAccountCollection' => $microsoftAccountCollection,
'swiftmailerConfigurations' => $swiftmailerConfigurationCollection,
'swiftmailerConfigurations' => $swiftMailerConfigurationCollection,
]);
}

Expand Down Expand Up @@ -255,7 +255,7 @@ public function updateMailboxConfiguration($id, Request $request, EntityManagerI
}, $microsoftAccountCollection);

# load swift mailer configuration
$swiftmailerConfigurationCollection = $swiftMailer->parseSwiftMailerConfigurations();
$swiftMailerConfigurationCollection = $swiftMailer->parseSwiftMailerConfigurations();

if ($request->getMethod() == 'POST') {
$params = $request->request->all();
Expand All @@ -277,7 +277,7 @@ public function updateMailboxConfiguration($id, Request $request, EntityManagerI
return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAccountCollection' => $microsoftAccountCollection,
'swiftmailerConfigurations' => $swiftmailerConfigurationCollection,
'swiftmailerConfigurations' => $swiftMailerConfigurationCollection,
]);
}

Expand All @@ -294,7 +294,7 @@ public function updateMailboxConfiguration($id, Request $request, EntityManagerI
return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAccountCollection' => $microsoftAccountCollection,
'swiftmailerConfigurations' => $swiftmailerConfigurationCollection,
'swiftmailerConfigurations' => $swiftMailerConfigurationCollection,
]);
}
} else if ($imapConfiguration instanceof IMAP\Transport\SimpleTransportConfigurationInterface) {
Expand Down Expand Up @@ -323,7 +323,7 @@ public function updateMailboxConfiguration($id, Request $request, EntityManagerI
return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAccountCollection' => $microsoftAccountCollection,
'swiftmailerConfigurations' => $swiftmailerConfigurationCollection,
'swiftmailerConfigurations' => $swiftMailerConfigurationCollection,
]);
}

Expand All @@ -340,7 +340,7 @@ public function updateMailboxConfiguration($id, Request $request, EntityManagerI
return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAccountCollection' => $microsoftAccountCollection,
'swiftmailerConfigurations' => $swiftmailerConfigurationCollection,
'swiftmailerConfigurations' => $swiftMailerConfigurationCollection,
]);
}
} else if ($smtpConfiguration instanceof SMTP\Transport\ResolvedTransportConfigurationInterface) {
Expand All @@ -367,8 +367,8 @@ public function updateMailboxConfiguration($id, Request $request, EntityManagerI
$mailbox = new Mailbox($params['id']);

// Swiftmailer Configuration
if (!empty($params['swiftmailer_id'])) {
foreach ($swiftmailerConfigurationCollection as $configuration) {
if (! empty($params['swiftmailer_id'])) {
foreach ($swiftMailerConfigurationCollection as $configuration) {
if ($configuration->getId() == $params['swiftmailer_id']) {
$swiftmailerConfiguration = $configuration;
break;
Expand Down Expand Up @@ -418,7 +418,7 @@ public function updateMailboxConfiguration($id, Request $request, EntityManagerI
'mailbox' => $mailbox,
'microsoftAppCollection' => $microsoftAppCollection,
'microsoftAccountCollection' => $microsoftAccountCollection,
'swiftmailerConfigurations' => $swiftmailerConfigurationCollection,
'swiftmailerConfigurations' => $swiftMailerConfigurationCollection,
]);
}
}
22 changes: 13 additions & 9 deletions Controller/MailboxChannelXHR.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public function processRawContentMail(Request $request)

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

exit(0);
}

Expand All @@ -44,8 +45,8 @@ public function loadMailboxesXHR(Request $request)

$collection = array_map(function ($mailbox) use ($defaultMailbox) {
return [
'id' => $mailbox->getId(),
'name' => $mailbox->getName(),
'id' => $mailbox->getId(),
'name' => $mailbox->getName(),
'isEnabled' => $mailbox->getIsEnabled(),
];
}, array_values($mailboxConfiguration->getMailboxes()));
Expand All @@ -68,7 +69,7 @@ public function removeMailboxConfiguration($id, Request $request)

if (empty($mailbox)) {
return new JsonResponse([
'alertClass' => 'danger',
'alertClass' => 'danger',
'alertMessage' => "No mailbox found with id '$id'.",
], 404);
}
Expand All @@ -86,7 +87,7 @@ public function removeMailboxConfiguration($id, Request $request)
file_put_contents($mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration);

return new JsonResponse([
'alertClass' => 'success',
'alertClass' => 'success',
'alertMessage' => $this->translator->trans('Mailbox configuration removed successfully.'),
]);
}
Expand Down Expand Up @@ -158,13 +159,16 @@ public function processOutlookMailXHR(Request $request, MailboxService $mailboxS

$responseMessage = $processedThread['message'];

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

if (!empty($processedThread['content']['ticket']) && !empty($processedThread['content']['thread'])) {
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'])) {
} else if (! empty($processedThread['content']['ticket'])) {
$responseMessage .= " <comment>[tickets/" . $processedThread['content']['ticket'] . "]</comment>";
}

Expand Down
3 changes: 2 additions & 1 deletion Resources/views/listConfigurations.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
globalMessageResponse = null;
},
error: function (model, xhr, options) {
if(url = xhr.getResponseHeader('Location'))
if (url = xhr.getResponseHeader('Location'))
window.location = url;
}
});
Expand All @@ -237,6 +237,7 @@
},
render: function() {
this.$el.html(this.template(this.model));
return this;
},
confirmRemove: function(e) {
Expand Down
Loading

0 comments on commit efede9c

Please sign in to comment.