mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Resolve more cache issue with #1003
This commit is contained in:
parent
206c8abdf5
commit
eaf4bbe6d3
6 changed files with 71 additions and 81 deletions
|
|
@ -18,6 +18,24 @@ namespace MailSo\Base;
|
||||||
abstract class Utils
|
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
|
public static function NormalizeCharset(string $sEncoding, bool $bAsciAsUtf8 = false) : string
|
||||||
{
|
{
|
||||||
$sEncoding = \preg_replace('/^iso8/', 'iso-8', \strtolower($sEncoding));
|
$sEncoding = \preg_replace('/^iso8/', 'iso-8', \strtolower($sEncoding));
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,20 @@ class Attachment implements \JsonSerializable
|
||||||
#[\ReturnTypeWillChange]
|
#[\ReturnTypeWillChange]
|
||||||
public function jsonSerialize()
|
public function jsonSerialize()
|
||||||
{
|
{
|
||||||
return \array_merge([
|
$aResult = \array_merge([
|
||||||
'@Object' => 'Object/Attachment',
|
'@Object' => 'Object/Attachment',
|
||||||
'folder' => $this->sFolder,
|
'folder' => $this->sFolder,
|
||||||
'uid' => $this->iUid
|
'uid' => $this->iUid
|
||||||
], $this->oBodyStructure->jsonSerialize());
|
], $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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -511,6 +511,7 @@ class Message implements \JsonSerializable
|
||||||
'@Object' => 'Object/Message',
|
'@Object' => 'Object/Message',
|
||||||
'folder' => $this->sFolder,
|
'folder' => $this->sFolder,
|
||||||
'uid' => $this->Uid,
|
'uid' => $this->Uid,
|
||||||
|
'hash' => \md5($this->sFolder . $this->Uid),
|
||||||
'subject' => \trim(Utils::Utf8Clear($this->sSubject)),
|
'subject' => \trim(Utils::Utf8Clear($this->sSubject)),
|
||||||
'encrypted' => 'multipart/encrypted' == $this->sContentType || $this->pgpEncrypted,
|
'encrypted' => 'multipart/encrypted' == $this->sContentType || $this->pgpEncrypted,
|
||||||
'messageId' => $this->sMessageId,
|
'messageId' => $this->sMessageId,
|
||||||
|
|
|
||||||
|
|
@ -164,4 +164,11 @@ class EmailCollection extends \MailSo\Base\Collection
|
||||||
catch (\InvalidArgumentException $oException) {}
|
catch (\InvalidArgumentException $oException) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[\ReturnTypeWillChange]
|
||||||
|
public function jsonSerialize()
|
||||||
|
{
|
||||||
|
return \array_slice($this->getArrayCopy(), 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1003,7 +1003,12 @@ class Actions
|
||||||
$oConfig = $this->oConfig;
|
$oConfig = $this->oConfig;
|
||||||
$aResult = array(
|
$aResult = array(
|
||||||
'AdditionalAccounts' => (bool) $oConfig->Get('webmail', 'allow_additional_accounts', false),
|
'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),
|
'AttachmentsActions' => (bool) $oConfig->Get('capa', 'attachments_actions', false),
|
||||||
'Contacts' => (bool) $oConfig->Get('contacts', 'enable', false),
|
'Contacts' => (bool) $oConfig->Get('contacts', 'enable', false),
|
||||||
'DangerousActions' => (bool) $oConfig->Get('capa', 'dangerous_actions', true),
|
'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)) {
|
if ($sKey && $this->oConfig->Get('cache', 'enable', true) && $this->oConfig->Get('cache', 'http', true)) {
|
||||||
\MailSo\Base\Http::ServerUseCache(
|
\MailSo\Base\Http::ServerUseCache(
|
||||||
$this->etag($sKey),
|
$this->etag($sKey),
|
||||||
1382478804,
|
0, // issue with messages
|
||||||
$this->oConfig->Get('cache', 'http_expires', 3600)
|
$this->oConfig->Get('cache', 'http_expires', 3600)
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -1073,7 +1078,7 @@ class Actions
|
||||||
return $oAccount;
|
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() : '')));
|
return \SnappyMail\Crypt::EncryptUrlSafe($aValues, \sha1(APP_SALT . ($oAccount ? $oAccount->Hash() : '')));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
* @param mixed $mResponse
|
||||||
*
|
*
|
||||||
|
|
@ -112,80 +92,64 @@ trait Response
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mResponse instanceof \MailSo\Mail\Message) {
|
if ($mResponse instanceof \MailSo\Mail\Message) {
|
||||||
$mResult = $mResponse->jsonSerialize();
|
$aResult = $mResponse->jsonSerialize();
|
||||||
|
|
||||||
$oAccount = $this->getAccountFromToken();
|
$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;
|
$iDateTimeStampInUTC = $mResponse->HeaderTimeStampInUTC;
|
||||||
if ($iDateTimeStampInUTC) {
|
if ($iDateTimeStampInUTC) {
|
||||||
$mResult['dateTimeStampInUTC'] = $iDateTimeStampInUTC;
|
$aResult['dateTimeStampInUTC'] = $iDateTimeStampInUTC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// \MailSo\Mime\EmailCollection
|
// \MailSo\Mime\EmailCollection
|
||||||
foreach (['replyTo','from','to','cc','bcc','sender','deliveredTo'] as $prop) {
|
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'];
|
$sSubject = $aResult['subject'];
|
||||||
$mResult['hash'] = \md5($mResult['folder'].$mResult['uid']);
|
$aResult['requestHash'] = $this->encodeRawKey($oAccount, array(
|
||||||
$mResult['requestHash'] = $this->encodeRawKey($oAccount, array(
|
'folder' => $aResult['folder'],
|
||||||
'folder' => $mResult['folder'],
|
'uid' => $aResult['uid'],
|
||||||
'uid' => $mResult['uid'],
|
|
||||||
'mimeType' => 'message/rfc822',
|
'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) {
|
if (!$sParent) {
|
||||||
$mResult['draftInfo'] = $mResponse->DraftInfo;
|
$aResult['draftInfo'] = $mResponse->DraftInfo;
|
||||||
$mResult['unsubsribeLinks'] = $mResponse->UnsubsribeLinks;
|
$aResult['unsubsribeLinks'] = $mResponse->UnsubsribeLinks;
|
||||||
$mResult['references'] = $mResponse->References;
|
$aResult['references'] = $mResponse->References;
|
||||||
|
|
||||||
$mResult['html'] = $mResponse->Html();
|
$aResult['html'] = $mResponse->Html();
|
||||||
$mResult['plain'] = $mResponse->Plain();
|
$aResult['plain'] = $mResponse->Plain();
|
||||||
|
|
||||||
// $this->GetCapa(Capa::OPEN_PGP) || $this->GetCapa(Capa::GNUPG)
|
// $this->GetCapa(Capa::OPEN_PGP) || $this->GetCapa(Capa::GNUPG)
|
||||||
$mResult['pgpSigned'] = $mResponse->pgpSigned;
|
$aResult['pgpSigned'] = $mResponse->pgpSigned;
|
||||||
$mResult['pgpEncrypted'] = $mResponse->pgpEncrypted;
|
$aResult['pgpEncrypted'] = $mResponse->pgpEncrypted;
|
||||||
|
|
||||||
$mResult['readReceipt'] = $mResponse->ReadReceipt;
|
$aResult['readReceipt'] = $mResponse->ReadReceipt;
|
||||||
if (\strlen($mResult['readReceipt']) && !\in_array('$forwarded', $mResult['flags'])) {
|
if (\strlen($aResult['readReceipt']) && !\in_array('$forwarded', $aResult['flags'])) {
|
||||||
// \in_array('$mdnsent', $mResult['flags'])
|
// \in_array('$mdnsent', $aResult['flags'])
|
||||||
if (\strlen($mResult['readReceipt'])) {
|
if (\strlen($aResult['readReceipt'])) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$oReadReceipt = \MailSo\Mime\Email::Parse($mResult['readReceipt']);
|
$oReadReceipt = \MailSo\Mime\Email::Parse($aResult['readReceipt']);
|
||||||
if (!$oReadReceipt) {
|
if (!$oReadReceipt) {
|
||||||
$mResult['readReceipt'] = '';
|
$aResult['readReceipt'] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (\Throwable $oException) { unset($oException); }
|
catch (\Throwable $oException) { unset($oException); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\strlen($mResult['readReceipt']) && '1' === $this->Cacher($oAccount)->Get(
|
if (\strlen($aResult['readReceipt']) && '1' === $this->Cacher($oAccount)->Get(
|
||||||
\RainLoop\KeyPathHelper::ReadReceiptCache($oAccount->Email(), $mResult['folder'], $mResult['uid']), '0'))
|
\RainLoop\KeyPathHelper::ReadReceiptCache($oAccount->Email(), $aResult['folder'], $aResult['uid']), '0'))
|
||||||
{
|
{
|
||||||
$mResult['readReceipt'] = '';
|
$aResult['readReceipt'] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $mResult;
|
return $aResult;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mResponse instanceof \MailSo\Imap\Folder) {
|
if ($mResponse instanceof \MailSo\Imap\Folder) {
|
||||||
|
|
@ -209,21 +173,6 @@ trait Response
|
||||||
return $aResult;
|
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;
|
return $mResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue