Ejemplo n.º 1
0
 /**
  * @param bool $bDownload
  * @param bool $bThumbnail = false
  *
  * @return bool
  */
 private function rawSmart($bDownload, $bThumbnail = false)
 {
     $sRawKey = (string) $this->GetActionParam('RawKey', '');
     $aValues = $this->getDecodedRawKeyValue($sRawKey);
     $sFolder = isset($aValues['Folder']) ? $aValues['Folder'] : '';
     $iUid = isset($aValues['Uid']) ? (int) $aValues['Uid'] : 0;
     $sMimeIndex = isset($aValues['MimeIndex']) ? (string) $aValues['MimeIndex'] : '';
     $sContentTypeIn = isset($aValues['MimeType']) ? (string) $aValues['MimeType'] : '';
     $sFileNameIn = isset($aValues['FileName']) ? (string) $aValues['FileName'] : '';
     $sFileHashIn = isset($aValues['FileHash']) ? (string) $aValues['FileHash'] : '';
     if (!empty($sFileHashIn)) {
         $this->verifyCacheByKey($sRawKey);
         $oAccount = $this->getAccountFromToken();
         $sContentTypeOut = empty($sContentTypeIn) ? \MailSo\Base\Utils::MimeContentType($sFileNameIn) : $sContentTypeIn;
         $sFileNameOut = $this->MainClearFileName($sFileNameIn, $sContentTypeIn, $sMimeIndex);
         $rResource = $this->FilesProvider()->GetFile($oAccount, $sFileHashIn);
         if (\is_resource($rResource)) {
             $sFileNameOut = \MailSo\Base\Utils::ConvertEncoding($sFileNameOut, \MailSo\Base\Enumerations\Charset::UTF_8, \MailSo\Base\Enumerations\Charset::CP858);
             \header('Content-Type: ' . $sContentTypeOut);
             \header('Content-Disposition: attachment; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true);
             \header('Accept-Ranges: none', true);
             \header('Content-Transfer-Encoding: binary');
             \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource);
             return true;
         }
         return false;
     } else {
         if (!empty($sFolder) && 0 < $iUid) {
             $this->verifyCacheByKey($sRawKey);
         }
     }
     $oAccount = $this->initMailClientConnection();
     $self = $this;
     return $this->MailClient()->MessageMimeStream(function ($rResource, $sContentType, $sFileName, $sMimeIndex = '') use($self, $oAccount, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload, $bThumbnail) {
         if ($oAccount && \is_resource($rResource)) {
             $sContentTypeOut = $sContentTypeIn;
             if (empty($sContentTypeOut)) {
                 $sContentTypeOut = $sContentType;
                 if (empty($sContentTypeOut)) {
                     $sContentTypeOut = empty($sFileName) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName);
                 }
             }
             $sFileNameOut = $sFileNameIn;
             if (empty($sFileNameOut)) {
                 $sFileNameOut = $sFileName;
             }
             $sFileNameOut = $self->MainClearFileName($sFileNameOut, $sContentTypeOut, $sMimeIndex);
             $self->cacheByKey($sRawKey);
             $bDone = false;
             if ($bThumbnail && !$bDownload) {
                 $sFileName = '';
                 $rTempResource = \MailSo\Base\StreamWrappers\TempFile::CreateStream(\MailSo\Base\Utils::Md5Rand($sFileNameOut), $sFileName);
                 if (@\is_resource($rTempResource)) {
                     $bDone = true;
                     \MailSo\Base\Utils::MultipleStreamWriter($rResource, array($rTempResource));
                     @\fclose($rTempResource);
                     try {
                         $oThumb = new \PHPThumb\GD($sFileName);
                         if ($oThumb) {
                             $oThumb->adaptiveResize(60, 60)->show();
                         }
                     } catch (\Exception $oException) {
                         $self->Logger()->WriteExceptionShort($oException);
                     }
                 }
             }
             if (!$bDone) {
                 \header('Content-Type: ' . $sContentTypeOut);
                 \header('Content-Disposition: ' . ($bDownload ? 'attachment' : 'inline') . '; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true);
                 \header('Accept-Ranges: none', true);
                 \header('Content-Transfer-Encoding: binary');
                 \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource);
             }
         }
     }, $sFolder, $iUid, true, $sMimeIndex);
 }
Ejemplo n.º 2
0
 /**
  * @param bool $bDownload
  * @param bool $bThumbnail = false
  *
  * @return bool
  */
 private function rawSmart($bDownload, $bThumbnail = false)
 {
     $sRawKey = (string) $this->GetActionParam('RawKey', '');
     $aValues = $this->getDecodedRawKeyValue($sRawKey);
     $sFolder = isset($aValues['Folder']) ? $aValues['Folder'] : '';
     $iUid = (int) isset($aValues['Uid']) ? $aValues['Uid'] : 0;
     $sMimeIndex = (string) isset($aValues['MimeIndex']) ? $aValues['MimeIndex'] : '';
     $sContentTypeIn = (string) isset($aValues['MimeType']) ? $aValues['MimeType'] : '';
     $sFileNameIn = (string) isset($aValues['FileName']) ? $aValues['FileName'] : '';
     if (!empty($sFolder) && 0 < $iUid) {
         $this->verifyCacheByKey($sRawKey);
     }
     $oAccount = $this->initMailClientConnection();
     $self = $this;
     return $this->MailClient()->MessageMimeStream(function ($rResource, $sContentType, $sFileName, $sMimeIndex = '') use($self, $oAccount, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload, $bThumbnail) {
         if ($oAccount && \is_resource($rResource)) {
             $sContentTypeOut = $sContentTypeIn;
             if (empty($sContentTypeOut)) {
                 $sContentTypeOut = $sContentType;
                 if (empty($sContentTypeOut)) {
                     $sContentTypeOut = empty($sFileName) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName);
                 }
             }
             $sFileNameOut = $sFileNameIn;
             if (empty($sFileNameOut)) {
                 $sFileNameOut = $sFileName;
             }
             $sFileNameOut = $self->MainClearFileName($sFileNameOut, $sContentTypeOut, $sMimeIndex);
             $self->cacheByKey($sRawKey);
             $bDone = false;
             if ($bThumbnail && !$bDownload) {
                 \MailSo\Base\StreamWrappers\TempFile::Reg();
                 $sFileName = 'mailsotempfile://' . \MailSo\Base\Utils::Md5Rand($sFileNameOut);
                 $rTempResource = @\fopen($sFileName, 'r+b');
                 if (@\is_resource($rTempResource)) {
                     \MailSo\Base\Utils::MultipleStreamWriter($rResource, array($rTempResource));
                     @\fclose($rTempResource);
                     $oThumb = @new \PHPThumb\GD($sFileName);
                     if ($oThumb) {
                         $oThumb->adaptiveResize(60, 60)->show();
                         $bDone = true;
                     }
                 }
             }
             if (!$bDone) {
                 \header('Content-Type: ' . $sContentTypeOut);
                 \header('Content-Disposition: ' . ($bDownload ? 'attachment' : 'inline') . '; ' . \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileNameOut)), true);
                 \header('Accept-Ranges: none', true);
                 \header('Content-Transfer-Encoding: binary');
                 \MailSo\Base\Utils::FpassthruWithTimeLimitReset($rResource);
             }
         }
     }, $sFolder, $iUid, true, $sMimeIndex);
 }