diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Collection.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Collection.php index a5af47a7b..59a249d70 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Collection.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Collection.php @@ -15,7 +15,7 @@ namespace MailSo\Base; * @category MailSo * @package Base */ -abstract class Collection extends \ArrayObject +abstract class Collection extends \ArrayObject implements \JsonSerializable { function __construct($input = array(), int $flags = 0, string $iterator_class = "ArrayIterator") { @@ -64,4 +64,14 @@ abstract class Collection extends \ArrayObject ); return $this; } + + public function jsonSerialize() + { + $aNames = explode('\\', get_class($this)); + return array( + '@Object' => 'Collection/' . end($aNames), + '@Count' => $this->Count(), + '@Collection' => $this->getArrayCopy() + ); + } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Attachment.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Attachment.php index 34fcd9095..9d99cb270 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Attachment.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Attachment.php @@ -15,7 +15,7 @@ namespace MailSo\Mail; * @category MailSo * @package Mail */ -class Attachment +class Attachment implements \JsonSerializable { /** * @var string @@ -160,4 +160,20 @@ class Attachment $this->oBodyStructure = $oBodyStructure; return $this; } + + public function jsonSerialize() + { + return array( + '@Object' => 'Object/Attachment', + 'Folder' => $this->Folder(), + 'Uid' => (string) $this->Uid(), + 'MimeIndex' => (string) $this->MimeIndex(), + 'MimeType' => $this->MimeType(), + 'FileName' => \MailSo\Base\Utils::ClearFileName(\MailSo\Base\Utils::ClearXss($this->FileName(true))), + 'EstimatedSize' => $this->EstimatedSize(), + 'Cid' => $this->Cid(), + 'ContentLocation' => $this->ContentLocation(), + 'IsInline' => $this->IsInline() + ); + } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/AttachmentCollection.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/AttachmentCollection.php index b7955dcb4..01494c392 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/AttachmentCollection.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/AttachmentCollection.php @@ -55,4 +55,11 @@ class AttachmentCollection extends \MailSo\Base\Collection } return $aResult; } + + public function jsonSerialize() + { + return array_merge(parent::jsonSerialize(), array( + 'InlineCount' => $this->InlineCount() + )); + } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Folder.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Folder.php index 4112a996a..3faedf643 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Folder.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Folder.php @@ -15,7 +15,7 @@ namespace MailSo\Mail; * @category MailSo * @package Mail */ -class Folder +class Folder implements \JsonSerializable { /** * @var string @@ -226,4 +226,20 @@ class Folder return $iListType; } + + public function jsonSerialize() + { + return array( + '@Object' => 'Object/Folder', + 'Name' => $this->Name(), + 'FullName' => $this->FullName(), + 'FullNameRaw' => $this->FullNameRaw(), + 'Delimiter' => (string) $this->Delimiter(), + 'HasVisibleSubFolders' => $this->HasVisibleSubFolders(), + 'IsSubscribed' => $this->IsSubscribed(), + 'IsExists' => $this->IsExists(), + 'IsSelectable' => $this->IsSelectable(), + 'Flags' => $this->FlagsLowerCase() + ); + } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/FolderCollection.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/FolderCollection.php index 3fc2e129c..8db19093f 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/FolderCollection.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/FolderCollection.php @@ -232,4 +232,17 @@ class FolderCollection extends \MailSo\Base\Collection } } } + + public function jsonSerialize() + { + return array_merge(parent::jsonSerialize(), array( + 'Namespace' => $this->GetNamespace(), + 'FoldersHash' => $this->FoldersHash ?: '', + 'IsThreadsSupported' => $this->IsThreadsSupported, + 'Optimized' => $this->Optimized, + 'CountRec' => $this->CountRec(), + 'SystemFolders' => isset($this->SystemFolders) && \is_array($this->SystemFolders) ? + $this->SystemFolders : array() + )); + } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php index 16fb3cac1..176c1626b 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php @@ -15,7 +15,7 @@ namespace MailSo\Mail; * @category MailSo * @package Mail */ -class Message +class Message implements \JsonSerializable { /** * @var string @@ -744,4 +744,44 @@ class Message return $this; } + + public function jsonSerialize() + { + $oAttachments = $this->Attachments(); + $aFlags = $this->FlagsLowerCase(); + return array( + '@Object' => 'Object/Message', + 'Folder' => $this->Folder(), + 'Uid' => (string) $this->Uid(), + 'Subject' => \trim(\MailSo\Base\Utils::Utf8Clear($this->Subject())), + 'MessageId' => $this->MessageId(), + 'Size' => $this->Size(), + 'DateTimeStampInUTC' => $this->InternalTimeStampInUTC(), + + // \MailSo\Mime\EmailCollection + 'From' => $this->From(), + 'ReplyTo' => $this->ReplyTo(), + 'To' => $this->To(), + 'Cc' => $this->Cc(), + 'Bcc' => $this->Bcc(), + 'Sender' => $this->Sender(), + 'DeliveredTo' => $this->DeliveredTo(), + + 'Priority' => $this->Priority(), + 'Threads' => $this->Threads(), + 'Sensitivity' => $this->Sensitivity(), + 'UnsubsribeLinks' => $this->UnsubsribeLinks(), + 'ExternalProxy' => false, + 'ReadReceipt' => '', + + 'HasAttachments' => $oAttachments ? 0 < $oAttachments->Count() : false, + 'AttachmentsSpecData' => $oAttachments ? $oAttachments->SpecData() : array(), + + // Flags + 'IsSeen' => \in_array('\\seen', $aFlags), + 'IsFlagged' => \in_array('\\flagged', $aFlags), + 'IsAnswered' => \in_array('\\answered', $aFlags), + 'IsDeleted' => \in_array('\\deleted', $aFlags) + ); + } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MessageCollection.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MessageCollection.php index 1c709bc4b..ebdd4bb7e 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MessageCollection.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MessageCollection.php @@ -110,4 +110,22 @@ class MessageCollection extends \MailSo\Base\Collection $this->Filtered = false; } + + public function jsonSerialize() + { + return array_merge(parent::jsonSerialize(), array( + 'MessageCount' => $this->MessageCount, + 'MessageUnseenCount' => $this->MessageUnseenCount, + 'MessageResultCount' => $this->MessageResultCount, + 'Folder' => $this->FolderName, + 'FolderHash' => $this->FolderHash, + 'UidNext' => $this->UidNext, + 'ThreadUid' => $this->ThreadUid, + 'NewMessages' => $this->NewMessages, + 'Filtered' => $this->Filtered, + 'Offset' => $this->Offset, + 'Limit' => $this->Limit, + 'Search' => $this->Search + )); + } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php index 15cbd922d..f9328afd9 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php @@ -193,389 +193,278 @@ trait Response private $aCheckableFolder = null; private function responseObject($mResponse, string $sParent = '', array $aParameters = array()) { - /** - \MailSo\Mime\Email - \RainLoop\Model\Domain - \RainLoop\Model\Identity - \RainLoop\Model\Template - \RainLoop\Providers\AddressBook\Classes\Contact - \RainLoop\Providers\AddressBook\Classes\Property - \RainLoop\Providers\AddressBook\Classes\Tag - \RainLoop\Providers\Filters\Classes\Filter - \RainLoop\Providers\Filters\Classes\FilterCondition - */ - if ($mResponse instanceof \JsonSerializable) { -// return $mResponse->jsonSerialize(); + if (!($mResponse instanceof \JsonSerializable)) + { + if (\is_array($mResponse)) + { + foreach ($mResponse as $iKey => $oItem) + { + $mResponse[$iKey] = $this->responseObject($oItem, $sParent, $aParameters); + } + } + + if (\is_object($mResponse)) + { + return '["'.\get_class($mResponse).'"]'; + } + return $mResponse; } - if (\is_object($mResponse)) + if ($mResponse instanceof \MailSo\Mail\Message) { - $sClassName = \get_class($mResponse); + $mResult = $mResponse->jsonSerialize(); - if ('MailSo\Mail\Message' === $sClassName) + if (null === $this->oAccount) { + $this->oAccount = $this->getAccountFromToken(false); + } + $oAccount = $this->oAccount; + + if (!$mResult['DateTimeStampInUTC'] || !!$this->Config()->Get('labs', 'date_from_headers', false)) { + $iDateTimeStampInUTC = $mResponse->HeaderTimeStampInUTC(); + if ($iDateTimeStampInUTC) { + $mResult['DateTimeStampInUTC'] = $iDateTimeStampInUTC; + } + } + + // \MailSo\Mime\EmailCollection + foreach (['ReplyTo','From','To','Cc','Bcc','Sender','DeliveredTo','ReplyTo'] as $prop) { + $mResult[$prop] = $this->responseObject($mResult[$prop], $sParent, $aParameters); + } + + $mResult['SubjectParts'] = $this->explodeSubject($mResult['Subject']); + + $sSubject = $mResult['Subject']; + $mResult['Hash'] = \md5($mResult['Folder'].$mResult['Uid']); + $mResult['RequestHash'] = 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' + )); + + $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, false, Capa::COMPOSER, $oAccount)) + { + $mResult['IsReadReceipt'] = true; + } + + $mResult['TextPartIsTrimmed'] = false; + + if ('Message' === $sParent) + { + $oAttachments = /* @var \MailSo\Mail\AttachmentCollection */ $mResponse->Attachments(); + + $bHasExternals = false; + $mFoundedCIDs = array(); + $aContentLocationUrls = array(); + $mFoundedContentLocationUrls = array(); + + if ($oAttachments && 0 < $oAttachments->Count()) + { + foreach ($oAttachments as /* @var \MailSo\Mail\Attachment */ $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['UnsubsribeLinks'] = $mResponse->UnsubsribeLinks(); + $mResult['References'] = $mResponse->References(); + + $fAdditionalExternalFilter = null; + if (!!$this->Config()->Get('labs', 'use_local_proxy_for_external_images', false)) + { + $fAdditionalExternalFilter = function ($sUrl) { + return './?/ProxyExternal/'.Utils::EncodeKeyValuesQ(array( + 'Rnd' => \md5(\microtime(true)), + 'Token' => Utils::GetConnectionToken(), + 'Url' => $sUrl + )).'/'; + }; + } + + $sHtml = \preg_replace_callback('/(
]*>)([\s\S\r\n\t]*?)(<\/pre>)/mi', function ($aMatches) {
+ return \preg_replace('/[\r\n]+/', '
', $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, null, !!$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 (\Throwable $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'] = '';
+ }
+ }
+ }
+ return $mResult;
+ }
+
+ if ($mResponse instanceof \MailSo\Mail\Attachment)
+ {
+ $mResult = $mResponse->jsonSerialize();
+
+ if (null === $this->oAccount) {
+ $this->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['IsLinked'] = ($mFoundedCIDs && \in_array(\trim(\trim($mResponse->Cid()), '<>'), $mFoundedCIDs))
+ || ($mFoundedContentLocationUrls && \in_array(\trim($mResponse->ContentLocation()), $mFoundedContentLocationUrls));
+
+ $mResult['Framed'] = $this->isFileHasFramedPreview($mResult['FileName']);
+ $mResult['IsThumbnail'] = $this->GetCapa(false, false, Capa::ATTACHMENT_THUMBNAILS) && $this->isFileHasThumbnail($mResult['FileName']);
+
+ $mResult['Download'] = Utils::EncodeKeyValuesQ(array(
+ 'V' => APP_VERSION,
+ 'Account' => $this->oAccount ? \md5($this->oAccount->Hash()) : '',
+ 'Folder' => $mResult['Folder'],
+ 'Uid' => $mResult['Uid'],
+ 'MimeIndex' => $mResult['MimeIndex'],
+ 'MimeType' => $mResult['MimeType'],
+ 'FileName' => $mResult['FileName'],
+ 'Framed' => $mResult['Framed']
+ ));
+ return $mResult;
+ }
+
+ if ($mResponse instanceof \MailSo\Mail\Folder)
+ {
+ $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'])
+// );
+// }
+
+ if (null === $this->aCheckableFolder)
{
if (null === $this->oAccount) {
$this->oAccount = $this->getAccountFromToken(false);
}
- $oAccount = $this->oAccount;
-
- $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(),
- 'UnsubsribeLinks' => $mResponse->UnsubsribeLinks(),
- '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'] = 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, false, Capa::COMPOSER, $oAccount))
- {
- $mResult['IsReadReceipt'] = true;
- }
-
- $mResult['TextPartIsTrimmed'] = false;
-
- if ('Message' === $sParent)
- {
- $oAttachments = /* @var \MailSo\Mail\AttachmentCollection */ $mResponse->Attachments();
-
- $bHasExternals = false;
- $mFoundedCIDs = array();
- $aContentLocationUrls = array();
- $mFoundedContentLocationUrls = array();
-
- if ($oAttachments && 0 < $oAttachments->Count())
- {
- foreach ($oAttachments as /* @var \MailSo\Mail\Attachment */ $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['UnsubsribeLinks'] = $mResponse->UnsubsribeLinks();
- $mResult['References'] = $mResponse->References();
-
- $fAdditionalExternalFilter = null;
- if (!!$this->Config()->Get('labs', 'use_local_proxy_for_external_images', false))
- {
- $fAdditionalExternalFilter = function ($sUrl) {
- return './?/ProxyExternal/'.Utils::EncodeKeyValuesQ(array(
- 'Rnd' => \md5(\microtime(true)),
- 'Token' => Utils::GetConnectionToken(),
- 'Url' => $sUrl
- )).'/';
- };
- }
-
- $sHtml = \preg_replace_callback('/(]*>)([\s\S\r\n\t]*?)(<\/pre>)/mi', function ($aMatches) {
- return \preg_replace('/[\r\n]+/', '
', $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, null, !!$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 (\Throwable $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'] = '';
- }
- }
- }
- return $mResult;
+ $aCheckable = \json_decode(
+ $this->SettingsProvider(true)
+ ->Load($this->oAccount)
+ ->GetConf('CheckableFolder', '[]')
+ );
+ $this->aCheckableFolder = \is_array($aCheckable) ? $aCheckable : array();
}
- if ('MailSo\Mail\Attachment' === $sClassName)
- {
- if (null === $this->oAccount) {
- $this->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' => $this->GetCapa(false, false, Capa::ATTACHMENT_THUMBNAILS),
- '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'] = Utils::EncodeKeyValuesQ(array(
- 'V' => APP_VERSION,
- 'Account' => $this->oAccount ? \md5($this->oAccount->Hash()) : '',
- 'Folder' => $mResult['Folder'],
- 'Uid' => $mResult['Uid'],
- 'MimeIndex' => $mResult['MimeIndex'],
- 'MimeType' => $mResult['MimeType'],
- 'FileName' => $mResult['FileName'],
- 'Framed' => $mResult['Framed']
- ));
- return $mResult;
- }
-
- 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'])
-// );
-// }
-
- if (null === $this->aCheckableFolder)
- {
- if (null === $this->oAccount) {
- $this->oAccount = $this->getAccountFromToken(false);
- }
- $aCheckable = \json_decode(
- $this->SettingsProvider(true)
- ->Load($this->oAccount)
- ->GetConf('CheckableFolder', '[]')
- );
- $this->aCheckableFolder = \is_array($aCheckable) ? $aCheckable : array();
- }
-
- return \array_merge($this->objectData($mResponse, $sParent, $aParameters), array(
- 'Name' => $mResponse->Name(),
- 'FullName' => $mResponse->FullName(),
- 'FullNameRaw' => $mResponse->FullNameRaw(),
+ return \array_merge(
+ $mResponse->jsonSerialize(),
+ array(
'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(), $this->aCheckableFolder),
'Extended' => $aExtended,
'SubFolders' => $this->responseObject($mResponse->SubFolders(), $sParent, $aParameters)
- ));
- }
-
- if ('MailSo\Mail\MessageCollection' === $sClassName)
- {
- return \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
- ));
- }
-
- if ('MailSo\Mail\AttachmentCollection' === $sClassName)
- {
- return \array_merge($this->objectData($mResponse, $sParent, $aParameters), array(
- 'InlineCount' => $mResponse->InlineCount()
- ));
- }
-
- if ('MailSo\Mail\FolderCollection' === $sClassName)
- {
- return \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()
- ));
- }
-
- if ('MailSo\Mime\EmailCollection' === $sClassName)
- {
- $mResult = array();
- if (100 < \count($mResponse)) {
- $mResponse = $mResponse->Slice(0, 100);
- }
- foreach ($mResponse as $iKey => $oItem) {
- $mResult[$iKey] = $this->responseObject($oItem, $sParent, $aParameters);
- }
- return $mResult;
- }
-
- if ($mResponse instanceof \MailSo\Base\Collection)
- {
- $mResult = array();
- foreach ($mResponse as $iKey => $oItem) {
- $mResult[$iKey] = $this->responseObject($oItem, $sParent, $aParameters);
- }
- return $mResult;
- }
-
- return '["'.$sClassName.'"]';
+ )
+ );
}
- if (\is_array($mResponse))
+ if ($mResponse instanceof \MailSo\Base\Collection)
{
- foreach ($mResponse as $iKey => $oItem)
- {
- $mResponse[$iKey] = $this->responseObject($oItem, $sParent, $aParameters);
+ $mResult = $mResponse->jsonSerialize();
+ $mResult['@Collection'] = $this->responseObject($mResult['@Collection'], $sParent, $aParameters);
+ if ($mResponse instanceof \MailSo\Mail\EmailCollection) {
+ return array_slice($mResult['@Collection'], 0, 100);
}
-
- return $mResponse;
+ if ($mResponse instanceof \MailSo\Mail\AttachmentCollection
+ || $mResponse instanceof \MailSo\Mail\FolderCollection
+ || $mResponse instanceof \MailSo\Mail\MessageCollection
+ ) {
+ return $mResult;
+ }
+ return $mResult['@Collection'];
}
return $mResponse;