Example #1
0
 /**
  * @param string $sParent
  * @param string $sLiteralAtomUpperCase
  * @param resource $rImapStream
  * @param int $iLiteralLen
  *
  * @return bool
  */
 private function partialResponseLiteralCallbackCallable($sParent, $sLiteralAtomUpperCase, $rImapStream, $iLiteralLen)
 {
     $sLiteralAtomUpperCasePeek = '';
     if (0 === \strpos($sLiteralAtomUpperCase, 'BODY')) {
         $sLiteralAtomUpperCasePeek = \str_replace('BODY', 'BODY.PEEK', $sLiteralAtomUpperCase);
     }
     $sFetchKey = '';
     if (\is_array($this->aFetchCallbacks)) {
         if (0 < \strlen($sLiteralAtomUpperCasePeek) && isset($this->aFetchCallbacks[$sLiteralAtomUpperCasePeek])) {
             $sFetchKey = $sLiteralAtomUpperCasePeek;
         } else {
             if (0 < \strlen($sLiteralAtomUpperCase) && isset($this->aFetchCallbacks[$sLiteralAtomUpperCase])) {
                 $sFetchKey = $sLiteralAtomUpperCase;
             }
         }
     }
     $bResult = false;
     if (0 < \strlen($sFetchKey) && '' !== $this->aFetchCallbacks[$sFetchKey] && \is_callable($this->aFetchCallbacks[$sFetchKey])) {
         $rImapLiteralStream = \MailSo\Base\StreamWrappers\Literal::CreateStream($rImapStream, $iLiteralLen);
         $bResult = true;
         $this->writeLog('Start Callback for ' . $sParent . ' / ' . $sLiteralAtomUpperCase . ' - try to read ' . $iLiteralLen . ' bytes.', \MailSo\Log\Enumerations\Type::NOTE);
         $this->bRunningCallback = true;
         try {
             \call_user_func($this->aFetchCallbacks[$sFetchKey], $sParent, $sLiteralAtomUpperCase, $rImapLiteralStream);
         } catch (\Exception $oException) {
             $this->writeLog('Callback Exception', \MailSo\Log\Enumerations\Type::NOTICE);
             $this->writeLogException($oException);
         }
         if (\is_resource($rImapLiteralStream)) {
             $iNotReadLiteralLen = 0;
             $bFeof = \feof($rImapLiteralStream);
             $this->writeLog('End Callback for ' . $sParent . ' / ' . $sLiteralAtomUpperCase . ' - feof = ' . ($bFeof ? 'good' : 'BAD'), $bFeof ? \MailSo\Log\Enumerations\Type::NOTE : \MailSo\Log\Enumerations\Type::WARNING);
             if (!$bFeof) {
                 while (!@\feof($rImapLiteralStream)) {
                     $sBuf = @\fread($rImapLiteralStream, 1024 * 1024);
                     if (false === $sBuf || 0 === \strlen($sBuf) || null === $sBuf) {
                         break;
                     }
                     \MailSo\Base\Utils::ResetTimeLimit();
                     $iNotReadLiteralLen += \strlen($sBuf);
                 }
                 if (\is_resource($rImapLiteralStream) && !@\feof($rImapLiteralStream)) {
                     @\stream_get_contents($rImapLiteralStream);
                 }
             }
             if (\is_resource($rImapLiteralStream)) {
                 @\fclose($rImapLiteralStream);
             }
             if ($iNotReadLiteralLen > 0) {
                 $this->writeLog('Not read literal size is ' . $iNotReadLiteralLen . ' bytes.', \MailSo\Log\Enumerations\Type::WARNING);
             }
         } else {
             $this->writeLog('Literal stream is not resource after callback.', \MailSo\Log\Enumerations\Type::WARNING);
         }
         \MailSo\Base\Loader::IncStatistic('NetRead', $iLiteralLen);
         $this->bRunningCallback = false;
     }
     return $bResult;
 }
Example #2
0
 /**
  * @param string $sParent
  * @param string $sLiteralAtomUpperCase
  * @param resource $rImapStream
  * @param int $iLiteralLen
  *
  * @return bool
  */
 private function partialResponseLiteralCallbackCallable($sParent, $sLiteralAtomUpperCase, $rImapStream, $iLiteralLen)
 {
     $sLiteralAtomUpperCasePeek = '';
     if (0 === strpos($sLiteralAtomUpperCase, 'BODY')) {
         $sLiteralAtomUpperCasePeek = str_replace('BODY', 'BODY.PEEK', $sLiteralAtomUpperCase);
     }
     $sFetchKey = '';
     if (is_array($this->aFetchCallbacks)) {
         if (0 < strlen($sLiteralAtomUpperCasePeek) && isset($this->aFetchCallbacks[$sLiteralAtomUpperCasePeek])) {
             $sFetchKey = $sLiteralAtomUpperCasePeek;
         } else {
             if (0 < strlen($sLiteralAtomUpperCase) && isset($this->aFetchCallbacks[$sLiteralAtomUpperCase])) {
                 $sFetchKey = $sLiteralAtomUpperCase;
             }
         }
     }
     $bResult = false;
     if (0 < \strlen($sFetchKey) && '' !== $this->aFetchCallbacks[$sFetchKey] && \is_callable($this->aFetchCallbacks[$sFetchKey])) {
         $rImapLiteralStream = \MailSo\Base\StreamWrappers\Literal::CreateStream($rImapStream, $iLiteralLen);
         $bResult = true;
         $this->writeLog('Callback for ' . $sParent . ' / ' . $sLiteralAtomUpperCase . ' - try to read ' . $iLiteralLen . ' bytes.', \MailSo\Log\Enumerations\Type::NOTE);
         \call_user_func($this->aFetchCallbacks[$sFetchKey], $sParent, $sLiteralAtomUpperCase, $rImapLiteralStream);
         $iTimer = 0;
         $iNotReadLiteralLen = 0;
         while (!\feof($rImapLiteralStream)) {
             $sBuf = \fread($rImapLiteralStream, 8192);
             if (false !== $sBuf) {
                 \MailSo\Base\Utils::ResetTimeLimit($iTimer);
                 $iNotReadLiteralLen += \strlen($sBuf);
                 continue;
             }
             break;
         }
         if ($iNotReadLiteralLen > 0) {
             $this->writeLog('Not read literal size ' . $iNotReadLiteralLen . ' bytes.', \MailSo\Log\Enumerations\Type::WARNING);
         }
         \MailSo\Base\Loader::IncStatistic('NetRead', $iLiteralLen);
         if (\is_resource($rImapLiteralStream)) {
             \fclose($rImapLiteralStream);
         }
     }
     return $bResult;
 }