/** * @param mixed $mResponse * @param string $sParent * @param array $aParameters = array() * * @return mixed */ protected function responseObject($mResponse, $sParent = '', $aParameters = array()) { $mResult = $mResponse; if (\is_object($mResponse)) { $bHook = true; $self = $this; $sClassName = \get_class($mResponse); $bHasSimpleJsonFunc = \method_exists($mResponse, 'ToSimpleJSON'); $bThumb = $this->GetCapa(false, \RainLoop\Enumerations\Capa::ATTACHMENT_THUMBNAILS); $oAccountCache = null; $fGetAccount = function () use($self, &$oAccountCache) { if (null === $oAccountCache) { $oAccount = $self->getAccountFromToken(false); $oAccountCache = $oAccount; } return $oAccountCache; }; $aCheckableFoldersCache = null; $fGetCheckableFolder = function () use($self, &$aCheckableFoldersCache) { if (null === $aCheckableFoldersCache) { $oAccount = $self->getAccountFromToken(false); $oSettingsLocal = $self->SettingsProvider(true)->Load($oAccount); $sCheckable = $oSettingsLocal->GetConf('CheckableFolder', '[]'); $aCheckable = @\json_decode($sCheckable); if (!\is_array($aCheckable)) { $aCheckable = array(); } $aCheckableFoldersCache = $aCheckable; } return $aCheckableFoldersCache; }; if ($bHasSimpleJsonFunc) { $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), $mResponse->ToSimpleJSON(true)); } else { if ('MailSo\\Mail\\Message' === $sClassName) { $oAccount = \call_user_func($fGetAccount); $iDateTimeStampInUTC = $mResponse->InternalTimeStampInUTC(); if (0 === $iDateTimeStampInUTC || !!$this->Config()->Get('labs', 'date_from_headers', false)) { $iDateTimeStampInUTC = $mResponse->HeaderTimeStampInUTC(); if (0 === $iDateTimeStampInUTC) { $iDateTimeStampInUTC = $mResponse->InternalTimeStampInUTC(); } } $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Folder' => $mResponse->Folder(), 'Uid' => (string) $mResponse->Uid(), 'Subject' => \trim(\MailSo\Base\Utils::Utf8Clear($mResponse->Subject())), 'MessageId' => $mResponse->MessageId(), 'Size' => $mResponse->Size(), 'DateTimeStampInUTC' => $iDateTimeStampInUTC, 'ReplyTo' => $this->responseObject($mResponse->ReplyTo(), $sParent, $aParameters), 'From' => $this->responseObject($mResponse->From(), $sParent, $aParameters), 'To' => $this->responseObject($mResponse->To(), $sParent, $aParameters), 'Cc' => $this->responseObject($mResponse->Cc(), $sParent, $aParameters), 'Bcc' => $this->responseObject($mResponse->Bcc(), $sParent, $aParameters), 'Sender' => $this->responseObject($mResponse->Sender(), $sParent, $aParameters), 'DeliveredTo' => $this->responseObject($mResponse->DeliveredTo(), $sParent, $aParameters), 'Priority' => $mResponse->Priority(), 'Threads' => $mResponse->Threads(), 'Sensitivity' => $mResponse->Sensitivity(), 'ExternalProxy' => false, 'ReadReceipt' => '')); $mResult['SubjectParts'] = $this->explodeSubject($mResult['Subject']); $oAttachments = $mResponse->Attachments(); $iAttachmentsCount = $oAttachments ? $oAttachments->Count() : 0; $mResult['HasAttachments'] = 0 < $iAttachmentsCount; $mResult['AttachmentsSpecData'] = $mResult['HasAttachments'] ? $oAttachments->SpecData() : array(); $sSubject = $mResult['Subject']; $mResult['Hash'] = \md5($mResult['Folder'] . $mResult['Uid']); $mResult['RequestHash'] = \RainLoop\Utils::EncodeKeyValuesQ(array('V' => APP_VERSION, 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeType' => 'message/rfc822', 'FileName' => (0 === \strlen($sSubject) ? 'message-' . $mResult['Uid'] : \MailSo\Base\Utils::ClearXss($sSubject)) . '.eml')); // Flags $aFlags = $mResponse->FlagsLowerCase(); $mResult['IsSeen'] = \in_array('\\seen', $aFlags); $mResult['IsFlagged'] = \in_array('\\flagged', $aFlags); $mResult['IsAnswered'] = \in_array('\\answered', $aFlags); $mResult['IsDeleted'] = \in_array('\\deleted', $aFlags); $sForwardedFlag = $this->Config()->Get('labs', 'imap_forwarded_flag', ''); $sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', ''); $mResult['IsForwarded'] = 0 < \strlen($sForwardedFlag) && \in_array(\strtolower($sForwardedFlag), $aFlags); $mResult['IsReadReceipt'] = 0 < \strlen($sReadReceiptFlag) && \in_array(\strtolower($sReadReceiptFlag), $aFlags); if (!$this->GetCapa(false, \RainLoop\Enumerations\Capa::COMPOSER, $oAccount)) { $mResult['IsReadReceipt'] = true; } $mResult['TextPartIsTrimmed'] = false; if ('Message' === $sParent) { $oAttachments = $mResponse->Attachments(); $bHasExternals = false; $mFoundedCIDs = array(); $aContentLocationUrls = array(); $mFoundedContentLocationUrls = array(); if ($oAttachments && 0 < $oAttachments->Count()) { $aList =& $oAttachments->GetAsArray(); foreach ($aList as $oAttachment) { if ($oAttachment) { $sContentLocation = $oAttachment->ContentLocation(); if ($sContentLocation && 0 < \strlen($sContentLocation)) { $aContentLocationUrls[] = $oAttachment->ContentLocation(); } } } } $sPlain = ''; $sHtml = \trim($mResponse->Html()); if (0 === \strlen($sHtml)) { $sPlain = \trim($mResponse->Plain()); } $mResult['DraftInfo'] = $mResponse->DraftInfo(); $mResult['InReplyTo'] = $mResponse->InReplyTo(); $mResult['References'] = $mResponse->References(); $fAdditionalDomReader = null; if (0 < \strlen($sHtml) && $this->Config()->Get('labs', 'emogrifier', false)) { if (!\class_exists('Pelago\\Emogrifier', false)) { include_once APP_VERSION_ROOT_PATH . 'app/libraries/emogrifier/Emogrifier.php'; } if (\class_exists('Pelago\\Emogrifier', false)) { $fAdditionalDomReader = function ($oDom) { $oEmogrifier = new \Pelago\Emogrifier(); $oEmogrifier->preserveEncoding = false; return $oEmogrifier->emogrify($oDom); }; } } $fAdditionalExternalFilter = null; if (!!$this->Config()->Get('labs', 'use_local_proxy_for_external_images', false)) { $fAdditionalExternalFilter = function ($sUrl) { return './?/ProxyExternal/' . \RainLoop\Utils::EncodeKeyValuesQ(array('Rnd' => \md5(\microtime(true)), 'Token' => \RainLoop\Utils::GetConnectionToken(), 'Url' => $sUrl)) . '/'; }; } $sHtml = \preg_replace_callback('/(<pre[^>]*>)([\\s\\S\\r\\n\\t]*?)(<\\/pre>)/mi', function ($aMatches) { return \preg_replace('/[\\r\\n]+/', '<br />', $aMatches[1] . \trim($aMatches[2]) . $aMatches[3]); }, $sHtml); $mResult['Html'] = 0 === \strlen($sHtml) ? '' : \MailSo\Base\HtmlUtils::ClearHtml($sHtml, $bHasExternals, $mFoundedCIDs, $aContentLocationUrls, $mFoundedContentLocationUrls, false, false, $fAdditionalExternalFilter, $fAdditionalDomReader, !!$this->Config()->Get('labs', 'try_to_detect_hidden_images', false)); $mResult['ExternalProxy'] = null !== $fAdditionalExternalFilter; $mResult['Plain'] = $sPlain; // $mResult['Plain'] = 0 === \strlen($sPlain) ? '' : \MailSo\Base\HtmlUtils::ConvertPlainToHtml($sPlain); $mResult['TextHash'] = \md5($mResult['Html'] . $mResult['Plain']); $mResult['TextPartIsTrimmed'] = $mResponse->TextPartIsTrimmed(); $mResult['PgpSigned'] = $mResponse->PgpSigned(); $mResult['PgpEncrypted'] = $mResponse->PgpEncrypted(); $mResult['PgpSignature'] = $mResponse->PgpSignature(); unset($sHtml, $sPlain); $mResult['HasExternals'] = $bHasExternals; $mResult['HasInternals'] = \is_array($mFoundedCIDs) && 0 < \count($mFoundedCIDs) || \is_array($mFoundedContentLocationUrls) && 0 < \count($mFoundedContentLocationUrls); $mResult['FoundedCIDs'] = $mFoundedCIDs; $mResult['Attachments'] = $this->responseObject($oAttachments, $sParent, \array_merge($aParameters, array('FoundedCIDs' => $mFoundedCIDs, 'FoundedContentLocationUrls' => $mFoundedContentLocationUrls))); $mResult['ReadReceipt'] = $mResponse->ReadReceipt(); if (0 < \strlen($mResult['ReadReceipt']) && !$mResult['IsReadReceipt']) { if (0 < \strlen($mResult['ReadReceipt'])) { try { $oReadReceipt = \MailSo\Mime\Email::Parse($mResult['ReadReceipt']); if (!$oReadReceipt) { $mResult['ReadReceipt'] = ''; } } catch (\Exception $oException) { unset($oException); } } if (0 < \strlen($mResult['ReadReceipt']) && '1' === $this->Cacher($oAccount)->Get(\RainLoop\KeyPathHelper::ReadReceiptCache($oAccount->Email(), $mResult['Folder'], $mResult['Uid']), '0')) { $mResult['ReadReceipt'] = ''; } } } } else { if ('MailSo\\Mime\\Email' === $sClassName) { $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Name' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetDisplayName()), 'Email' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetEmail(true)), 'DkimStatus' => $mResponse->GetDkimStatus(), 'DkimValue' => $mResponse->GetDkimValue())); } else { if ('RainLoop\\Providers\\AddressBook\\Classes\\Contact' === $sClassName) { $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdContact' => $mResponse->IdContact, 'Display' => \MailSo\Base\Utils::Utf8Clear($mResponse->Display), 'ReadOnly' => $mResponse->ReadOnly, 'IdPropertyFromSearch' => $mResponse->IdPropertyFromSearch, 'Properties' => $this->responseObject($mResponse->Properties, $sParent, $aParameters))); } else { if ('RainLoop\\Providers\\AddressBook\\Classes\\Tag' === $sClassName) { $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdContactTag' => $mResponse->IdContactTag, 'Name' => \MailSo\Base\Utils::Utf8Clear($mResponse->Name), 'ReadOnly' => $mResponse->ReadOnly)); } else { if ('RainLoop\\Providers\\AddressBook\\Classes\\Property' === $sClassName) { // Simple hack if ($mResponse && $mResponse->IsWeb()) { $mResponse->Value = \preg_replace('/(skype|ftp|http[s]?)\\\\:\\/\\//i', '$1://', $mResponse->Value); } $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdProperty' => $mResponse->IdProperty, 'Type' => $mResponse->Type, 'TypeStr' => $mResponse->TypeStr, 'Value' => \MailSo\Base\Utils::Utf8Clear($mResponse->Value))); } else { if ('MailSo\\Mail\\Attachment' === $sClassName) { $oAccount = $this->getAccountFromToken(false); $mFoundedCIDs = isset($aParameters['FoundedCIDs']) && \is_array($aParameters['FoundedCIDs']) && 0 < \count($aParameters['FoundedCIDs']) ? $aParameters['FoundedCIDs'] : null; $mFoundedContentLocationUrls = isset($aParameters['FoundedContentLocationUrls']) && \is_array($aParameters['FoundedContentLocationUrls']) && 0 < \count($aParameters['FoundedContentLocationUrls']) ? $aParameters['FoundedContentLocationUrls'] : null; if ($mFoundedCIDs || $mFoundedContentLocationUrls) { $mFoundedCIDs = \array_merge($mFoundedCIDs ? $mFoundedCIDs : array(), $mFoundedContentLocationUrls ? $mFoundedContentLocationUrls : array()); $mFoundedCIDs = 0 < \count($mFoundedCIDs) ? $mFoundedCIDs : null; } $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Folder' => $mResponse->Folder(), 'Uid' => (string) $mResponse->Uid(), 'Framed' => false, 'MimeIndex' => (string) $mResponse->MimeIndex(), 'MimeType' => $mResponse->MimeType(), 'FileName' => \MailSo\Base\Utils::ClearFileName(\MailSo\Base\Utils::ClearXss($mResponse->FileName(true))), 'EstimatedSize' => $mResponse->EstimatedSize(), 'CID' => $mResponse->Cid(), 'ContentLocation' => $mResponse->ContentLocation(), 'IsInline' => $mResponse->IsInline(), 'IsThumbnail' => $bThumb, 'IsLinked' => $mFoundedCIDs && \in_array(\trim(\trim($mResponse->Cid()), '<>'), $mFoundedCIDs) || $mFoundedContentLocationUrls && \in_array(\trim($mResponse->ContentLocation()), $mFoundedContentLocationUrls))); $mResult['Framed'] = $this->isFileHasFramedPreview($mResult['FileName']); if ($mResult['IsThumbnail']) { $mResult['IsThumbnail'] = $this->isFileHasThumbnail($mResult['FileName']); } $mResult['Download'] = \RainLoop\Utils::EncodeKeyValuesQ(array('V' => APP_VERSION, 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeIndex' => $mResult['MimeIndex'], 'MimeType' => $mResult['MimeType'], 'FileName' => $mResult['FileName'], 'Framed' => $mResult['Framed'])); } else { if ('MailSo\\Mail\\Folder' === $sClassName) { $aExtended = null; // $mStatus = $mResponse->Status(); // if (\is_array($mStatus) && isset($mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT'])) // { // $aExtended = array( // 'MessageCount' => (int) $mStatus['MESSAGES'], // 'MessageUnseenCount' => (int) $mStatus['UNSEEN'], // 'UidNext' => (string) $mStatus['UIDNEXT'], // 'Hash' => $this->MailClient()->GenerateFolderHash( // $mResponse->FullNameRaw(), $mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT'], // empty($mStatus['HIGHESTMODSEQ']) ? '' : $mStatus['HIGHESTMODSEQ']) // ); // } $aCheckableFolder = \call_user_func($fGetCheckableFolder); if (!\is_array($aCheckableFolder)) { $aCheckableFolder = array(); } $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Name' => $mResponse->Name(), 'FullName' => $mResponse->FullName(), 'FullNameRaw' => $mResponse->FullNameRaw(), 'FullNameHash' => $this->hashFolderFullName($mResponse->FullNameRaw(), $mResponse->FullName()), 'Delimiter' => (string) $mResponse->Delimiter(), 'HasVisibleSubFolders' => $mResponse->HasVisibleSubFolders(), 'IsSubscribed' => $mResponse->IsSubscribed(), 'IsExists' => $mResponse->IsExists(), 'IsSelectable' => $mResponse->IsSelectable(), 'Flags' => $mResponse->FlagsLowerCase(), 'Checkable' => \in_array($mResponse->FullNameRaw(), $aCheckableFolder), 'Extended' => $aExtended, 'SubFolders' => $this->responseObject($mResponse->SubFolders(), $sParent, $aParameters))); } else { if ('MailSo\\Mail\\MessageCollection' === $sClassName) { $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('MessageCount' => $mResponse->MessageCount, 'MessageUnseenCount' => $mResponse->MessageUnseenCount, 'MessageResultCount' => $mResponse->MessageResultCount, 'Folder' => $mResponse->FolderName, 'FolderHash' => $mResponse->FolderHash, 'UidNext' => $mResponse->UidNext, 'ThreadUid' => $mResponse->ThreadUid, 'NewMessages' => $this->responseObject($mResponse->NewMessages), 'Filtered' => $mResponse->Filtered, 'Offset' => $mResponse->Offset, 'Limit' => $mResponse->Limit, 'Search' => $mResponse->Search)); } else { if ('MailSo\\Mail\\AttachmentCollection' === $sClassName) { $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('InlineCount' => $mResponse->InlineCount())); } else { if ('MailSo\\Mail\\FolderCollection' === $sClassName) { $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Namespace' => $mResponse->GetNamespace(), 'FoldersHash' => isset($mResponse->FoldersHash) ? $mResponse->FoldersHash : '', 'IsThreadsSupported' => $mResponse->IsThreadsSupported, 'Optimized' => $mResponse->Optimized, 'CountRec' => $mResponse->CountRec(), 'SystemFolders' => isset($mResponse->SystemFolders) && \is_array($mResponse->SystemFolders) ? $mResponse->SystemFolders : array())); } else { if ($mResponse instanceof \MailSo\Base\Collection) { $aList =& $mResponse->GetAsArray(); if (100 < \count($aList) && $mResponse instanceof \MailSo\Mime\EmailCollection) { $aList = \array_slice($aList, 0, 100); } $mResult = $this->responseObject($aList, $sParent, $aParameters); $bHook = false; } else { $mResult = '["' . \get_class($mResponse) . '"]'; $bHook = false; } } } } } } } } } } } } if ($bHook) { $this->Plugins()->RunHook('filter.response-object', array($sClassName, $mResult), false); } } else { if (\is_array($mResponse)) { foreach ($mResponse as $iKey => $oItem) { $mResponse[$iKey] = $this->responseObject($oItem, $sParent, $aParameters); } $mResult = $mResponse; } } unset($mResponse); return $mResult; }
/** * @return string */ public function GetAuthTokenQ() { return \RainLoop\Utils::EncodeKeyValuesQ(array('token', $this->sEmail, $this->sLogin, $this->sPassword, \RainLoop\Utils::Fingerprint(), $this->sSignMeToken, $this->sParentEmail, \RainLoop\Utils::GetShortToken(), $this->sProxyAuthUser, $this->sProxyAuthPassword, 0)); }
/** * @param string $sEmail * @param string $sPassword * @param array $aAdditionalOptions = array() * @param bool $bUseTimeout = true * * @return string */ public static function GetUserSsoHash($sEmail, $sPassword, $aAdditionalOptions = array(), $bUseTimeout = true) { $sSsoHash = \MailSo\Base\Utils::Sha1Rand($sEmail . $sPassword); return \RainLoop\Api::Actions()->Cacher()->Set(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash), \RainLoop\Utils::EncodeKeyValuesQ(array('Email' => $sEmail, 'Password' => $sPassword, 'AdditionalOptions' => $aAdditionalOptions, 'Time' => $bUseTimeout ? \time() : 0))) ? $sSsoHash : ''; }