Skip to content

Commit

Permalink
Merge branch '1.0' of https://github.com/uvdesk/mailbox-component int…
Browse files Browse the repository at this point in the history
…o HEAD
  • Loading branch information
akshay kumar committed Oct 22, 2019
2 parents caf740f + 0d4d696 commit f71a0ea
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ CHANGELOG for 1.0.x

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

* 1.0.2 (2019-10-22)
* **Misc. Updates:**
* Use https when available while refreshing mailboxes via CLI
* Updated README.md with link to the official gitter chat for uvdesk/mailbox-component

* 1.0.1 (2019-10-15)
* **Misc. Updates:**
* Only users with admin level privileges can configure mailbox settings
Expand Down
26 changes: 20 additions & 6 deletions Console/RefreshMailboxCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ public function refreshMailbox($server_host, $server_username, $server_password,

if (is_array($emailCollection)) {
$emailCount = count($emailCollection);
$useSecureConnection = $this->isSecureConnectionAvailable();

$output->writeln("\n <comment>5. Total fetched email -> </comment><info>$emailCount</info><comment></comment>");
$output->writeln("\n <comment>6. Starting to convert Emails into Tickets -> </comment>\n=============================================\n=============================================\n");
$counter = 1;

foreach ($emailCollection as $id => $messageNumber) {
$output->writeln("\n <comment> Converting email </comment><info>$counter</info><comment> out of </comment><info>$emailCount</info><comment>.</comment>");
$message = imap_fetchbody($imap, $messageNumber, "");
$this->pushMessage($message);
$this->pushMessage($message, $useSecureConnection);
$counter ++;
}

Expand All @@ -113,24 +115,36 @@ public function refreshMailbox($server_host, $server_username, $server_password,
return;
}

public function pushMessage($message)
public function pushMessage($message, bool $secure = false)
{
$router = $this->container->get('router');
$router->getContext()->setHost($this->container->getParameter('uvdesk.site_url'));
$router->getContext()->setScheme(true === $secure ? 'https' : 'http');

$curlHandler = curl_init();
$requestUrl = $router->generate('helpdesk_member_mailbox_notification', [], UrlGeneratorInterface::ABSOLUTE_URL);

if ($this->container->getParameter('uvdesk.site_url') != $router->getContext()->getHost()) {
$requestUrl = str_replace($router->getContext()->getHost(), $this->container->getParameter('uvdesk.site_url'), $requestUrl);
}

curl_setopt($curlHandler, CURLOPT_HEADER, 0);
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandler, CURLOPT_POST, 1);
curl_setopt($curlHandler, CURLOPT_URL, $requestUrl);
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, http_build_query(['email' => $message]));

$curlResponse = curl_exec($curlHandler);
curl_close($curlHandler);
}

protected function isSecureConnectionAvailable()
{
$headers = [CURLOPT_NOBODY => true, CURLOPT_HEADER => false];
$curlHandler = curl_init('https://' . $this->container->getParameter('uvdesk.site_url'));

curl_setopt_array($curlHandler, $headers);
curl_exec($curlHandler);

$isSecureRequestAvailable = curl_errno($curlHandler) === 0 ? true : false;
curl_close($curlHandler);

return $isSecureRequestAvailable;
}
}
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# mailbox
The Mailbox component provides tools that allows your helpdesk to process tickets from multiple email sources.

<p align="center"><a href="https://www.uvdesk.com/en/" target="_blank">
<img src="https://s3-ap-southeast-1.amazonaws.com/cdn.uvdesk.com/uvdesk/bundles/webkuldefault/images/uvdesk-wide.svg">
</a></p>

<p align="center">
<a href="https://packagist.org/packages/uvdesk/mailbox-component"><img src="https://poser.pugx.org/uvdesk/mailbox-component/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/uvdesk/mailbox-component"><img src="https://poser.pugx.org/uvdesk/mailbox-component/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/uvdesk/mailbox-component"><img src="https://poser.pugx.org/uvdesk/mailbox-component/license.svg" alt="License"></a>
<a href="https://gitter.im/uvdesk/mailbox-component"><img src="https://badges.gitter.im/uvdesk/mailbox-component.svg" alt="connect on gitter"></a>
</p>

The **Mailbox** component enables your [UVDesk Community][1] helpdesk to fetch emails from multiple sources and process them into tickets effortlessly.

Installation
--------------

Before installing, make sure that you have [Composer][2] installed.

To require mailbox-component into your helpdesk project, simply run the following composer command from your project root:

```bash
$ composer require uvdesk/mailbox-component
```

License
--------------

The **Mailbox** component and libraries included within the bundle are released under the MIT or BSD license.

[1]: https://www.uvdesk.com/
[2]: https://getcomposer.org/

0 comments on commit f71a0ea

Please sign in to comment.