/**
  * Get email ids and create iterator
  *
  * @param EmailOrigin $origin
  * @param ImapEmailFolder $imapFolder
  * @param EmailFolder $folder
  *
  * @return ImapEmailIterator
  */
 protected function getEmailIterator(EmailOrigin $origin, ImapEmailFolder $imapFolder, EmailFolder $folder)
 {
     if ($origin->getMailbox()) {
         // build search query for emails sync
         $sqb = $this->manager->getSearchQueryBuilder();
         if ($origin->getSynchronizedAt() && $folder->getSynchronizedAt()) {
             if ($folder->getType() === FolderType::SENT) {
                 $sqb->sent($folder->getSynchronizedAt());
             } else {
                 $sqb->received($folder->getSynchronizedAt());
             }
         }
         $searchQuery = $sqb->get();
         $this->logger->info(sprintf('Loading emails from "%s" folder ...', $folder->getFullName()));
         $this->logger->info(sprintf('Query: "%s".', $searchQuery->convertToSearchString()));
         $emails = $this->manager->getEmails($searchQuery);
     } else {
         $lastUid = $this->em->getRepository('OroImapBundle:ImapEmail')->findLastUidByFolder($imapFolder);
         $this->logger->info(sprintf('Previous max email UID "%s"', $lastUid));
         $emails = $this->manager->getEmailsUidBased(sprintf('%s:*', ++$lastUid));
     }
     return $emails;
 }
示例#2
0
 /**
  * @param EmailModel  $model
  * @param \DateTime   $messageDate
  * @param EmailOrigin $origin
  *
  * @return EmailUser
  */
 protected function createEmailUser(EmailModel $model, $messageDate, EmailOrigin $origin)
 {
     $emailUser = $this->emailEntityBuilder->emailUser($model->getSubject(), $model->getFrom(), $model->getTo(), $messageDate, $messageDate, $messageDate, Email::NORMAL_IMPORTANCE, $model->getCc(), $model->getBcc(), $origin->getOwner(), $origin->getOrganization());
     if ($origin instanceof UserEmailOrigin && $origin->getMailbox() !== null) {
         $emailUser->setOwner(null);
         $emailUser->setMailboxOwner($origin->getMailbox());
     }
     return $emailUser;
 }