Skip to content

Commit 794cdc1

Browse files
author
Sanjeev Papnoi
committed
Merge remote-tracking branch 'origin/1.0' into HEAD
2 parents f5a157b + c530bc6 commit 794cdc1

File tree

9 files changed

+67
-9
lines changed

9 files changed

+67
-9
lines changed

Console/RefreshMailboxCommand.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
7979
}
8080

8181
$output->writeln("\n <comment>2. Opening imap stream... </comment>");
82-
$this->refreshMailbox($mailbox['imap_server']['host'], $mailbox['imap_server']['username'], $mailbox['imap_server']['password'], $timestamp, $output);
82+
$this->refreshMailbox($mailbox['imap_server']['host'], $mailbox['imap_server']['username'], base64_decode($mailbox['imap_server']['password']), $timestamp, $output, $mailbox);
8383
}
8484
}
8585

86-
public function refreshMailbox($server_host, $server_username, $server_password, \DateTime $timestamp, OutputInterface $output)
86+
public function refreshMailbox($server_host, $server_username, $server_password, \DateTime $timestamp, OutputInterface $output, $mailbox)
8787
{
8888
$imap = imap_open($server_host, $server_username, $server_password);
8989
$output->writeln("\n <comment>3. IMAP stream opened.</comment>");
@@ -105,10 +105,17 @@ public function refreshMailbox($server_host, $server_username, $server_password,
105105
$output->writeln("\n <comment> Converting email </comment><info>$counter</info><comment> out of </comment><info>$emailCount</info><comment>.</comment>");
106106
$message = imap_fetchbody($imap, $messageNumber, "");
107107
$this->pushMessage($message, $useSecureConnection);
108+
if (true == $mailbox['deleted']) {
109+
imap_delete($imap, $messageNumber);
110+
}
108111
$counter ++;
109112
}
110113

111114
$output->writeln("\n <comment>Mailbox refreshed successfully !!!</comment>");
115+
if (true == $mailbox['deleted']) {
116+
imap_expunge($imap);
117+
imap_close($imap,CL_EXPUNGE);
118+
}
112119
}
113120
}
114121

Controller/MailboxChannel.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function createMailboxConfiguration(Request $request)
5353
if (!empty($params['imap']['transport'])) {
5454
($imapConfiguration = ImapConfiguration::createTransportDefinition($params['imap']['transport'], !empty($params['imap']['host']) ? trim($params['imap']['host'], '"') : null))
5555
->setUsername($params['imap']['username'])
56-
->setPassword($params['imap']['password']);
56+
->setPassword(base64_encode($params['imap']['password']));
5757
}
5858

5959
// Swiftmailer Configuration
@@ -73,6 +73,7 @@ public function createMailboxConfiguration(Request $request)
7373
($mailbox = new Mailbox(!empty($params['id']) ? $params['id'] : null))
7474
->setName($params['name'])
7575
->setIsEnabled(!empty($params['isEnabled']) && 'on' == $params['isEnabled'] ? true : false)
76+
->setIsDeleted(!empty($params['isDeleted']) && 'on' == $params['isDeleted'] ? true : false)
7677
->setImapConfiguration($imapConfiguration)
7778
->setSwiftMailerConfiguration($swiftmailerConfiguration);
7879

@@ -117,7 +118,7 @@ public function updateMailboxConfiguration($id, Request $request)
117118
if (!empty($params['imap']['transport'])) {
118119
($imapConfiguration = ImapConfiguration::createTransportDefinition($params['imap']['transport'], !empty($params['imap']['host']) ? trim($params['imap']['host'], '"') : null))
119120
->setUsername($params['imap']['username'])
120-
->setPassword($params['imap']['password']);
121+
->setPassword(base64_encode($params['imap']['password']));
121122
}
122123

123124
// Swiftmailer Configuration
@@ -145,6 +146,7 @@ public function updateMailboxConfiguration($id, Request $request)
145146
$mailbox
146147
->setName($params['name'])
147148
->setIsEnabled(!empty($params['isEnabled']) && 'on' == $params['isEnabled'] ? true : false)
149+
->setIsDeleted(!empty($params['isDeleted']) && 'on' == $params['isDeleted'] ? true : false)
148150
->setImapConfiguration($imapConfiguration)
149151
->setSwiftMailerConfiguration($swiftmailerConfiguration);
150152

Controller/MailboxChannelXHR.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function loadMailboxesXHR(Request $request)
4141
'id' => $mailbox->getId(),
4242
'name' => $mailbox->getName(),
4343
'isEnabled' => $mailbox->getIsEnabled(),
44+
'isDeleted' => $mailbox->getIsDeleted() ? $mailbox->getIsDeleted() : false,
4445
];
4546
}, $this->mailboxService->parseMailboxConfigurations()->getMailboxes());
4647

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function getConfigTreeBuilder()
2323
->children()
2424
->node('name', 'scalar')->cannotBeEmpty()->end()
2525
->node('enabled', 'boolean')->defaultFalse()->end()
26+
->node('deleted', 'boolean')->defaultFalse()->end()
2627
->node('smtp_server', 'array')
2728
->children()
2829
->node('mailer_id', 'scalar')->defaultValue('default')->end()

Resources/views/manageConfigurations.html.twig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@
8585
</label>
8686
</div>
8787

88+
<div class="uv-element-block">
89+
<label>
90+
<div class="uv-checkbox">
91+
{% if mailbox.isDeleted is defined and mailbox.isDeleted == true %}
92+
<input name="isDeleted" type="checkbox" checked="">
93+
{% else %}
94+
<input name="isDeleted" type="checkbox">
95+
{% endif %}
96+
97+
<span class="uv-checkbox-view"></span>
98+
</div>
99+
100+
<span class="uv-checkbox-label">{{ 'Delete from Inbox'|trans }}</span>
101+
</label>
102+
</div>
103+
88104
<div class="uv-hr"></div>
89105

