Example #1
0
 /**
  * @param string $sBuffer
  *
  * @return void
  */
 public function WriteBody($sBuffer)
 {
     if (null === $this->oCurrentMime->Body) {
         $this->oCurrentMime->Body = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
     }
     if (\is_resource($this->oCurrentMime->Body)) {
         \fwrite($this->oCurrentMime->Body, $sBuffer);
     }
 }
Example #2
0
 /**
  * @return bool
  */
 private function rawFiles($bDownload = true, $bThumbnail = false)
 {
     $sRawKey = (string) $this->getParamValue('RawKey', '');
     $aValues = \CApi::DecodeKeyValues($sRawKey);
     if ($bThumbnail) {
         $this->verifyCacheByKey($sRawKey);
     }
     $sHash = (string) $this->getParamValue('TenantHash', '');
     $oMin = \CApi::Manager('min');
     $mMin = $oMin->getMinByHash($sHash);
     $oAccount = null;
     if (!empty($mMin['__hash__'])) {
         $oAccount = $this->oApiUsers->getAccountById($mMin['Account']);
     } else {
         if (isset($aValues['Iframed'], $aValues['Time']) && $aValues['Iframed'] && $aValues['Time']) {
             $oAccount = $this->getAccountFromParam(true, !($aValues['Time'] > \ProjectCore\Base\Utils::iframedTimestamp()));
             if (!$oAccount->IsDefaultAccount) {
                 $iAccountId = $this->oApiUsers->getDefaultAccountId($oAccount->IdUser);
                 if (0 < $iAccountId) {
                     $oAccount = $this->oApiUsers->getAccountById($iAccountId);
                 } else {
                     throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::AuthError);
                 }
             }
         } else {
             $oAccount = $this->getDefaultAccountFromParam();
         }
     }
     $oTenant = null;
     if ($oAccount && $this->oApiTenants) {
         $oTenant = 0 < $oAccount->IdTenant ? $this->oApiTenants->getTenantById($oAccount->IdTenant) : $this->oApiTenants->getDefaultGlobalTenant();
     }
     if ($this->oApiCapability->isFilesSupported($oAccount) && $oTenant && isset($aValues['Type'], $aValues['Path'], $aValues['Name'])) {
         $mResult = false;
         $sFileName = $aValues['Name'];
         $sContentType = empty($sFileName) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName);
         $oFileInfo = $this->oApiFilestorage->getFileInfo($oAccount, $aValues['Type'], $aValues['Path'], $aValues['Name']);
         if ($oFileInfo->IsLink) {
             $iLinkType = \api_Utils::GetLinkType($oFileInfo->LinkUrl);
             if (isset($iLinkType)) {
                 if (\EFileStorageLinkType::GoogleDrive === $iLinkType) {
                     $oSocial = $oTenant->getSocialByName('google');
                     if ($oSocial) {
                         $oInfo = \api_Utils::GetGoogleDriveFileInfo($oFileInfo->LinkUrl, $oSocial->SocialApiKey);
                         $sFileName = isset($oInfo->title) ? $oInfo->title : $sFileName;
                         $sContentType = \MailSo\Base\Utils::MimeContentType($sFileName);
                         if (isset($oInfo->downloadUrl)) {
                             $mResult = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
                             $this->oHttp->SaveUrlToFile($oInfo->downloadUrl, $mResult);
                             rewind($mResult);
                         }
                     }
                 } else {
                     if (\EFileStorageLinkType::DropBox === $iLinkType) {
                         $oFileInfo->LinkUrl = str_replace('www.dropbox.com', 'dl.dropboxusercontent.com', $oFileInfo->LinkUrl);
                     }
                     $mResult = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
                     $sFileName = basename($oFileInfo->LinkUrl);
                     $sContentType = \MailSo\Base\Utils::MimeContentType($sFileName);
                     $this->oHttp->SaveUrlToFile($oFileInfo->LinkUrl, $mResult);
                     rewind($mResult);
                 }
             }
         } else {
             $mResult = $this->oApiFilestorage->getFile($oAccount, $aValues['Type'], $aValues['Path'], $aValues['Name']);
         }
         if (false !== $mResult) {
             if (is_resource($mResult)) {
                 $sFileName = $this->clearFileName($oFileInfo->Name, $sContentType);
                 $sContentType = \MailSo\Base\Utils::MimeContentType($sFileName);
                 $this->RawOutputHeaders($bDownload, $sContentType, $sFileName);
                 if ($bThumbnail) {
                     $this->cacheByKey($sRawKey);
                     $this->thumbResource($oAccount, $mResult, $sFileName);
                 } else {
                     \MailSo\Base\Utils::FpassthruWithTimeLimitReset($mResult);
                 }
                 @fclose($mResult);
             }
             return true;
         }
     }
     return false;
 }
Example #3
0
 /**
  * @param string $sRawMessage
  * @return \MailSo\Mime\Part
  */
 public function ParseFromString($sRawMessage)
 {
     $rStreamHandle = 0 < strlen($sRawMessage) ? \MailSo\Base\ResourceRegistry::CreateMemoryResource() : false;
     if (is_resource($rStreamHandle)) {
         fwrite($rStreamHandle, $sRawMessage);
         unset($sRawMessage);
         fseek($rStreamHandle, 0);
         $this->ParseFromStream($rStreamHandle);
         \MailSo\Base\ResourceRegistry::CloseMemoryResource($rStreamHandle);
     }
     return $this;
 }
