예제 #1
0
 /**
  * @param array $aSubStreams
  *
  * @return resource|bool
  */
 public static function CreateStream($aSubStreams)
 {
     if (!\in_array(self::STREAM_NAME, \stream_get_wrappers())) {
         \stream_wrapper_register(self::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\SubStreams');
     }
     $sHashName = \MailSo\Base\Utils::Md5Rand();
     self::$aStreams[$sHashName] = $aSubStreams;
     \MailSo\Base\Loader::IncStatistic('CreateStream/SubStreams');
     return \fopen(self::STREAM_NAME . '://' . $sHashName, 'rb');
 }
예제 #2
0
 /**
  * @return string
  */
 public static function GetShortToken()
 {
     $sKey = 'rlsession';
     $sToken = \RainLoop\Utils::GetCookie($sKey, null);
     if (null === $sToken) {
         $sToken = \MailSo\Base\Utils::Md5Rand(APP_SALT);
         \RainLoop\Utils::SetCookie($sKey, $sToken, 0, '/', null, null, true);
     }
     return \md5('Session' . APP_SALT . $sToken . 'Token' . APP_SALT);
 }
예제 #3
0
 /**
  * @param string $sSearch
  *
  * @return array
  */
 private function parseSearchString($sSearch)
 {
     $aResult = array('OTHER' => '');
     $aCache = array();
     $sReg = 'e?mail|from|to|subject|has|is|date|text|body|size|larger|bigger|smaller|maxsize|minsize';
     $sSearch = \MailSo\Base\Utils::StripSpaces($sSearch);
     $sSearch = \trim(\preg_replace('/(' . $sReg . '): /i', '\\1:', $sSearch));
     $mMatch = array();
     \preg_match_all('/".*?(?<!\\\\)"/', $sSearch, $mMatch);
     if (\is_array($mMatch) && isset($mMatch[0]) && \is_array($mMatch[0]) && 0 < \count($mMatch[0])) {
         foreach ($mMatch[0] as $sItem) {
             do {
                 $sKey = \MailSo\Base\Utils::Md5Rand();
             } while (isset($aCache[$sKey]));
             $aCache[$sKey] = \stripcslashes($sItem);
             $sSearch = \str_replace($sItem, $sKey, $sSearch);
         }
     }
     \preg_match_all('/\'.*?(?<!\\\\)\'/', $sSearch, $mMatch);
     if (\is_array($mMatch) && isset($mMatch[0]) && \is_array($mMatch[0]) && 0 < \count($mMatch[0])) {
         foreach ($mMatch[0] as $sItem) {
             do {
                 $sKey = \MailSo\Base\Utils::Md5Rand();
             } while (isset($aCache[$sKey]));
             $aCache[$sKey] = \stripcslashes($sItem);
             $sSearch = \str_replace($sItem, $sKey, $sSearch);
         }
     }
     $mMatch = array();
     \preg_match_all('/(' . $sReg . '):([^\\s]*)/i', $sSearch, $mMatch);
     if (\is_array($mMatch) && isset($mMatch[1]) && \is_array($mMatch[1]) && 0 < \count($mMatch[1])) {
         if (\is_array($mMatch[0])) {
             foreach ($mMatch[0] as $sToken) {
                 $sSearch = \str_replace($sToken, '', $sSearch);
             }
             $sSearch = \MailSo\Base\Utils::StripSpaces($sSearch);
         }
         foreach ($mMatch[1] as $iIndex => $sName) {
             if (isset($mMatch[2][$iIndex]) && 0 < \strlen($mMatch[2][$iIndex])) {
                 $sName = \strtoupper($sName);
                 $sValue = $mMatch[2][$iIndex];
                 switch ($sName) {
                     case 'TEXT':
                     case 'BODY':
                     case 'EMAIL':
                     case 'MAIL':
                     case 'FROM':
                     case 'TO':
                     case 'SUBJECT':
                     case 'IS':
                     case 'HAS':
                     case 'SIZE':
                     case 'SMALLER':
                     case 'LARGER':
                     case 'BIGGER':
                     case 'MAXSIZE':
                     case 'MINSIZE':
                     case 'DATE':
                         if ('MAIL' === $sName) {
                             $sName = 'EMAIL';
                         }
                         if ('BODY' === $sName) {
                             $sName = 'TEXT';
                         }
                         if ('SIZE' === $sName || 'BIGGER' === $sName || 'MINSIZE' === $sName) {
                             $sName = 'LARGER';
                         }
                         if ('MAXSIZE' === $sName) {
                             $sName = 'SMALLER';
                         }
                         $aResult[$sName] = $sValue;
                         break;
                 }
             }
         }
     }
     $aResult['OTHER'] = $sSearch;
     foreach ($aResult as $sName => $sValue) {
         if (isset($aCache[$sValue])) {
             $aResult[$sName] = \trim($aCache[$sValue], '"\' ');
         }
     }
     return $aResult;
 }
예제 #4
0
 /**
  * @staticvar string $sCache;
  *
  * @return string
  */
 public static function Guid()
 {
     static $sCache = null;
     if (null === $sCache) {
         $sCache = \substr(\MailSo\Base\Utils::Md5Rand(), -8);
     }
     return $sCache;
 }
예제 #5
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sHash
  *
  * @return array
  */
 private function getMimeFileByHash($oAccount, $sHash)
 {
     $aValues = $this->getDecodedRawKeyValue($sHash);
     $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'] : '';
     $oFileProvider = $this->FilesProvider();
     $sResultHash = '';
     $mResult = $this->MailClient()->MessageMimeStream(function ($rResource, $sContentType, $sFileName, $sMimeIndex = '') use($oAccount, $oFileProvider, $sFileNameIn, $sContentTypeIn, &$sResultHash) {
         unset($sContentType, $sFileName, $sMimeIndex);
         if ($oAccount && \is_resource($rResource)) {
             $sHash = \MailSo\Base\Utils::Md5Rand($sFileNameIn . '~' . $sContentTypeIn);
             $rTempResource = $oFileProvider->GetFile($oAccount, $sHash, 'wb+');
             if (@\is_resource($rTempResource)) {
                 if (false !== \MailSo\Base\Utils::MultipleStreamWriter($rResource, array($rTempResource))) {
                     $sResultHash = $sHash;
                 }
                 @\fclose($rTempResource);
             }
         }
     }, $sFolder, $iUid, true, $sMimeIndex);
     $aValues['FileHash'] = '';
     if ($mResult) {
         $aValues['FileHash'] = $sResultHash;
     }
     return $aValues;
 }
예제 #6
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);
 }
예제 #7
0
 /**
  * @return array
  */
 public function RegenerateContactStr()
 {
     $this->IdContactStr = \class_exists('SabreForRainLoop\\DAV\\Client') ? \SabreForRainLoop\DAV\UUIDUtil::getUUID() : \MailSo\Base\Utils::Md5Rand();
 }
예제 #8
0
 /**
  * @return bool
  */
 public function GenerateID()
 {
     return $this->sId = \MailSo\Base\Utils::Md5Rand();
 }
예제 #9
0
 /**
  * @param string $sHostName = ''
  *
  * @return string
  */
 private function generateNewMessageId($sHostName = '')
 {
     if (0 === \strlen($sHostName)) {
         $sHostName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
     }
     if (empty($sHostName) && \MailSo\Base\Utils::FunctionExistsAndEnabled('php_uname')) {
         $sHostName = \php_uname('n');
     }
     if (empty($sHostName)) {
         $sHostName = 'localhost';
     }
     return '<' . \MailSo\Base\Utils::Md5Rand($sHostName . (\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? @\getmypid() : '')) . '@' . $sHostName . '>';
 }
예제 #10
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);
 }