Example #1
0
 /**
  * @param array $aInputFetchItems
  * @param string $sIndexRange
  * @param bool $bIndexIsUid
  *
  * @return array
  *
  * @throws \MailSo\Base\Exceptions\InvalidArgumentException
  * @throws \MailSo\Net\Exceptions\Exception
  * @throws \MailSo\Imap\Exceptions\Exception
  */
 public function Fetch(array $aInputFetchItems, $sIndexRange, $bIndexIsUid)
 {
     $sIndexRange = (string) $sIndexRange;
     if (!\MailSo\Base\Validator::NotEmptyString($sIndexRange, true)) {
         $this->writeLogException(new \MailSo\Base\Exceptions\InvalidArgumentException(), \MailSo\Log\Enumerations\Type::ERROR, true);
     }
     $aFetchItems = \MailSo\Imap\Enumerations\FetchType::ChangeFetchItemsBefourRequest($aInputFetchItems);
     foreach ($aFetchItems as $sName => $mItem) {
         if (0 < \strlen($sName) && '' !== $mItem) {
             if (null === $this->aFetchCallbacks) {
                 $this->aFetchCallbacks = array();
             }
             $this->aFetchCallbacks[$sName] = $mItem;
         }
     }
     $this->SendRequest(($bIndexIsUid ? 'UID ' : '') . 'FETCH', array($sIndexRange, \array_keys($aFetchItems)));
     $aResult = $this->validateResponse($this->parseResponse());
     $this->aFetchCallbacks = null;
     $aReturn = array();
     $oImapResponse = null;
     foreach ($aResult as $oImapResponse) {
         if (FetchResponse::IsValidFetchImapResponse($oImapResponse)) {
             if (FetchResponse::IsNotEmptyFetchImapResponse($oImapResponse)) {
                 $aReturn[] = FetchResponse::NewInstance($oImapResponse);
             } else {
                 if ($this->oLogger) {
                     $this->oLogger->Write('Skipped Imap Response! [' . $oImapResponse->ToLine() . ']', \MailSo\Log\Enumerations\Type::NOTICE);
                 }
             }
         }
     }
     return $aReturn;
 }
Example #2
0
 /**
  * @param string $sFolderName
  * @param string $sPrevUidNext
  * @param string $sCurrentUidNext
  *
  * @return array
  */
 private function getFolderNextMessageInformation($sFolderName, $sPrevUidNext, $sCurrentUidNext)
 {
     $aNewMessages = array();
     if (0 < \strlen($sPrevUidNext) && (string) $sPrevUidNext !== (string) $sCurrentUidNext) {
         $this->oImapClient->FolderExamine($sFolderName);
         $aFetchResponse = $this->oImapClient->Fetch(array(\MailSo\Imap\Enumerations\FetchType::INDEX, \MailSo\Imap\Enumerations\FetchType::UID, \MailSo\Imap\Enumerations\FetchType::FLAGS, \MailSo\Imap\Enumerations\FetchType::BuildBodyCustomHeaderRequest(array(\MailSo\Mime\Enumerations\Header::FROM_, \MailSo\Mime\Enumerations\Header::SUBJECT, \MailSo\Mime\Enumerations\Header::CONTENT_TYPE))), $sPrevUidNext . ':*', true);
         if (\is_array($aFetchResponse) && 0 < \count($aFetchResponse)) {
             foreach ($aFetchResponse as $oFetchResponse) {
                 $aFlags = \array_map('strtolower', $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::FLAGS));
                 if (\in_array(\strtolower(\MailSo\Imap\Enumerations\MessageFlag::RECENT), $aFlags) || !\in_array(\strtolower(\MailSo\Imap\Enumerations\MessageFlag::SEEN), $aFlags)) {
                     $sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
                     $sHeaders = $oFetchResponse->GetHeaderFieldsValue();
                     $oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sHeaders);
                     $sContentTypeCharset = $oHeaders->ParameterValue(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, \MailSo\Mime\Enumerations\Parameter::CHARSET);
                     $sCharset = '';
                     if (0 < \strlen($sContentTypeCharset)) {
                         $sCharset = $sContentTypeCharset;
                     }
                     if (0 < \strlen($sCharset)) {
                         $oHeaders->SetParentCharset($sCharset);
                     }
                     $aNewMessages[] = array('Folder' => $sFolderName, 'Uid' => $sUid, 'Subject' => $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SUBJECT, 0 === \strlen($sCharset)), 'From' => $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::FROM_, 0 === \strlen($sCharset)));
                 }
             }
         }
     }
     return $aNewMessages;
 }
Example #3
0
 /**
  * Retrieves information about new message, primarily used for Inbox folder. 
  * 
  * @param CAccount $oAccount Account object.
  * @param string $sFolderFullNameRaw Raw full name of the folder.
  * @param string $sUidnext UIDNEXT value used for this operation.
  *
  * @return array
  */
 public function getNewMessagesInformation($oAccount, $sFolderFullNameRaw, $sUidnext, $sNewInboxUidnext)
 {
     if (!isset($sNewInboxUidnext) || $sNewInboxUidnext === '') {
         $sNewInboxUidnext = '*';
     }
     if (0 === strlen($sFolderFullNameRaw) || 0 === strlen($sFolderFullNameRaw)) {
         throw new CApiInvalidArgumentException();
     }
     $oImapClient =& $this->_getImapClient($oAccount);
     $oImapClient->FolderExamine($sFolderFullNameRaw);
     $aResult = array();
     $aFetchResponse = $oImapClient->Fetch(array(\MailSo\Imap\Enumerations\FetchType::INDEX, \MailSo\Imap\Enumerations\FetchType::UID, \MailSo\Imap\Enumerations\FetchType::FLAGS, \MailSo\Imap\Enumerations\FetchType::BuildBodyCustomHeaderRequest(array(\MailSo\Mime\Enumerations\Header::FROM_, \MailSo\Mime\Enumerations\Header::SUBJECT, \MailSo\Mime\Enumerations\Header::CONTENT_TYPE))), $sUidnext . ':' . $sNewInboxUidnext, true);
     if (\is_array($aFetchResponse) && 0 < \count($aFetchResponse)) {
         foreach ($aFetchResponse as $oFetchResponse) {
             $aFlags = \array_map('strtolower', $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::FLAGS));
             if (!\in_array(\strtolower(\MailSo\Imap\Enumerations\MessageFlag::SEEN), $aFlags)) {
                 $sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
                 $sHeaders = $oFetchResponse->GetHeaderFieldsValue();
                 $oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sHeaders);
                 $sContentTypeCharset = $oHeaders->ParameterValue(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, \MailSo\Mime\Enumerations\Parameter::CHARSET);
                 $sCharset = '';
                 if (0 < \strlen($sContentTypeCharset)) {
                     $sCharset = $sContentTypeCharset;
                 }
                 if (0 < \strlen($sCharset)) {
                     $oHeaders->SetParentCharset($sCharset);
                 }
                 if ($sUid !== $sNewInboxUidnext) {
                     $aResult[] = array('Folder' => $sFolderFullNameRaw, 'Uid' => $sUid, 'Subject' => $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::SUBJECT, 0 === \strlen($sCharset)), 'From' => $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::FROM_, 0 === \strlen($sCharset)));
                 }
             }
         }
     }
     return $aResult;
 }