/**
  * @inheritdoc
  */
 public function getMailAccounts(\Conjoon\User\User $user)
 {
     $em = $this->getEntityManager();
     $query = $em->createQuery("SELECT a FROM \\Conjoon\\Data\\Entity\\Mail\\DefaultMailAccountEntity a" . ",\\Conjoon\\Data\\Entity\\User\\DefaultUserEntity u" . " WHERE u.id = ?1 " . " AND a.user=u " . " AND a.isDeleted = ?2");
     $query->setParameter(1, $user->getId());
     $query->setParameter(2, false);
     try {
         $res = $query->getResult();
     } catch (\Doctrine\ORM\NoResultException $e) {
         return array();
     }
     return $res;
 }
 /**
  * @inheritdoc
  */
 public function setFlagsForUser(\Conjoon\Mail\Client\Message\Flag\FolderFlagCollection $folderFlagCollection, \Conjoon\User\User $user)
 {
     /**
      * @refactor
      */
     /**
      * @see Conjoon_Modules_Groupware_Email_Item_Model_Flag
      */
     require_once 'Conjoon/Modules/Groupware/Email/Item/Model/Flag.php';
     $flagModel = new \Conjoon_Modules_Groupware_Email_Item_Model_Flag();
     $userId = $user->getId();
     $flags = $folderFlagCollection->getFlagCollection()->getFlags();
     for ($i = 0, $len = count($flags); $i < $len; $i++) {
         $uId = $flags[$i]->getUId();
         $clear = $flags[$i]->isClear();
         switch (true) {
             case $flags[$i]->__toString() === '\\Seen':
                 try {
                     $isRead = !$clear;
                     $flagModel->flagItemAsRead($uId, $userId, $isRead);
                 } catch (\Exception $e) {
                     throw new MailRepositoryException("Exception thrown by previous exception: " . $e->getMessage(), 0, $e);
                 }
                 break;
             case $flags[$i]->__toString() === '$Junk':
                 try {
                     $isSpam = !$clear;
                     $flagModel->flagItemAsSpam($uId, $userId, $isSpam);
                 } catch (\Exception $e) {
                     throw new MailRepositoryException("Exception thrown by previous exception: " . $e->getMessage(), 0, $e);
                 }
                 break;
             case $flags[$i]->__toString() === '$NotJunk':
                 try {
                     $flagModel->flagItemAsSpam($uId, $userId, false);
                 } catch (\Exception $e) {
                     throw new MailRepositoryException("Exception thrown by previous exception: " . $e->getMessage(), 0, $e);
                 }
                 break;
             default:
                 throw new MailRepositoryException("Unknown flag \"" . $flags[$i]->__toString() . "\"");
                 break;
         }
     }
 }
 /**
  * @inheritdoc
  */
 public function getMessage($id, $path, \Conjoon\User\User $user, \Conjoon\Mail\Client\Message\Strategy\ReadableStrategy $readableStrategy)
 {
     try {
         $messageCacheService = $this->messageCacheService;
         $format = 'plain';
         $externalResources = false;
         if ($readableStrategy instanceof \Conjoon\Mail\Client\Message\Strategy\HtmlReadableStrategy) {
             $format = 'html';
             $externalResources = $readableStrategy->areExternalResourcesAllowed();
         }
         $keyConfig = array('userId' => $user->getId(), 'messageId' => $id, 'path' => $path, 'format' => $format, 'externalResources' => $externalResources);
         $data = $messageCacheService->load($keyConfig);
         if ($data === null) {
             $data = $this->messageServiceFacade->getMessage($id, $path, $user, $readableStrategy);
             if ($data->isSuccess()) {
                 $messageCacheService->save($data, $keyConfig);
             }
         }
         return $data;
     } catch (\Exception $e) {
         return new GetMessageServiceResult(new MessageServiceException("Exception thrown by previous exception: " . $e->getMessage(), 0, $e));
     }
 }