diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php index 7f439d1a0..1d9404562 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php @@ -18,6 +18,24 @@ namespace MailSo\Base; abstract class Utils { + public static function fileHasThumbnail(string $sFileName) : bool + { + static $aCache = array(); + + $sExt = static::GetFileExtension($sFileName); + if (isset($aCache[$sExt])) { + return $aCache[$sExt]; + } + + $aCache[$sExt] = ( + \extension_loaded('gd') + || \extension_loaded('gmagick') + || \extension_loaded('imagick') + ) && \in_array($sExt, ['png', 'gif', 'jpg', 'jpeg', 'webp']); + + return $aCache[$sExt]; + } + public static function NormalizeCharset(string $sEncoding, bool $bAsciAsUtf8 = false) : string { $sEncoding = \preg_replace('/^iso8/', 'iso-8', \strtolower($sEncoding)); 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 aa11a1c81..fe8677ddc 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 @@ -59,10 +59,20 @@ class Attachment implements \JsonSerializable #[\ReturnTypeWillChange] public function jsonSerialize() { - return \array_merge([ + $aResult = \array_merge([ '@Object' => 'Object/Attachment', 'folder' => $this->sFolder, 'uid' => $this->iUid ], $this->oBodyStructure->jsonSerialize()); + $aResult['isThumbnail'] = \MailSo\Base\Utils::fileHasThumbnail($aResult['fileName']); + $oActions = \RainLoop\Api::Actions(); + $aResult['download'] = $oActions->encodeRawKey($oActions->getAccountFromToken(), array( + 'folder' => $aResult['folder'], + 'uid' => $aResult['uid'], + 'mimeIndex' => $aResult['mimeIndex'], + 'mimeType' => $aResult['mimeType'], + 'fileName' => $aResult['fileName'] + )); + return $aResult; } } 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 622a273e2..55d743fc7 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 @@ -511,6 +511,7 @@ class Message implements \JsonSerializable '@Object' => 'Object/Message', 'folder' => $this->sFolder, 'uid' => $this->Uid, + 'hash' => \md5($this->sFolder . $this->Uid), 'subject' => \trim(Utils::Utf8Clear($this->sSubject)), 'encrypted' => 'multipart/encrypted' == $this->sContentType || $this->pgpEncrypted, 'messageId' => $this->sMessageId, diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/EmailCollection.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/EmailCollection.php index adda686d7..ba60a0887 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/EmailCollection.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/EmailCollection.php @@ -164,4 +164,11 @@ class EmailCollection extends \MailSo\Base\Collection catch (\InvalidArgumentException $oException) {} } } + + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return \array_slice($this->getArrayCopy(), 0, 100); + } + } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 44d6ac743..42d9f4db0 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -1003,7 +1003,12 @@ class Actions $oConfig = $this->oConfig; $aResult = array( 'AdditionalAccounts' => (bool) $oConfig->Get('webmail', 'allow_additional_accounts', false), - 'AttachmentThumbnails' => (bool) $oConfig->Get('interface', 'show_attachment_thumbnail', true), + 'AttachmentThumbnails' => (bool) $oConfig->Get('interface', 'show_attachment_thumbnail', true) + && ($bAdmin + || \extension_loaded('gd') + || \extension_loaded('gmagick') + || \extension_loaded('imagick') + ), 'AttachmentsActions' => (bool) $oConfig->Get('capa', 'attachments_actions', false), 'Contacts' => (bool) $oConfig->Get('contacts', 'enable', false), 'DangerousActions' => (bool) $oConfig->Get('capa', 'dangerous_actions', true), @@ -1036,7 +1041,7 @@ class Actions if ($sKey && $this->oConfig->Get('cache', 'enable', true) && $this->oConfig->Get('cache', 'http', true)) { \MailSo\Base\Http::ServerUseCache( $this->etag($sKey), - 1382478804, + 0, // issue with messages $this->oConfig->Get('cache', 'http_expires', 3600) ); return true; @@ -1073,7 +1078,7 @@ class Actions return $oAccount; } - protected function encodeRawKey(?Model\Account $oAccount, array $aValues): string + public function encodeRawKey(?Model\Account $oAccount, array $aValues): string { return \SnappyMail\Crypt::EncryptUrlSafe($aValues, \sha1(APP_SALT . ($oAccount ? $oAccount->Hash() : ''))); } 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 21063a73e..cc816af5c 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 @@ -69,26 +69,6 @@ trait Response ]); } - private function isFileHasThumbnail(string $sFileName) : bool - { - static $aCache = array(); - - $sExt = \MailSo\Base\Utils::GetFileExtension($sFileName); - if (isset($aCache[$sExt])) { - return $aCache[$sExt]; - } - - $bResult = ( - \extension_loaded('gd') - || \extension_loaded('gmagick') - || \extension_loaded('imagick') - ) && \in_array($sExt, ['png', 'gif', 'jpg', 'jpeg']); - - $aCache[$sExt] = $bResult; - - return $bResult; - } - /** * @param mixed $mResponse * @@ -112,80 +92,64 @@ trait Response } if ($mResponse instanceof \MailSo\Mail\Message) { - $mResult = $mResponse->jsonSerialize(); + $aResult = $mResponse->jsonSerialize(); $oAccount = $this->getAccountFromToken(); - if (!$mResult['dateTimeStampInUTC'] || $this->Config()->Get('labs', 'date_from_headers', true)) { + if (!$aResult['dateTimeStampInUTC'] || $this->Config()->Get('labs', 'date_from_headers', true)) { $iDateTimeStampInUTC = $mResponse->HeaderTimeStampInUTC; if ($iDateTimeStampInUTC) { - $mResult['dateTimeStampInUTC'] = $iDateTimeStampInUTC; + $aResult['dateTimeStampInUTC'] = $iDateTimeStampInUTC; } } // \MailSo\Mime\EmailCollection foreach (['replyTo','from','to','cc','bcc','sender','deliveredTo'] as $prop) { - $mResult[$prop] = $this->responseObject($mResult[$prop], $prop); + $aResult[$prop] = $this->responseObject($aResult[$prop], $prop); } - $sSubject = $mResult['subject']; - $mResult['hash'] = \md5($mResult['folder'].$mResult['uid']); - $mResult['requestHash'] = $this->encodeRawKey($oAccount, array( - 'folder' => $mResult['folder'], - 'uid' => $mResult['uid'], + $sSubject = $aResult['subject']; + $aResult['requestHash'] = $this->encodeRawKey($oAccount, array( + 'folder' => $aResult['folder'], + 'uid' => $aResult['uid'], 'mimeType' => 'message/rfc822', - 'fileName' => (\strlen($sSubject) ? \MailSo\Base\Utils::SecureFileName($sSubject) : 'message-'.$mResult['uid']) . '.eml' + 'fileName' => (\strlen($sSubject) ? \MailSo\Base\Utils::SecureFileName($sSubject) : 'message-'.$aResult['uid']) . '.eml' )); - $mResult['attachments'] = $this->responseObject($mResponse->Attachments, 'attachments'); - if (!$sParent) { - $mResult['draftInfo'] = $mResponse->DraftInfo; - $mResult['unsubsribeLinks'] = $mResponse->UnsubsribeLinks; - $mResult['references'] = $mResponse->References; + $aResult['draftInfo'] = $mResponse->DraftInfo; + $aResult['unsubsribeLinks'] = $mResponse->UnsubsribeLinks; + $aResult['references'] = $mResponse->References; - $mResult['html'] = $mResponse->Html(); - $mResult['plain'] = $mResponse->Plain(); + $aResult['html'] = $mResponse->Html(); + $aResult['plain'] = $mResponse->Plain(); // $this->GetCapa(Capa::OPEN_PGP) || $this->GetCapa(Capa::GNUPG) - $mResult['pgpSigned'] = $mResponse->pgpSigned; - $mResult['pgpEncrypted'] = $mResponse->pgpEncrypted; + $aResult['pgpSigned'] = $mResponse->pgpSigned; + $aResult['pgpEncrypted'] = $mResponse->pgpEncrypted; - $mResult['readReceipt'] = $mResponse->ReadReceipt; - if (\strlen($mResult['readReceipt']) && !\in_array('$forwarded', $mResult['flags'])) { - // \in_array('$mdnsent', $mResult['flags']) - if (\strlen($mResult['readReceipt'])) { + $aResult['readReceipt'] = $mResponse->ReadReceipt; + if (\strlen($aResult['readReceipt']) && !\in_array('$forwarded', $aResult['flags'])) { + // \in_array('$mdnsent', $aResult['flags']) + if (\strlen($aResult['readReceipt'])) { try { - $oReadReceipt = \MailSo\Mime\Email::Parse($mResult['readReceipt']); + $oReadReceipt = \MailSo\Mime\Email::Parse($aResult['readReceipt']); if (!$oReadReceipt) { - $mResult['readReceipt'] = ''; + $aResult['readReceipt'] = ''; } } catch (\Throwable $oException) { unset($oException); } } - if (\strlen($mResult['readReceipt']) && '1' === $this->Cacher($oAccount)->Get( - \RainLoop\KeyPathHelper::ReadReceiptCache($oAccount->Email(), $mResult['folder'], $mResult['uid']), '0')) + if (\strlen($aResult['readReceipt']) && '1' === $this->Cacher($oAccount)->Get( + \RainLoop\KeyPathHelper::ReadReceiptCache($oAccount->Email(), $aResult['folder'], $aResult['uid']), '0')) { - $mResult['readReceipt'] = ''; + $aResult['readReceipt'] = ''; } } } - return $mResult; - } - - if ($mResponse instanceof \MailSo\Mail\Attachment) { - $mResult = $mResponse->jsonSerialize(); - $mResult['isThumbnail'] = $this->GetCapa(Capa::ATTACHMENT_THUMBNAILS) && $this->isFileHasThumbnail($mResult['fileName']); - $mResult['download'] = $this->encodeRawKey($this->getAccountFromToken(), array( - 'folder' => $mResult['folder'], - 'uid' => $mResult['uid'], - 'mimeIndex' => $mResult['mimeIndex'], - 'mimeType' => $mResult['mimeType'], - 'fileName' => $mResult['fileName'] - )); - return $mResult; + return $aResult; } if ($mResponse instanceof \MailSo\Imap\Folder) { @@ -209,21 +173,6 @@ trait Response return $aResult; } - if ($mResponse instanceof \MailSo\Base\Collection) { - $mResult = $mResponse->jsonSerialize(); - $mResult['@Collection'] = $this->responseObject($mResult['@Collection'], 'Collection'); - if ($mResponse instanceof \MailSo\Mail\EmailCollection) { - return \array_slice($mResult['@Collection'], 0, 100); - } - if ($mResponse instanceof \MailSo\Mail\AttachmentCollection - || $mResponse instanceof \MailSo\Imap\FolderCollection - || $mResponse instanceof \MailSo\Mail\MessageCollection - ) { - return $mResult; - } - return $mResult['@Collection']; - } - return $mResponse; } }