2020-08-07 00:24:46 +08:00
|
|
|
import { pString, pInt } from 'Common/Utils';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import {
|
|
|
|
CONTACTS_SYNC_AJAX_TIMEOUT,
|
|
|
|
DEFAULT_AJAX_TIMEOUT,
|
|
|
|
SEARCH_AJAX_TIMEOUT,
|
|
|
|
SAVE_MESSAGE_AJAX_TIMEOUT,
|
|
|
|
SEND_MESSAGE_AJAX_TIMEOUT
|
|
|
|
} from 'Common/Consts';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import {
|
|
|
|
getFolderHash,
|
|
|
|
getFolderInboxName,
|
|
|
|
getFolderUidNext,
|
|
|
|
getFolderFromCacheList,
|
|
|
|
getMessageFlagsFromCache
|
|
|
|
} from 'Common/Cache';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { subQueryPrefix } from 'Common/Links';
|
2016-08-17 06:01:20 +08:00
|
|
|
import * as Settings from 'Storage/Settings';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import AppStore from 'Stores/User/App';
|
|
|
|
import SettingsStore from 'Stores/User/Settings';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { getApp } from 'Helper/Apps/User';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { AbstractAjaxRemote } from 'Remote/AbstractAjax';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-08-20 04:23:28 +08:00
|
|
|
//const toUTF8 = window.TextEncoder
|
|
|
|
// ? text => String.fromCharCode(...new TextEncoder().encode(text))
|
|
|
|
// : text => unescape(encodeURIComponent(text)),
|
2020-08-20 13:28:08 +08:00
|
|
|
const urlsafeArray = array => btoa(unescape(encodeURIComponent(array.join('\x00').replace(/\r\n/g, '\n'))))
|
2020-08-20 04:23:28 +08:00
|
|
|
.replace('+', '-')
|
|
|
|
.replace('/', '_')
|
|
|
|
.replace('=', '');
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
class RemoteUserAjax extends AbstractAjaxRemote {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.oRequests = {};
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
folders(fCallback) {
|
2019-07-05 03:19:24 +08:00
|
|
|
this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'Folders',
|
|
|
|
{
|
2020-08-18 03:32:57 +08:00
|
|
|
SentFolder: Settings.settingsGet('SentFolder'),
|
|
|
|
DraftFolder: Settings.settingsGet('DraftFolder'),
|
|
|
|
SpamFolder: Settings.settingsGet('SpamFolder'),
|
|
|
|
TrashFolder: Settings.settingsGet('TrashFolder'),
|
|
|
|
ArchiveFolder: Settings.settingsGet('ArchiveFolder')
|
2019-07-05 03:19:24 +08:00
|
|
|
},
|
|
|
|
null,
|
|
|
|
'',
|
|
|
|
['Folders']
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sEmail
|
|
|
|
* @param {string} sLogin
|
|
|
|
* @param {string} sPassword
|
|
|
|
* @param {boolean} bSignMe
|
|
|
|
* @param {string=} sLanguage
|
|
|
|
* @param {string=} sAdditionalCode
|
|
|
|
* @param {boolean=} bAdditionalCodeSignMe
|
|
|
|
*/
|
|
|
|
login(fCallback, sEmail, sLogin, sPassword, bSignMe, sLanguage, sAdditionalCode, bAdditionalCodeSignMe) {
|
|
|
|
this.defaultRequest(fCallback, 'Login', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Email: sEmail,
|
|
|
|
Login: sLogin,
|
|
|
|
Password: sPassword,
|
|
|
|
Language: sLanguage || '',
|
|
|
|
AdditionalCode: sAdditionalCode || '',
|
|
|
|
AdditionalCodeSignMe: bAdditionalCodeSignMe ? 1 : 0,
|
|
|
|
SignMe: bSignMe ? 1 : 0
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
getTwoFactor(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'GetTwoFactorInfo');
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
createTwoFactor(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'CreateTwoFactorSecret');
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
clearTwoFactor(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'ClearTwoFactorInfo');
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
showTwoFactorSecret(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'ShowTwoFactorSecret');
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sCode
|
|
|
|
*/
|
|
|
|
testTwoFactor(fCallback, sCode) {
|
|
|
|
this.defaultRequest(fCallback, 'TestTwoFactorInfo', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Code: sCode
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {boolean} bEnable
|
|
|
|
*/
|
|
|
|
enableTwoFactor(fCallback, bEnable) {
|
|
|
|
this.defaultRequest(fCallback, 'EnableTwoFactor', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Enable: bEnable ? 1 : 0
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
clearTwoFactorInfo(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'ClearTwoFactorInfo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
contactsSync(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'ContactsSync', null, CONTACTS_SYNC_AJAX_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {boolean} bEnable
|
|
|
|
* @param {string} sUrl
|
|
|
|
* @param {string} sUser
|
|
|
|
* @param {string} sPassword
|
|
|
|
*/
|
|
|
|
saveContactsSyncData(fCallback, bEnable, sUrl, sUser, sPassword) {
|
|
|
|
this.defaultRequest(fCallback, 'SaveContactsSyncData', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Enable: bEnable ? 1 : 0,
|
|
|
|
Url: sUrl,
|
|
|
|
User: sUser,
|
|
|
|
Password: sPassword
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sEmail
|
|
|
|
* @param {string} sPassword
|
|
|
|
* @param {boolean=} bNew
|
|
|
|
*/
|
|
|
|
accountSetup(fCallback, sEmail, sPassword, bNew = true) {
|
|
|
|
this.defaultRequest(fCallback, 'AccountSetup', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Email: sEmail,
|
|
|
|
Password: sPassword,
|
|
|
|
New: bNew ? 1 : 0
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sEmailToDelete
|
|
|
|
*/
|
|
|
|
accountDelete(fCallback, sEmailToDelete) {
|
|
|
|
this.defaultRequest(fCallback, 'AccountDelete', {
|
2020-08-18 03:32:57 +08:00
|
|
|
EmailToDelete: sEmailToDelete
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {Array} aAccounts
|
|
|
|
* @param {Array} aIdentities
|
|
|
|
*/
|
|
|
|
accountsAndIdentitiesSortOrder(fCallback, aAccounts, aIdentities) {
|
|
|
|
this.defaultRequest(fCallback, 'AccountsAndIdentitiesSortOrder', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Accounts: aAccounts,
|
|
|
|
Identities: aIdentities
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sId
|
|
|
|
* @param {string} sEmail
|
|
|
|
* @param {string} sName
|
|
|
|
* @param {string} sReplyTo
|
|
|
|
* @param {string} sBcc
|
|
|
|
* @param {string} sSignature
|
|
|
|
* @param {boolean} bSignatureInsertBefore
|
|
|
|
*/
|
|
|
|
identityUpdate(fCallback, sId, sEmail, sName, sReplyTo, sBcc, sSignature, bSignatureInsertBefore) {
|
|
|
|
this.defaultRequest(fCallback, 'IdentityUpdate', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Id: sId,
|
|
|
|
Email: sEmail,
|
|
|
|
Name: sName,
|
|
|
|
ReplyTo: sReplyTo,
|
|
|
|
Bcc: sBcc,
|
|
|
|
Signature: sSignature,
|
|
|
|
SignatureInsertBefore: bSignatureInsertBefore ? 1 : 0
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sIdToDelete
|
|
|
|
*/
|
|
|
|
identityDelete(fCallback, sIdToDelete) {
|
|
|
|
this.defaultRequest(fCallback, 'IdentityDelete', {
|
2020-08-18 03:32:57 +08:00
|
|
|
IdToDelete: sIdToDelete
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
accountsAndIdentities(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'AccountsAndIdentities');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {Array} filters
|
|
|
|
* @param {string} raw
|
|
|
|
* @param {boolean} isRawIsActive
|
|
|
|
*/
|
|
|
|
filtersSave(fCallback, filters, raw, isRawIsActive) {
|
|
|
|
this.defaultRequest(fCallback, 'FiltersSave', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Raw: raw,
|
|
|
|
RawIsActive: isRawIsActive ? 1 : 0,
|
|
|
|
Filters: filters.map(item => item.toJson())
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
filtersGet(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'Filters', {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
templates(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'Templates', {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Function} fCallback
|
|
|
|
* @param {string} sID
|
|
|
|
*/
|
|
|
|
templateGetById(fCallback, sID) {
|
|
|
|
this.defaultRequest(fCallback, 'TemplateGetByID', {
|
2020-08-18 03:32:57 +08:00
|
|
|
ID: sID
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Function} fCallback
|
|
|
|
* @param {string} sID
|
|
|
|
*/
|
|
|
|
templateDelete(fCallback, sID) {
|
|
|
|
this.defaultRequest(fCallback, 'TemplateDelete', {
|
2020-08-18 03:32:57 +08:00
|
|
|
IdToDelete: sID
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Function} fCallback
|
|
|
|
* @param {string} sID
|
|
|
|
* @param {string} sName
|
|
|
|
* @param {string} sBody
|
|
|
|
*/
|
|
|
|
templateSetup(fCallback, sID, sName, sBody) {
|
|
|
|
this.defaultRequest(fCallback, 'TemplateSetup', {
|
2020-08-18 03:32:57 +08:00
|
|
|
ID: sID,
|
|
|
|
Name: sName,
|
|
|
|
Body: sBody
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Function} fCallback
|
|
|
|
* @param {string} sFolderFullNameRaw
|
|
|
|
* @param {number=} iOffset = 0
|
|
|
|
* @param {number=} iLimit = 20
|
|
|
|
* @param {string=} sSearch = ''
|
|
|
|
* @param {string=} sThreadUid = ''
|
|
|
|
* @param {boolean=} bSilent = false
|
|
|
|
*/
|
|
|
|
messageList(fCallback, sFolderFullNameRaw, iOffset = 0, iLimit = 20, sSearch = '', sThreadUid = '', bSilent = false) {
|
|
|
|
sFolderFullNameRaw = pString(sFolderFullNameRaw);
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
const folderHash = getFolderHash(sFolderFullNameRaw),
|
2016-08-17 06:01:20 +08:00
|
|
|
useThreads = AppStore.threadsAllowed() && SettingsStore.useThreads(),
|
|
|
|
inboxUidNext = getFolderInboxName() === sFolderFullNameRaw ? getFolderUidNext(sFolderFullNameRaw) : '';
|
|
|
|
|
2020-07-28 23:20:14 +08:00
|
|
|
if (folderHash && (!sSearch || !sSearch.includes('is:'))) {
|
2019-07-05 03:19:24 +08:00
|
|
|
return this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'MessageList',
|
|
|
|
{},
|
2020-07-28 23:20:14 +08:00
|
|
|
sSearch ? SEARCH_AJAX_TIMEOUT : DEFAULT_AJAX_TIMEOUT,
|
2019-07-05 03:19:24 +08:00
|
|
|
'MessageList/' +
|
|
|
|
subQueryPrefix() +
|
|
|
|
'/' +
|
2020-08-20 04:23:28 +08:00
|
|
|
urlsafeArray([
|
|
|
|
sFolderFullNameRaw,
|
|
|
|
iOffset,
|
|
|
|
iLimit,
|
|
|
|
sSearch,
|
|
|
|
AppStore.projectHash(),
|
|
|
|
folderHash,
|
|
|
|
inboxUidNext,
|
|
|
|
useThreads ? 1 : 0,
|
|
|
|
useThreads ? sThreadUid : ''
|
|
|
|
]),
|
2019-07-05 03:19:24 +08:00
|
|
|
bSilent ? [] : ['MessageList']
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
return this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'MessageList',
|
|
|
|
{
|
|
|
|
Folder: sFolderFullNameRaw,
|
|
|
|
Offset: iOffset,
|
|
|
|
Limit: iLimit,
|
|
|
|
Search: sSearch,
|
|
|
|
UidNext: inboxUidNext,
|
2020-08-18 03:32:57 +08:00
|
|
|
UseThreads: useThreads ? 1 : 0,
|
2019-07-05 03:19:24 +08:00
|
|
|
ThreadUid: useThreads ? sThreadUid : ''
|
|
|
|
},
|
2020-07-28 23:20:14 +08:00
|
|
|
sSearch ? SEARCH_AJAX_TIMEOUT : DEFAULT_AJAX_TIMEOUT,
|
2019-07-05 03:19:24 +08:00
|
|
|
'',
|
|
|
|
bSilent ? [] : ['MessageList']
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {Array} aDownloads
|
|
|
|
*/
|
|
|
|
messageUploadAttachments(fCallback, aDownloads) {
|
2019-07-05 03:19:24 +08:00
|
|
|
this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'MessageUploadAttachments',
|
|
|
|
{
|
2020-08-18 03:32:57 +08:00
|
|
|
Attachments: aDownloads
|
2019-07-05 03:19:24 +08:00
|
|
|
},
|
|
|
|
999000
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sFolderFullNameRaw
|
|
|
|
* @param {number} iUid
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
message(fCallback, sFolderFullNameRaw, iUid) {
|
|
|
|
sFolderFullNameRaw = pString(sFolderFullNameRaw);
|
|
|
|
iUid = pInt(iUid);
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (getFolderFromCacheList(sFolderFullNameRaw) && 0 < iUid) {
|
|
|
|
this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'Message',
|
|
|
|
{},
|
|
|
|
null,
|
|
|
|
'Message/' +
|
|
|
|
subQueryPrefix() +
|
|
|
|
'/' +
|
2020-08-20 04:23:28 +08:00
|
|
|
urlsafeArray([
|
|
|
|
sFolderFullNameRaw,
|
|
|
|
iUid,
|
|
|
|
AppStore.projectHash(),
|
|
|
|
AppStore.threadsAllowed() && SettingsStore.useThreads() ? 1 : 0
|
|
|
|
]),
|
2019-07-05 03:19:24 +08:00
|
|
|
['Message']
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {Array} aExternals
|
|
|
|
*/
|
|
|
|
composeUploadExternals(fCallback, aExternals) {
|
2019-07-05 03:19:24 +08:00
|
|
|
this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'ComposeUploadExternals',
|
|
|
|
{
|
2020-08-18 03:32:57 +08:00
|
|
|
Externals: aExternals
|
2019-07-05 03:19:24 +08:00
|
|
|
},
|
|
|
|
999000
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sUrl
|
|
|
|
* @param {string} sAccessToken
|
|
|
|
*/
|
|
|
|
composeUploadDrive(fCallback, sUrl, sAccessToken) {
|
2019-07-05 03:19:24 +08:00
|
|
|
this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'ComposeUploadDrive',
|
|
|
|
{
|
2020-08-18 03:32:57 +08:00
|
|
|
AccessToken: sAccessToken,
|
|
|
|
Url: sUrl
|
2019-07-05 03:19:24 +08:00
|
|
|
},
|
|
|
|
999000
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} folder
|
|
|
|
* @param {Array=} list = []
|
|
|
|
*/
|
|
|
|
folderInformation(fCallback, folder, list = []) {
|
|
|
|
let request = true;
|
|
|
|
const uids = [];
|
|
|
|
|
2020-07-30 03:49:41 +08:00
|
|
|
if (Array.isArray(list) && list.length) {
|
2016-08-17 06:01:20 +08:00
|
|
|
request = false;
|
2020-07-22 20:49:18 +08:00
|
|
|
list.forEach(messageListItem => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (!getMessageFlagsFromCache(messageListItem.folderFullNameRaw, messageListItem.uid)) {
|
2016-08-17 06:01:20 +08:00
|
|
|
uids.push(messageListItem.uid);
|
|
|
|
}
|
|
|
|
|
2020-07-28 18:35:41 +08:00
|
|
|
if (messageListItem.threads().length) {
|
2020-07-22 20:49:18 +08:00
|
|
|
messageListItem.threads().forEach(uid => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (!getMessageFlagsFromCache(messageListItem.folderFullNameRaw, uid)) {
|
2016-08-17 06:01:20 +08:00
|
|
|
uids.push(uid);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-28 18:35:41 +08:00
|
|
|
if (uids.length) {
|
2016-08-17 06:01:20 +08:00
|
|
|
request = true;
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (request) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.defaultRequest(fCallback, 'FolderInformation', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Folder: folder,
|
|
|
|
FlagsUids: Array.isArray(uids) ? uids.join(',') : '',
|
|
|
|
UidNext: getFolderInboxName() === folder ? getFolderUidNext(folder) : ''
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2019-07-05 03:19:24 +08:00
|
|
|
} else if (SettingsStore.useThreads()) {
|
2016-08-17 06:01:20 +08:00
|
|
|
getApp().reloadFlagsCurrentMessageListAndMessageFromCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {Array} aFolders
|
|
|
|
*/
|
|
|
|
folderInformationMultiply(fCallback, aFolders) {
|
|
|
|
this.defaultRequest(fCallback, 'FolderInformationMultiply', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Folders: aFolders
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
logout(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'Logout');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sFolderFullNameRaw
|
|
|
|
* @param {Array} aUids
|
|
|
|
* @param {boolean} bSetFlagged
|
|
|
|
*/
|
|
|
|
messageSetFlagged(fCallback, sFolderFullNameRaw, aUids, bSetFlagged) {
|
|
|
|
this.defaultRequest(fCallback, 'MessageSetFlagged', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Folder: sFolderFullNameRaw,
|
|
|
|
Uids: aUids.join(','),
|
|
|
|
SetAction: bSetFlagged ? 1 : 0
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sFolderFullNameRaw
|
|
|
|
* @param {Array} aUids
|
|
|
|
* @param {boolean} bSetSeen
|
|
|
|
*/
|
|
|
|
messageSetSeen(fCallback, sFolderFullNameRaw, aUids, bSetSeen) {
|
|
|
|
this.defaultRequest(fCallback, 'MessageSetSeen', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Folder: sFolderFullNameRaw,
|
|
|
|
Uids: aUids.join(','),
|
|
|
|
SetAction: bSetSeen ? 1 : 0
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sFolderFullNameRaw
|
|
|
|
* @param {boolean} bSetSeen
|
2016-12-15 05:56:17 +08:00
|
|
|
* @param {Array} aThreadUids = null
|
2016-08-17 06:01:20 +08:00
|
|
|
*/
|
2016-12-15 05:56:17 +08:00
|
|
|
messageSetSeenToAll(fCallback, sFolderFullNameRaw, bSetSeen, aThreadUids = null) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.defaultRequest(fCallback, 'MessageSetSeenToAll', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Folder: sFolderFullNameRaw,
|
|
|
|
SetAction: bSetSeen ? 1 : 0,
|
|
|
|
ThreadUids: aThreadUids ? aThreadUids.join(',') : ''
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
2020-08-18 03:32:57 +08:00
|
|
|
* @param {Object} oData
|
|
|
|
*/
|
|
|
|
saveMessage(fCallback, oData) {
|
|
|
|
this.defaultRequest(fCallback, 'SaveMessage', oData, SAVE_MESSAGE_AJAX_TIMEOUT);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sMessageFolder
|
|
|
|
* @param {string} sMessageUid
|
|
|
|
* @param {string} sReadReceipt
|
|
|
|
* @param {string} sSubject
|
|
|
|
* @param {string} sText
|
|
|
|
*/
|
|
|
|
sendReadReceiptMessage(fCallback, sMessageFolder, sMessageUid, sReadReceipt, sSubject, sText) {
|
|
|
|
this.defaultRequest(fCallback, 'SendReadReceiptMessage', {
|
2020-08-18 03:32:57 +08:00
|
|
|
MessageFolder: sMessageFolder,
|
|
|
|
MessageUid: sMessageUid,
|
|
|
|
ReadReceipt: sReadReceipt,
|
|
|
|
Subject: sSubject,
|
|
|
|
Text: sText
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
2020-08-18 03:32:57 +08:00
|
|
|
* @param {Object} oData
|
|
|
|
*/
|
|
|
|
sendMessage(fCallback, oData) {
|
|
|
|
this.defaultRequest(fCallback, 'SendMessage', oData, SEND_MESSAGE_AJAX_TIMEOUT);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {Object} oData
|
|
|
|
*/
|
|
|
|
saveSystemFolders(fCallback, oData) {
|
|
|
|
this.defaultRequest(fCallback, 'SystemFoldersUpdate', oData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {Object} oData
|
|
|
|
*/
|
|
|
|
saveSettings(fCallback, oData) {
|
|
|
|
this.defaultRequest(fCallback, 'SettingsUpdate', oData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} key
|
|
|
|
* @param {?Function} valueFn
|
|
|
|
* @param {?Function} fn
|
|
|
|
*/
|
|
|
|
saveSettingsHelper(key, valueFn, fn) {
|
|
|
|
return (value) => {
|
|
|
|
this.saveSettings(fn || null, {
|
|
|
|
[key]: valueFn ? valueFn(value) : value
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sFolderFullNameRaw
|
|
|
|
*/
|
|
|
|
folderClear(fCallback, sFolderFullNameRaw) {
|
|
|
|
this.defaultRequest(fCallback, 'FolderClear', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Folder: sFolderFullNameRaw
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sFolderFullNameRaw
|
|
|
|
* @param {boolean} bSubscribe
|
|
|
|
*/
|
|
|
|
folderSetSubscribe(fCallback, sFolderFullNameRaw, bSubscribe) {
|
|
|
|
this.defaultRequest(fCallback, 'FolderSubscribe', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Folder: sFolderFullNameRaw,
|
|
|
|
Subscribe: bSubscribe ? 1 : 0
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sFolderFullNameRaw
|
|
|
|
* @param {boolean} bCheckable
|
|
|
|
*/
|
|
|
|
folderSetCheckable(fCallback, sFolderFullNameRaw, bCheckable) {
|
|
|
|
this.defaultRequest(fCallback, 'FolderCheckable', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Folder: sFolderFullNameRaw,
|
|
|
|
Checkable: bCheckable ? 1 : 0
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sFolder
|
|
|
|
* @param {string} sToFolder
|
|
|
|
* @param {Array} aUids
|
|
|
|
* @param {string=} sLearning
|
|
|
|
* @param {boolean=} bMarkAsRead
|
|
|
|
*/
|
|
|
|
messagesMove(fCallback, sFolder, sToFolder, aUids, sLearning, bMarkAsRead) {
|
2019-07-05 03:19:24 +08:00
|
|
|
this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'MessageMove',
|
|
|
|
{
|
2020-08-18 03:32:57 +08:00
|
|
|
FromFolder: sFolder,
|
|
|
|
ToFolder: sToFolder,
|
|
|
|
Uids: aUids.join(','),
|
|
|
|
MarkAsRead: bMarkAsRead ? 1 : 0,
|
|
|
|
Learning: sLearning || ''
|
2019-07-05 03:19:24 +08:00
|
|
|
},
|
|
|
|
null,
|
|
|
|
'',
|
|
|
|
['MessageList']
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sFolder
|
|
|
|
* @param {string} sToFolder
|
|
|
|
* @param {Array} aUids
|
|
|
|
*/
|
|
|
|
messagesCopy(fCallback, sFolder, sToFolder, aUids) {
|
|
|
|
this.defaultRequest(fCallback, 'MessageCopy', {
|
2020-08-18 03:32:57 +08:00
|
|
|
FromFolder: sFolder,
|
|
|
|
ToFolder: sToFolder,
|
|
|
|
Uids: aUids.join(',')
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sFolder
|
|
|
|
* @param {Array} aUids
|
|
|
|
*/
|
|
|
|
messagesDelete(fCallback, sFolder, aUids) {
|
2019-07-05 03:19:24 +08:00
|
|
|
this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'MessageDelete',
|
|
|
|
{
|
2020-08-18 03:32:57 +08:00
|
|
|
Folder: sFolder,
|
|
|
|
Uids: aUids.join(',')
|
2019-07-05 03:19:24 +08:00
|
|
|
},
|
|
|
|
null,
|
|
|
|
'',
|
|
|
|
['MessageList']
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
appDelayStart(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'AppDelayStart');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
quota(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'Quota');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {number} iOffset
|
|
|
|
* @param {number} iLimit
|
|
|
|
* @param {string} sSearch
|
|
|
|
*/
|
|
|
|
contacts(fCallback, iOffset, iLimit, sSearch) {
|
2019-07-05 03:19:24 +08:00
|
|
|
this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'Contacts',
|
|
|
|
{
|
2020-08-18 03:32:57 +08:00
|
|
|
Offset: iOffset,
|
|
|
|
Limit: iLimit,
|
|
|
|
Search: sSearch
|
2019-07-05 03:19:24 +08:00
|
|
|
},
|
|
|
|
null,
|
|
|
|
'',
|
|
|
|
['Contacts']
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sRequestUid
|
|
|
|
* @param {string} sUid
|
|
|
|
* @param {Array} aProperties
|
|
|
|
*/
|
|
|
|
contactSave(fCallback, sRequestUid, sUid, aProperties) {
|
|
|
|
this.defaultRequest(fCallback, 'ContactSave', {
|
2020-08-18 03:32:57 +08:00
|
|
|
RequestUid: sRequestUid,
|
|
|
|
Uid: sUid.trim(),
|
|
|
|
Properties: aProperties
|
2013-11-16 06:21:12 +08:00
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {Array} aUids
|
|
|
|
*/
|
|
|
|
contactsDelete(fCallback, aUids) {
|
|
|
|
this.defaultRequest(fCallback, 'ContactsDelete', {
|
2020-08-18 03:32:57 +08:00
|
|
|
Uids: aUids.join(',')
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
* @param {string} sQuery
|
|
|
|
* @param {number} iPage
|
|
|
|
*/
|
|
|
|
suggestions(fCallback, sQuery, iPage) {
|
2019-07-05 03:19:24 +08:00
|
|
|
this.defaultRequest(
|
|
|
|
fCallback,
|
|
|
|
'Suggestions',
|
|
|
|
{
|
2020-08-18 03:32:57 +08:00
|
|
|
Query: sQuery,
|
|
|
|
Page: iPage
|
2019-07-05 03:19:24 +08:00
|
|
|
},
|
|
|
|
null,
|
|
|
|
'',
|
|
|
|
['Suggestions']
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {?Function} fCallback
|
|
|
|
*/
|
|
|
|
clearUserBackground(fCallback) {
|
|
|
|
this.defaultRequest(fCallback, 'ClearUserBackground');
|
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
export default new RemoteUserAjax();
|