/**
  * @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;
 }
Esempio n. 2
0
 /**
  * @return string
  */
 public function ServiceSso()
 {
     $oException = null;
     $oAccount = null;
     $bLogout = true;
     $sSsoHash = $this->oHttp->GetRequest('hash', '');
     if (!empty($sSsoHash)) {
         $mData = null;
         $sSsoSubData = $this->Cacher()->Get(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
         if (!empty($sSsoSubData)) {
             $mData = \RainLoop\Utils::DecodeKeyValuesQ($sSsoSubData);
             $this->Cacher()->Delete(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
             if (\is_array($mData) && !empty($mData['Email']) && isset($mData['Password'], $mData['Time']) && (0 === $mData['Time'] || \time() - 10 < $mData['Time'])) {
                 $sEmail = \trim($mData['Email']);
                 $sPassword = $mData['Password'];
                 $aAdditionalOptions = isset($mData['AdditionalOptions']) && \is_array($mData['AdditionalOptions']) && 0 < \count($mData['AdditionalOptions']) ? $mData['AdditionalOptions'] : null;
                 try {
                     $oAccount = $this->oActions->LoginProcess($sEmail, $sPassword);
                     if ($oAccount instanceof \RainLoop\Model\Account && $aAdditionalOptions) {
                         $bNeedToSettings = false;
                         $oSettings = $this->SettingsProvider()->Load($oAccount);
                         if ($oSettings) {
                             $sLanguage = isset($aAdditionalOptions['Language']) ? $aAdditionalOptions['Language'] : '';
                             if ($sLanguage) {
                                 $sLanguage = $this->oActions->ValidateLanguage($sLanguage);
                                 if ($sLanguage !== $oSettings->GetConf('Language', '')) {
                                     $bNeedToSettings = true;
                                     $oSettings->SetConf('Language', $sLanguage);
                                 }
                             }
                         }
                         if ($bNeedToSettings) {
                             $this->SettingsProvider()->Save($oAccount, $oSettings);
                         }
                     }
                     $this->oActions->AuthToken($oAccount);
                     $bLogout = !$oAccount instanceof \RainLoop\Model\Account;
                 } catch (\Exception $oException) {
                     $this->oActions->Logger()->WriteException($oException);
                 }
             }
         }
     }
     if ($bLogout) {
         $this->oActions->SetAuthLogoutToken();
     }
     $this->oActions->Location('./');
     return '';
 }
Esempio n. 3
0
 /**
  * @param string $sSsoHash
  *
  * @return bool
  */
 public static function ClearUserSsoHash($sSsoHash)
 {
     return \RainLoop\Api::Actions()->Cacher()->Delete(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
 }
 /**
  * @return string
  */
 public function ServiceSso()
 {
     $oException = null;
     $oAccount = null;
     $bLogout = true;
     $sSsoHash = $this->oHttp->GetRequest('hash', '');
     if (!empty($sSsoHash)) {
         $mData = null;
         $sSsoSubData = $this->Cacher()->Get(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
         if (!empty($sSsoSubData)) {
             $mData = \RainLoop\Utils::DecodeKeyValues($sSsoSubData);
             $this->Cacher()->Delete(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
             if (\is_array($mData) && !empty($mData['Email']) && isset($mData['Password'], $mData['Time']) && (0 === $mData['Time'] || \time() - 10 < $mData['Time'])) {
                 $sEmail = \trim($mData['Email']);
                 $sPassword = $mData['Password'];
                 try {
                     $oAccount = $this->oActions->LoginProcess($sEmail, $sPassword);
                     $this->oActions->AuthProcess($oAccount);
                     $bLogout = !$oAccount instanceof \RainLoop\Account;
                 } catch (\Exception $oException) {
                     $this->oActions->Logger()->WriteException($oException);
                 }
             }
         }
     }
     if ($bLogout) {
         $this->oActions->SetAuthLogoutToken();
     }
     $this->oActions->Location('./');
     return '';
 }
Esempio n. 5
0
 /**
  * @todo
  * @param string $sEmail
  *
  * @return bool
  */
 public static function ClearUserDateStorage($sEmail)
 {
     $sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail);
     // TwoFactor Auth User Data
     self::Actions()->StorageProvider()->Clear(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, \RainLoop\KeyPathHelper::TwoFactorAuthUserData($sEmail));
 }
Esempio n. 6
0
 /**
  * @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;
         $sClassName = \get_class($mResponse);
         $bHasSimpleJsonFunc = \method_exists($mResponse, 'ToSimpleJSON');
         $bThumb = $this->GetCapa(false, \RainLoop\Enumerations\Capa::ATTACHMENT_THUMBNAILS);
         if ($bHasSimpleJsonFunc) {
             $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), $mResponse->ToSimpleJSON(true));
         } else {
             if ('MailSo\\Mail\\Message' === $sClassName) {
                 $oAccount = $this->getAccountFromToken(false);
                 $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' => !!$this->Config()->Get('labs', 'date_from_headers', false) ? $mResponse->HeaderTimeStampInUTC() : $mResponse->InternalTimeStampInUTC(), '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(), 'ThreadsLen' => $mResponse->ThreadsLen(), 'ParentThread' => $mResponse->ParentThread(), '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['AttachmentsMainType'] = '';
                 if (0 < $iAttachmentsCount) {
                     switch (true) {
                         case $iAttachmentsCount === $oAttachments->ImageCount():
                             $mResult['AttachmentsMainType'] = 'image';
                             break;
                         case $iAttachmentsCount === $oAttachments->ArchiveCount():
                             $mResult['AttachmentsMainType'] = 'archive';
                             break;
                         case $iAttachmentsCount === $oAttachments->PdfCount():
                             $mResult['AttachmentsMainType'] = 'pdf';
                             break;
                         case $iAttachmentsCount === $oAttachments->DocCount():
                             $mResult['AttachmentsMainType'] = 'doc';
                             break;
                         case $iAttachmentsCount === $oAttachments->CertificateCount():
                             $mResult['AttachmentsMainType'] = 'certificate';
                             break;
                     }
                 }
                 $sSubject = $mResult['Subject'];
                 $mResult['Hash'] = \md5($mResult['Folder'] . $mResult['Uid']);
                 $mResult['RequestHash'] = \RainLoop\Utils::EncodeKeyValues(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);
                 $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();
                     $fAdditionalExternalFilter = null;
                     if (!!$this->Config()->Get('labs', 'use_local_proxy_for_external_images', false)) {
                         $fAdditionalExternalFilter = function ($sUrl) {
                             return './?/ProxyExternal/' . \RainLoop\Utils::EncodeKeyValues(array('Rnd' => \md5(\microtime(true)), 'Token' => \RainLoop\Utils::GetConnectionToken(), 'Url' => $sUrl)) . '/';
                         };
                     }
                     $mResult['Html'] = 0 === \strlen($sHtml) ? '' : \MailSo\Base\HtmlUtils::ClearHtml($sHtml, $bHasExternals, $mFoundedCIDs, $aContentLocationUrls, $mFoundedContentLocationUrls, false, false, $fAdditionalExternalFilter);
                     $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::EncodeKeyValues(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' => \MailSo\Mail\MailClient::GenerateHash($mResponse->FullNameRaw(), $mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT']));
                                         }
                                         $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(), '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, 'NewMessages' => $this->responseObject($mResponse->NewMessages), 'LastCollapsedThreadUids' => $mResponse->LastCollapsedThreadUids, '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, '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 {
                                                         if ('RainLoop\\Providers\\AddressBook\\Classes\\Group' === $sClassName) {
                                                             $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdGroup' => $mResponse->IdGroup, 'Name' => $mResponse->Name, 'Contacts' => $this->responseObject($mResponse->Contacts, $sParent, $aParameters)));
                                                         } else {
                                                             if ('RainLoop\\Providers\\AddressBook\\Classes\\GroupContact' === $sClassName) {
                                                                 $mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('IdContact' => $mResponse->IdContact, 'IdGroup' => $mResponse->IdGroup, 'Name' => $mResponse->Name, 'Email' => $mResponse->Email, 'Phone' => $mResponse->Phone));
                                                             } 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;
 }
 /**
  * @param string $sEmail
  *
  * @return bool
  */
 public static function ClearUserData($sEmail)
 {
     if (0 < \strlen($sEmail)) {
         $sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail);
         $oStorageProvider = \RainLoop\Api::Actions()->StorageProvider();
         if ($oStorageProvider && $oStorageProvider->IsActive()) {
             // TwoFactor Auth User Data
             $oStorageProvider->Clear(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, \RainLoop\KeyPathHelper::TwoFactorAuthUserData($sEmail));
             // Accounts list
             $oStorageProvider->Clear(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, \RainLoop\KeyPathHelper::WebmailAccounts($sEmail));
             // Contact sync data
             $oStorageProvider->Clear($sEmail, \RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG, 'contacts_sync');
         }
         \RainLoop\Api::Actions()->SettingsProvider()->ClearByEmail($sEmail);
         if (\RainLoop\Api::Actions()->AddressBookProvider() && \RainLoop\Api::Actions()->AddressBookProvider()->IsActive()) {
             \RainLoop\Api::Actions()->AddressBookProvider()->DeleteAllContactsAndTags($sEmail);
         }
         return true;
     }
     return false;
 }