Example #4
0
 /**
  * @param array $aAlternativeData
  *
  * @return \MailSo\Mime\Part
  */
 private function createNewMessageAlternativePartBody($aAlternativeData)
 {
     $oAlternativePart = null;
     if (is_array($aAlternativeData) && isset($aAlternativeData[0])) {
         $oAlternativePart = Part::NewInstance();
         $oParameters = ParameterCollection::NewInstance();
         $oParameters->Add(Parameter::NewInstance(\MailSo\Mime\Enumerations\Parameter::CHARSET, \MailSo\Base\Enumerations\Charset::UTF_8));
         if (isset($aAlternativeData[3]) && \is_array($aAlternativeData[3]) && 0 < \count($aAlternativeData[3])) {
             foreach ($aAlternativeData[3] as $sName => $sValue) {
                 $oParameters->Add(Parameter::NewInstance($sName, $sValue));
             }
         }
         $oAlternativePart->Headers->Add(Header::NewInstance(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, $aAlternativeData[0] . '; ' . $oParameters->ToString()));
         $oAlternativePart->Body = null;
         if (isset($aAlternativeData[1])) {
             if (is_resource($aAlternativeData[1])) {
                 $oAlternativePart->Body = $aAlternativeData[1];
             } else {
                 if (is_string($aAlternativeData[1]) && 0 < strlen($aAlternativeData[1])) {
                     $oAlternativePart->Body = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString($aAlternativeData[1]);
                 }
             }
         }
         if (isset($aAlternativeData[2]) && 0 < strlen($aAlternativeData[2])) {
             $oAlternativePart->Headers->Add(Header::NewInstance(\MailSo\Mime\Enumerations\Header::CONTENT_TRANSFER_ENCODING, $aAlternativeData[2]));
             if (is_resource($oAlternativePart->Body)) {
                 if (!\MailSo\Base\StreamWrappers\Binary::IsStreamRemembed($oAlternativePart->Body)) {
                     $oAlternativePart->Body = \MailSo\Base\StreamWrappers\Binary::CreateStream($oAlternativePart->Body, \MailSo\Base\StreamWrappers\Binary::GetInlineDecodeOrEncodeFunctionName($aAlternativeData[2], false));
                     \MailSo\Base\StreamWrappers\Binary::RememberStream($oAlternativePart->Body);
                 }
             }
         }
         if (!is_resource($oAlternativePart->Body)) {
             $oAlternativePart->Body = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString('');
         }
     }
     return $oAlternativePart;
 }
Example #5
0
 /**
  * @param string $sUrl
  * @param string $sCustomUserAgent = 'MailSo Http User Agent (v1)'
  * @param string $sContentType = ''
  * @param int $iCode = 0
  * @param \MailSo\Log\Logger $oLogger = null
  * @param int $iTimeout = 10
  * @param string $sProxy = ''
  * @param string $sProxyAuth = ''
  * @param array $aHttpHeaders = array()
  * @param bool $bFollowLocation = true
  *
  * @return string|bool
  */
 public function GetUrlAsString($sUrl, $sCustomUserAgent = 'MailSo Http User Agent (v1)', &$sContentType = '', &$iCode = 0, $oLogger = null, $iTimeout = 10, $sProxy = '', $sProxyAuth = '', $aHttpHeaders = array(), $bFollowLocation = true)
 {
     $rMemFile = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
     if ($this->SaveUrlToFile($sUrl, $rMemFile, $sCustomUserAgent, $sContentType, $iCode, $oLogger, $iTimeout, $sProxy, $sProxyAuth, $aHttpHeaders, $bFollowLocation) && \is_resource($rMemFile)) {
         \rewind($rMemFile);
         return \stream_get_contents($rMemFile);
     }
     return false;
 }
 /**
  * @return array
  */
 public function DoSendReadReceiptMessage()
 {
     $oAccount = $this->initMailClientConnection();
     if (!$this->GetCapa(false, \RainLoop\Enumerations\Capa::COMPOSER, $oAccount)) {
         return $this->FalseResponse(__FUNCTION__);
     }
     $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, $iMessageStreamSize, false, false);
                 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($oAccount)->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__);
 }
Example #7
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;
 }
Example #8
0
 /**
  * @param string $sData
  *
  * @return \MailSo\Smtp\SmtpClient
  *
  * @throws \MailSo\Net\Exceptions\Exception
  * @throws \MailSo\Smtp\Exceptions\Exception
  */
 public function Data($sData)
 {
     if (!\MailSo\Base\Validator::NotEmptyString($sData, true)) {
         throw new \MailSo\Base\Exceptions\InvalidArgumentException();
     }
     $rDataStream = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString($sData);
     unset($sData);
     $this->DataWithStream($rDataStream);
     \MailSo\Base\ResourceRegistry::CloseMemoryResource($rDataStream);
     return $this;
 }
Example #9
0
 /**
  * @param string $sUrl
  * @param string $sCustomUserAgent = 'MaiSo Http User Agent (v1)'
  * @param string $sContentType = ''
  * @param int $iCode = 0
  * @param \MailSo\Log\Logger $oLogger = null
  *
  * @return string|bool
  */
 public function GetUrlAsString($sUrl, $sCustomUserAgent = 'MaiSo Http User Agent (v1)', &$sContentType = '', &$iCode = 0, $oLogger = null)
 {
     $rMemFile = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
     if ($this->SaveUrlToFile($sUrl, $rMemFile, $sCustomUserAgent, $sContentType, $iCode, $oLogger) && \is_resource($rMemFile)) {
         \rewind($rMemFile);
         return \stream_get_contents($rMemFile);
     }
     return false;
 }