/**
  * @inheritdoc
  */
 public function toArray()
 {
     $attachments = array();
     $attEntities = $this->entity->getAttachments();
     for ($i = 0, $len = count($attEntities); $i < $len; $i++) {
         $att =& $attEntities[$i];
         $attachments[] = array('mimeType' => $att->getMimeType(), 'encoding' => $att->getEncoding(), 'fileName' => $att->getFileName(), 'contentId' => $att->getContentId(), 'key' => $att->getKey());
     }
     return array('message' => array('id' => $this->entity->getId(), 'uId' => $this->messageLocation->getUId(), 'path' => array_merge(array($this->messageLocation->getFolder()->getRootId()), $this->messageLocation->getFolder()->getPath()), 'messageId' => $this->entity instanceof \Conjoon\Data\Entity\Mail\ImapMessageEntity ? $this->entity->getMessageId() : null, 'date' => $this->entity->getDate(), 'subject' => $this->entity->getSubject(), 'to' => $this->entity->getTo(), 'cc' => $this->entity->getCc(), 'bcc' => $this->entity->getBcc(), 'from' => $this->entity->getFrom(), 'replyTo' => $this->entity->getReplyTo(), 'inReplyTo' => $this->entity->getInReplyTo(), 'references' => $this->entity->getReferences(), 'contentTextHtml' => $this->entity->getContentTextHtml(), 'contentTextPlain' => $this->entity->getContentTextPlain(), 'attachments' => $attachments));
 }
 /**
  * @inheritdoc
  */
 public function getMessage(\Conjoon\Mail\Client\Message\MessageLocation $messageLocation, \Conjoon\User\User $user)
 {
     $folder = $messageLocation->getFolder();
     try {
         $mayRead = $this->mayUserReadFolder($folder, $user);
     } catch (\Conjoon\Mail\Client\Security\SecurityServiceException $e) {
         throw new \Conjoon\Mail\Server\Protocol\ProtocolException("Exception thrown by previous exception: " . $e->getMessage(), 0, $e);
     }
     if (!$mayRead) {
         throw new \Conjoon\Mail\Server\Protocol\ProtocolException("User must not access the folder \"" . $folder->getNodeId() . "\"");
     }
     try {
         $isRemoteMailbox = $this->isFolderRepresentingRemoteMailbox($folder, $user);
     } catch (\Conjoon\Mail\Client\Folder\FolderServiceException $e) {
         throw new \Conjoon\Mail\Server\Protocol\ProtocolException("Exception thrown by previous exception: " . $e->getMessage(), 0, $e);
     }
     if (!$isRemoteMailbox) {
         $entity = $this->doctrineMessageRepository->findById($messageLocation);
     } else {
         try {
             $account = $this->getAccountServiceForUser($user)->getMailAccountToAccessRemoteFolder($folder);
             if (!$account) {
                 throw new \Conjoon\Mail\Server\Protocol\ProtocolException("No mail account found for folder");
             }
             $imapMessageRepository = $this->defaultClassNames['imapMessageRepository'];
             $imapRepository = new $imapMessageRepository($account);
             $entity = $imapRepository->findById($messageLocation);
         } catch (\Exception $e) {
             throw new \Conjoon\Mail\Server\Protocol\ProtocolException("Exception thrown by previous exception: " . $e->getMessage(), 0, $e);
         }
     }
     if ($entity == null) {
         throw new \Conjoon\Mail\Server\Protocol\ProtocolException("Message not found");
     }
     /**
      * @see \Conjoon\Mail\Server\Protocol\DefaultResult\GetMessageResult
      */
     require_once 'Conjoon/Mail/Server/Protocol/DefaultResult/GetMessageResult.php';
     return new \Conjoon\Mail\Server\Protocol\DefaultResult\GetMessageResult($entity, $messageLocation);
 }