src/WellCommerce/Bundle/AppBundle/EventListener/ImapSubscriber.php line 52

Open in your IDE?
  1. <?php declare(strict_types=0);
  2. /*
  3.  * WellCommerce Foundation
  4.  *
  5.  * This file is part of the WellCommerce package.
  6.  *
  7.  * (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
  8.  *
  9.  * For the full copyright and license information,
  10.  * please view the LICENSE file that was distributed with this source code.
  11.  */
  12. namespace WellCommerce\Bundle\AppBundle\EventListener;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use WellCommerce\Bundle\AppBundle\Entity\Mailbox;
  15. use WellCommerce\Bundle\AppBundle\Service\Imap\ImapClient;
  16. use WellCommerce\Bundle\AppBundle\Service\Shop\Storage\ShopStorage;
  17. use WellCommerce\Bundle\CoreBundle\Event\MailEvent;
  18. /**
  19.  * Class CurrencySubscriber
  20.  *
  21.  * @author  Adam Piotrowski <adam@wellcommerce.org>
  22.  */
  23. class ImapSubscriber implements EventSubscriberInterface
  24. {
  25.     /**
  26.      * @var ShopStorage
  27.      */
  28.     protected $shopStorage;
  29.     /**
  30.      * @var ImapClient
  31.      */
  32.     protected $imapClient;
  33.     public function __construct(ShopStorage $shopStorageImapClient $imapClient)
  34.     {
  35.         $this->shopStorage $shopStorage;
  36.         $this->imapClient  $imapClient;
  37.     }
  38.     public static function getSubscribedEvents()
  39.     {
  40.         return [
  41.             'mail.post_send' => ['onMailPostSend'0],
  42.         ];
  43.     }
  44.     public function onMailPostSend(MailEvent $event)
  45.     {
  46.         $message $event->getMessage();
  47.         $mailbox $this->shopStorage->getCurrentShop()->getMailbox();
  48.         if ($mailbox instanceof Mailbox && $mailbox->isEnabled()) {
  49.             foreach ($message->getFrom() as $from => $name) {
  50.                 if ($mailbox->getUser() === $from) {
  51.                     $result $this->imapClient->saveMessage($message$mailbox);
  52.                 }
  53.             }
  54.         }
  55.     }
  56. }