예제 #1
0
 /**
  * @param int $iUserId
  * @param string $sKey
  * @param resource $rSource
  * @param string $sFileSuffix Default value is empty string.
  * @param string $sFolder Default value is empty string.
  *
  * @return bool
  */
 public function putFile($iUserId, $sKey, $rSource, $sFileSuffix = '', $sFolder = '')
 {
     $bResult = false;
     if ($rSource) {
         $rOpenOutput = @fopen($this->generateFileName($iUserId, $sKey, true, $sFileSuffix, $sFolder), 'w+b');
         if ($rOpenOutput) {
             $bResult = false !== \MailSo\Base\Utils::MultipleStreamWriter($rSource, array($rOpenOutput));
             @fclose($rOpenOutput);
         }
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Account $oAccount
  * @param string $sKey
  * @param resource $rSource
  *
  * @return bool
  */
 public function PutFile($oAccount, $sKey, $rSource)
 {
     $bResult = false;
     if ($rSource) {
         $rOpenOutput = @\fopen($this->generateFileName($oAccount, $sKey, true), 'w+b');
         if ($rOpenOutput) {
             $bResult = false !== \MailSo\Base\Utils::MultipleStreamWriter($rSource, array($rOpenOutput));
             @\fclose($rOpenOutput);
         }
     }
     return $bResult;
 }
예제 #3
0
 /**
  * @param string $sFolderName
  * @param resource $rMessageAppendStream
  * @param int $iStreamSize
  * @param array	$aAppendFlags = null
  * @param int $iUid = null
  * @param int $sDateTime = 0
  *
  * @return \MailSo\Imap\ImapClient
  *
  * @throws \MailSo\Base\Exceptions\InvalidArgumentException
  * @throws \MailSo\Net\Exceptions\Exception
  * @throws \MailSo\Imap\Exceptions\Exception
  */
 public function MessageAppendStream($sFolderName, $rMessageAppendStream, $iStreamSize, $aAppendFlags = null, &$iUid = null, $sDateTime = 0)
 {
     $aData = array($this->EscapeString($sFolderName), $aAppendFlags);
     if (0 < $sDateTime) {
         $aData[] = $this->EscapeString(\gmdate('d-M-Y H:i:s', $sDateTime) . ' +0000');
     }
     $aData[] = '{' . $iStreamSize . '}';
     $this->SendRequest('APPEND', $aData);
     $this->parseResponseWithValidation();
     $this->writeLog('Write to connection stream', \MailSo\Log\Enumerations\Type::NOTE);
     \MailSo\Base\Utils::MultipleStreamWriter($rMessageAppendStream, array($this->rConnect));
     $this->sendRaw('');
     $this->parseResponseWithValidation();
     if (null !== $iUid) {
         $aLastResponse = $this->GetLastResponse();
         if (\is_array($aLastResponse) && 0 < \count($aLastResponse) && $aLastResponse[\count($aLastResponse) - 1]) {
             $oLast = $aLastResponse[count($aLastResponse) - 1];
             if ($oLast && \MailSo\Imap\Enumerations\ResponseType::TAGGED === $oLast->ResponseType && \is_array($oLast->OptionalResponse)) {
                 if (0 < \strlen($oLast->OptionalResponse[0]) && 0 < \strlen($oLast->OptionalResponse[2]) && 'APPENDUID' === strtoupper($oLast->OptionalResponse[0]) && \is_numeric($oLast->OptionalResponse[2])) {
                     $iUid = (int) $oLast->OptionalResponse[2];
                 }
             }
         }
     }
     return $this;
 }
예제 #4
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;
 }
예제 #5
0
 /**
  * Saves message to a specific folder. The method is primarily used for saving drafts.
  * 
  * @param CAccount $oAccount Account object.
  * @param \MailSo\Mime\Message $oMessage Object representing message to be saved.
  * @param string $sDraftFolder Folder the message is saved to.
  * @param string $sDraftUid = ''. UID of the message to be replaced; saving new draft removes the previous version.
  *
  * @return array|bool Array containing name of the folder and UID of the message stored, or bool in case of failure.
  *
  * @throws CApiInvalidArgumentException
  */
 public function saveMessage($oAccount, $oMessage, $sDraftFolder, $sDraftUid = '')
 {
     if (!$oAccount || !$oMessage || 0 === strlen($sDraftFolder)) {
         throw new CApiInvalidArgumentException();
     }
     $oImapClient =& $this->_getImapClient($oAccount);
     $rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
     $iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter($oMessage->ToStream(), array($rMessageStream), 8192, true, true);
     $mResult = false;
     if (false !== $iMessageStreamSize && is_resource($rMessageStream)) {
         rewind($rMessageStream);
         $iNewUid = 0;
         $oImapClient->MessageAppendStream($sDraftFolder, $rMessageStream, $iMessageStreamSize, array(\MailSo\Imap\Enumerations\MessageFlag::SEEN), $iNewUid);
         if (null === $iNewUid || 0 === $iNewUid) {
             $sMessageId = $oMessage->MessageId();
             if (0 < strlen($sMessageId)) {
                 $iNewUid = $this->getMessageUid($oAccount, $sDraftFolder, $sMessageId);
             }
         }
         $mResult = true;
         if (0 < strlen($sDraftFolder) && 0 < strlen($sDraftUid)) {
             $this->deleteMessage($oAccount, $sDraftFolder, array($sDraftUid));
         }
         if (null !== $iNewUid && 0 < $iNewUid) {
             $mResult = array('NewFolder' => $sDraftFolder, 'NewUid' => $iNewUid);
         }
     }
     return $mResult;
 }
예제 #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
 /**
  * @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);
 }
예제 #8
0
 /**
  * @return array
  */
 public function DoSendReadReceiptMessage()
 {
     $oAccount = $this->initMailClientConnection();
     $oMessage = $this->buildReadReceiptMessage($oAccount);
     $this->Plugins()->RunHook('filter.send-read-receipt-message', array(&$oMessage, $oAccount));
     $mResult = false;
     try {
         if ($oMessage) {
             $rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
             $iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter($oMessage->ToStream(true), array($rMessageStream), 8192, true, true, true);
             if (false !== $iMessageStreamSize) {
                 $this->smtpSendMessage($oAccount, $oMessage, $rMessageStream);
                 if (\is_resource($rMessageStream)) {
                     @\fclose($rMessageStream);
                 }
                 $mResult = true;
                 $sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', '');
                 if (!empty($sReadReceiptFlag)) {
                     $sFolderFullName = $this->GetActionParam('MessageFolder', '');
                     $sUid = $this->GetActionParam('MessageUid', '');
                     $this->Cacher()->Set(\RainLoop\KeyPathHelper::ReadReceiptCache($oAccount->Email(), $sFolderFullName, $sUid), '1');
                     if (0 < \strlen($sFolderFullName) && 0 < \strlen($sUid)) {
                         try {
                             $this->MailClient()->MessageSetFlag($sFolderFullName, array($sUid), true, $sReadReceiptFlag, true, true);
                         } catch (\Exception $oException) {
                         }
                     }
                 }
             }
         }
     } catch (\RainLoop\Exceptions\ClientException $oException) {
         throw $oException;
     } catch (\Exception $oException) {
         throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSendMessage, $oException);
     }
     if (false === $mResult) {
         throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSendMessage);
     }
     return $this->TrueResponse(__FUNCTION__);
 }