Пример #1
0
 /**
  * @param string $sFolderName
  * @param string $sFolderHash
  * @param mixed $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/' . $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();
     } 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;
 }
 /**
  * @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)
 {
     $sSearchHash = '';
     if (\MailSo\Config::$MessageListUndeletedFilter) {
         $sSearchHash .= ' UNDELETED';
     }
     if (0 < \MailSo\Config::$MessageListDateFilter) {
         $iD = \time() - 3600 * 24 * 30 * \MailSo\Config::$MessageListDateFilter;
         $iTimeFilter = \gmmktime(1, 1, 1, \gmdate('n', $iD), 1, \gmdate('Y', $iD));
         $sSearchHash .= ' SINCE ' . \gmdate('j-M-Y', $iTimeFilter);
     }
     if ('' === \trim($sSearchHash)) {
         $sSearchHash = 'ALL';
     }
     if ($oCacher && $oCacher->IsInited()) {
         $sSerializedHash = 'ThreadsMap/' . $sSearchHash . '/' . $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)) {
                 if ($this->oLogger) {
                     $this->oLogger->Write('Get Serialized Thread UIDS from cache ("' . $sFolderName . '" / ' . $sSearchHash . ') [count:' . \count($aSerializedUids) . ']');
                 }
                 return $aSerializedUids;
             }
         }
     }
     $this->oImapClient->FolderExamine($sFolderName);
     $aThreadUids = array();
     try {
         $aThreadUids = $this->oImapClient->MessageSimpleThread($sSearchHash);
     } catch (\MailSo\Imap\Exceptions\RuntimeException $oException) {
         $aThreadUids = array();
     }
     $aResult = array();
     $aCompiledThreads = $this->compileThreadArray($aThreadUids);
     foreach ($aCompiledThreads as $mData) {
         if (\is_array($mData)) {
             foreach ($mData as $mSubData) {
                 $aResult[(int) $mSubData] = \array_diff($mData, array((int) $mSubData));
             }
         } else {
             if (\is_int($mData) || \is_string($mData)) {
                 $aResult[(int) $mData] = (int) $mData;
             }
         }
     }
     if ($oCacher && $oCacher->IsInited() && !empty($sSerializedHash)) {
         $oCacher->Set($sSerializedHash, serialize($aResult));
         if ($this->oLogger) {
             $this->oLogger->Write('Save Serialized Thread UIDS to cache ("' . $sFolderName . '" / ' . $sSearchHash . ') [count:' . \count($aResult) . ']');
         }
     }
     return $aResult;
 }
Пример #3
0
 /**
  * @param string $sFolderName
  * @param string $sFolderHash
  * @param array $aIndexOrUids
  * @param \MailSo\Cache\CacheClient $oCacher
  * @param bool $bCacheOnly = false
  *
  * @return array
  *
  * @throws \MailSo\Base\Exceptions\InvalidArgumentException
  * @throws \MailSo\Net\Exceptions\Exception
  * @throws \MailSo\Imap\Exceptions\Exception
  */
 public function MessageListThreadsMap($sFolderName, $sFolderHash, $aIndexOrUids, $oCacher, $bCacheOnly = false)
 {
     $iThreadLimit = \MailSo\Config::$LargeThreadLimit;
     $sSearchHash = '';
     if (0 < \MailSo\Config::$MessageListDateFilter) {
         $iD = \time() - 3600 * 24 * 30 * \MailSo\Config::$MessageListDateFilter;
         $iTimeFilter = \gmmktime(1, 1, 1, \gmdate('n', $iD), 1, \gmdate('Y', $iD));
         $sSearchHash .= ' SINCE ' . \gmdate('j-M-Y', $iTimeFilter);
     }
     if ('' === \trim($sSearchHash)) {
         $sSearchHash = 'ALL';
     }
     if ($oCacher && $oCacher->IsInited()) {
         $sSerializedHashKey = 'ThreadsMapSorted/' . $sSearchHash . '/' . 'Limit=' . $iThreadLimit . '/' . $sFolderName . '/' . $sFolderHash;
         if ($this->oLogger) {
             $this->oLogger->Write($sSerializedHashKey);
         }
         $sSerializedUids = $oCacher->Get($sSerializedHashKey);
         if (!empty($sSerializedUids)) {
             $aSerializedUids = @\json_decode($sSerializedUids, true);
             if (isset($aSerializedUids['ThreadsUids']) && \is_array($aSerializedUids['ThreadsUids'])) {
                 if ($this->oLogger) {
                     $this->oLogger->Write('Get Serialized Thread UIDS from cache ("' . $sFolderName . '" / ' . $sSearchHash . ') [count:' . \count($aSerializedUids['ThreadsUids']) . ']');
                 }
                 return $aSerializedUids['ThreadsUids'];
             }
         }
     }
     if ($bCacheOnly) {
         return null;
     }
     $this->oImapClient->FolderExamine($sFolderName);
     $aThreadUids = array();
     try {
         $aThreadUids = $this->oImapClient->MessageSimpleThread($sSearchHash);
     } catch (\MailSo\Imap\Exceptions\RuntimeException $oException) {
         unset($oException);
         $aThreadUids = array();
     }
     $aResult = array();
     $aCompiledThreads = $this->compileThreadArray($aThreadUids);
     foreach ($aCompiledThreads as $mData) {
         if (\is_array($mData)) {
             foreach ($mData as $mSubData) {
                 $aResult[(int) $mSubData] = \array_diff($mData, array((int) $mSubData));
             }
         } else {
             if (\is_int($mData) || \is_string($mData)) {
                 $aResult[(int) $mData] = (int) $mData;
             }
         }
     }
     $aParentsMap = array();
     foreach ($aIndexOrUids as $iUid) {
         if (isset($aResult[$iUid]) && \is_array($aResult[$iUid])) {
             foreach ($aResult[$iUid] as $iTempUid) {
                 $aParentsMap[$iTempUid] = $iUid;
                 if (isset($aResult[$iTempUid])) {
                     unset($aResult[$iTempUid]);
                 }
             }
         }
     }
     $aSortedThreads = array();
     foreach ($aIndexOrUids as $iUid) {
         if (isset($aResult[$iUid])) {
             $aSortedThreads[$iUid] = $iUid;
         }
     }
     foreach ($aIndexOrUids as $iUid) {
         if (!isset($aSortedThreads[$iUid]) && isset($aParentsMap[$iUid]) && isset($aSortedThreads[$aParentsMap[$iUid]])) {
             if (!\is_array($aSortedThreads[$aParentsMap[$iUid]])) {
                 $aSortedThreads[$aParentsMap[$iUid]] = array();
             }
             $aSortedThreads[$aParentsMap[$iUid]][] = $iUid;
         }
     }
     $aResult = $aSortedThreads;
     unset($aParentsMap, $aSortedThreads);
     $aTemp = array();
     foreach ($aResult as $iUid => $mValue) {
         if (0 < $iThreadLimit && \is_array($mValue) && $iThreadLimit < \count($mValue)) {
             $aParts = \array_chunk($mValue, $iThreadLimit);
             if (0 < count($aParts)) {
                 foreach ($aParts as $iIndex => $aItem) {
                     if (0 === $iIndex) {
                         $aResult[$iUid] = $aItem;
                     } else {
                         if (0 < $iIndex && \is_array($aItem)) {
                             $mFirst = \array_shift($aItem);
                             if (!empty($mFirst)) {
                                 $aTemp[$mFirst] = 0 < \count($aItem) ? $aItem : $mFirst;
                             }
                         }
                     }
                 }
             }
         }
     }
     foreach ($aTemp as $iUid => $mValue) {
         $aResult[$iUid] = $mValue;
     }
     unset($aTemp);
     $aLastResult = array();
     foreach ($aIndexOrUids as $iUid) {
         if (isset($aResult[$iUid])) {
             $aLastResult[$iUid] = $aResult[$iUid];
         }
     }
     $aResult = $aLastResult;
     unset($aLastResult);
     if ($oCacher && $oCacher->IsInited() && !empty($sSerializedHashKey)) {
         $oCacher->Set($sSerializedHashKey, @\json_encode(array('ThreadsUids' => $aResult)));
         if ($this->oLogger) {
             $this->oLogger->Write('Save Serialized Thread UIDS to cache ("' . $sFolderName . '" / ' . $sSearchHash . ') [count:' . \count($aResult) . ']');
         }
     }
     return $aResult;
 }