/**
  * Handle mail process
  * @param MessageProvider $provider
  * @return void
  */
 public function handle(MessageProvider $provider)
 {
     $processedMessages = [];
     $strategies = $this->strategyHolder->getStrategies();
     foreach ($provider->fetchMessagesToProcess() as $message) {
         foreach ($strategies as $strategy) {
             $this->processingContext->setStrategy($strategy);
             try {
                 if (!$message->isFailed() && !$message->isSystem()) {
                     $this->processingContext->execute($message);
                 }
                 if (false === isset($processedMessages[$message->getUniqueId()])) {
                     $processedMessages[$message->getUniqueId()] = $message;
                 }
             } catch (\Exception $e) {
                 // TODO
                 $this->logger->error(sprintf('Error processing message: %s', $e->getMessage()));
             }
         }
     }
     if ($this->settings->getDeleteProcessedMessages()) {
         $provider->deleteProcessedMessages($processedMessages);
     } else {
         $provider->markMessagesAsProcessed($processedMessages);
     }
 }
 /**
  * Handle mail process
  * @param MessageProvider $provider
  * @return void
  */
 public function handle(MessageProvider $provider)
 {
     $messagesToMove = array();
     $strategies = $this->strategyHolder->getStrategies();
     foreach ($provider->fetchMessagesToProcess() as $message) {
         foreach ($strategies as $strategy) {
             $this->processingContext->setStrategy($strategy);
             try {
                 if (!$message->isFailed()) {
                     $this->processingContext->execute($message);
                 }
                 if (false === isset($messagesToMove[$message->getUniqueId()])) {
                     $messagesToMove[$message->getUniqueId()] = $message;
                 }
             } catch (\Exception $e) {
                 $this->logger->error(sprintf('Error processing message: %s', $e->getMessage()));
             }
         }
     }
     $provider->markMessagesAsProcessed($messagesToMove);
 }