mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 12:09:20 +03:00
Bugfix and improved Remote.message() and Remote.messageList() by using JSON
This commit is contained in:
parent
739aeaded5
commit
1767ba7ec9
3 changed files with 30 additions and 54 deletions
|
|
@ -19,13 +19,10 @@ import { AbstractFetchRemote } from 'Remote/AbstractFetch';
|
|||
|
||||
import { FolderCollectionModel } from 'Model/FolderCollection';
|
||||
|
||||
//const toUTF8 = window.TextEncoder
|
||||
// ? text => String.fromCharCode(...new TextEncoder().encode(text))
|
||||
// : text => unescape(encodeURIComponent(text)),
|
||||
const urlsafeArray = array => btoa(unescape(encodeURIComponent(array.join('\x00').replace(/\r\n/g, '\n'))))
|
||||
.replace('+', '-')
|
||||
.replace('/', '_')
|
||||
.replace('=', '');
|
||||
const urlSafeJSON = data => btoa(JSON.stringify(data))
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/=+$/, '');
|
||||
|
||||
class RemoteUserFetch extends AbstractFetchRemote {
|
||||
/**
|
||||
|
|
@ -185,22 +182,22 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
|||
messageList(fCallback, params, bSilent = false) {
|
||||
const
|
||||
sFolderFullNameRaw = pString(params.Folder),
|
||||
folderHash = getFolderHash(sFolderFullNameRaw),
|
||||
useThreads = AppUserStore.threadsAllowed() && SettingsUserStore.useThreads() ? 1 : 0,
|
||||
inboxUidNext = getFolderInboxName() === sFolderFullNameRaw ? getFolderUidNext(sFolderFullNameRaw) : '';
|
||||
folderHash = getFolderHash(sFolderFullNameRaw);
|
||||
|
||||
params.Folder = sFolderFullNameRaw;
|
||||
params.ThreadUid = useThreads ? params.ThreadUid : 0;
|
||||
params = Object.assign({
|
||||
Folder: '',
|
||||
Offset: 0,
|
||||
Limit: SettingsUserStore.messagesPerPage(),
|
||||
Search: '',
|
||||
UidNext: inboxUidNext,
|
||||
UseThreads: useThreads,
|
||||
ThreadUid: 0,
|
||||
Sort: FolderUserStore.sortMode()
|
||||
UidNext: getFolderInboxName() === sFolderFullNameRaw ? getFolderUidNext(sFolderFullNameRaw) : '',
|
||||
Sort: FolderUserStore.sortMode(),
|
||||
Hash: folderHash + SettingsGet('AccountHash')
|
||||
}, params);
|
||||
params.Folder = sFolderFullNameRaw;
|
||||
if (AppUserStore.threadsAllowed() && SettingsUserStore.useThreads()) {
|
||||
params.UseThreads = 1;
|
||||
} else {
|
||||
params.ThreadUid = 0;
|
||||
}
|
||||
|
||||
let sGetAdd = '';
|
||||
|
||||
|
|
@ -208,7 +205,7 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
|||
sGetAdd = 'MessageList/' +
|
||||
SUB_QUERY_PREFIX +
|
||||
'/' +
|
||||
urlsafeArray([SettingsGet('ProjectHash'),folderHash].concat(Object.values(params)));
|
||||
urlSafeJSON(params);
|
||||
params = {};
|
||||
}
|
||||
|
||||
|
|
@ -256,11 +253,11 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
|||
'Message/' +
|
||||
SUB_QUERY_PREFIX +
|
||||
'/' +
|
||||
urlsafeArray([
|
||||
urlSafeJSON([
|
||||
sFolderFullNameRaw,
|
||||
iUid,
|
||||
SettingsGet('ProjectHash'),
|
||||
AppUserStore.threadsAllowed() && SettingsUserStore.useThreads() ? 1 : 0
|
||||
AppUserStore.threadsAllowed() && SettingsUserStore.useThreads() ? 1 : 0,
|
||||
SettingsGet('AccountHash')
|
||||
]),
|
||||
['Message']
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1026,8 +1026,6 @@ class Actions
|
|||
$aResult['Capa'] = $this->Capa(true);
|
||||
}
|
||||
|
||||
$aResult['ProjectHash'] = \md5($aResult['AccountHash'] . APP_VERSION . $this->Plugins()->Hash());
|
||||
|
||||
$sStaticCache = $this->StaticCache();
|
||||
|
||||
$aResult['Theme'] = $this->GetTheme($bAdmin);
|
||||
|
|
|
|||
|
|
@ -27,22 +27,19 @@ trait Messages
|
|||
$sSort = '';
|
||||
|
||||
$sRawKey = $this->GetActionParam('RawKey', '');
|
||||
$aValues = $this->getDecodedClientRawKeyValue($sRawKey, 10);
|
||||
$aValues = \json_decode(\MailSo\Base\Utils::UrlSafeBase64Decode($sRawKey), true);
|
||||
if ($aValues && 7 < \count($aValues))
|
||||
{
|
||||
$sFolder = (string) $aValues[2];
|
||||
$iOffset = (int) $aValues[3];
|
||||
$iLimit = (int) $aValues[4];
|
||||
$sSearch = (string) $aValues[5];
|
||||
$iUidNext = (int) $aValues[6];
|
||||
$bUseThreads = (bool) $aValues[7];
|
||||
|
||||
if ($bUseThreads)
|
||||
{
|
||||
$iThreadUid = isset($aValues[8]) ? (int) $aValues[8] : 0;
|
||||
$sFolder = (string) $aValues['Folder'];
|
||||
$iOffset = (int) $aValues['Offset'];
|
||||
$iLimit = (int) $aValues['Limit'];
|
||||
$sSearch = (string) $aValues['Search'];
|
||||
$iUidNext = (int) $aValues['UidNext'];
|
||||
$bUseThreads = !empty($aValues['UseThreads']);
|
||||
if ($bUseThreads) {
|
||||
$iThreadUid = (int) $aValues['ThreadUid'];
|
||||
}
|
||||
|
||||
$sSort = isset($aValues[9]) ? (string) $aValues[9] : '';
|
||||
$sSort = (string) $aValues['Sort'];
|
||||
|
||||
$this->verifyCacheByKey($sRawKey);
|
||||
}
|
||||
|
|
@ -445,8 +442,8 @@ trait Messages
|
|||
$sFolder = '';
|
||||
$iUid = 0;
|
||||
|
||||
$aValues = $this->getDecodedClientRawKeyValue($sRawKey, 4);
|
||||
if ($aValues && 4 === count($aValues))
|
||||
$aValues = \json_decode(\MailSo\Base\Utils::UrlSafeBase64Decode($sRawKey), true);
|
||||
if ($aValues && 2 <= \count($aValues))
|
||||
{
|
||||
$sFolder = (string) $aValues[0];
|
||||
$iUid = (int) $aValues[1];
|
||||
|
|
@ -846,22 +843,6 @@ trait Messages
|
|||
return $this->TrueResponse($sResponseFunction);
|
||||
}
|
||||
|
||||
private function getDecodedClientRawKeyValue(string $sRawKey, ?int $iLenCache = null) : ?array
|
||||
{
|
||||
if (!empty($sRawKey))
|
||||
{
|
||||
$sRawKey = \MailSo\Base\Utils::UrlSafeBase64Decode($sRawKey);
|
||||
$aValues = explode("\x0", $sRawKey);
|
||||
|
||||
if (null === $iLenCache || $iLenCache === count($aValues))
|
||||
{
|
||||
return $aValues;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function deleteMessageAttachmnets(Account $oAccount) : void
|
||||
{
|
||||
$aAttachments = $this->GetActionParam('Attachments', null);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue