/**
  * @return string
  */
 private function getWildcardDomainsLine()
 {
     if ($this->oCacher) {
         $sResult = $this->oCacher->Get($this->wildcardDomainsCacheKey());
         if (0 < \strlen($sResult)) {
             return $sResult;
         }
     }
     $sResult = '';
     $aNames = array();
     $aList = \glob($this->sDomainPath . '/*.ini');
     foreach ($aList as $sFile) {
         $sName = \substr(\basename($sFile), 0, -4);
         if ('default' === $sName || false !== \strpos($sName, '_wildcard_')) {
             $aNames[] = $this->codeFileName($sName, true);
         }
     }
     if (0 < \count($aNames)) {
         \rsort($aNames, SORT_STRING);
         $sResult = \implode(' ', $aNames);
     }
     if ($this->oCacher) {
         $this->oCacher->Set($this->wildcardDomainsCacheKey(), $sResult);
     }
     return $sResult;
 }
 /**
  * @param \MailSo\Cache\CacheClient|null $oCacher
  * @param string $sSearch
  * @param string $sFilter
  * @param string $sFolderName
  * @param string $sFolderHash
  * @param bool $bUseSortIfSupported = false
  *
  * @return array
  *
  * @throws \MailSo\Base\Exceptions\InvalidArgumentException
  * @throws \MailSo\Net\Exceptions\Exception
  * @throws \MailSo\Imap\Exceptions\Exception
  */
 public function GetUids($oCacher, $sSearch, $sFilter, $sFolderName, $sFolderHash, $bUseSortIfSupported = false)
 {
     $aResultUids = false;
     $bUidsFromCacher = false;
     $bUseCacheAfterSearch = true;
     $sSerializedHash = '';
     $sSerializedLog = '';
     $bUseSortIfSupported = $bUseSortIfSupported ? !!$this->oImapClient->IsSupported('SORT') : false;
     if (0 < \strlen($sSearch)) {
         $bUseSortIfSupported = false;
     }
     $sSearchCriterias = $this->getImapSearchCriterias($sSearch, $sFilter, 0, $bUseCacheAfterSearch);
     if ($bUseCacheAfterSearch && $oCacher && $oCacher->IsInited()) {
         $sSerializedHash = 'GetUids/' . ($bUseSortIfSupported ? 'S' : 'N') . '/' . $this->GenerateImapClientHash() . '/' . $sFolderName . '/' . $sSearchCriterias;
         $sSerializedLog = '"' . $sFolderName . '" / ' . $sSearchCriterias . '';
         $sSerialized = $oCacher->Get($sSerializedHash);
         if (!empty($sSerialized)) {
             $aSerialized = @\json_decode($sSerialized, true);
             if (\is_array($aSerialized) && isset($aSerialized['FolderHash'], $aSerialized['Uids']) && $sFolderHash === $aSerialized['FolderHash'] && \is_array($aSerialized['Uids'])) {
                 if ($this->oLogger) {
                     $this->oLogger->Write('Get Serialized UIDS from cache (' . $sSerializedLog . ') [count:' . \count($aSerialized['Uids']) . ']');
                 }
                 $aResultUids = $aSerialized['Uids'];
                 $bUidsFromCacher = true;
             }
         }
     }
     if (!\is_array($aResultUids)) {
         $aResultUids = $bUseSortIfSupported ? $this->oImapClient->MessageSimpleSort(array('REVERSE ARRIVAL'), $sSearchCriterias, true) : $this->oImapClient->MessageSimpleSearch($sSearchCriterias, true, \MailSo\Base\Utils::IsAscii($sSearchCriterias) ? '' : 'UTF-8');
         if (!$bUidsFromCacher && $bUseCacheAfterSearch && \is_array($aResultUids) && $oCacher && $oCacher->IsInited() && 0 < \strlen($sSerializedHash)) {
             $oCacher->Set($sSerializedHash, @\json_encode(array('FolderHash' => $sFolderHash, 'Uids' => $aResultUids)));
             if ($this->oLogger) {
                 $this->oLogger->Write('Save Serialized UIDS to cache (' . $sSerializedLog . ') [count:' . \count($aResultUids) . ']');
             }
         }
     }
     return \is_array($aResultUids) ? $aResultUids : array();
 }
示例#3
0
 /**
  * @param string $sSearch
  * @param string $sFolderName
  * @param string|bool $sFolderHash
  * @param bool $bUseSortIfSupported = true
  * @param bool $bUseESearchOrESortRequest = false
  * @param \MailSo\Cache\CacheClient|null $oCacher = null
  *
  * @return Array|bool
  */
 private function getSearchUidsResult($sSearch, $sFolderName, $sFolderHash, $bUseSortIfSupported = true, $bUseESearchOrESortRequest = false, $oCacher = null)
 {
     $bUidsFromCacher = false;
     $aResultUids = false;
     $bUseCacheAfterSearch = true;
     $sSerializedHash = '';
     $bESortSupported = $bUseSortIfSupported && $bUseESearchOrESortRequest ? $this->oImapClient->IsSupported('ESORT') : false;
     $bESearchSupported = $bUseESearchOrESortRequest ? $this->oImapClient->IsSupported('ESEARCH') : false;
     $bUseSortIfSupported = $bUseSortIfSupported ? $this->oImapClient->IsSupported('SORT') : false;
     $sSearchCriterias = $this->getImapSearchCriterias($sSearch, 0, $bUseCacheAfterSearch);
     if ($bUseCacheAfterSearch && $oCacher && $oCacher->IsInited()) {
         $sSerializedHash = ($bUseSortIfSupported ? 'S' : 'N') . '/' . $this->oImapClient->GetLogginedUser() . '@' . $this->oImapClient->GetConnectedHost() . ':' . $this->oImapClient->GetConnectedPort() . '/' . $sFolderName . '/' . $sSearchCriterias;
         $sSerializedLog = '"' . $sFolderName . '" / ' . $sSearchCriterias . '';
         $sSerialized = $oCacher->Get($sSerializedHash);
         if (!empty($sSerialized)) {
             $aSerialized = @\unserialize($sSerialized);
             if (\is_array($aSerialized) && isset($aSerialized['FolderHash'], $aSerialized['Uids']) && \is_array($aSerialized['Uids']) && $sFolderHash === $aSerialized['FolderHash']) {
                 if ($this->oLogger) {
                     $this->oLogger->Write('Get Serialized UIDS from cache (' . $sSerializedLog . ') [count:' . \count($aSerialized['Uids']) . ']');
                 }
                 $aResultUids = $aSerialized['Uids'];
                 $bUidsFromCacher = true;
             }
         }
     }
     if (!\is_array($aResultUids)) {
         if ($bUseSortIfSupported) {
             if ($bESortSupported) {
                 $aESorthData = $this->oImapClient->MessageSimpleESort(array('ARRIVAL'), $sSearchCriterias, array('ALL'), true, '');
                 if (isset($aESorthData['ALL'])) {
                     $aResultUids = \MailSo\Base\Utils::ParseFetchSequence($aESorthData['ALL']);
                     $aResultUids = \array_reverse($aResultUids);
                 }
                 unset($aESorthData);
             } else {
                 $aResultUids = $this->oImapClient->MessageSimpleSort(array('REVERSE ARRIVAL'), $sSearchCriterias, true);
             }
         } else {
             if (!\MailSo\Base\Utils::IsAscii($sSearch)) {
                 try {
                     if ($bESearchSupported) {
                         $aESearchData = $this->oImapClient->MessageSimpleESearch($sSearchCriterias, array('ALL'), true, '', 'UTF-8');
                         if (isset($aESearchData['ALL'])) {
                             $aResultUids = \MailSo\Base\Utils::ParseFetchSequence($aESearchData['ALL']);
                             $aResultUids = \array_reverse($aResultUids);
                         }
                         unset($aESearchData);
                     } else {
                         $aResultUids = $this->oImapClient->MessageSimpleSearch($sSearchCriterias, true, 'UTF-8');
                     }
                 } catch (\MailSo\Imap\Exceptions\NegativeResponseException $oException) {
                     $oException = null;
                     $aResultUids = false;
                 }
             }
             if (false === $aResultUids) {
                 if ($bESearchSupported) {
                     $aESearchData = $this->oImapClient->MessageSimpleESearch($sSearchCriterias, array('ALL'), true);
                     if (isset($aESearchData['ALL'])) {
                         $aResultUids = \MailSo\Base\Utils::ParseFetchSequence($aESearchData['ALL']);
                         $aResultUids = \array_reverse($aResultUids);
                     }
                     unset($aESearchData);
                 } else {
                     $aResultUids = $this->oImapClient->MessageSimpleSearch($sSearchCriterias, true);
                 }
             }
         }
         if (!$bUidsFromCacher && $bUseCacheAfterSearch && \is_array($aResultUids) && $oCacher && $oCacher->IsInited() && 0 < \strlen($sSerializedHash)) {
             $oCacher->Set($sSerializedHash, \serialize(array('FolderHash' => $sFolderHash, 'Uids' => $aResultUids)));
             if ($this->oLogger) {
                 $this->oLogger->Write('Save Serialized UIDS to cache (' . $sSerializedLog . ') [count:' . \count($aResultUids) . ']');
             }
         }
     }
     return $aResultUids;
 }
示例#4
0
 /**
  * @param string $sFolderName
  * @param string $sFolderHash
  * @param \MailSo\Cache\CacheClient $oCacher
  *
  * @return array
  *
  * @throws \MailSo\Base\Exceptions\InvalidArgumentException
  * @throws \MailSo\Net\Exceptions\Exception
  * @throws \MailSo\Imap\Exceptions\Exception
  */
 public function MessageListThreadsMap($sFolderName, $sFolderHash, $oCacher)
 {
     if ($oCacher && $oCacher->IsInited()) {
         $sSerializedHash = 'ThreadsMap/UNDELETED/' . $this->oImapClient->GetLogginedUser() . '@' . $this->oImapClient->GetConnectedHost() . ':' . $this->oImapClient->GetConnectedPort() . '/' . $sFolderName . '/' . $sFolderHash;
         $sSerializedUids = $oCacher->Get($sSerializedHash);
         if (!empty($sSerializedUids)) {
             $aSerializedUids = @\unserialize($sSerializedUids);
             if (is_array($aSerializedUids)) {
                 return $aSerializedUids;
             }
         }
     }
     $this->oImapClient->FolderExamine($sFolderName);
     $aThreadUids = array();
     try {
         $aThreadUids = $this->oImapClient->MessageSimpleThread('UNDELETED');
     } catch (\MailSo\Imap\Exceptions\RuntimeException $oException) {
         $aThreadUids = array();
     }
     $aResult = $this->compileThreadArray($aThreadUids);
     if ($oCacher && $oCacher->IsInited() && !empty($sSerializedHash)) {
         $oCacher->Set($sSerializedHash, serialize($aResult));
     }
     return $aResult;
 }