90106
{# IMAP Settings #}

Services/MailboxService.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function parseMailboxConfigurations(bool $ignoreInvalidAttributes = false
8686
($mailbox = new Mailbox($id))
8787
->setName($params['name'])
8888
->setIsEnabled($params['enabled'])
89+
->setIsDeleted(empty($params['deleted']) ? false : $params['deleted'])
8990
->setImapConfiguration($imapConfiguration);
9091

9192
if (!empty($swiftmailerConfiguration)) {
@@ -160,7 +161,7 @@ public function getEmailAddress($addresses)
160161
public function getMailboxByEmail($email)
161162
{
162163
foreach ($this->getRegisteredMailboxes() as $registeredMailbox) {
163-
if ($email === $registeredMailbox['imap_server']['username']) {
164+
if (strtolower($email) === strtolower($registeredMailbox['imap_server']['username'])) {
164165
return $registeredMailbox;
165166
}
166167
}
@@ -171,7 +172,7 @@ public function getMailboxByEmail($email)
171172
public function getMailboxByToEmail($email)
172173
{
173174
foreach ($this->getRegisteredMailboxes() as $registeredMailbox) {
174-
if ($email === $registeredMailbox['imap_server']['username']) {
175+
if (strtolower($email) === strtolower($registeredMailbox['imap_server']['username'])) {
175176
return true;
176177
}
177178
}
@@ -385,7 +386,7 @@ public function processMail($rawEmail)
385386
$thread = $this->entityManager->getRepository(Thread::class)->findOneByMessageId($mailData['messageId']);
386387

387388
if (!empty($thread)) {
388-
// Thread with the same message id exists. Skip processing.
389+
// Thread with the same message id exists skip process.
389390
return;
390391
}
391392

@@ -395,6 +396,13 @@ public function processMail($rawEmail)
395396

396397
$mailData['user'] = $user;
397398
$userDetails = $user->getCustomerInstance()->getPartialDetails();
399+
} else if ($this->entityManager->getRepository(Ticket::class)->isTicketCollaborator($ticket, $mailData['from'])){
400+
// Reply from collaborator
401+
$user = $this->entityManager->getRepository(User::class)->findOneByEmail($mailData['from']);
402+
403+
$mailData['user'] = $user;
404+
$mailData['createdBy'] = 'collaborator';
405+
$userDetails = $user->getCustomerInstance()->getPartialDetails();
398406
} else {
399407
$user = $this->entityManager->getRepository(User::class)->findOneByEmail($mailData['from']);
400408

@@ -443,6 +451,10 @@ public function processMail($rawEmail)
443451
$event = new GenericEvent(CoreWorkflowEvents\Ticket\CustomerReply::getId(), [
444452
'entity' => $ticket,
445453
]);
454+
} else if ($thread->getCreatedBy() == 'collaborator') {
455+
$event = new GenericEvent(CoreWorkflowEvents\Ticket\CollaboratorReply::getId(), [
456+
'entity' => $ticket,
457+
]);
446458
} else {
447459
$event = new GenericEvent(CoreWorkflowEvents\Ticket\AgentReply::getId(), [
448460
'entity' => $ticket,
@@ -456,4 +468,4 @@ public function processMail($rawEmail)
456468

457469
return;
458470
}
459-
}
471+
}

Templates/PackageConfigurations/Mailbox.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[[ id ]]:
55
name: [[ name ]]
66
enabled: [[ status ]]
7+
deleted: [[ delete_status ]]
78
89
# [SMTP] Outgoing mail server
910
# Swiftmailer smtp mailer to use for sending emails through on behalf of this mailbox

Utils/Mailbox/Mailbox.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Mailbox
1414
private $id = null;
1515
private $name = null;
1616
private $isEnabled = false;
17+
private $isDeleted = false;
1718
private $imapConfiguration = null;
1819
private $swiftmailerConfiguration = null;
1920

@@ -56,6 +57,19 @@ public function getIsEnabled() : bool
5657
return $this->isEnabled;
5758
}
5859

60+
public function getIsDeleted() : bool
61+
{
62+
return $this->isDeleted;
63+
}
64+
65+
public function setIsDeleted(bool $isDeleted)
66+
{
67+
$this->isDeleted = $isDeleted;
68+
69+
return $this;
70+
}
71+
72+
5973
public function setImapConfiguration(ImapConfiguration $imapConfiguration)
6074
{
6175
$this->imapConfiguration = $imapConfiguration;
@@ -94,6 +108,7 @@ public function __toString()
94108
'[[ id ]]' => $this->getId(),
95109
'[[ name ]]' => $this->getName(),
96110
'[[ status ]]' => $this->getIsEnabled() ? 'true' : 'false',
111+
'[[ delete_status ]]' => $this->getIsDeleted() ? 'true' : 'false',
97112
'[[ swiftmailer_id ]]' => $swiftmailerConfiguration ? $swiftmailerConfiguration->getId() : '~',
98113
'[[ imap_host ]]' => $imapConfiguration->getHost(),
99114
'[[ imap_username ]]' => $imapConfiguration->getUsername(),

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
"psr-4": { "Webkul\\UVDesk\\MailboxBundle\\": "" }
2121
},
2222
"extra": {
23-
"uvdesk-package-extension": "Webkul\\UVDesk\\MailboxBundle\\Package\\Composer"
23+
"uvdesk-package-extension": "Webkul\\UVDesk\\MailboxBundle\\Package\\Composer",
24+
"branch-alias": {
25+
"dev-master": "1.0.x-dev"
26+
}
2427
},
2528
"minimum-stability": "stable"
2629
}

0 commit comments

Comments
 (0)