2021-01-26 18:46:30 +08:00
|
|
|
import 'External/User/ko';
|
2021-01-26 05:00:13 +08:00
|
|
|
|
2021-11-01 23:26:07 +08:00
|
|
|
import { isArray, arrayLength, pString, forEachObjectValue } from 'Common/Utils';
|
2021-11-05 17:20:06 +08:00
|
|
|
import { delegateRunOnDestroy, mailToHelper, setLayoutResizer } from 'Common/UtilsUser';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
import {
|
2019-07-05 03:19:24 +08:00
|
|
|
Capa,
|
2021-04-23 05:53:39 +08:00
|
|
|
Notification,
|
2021-03-16 23:06:16 +08:00
|
|
|
Scope
|
2021-01-25 05:58:06 +08:00
|
|
|
} from 'Common/Enums';
|
|
|
|
|
|
|
|
import {
|
2019-07-05 03:19:24 +08:00
|
|
|
FolderType,
|
|
|
|
SetSystemFoldersNotification,
|
|
|
|
MessageSetAction,
|
2020-08-14 04:58:41 +08:00
|
|
|
ClientSideKeyName
|
2021-01-25 05:58:06 +08:00
|
|
|
} from 'Common/EnumsUser';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2021-02-17 03:12:23 +08:00
|
|
|
import {
|
|
|
|
doc,
|
|
|
|
elementById,
|
|
|
|
createElement,
|
|
|
|
$htmlCL,
|
|
|
|
Settings,
|
2021-03-10 18:44:48 +08:00
|
|
|
SettingsGet,
|
2021-02-17 03:12:23 +08:00
|
|
|
leftPanelDisabled
|
|
|
|
} from 'Common/Globals';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
2016-08-22 05:30:34 +08:00
|
|
|
|
|
|
|
import {
|
2020-10-25 20:50:26 +08:00
|
|
|
MessageFlagsCache,
|
2019-07-05 03:19:24 +08:00
|
|
|
setFolderHash,
|
|
|
|
getFolderHash,
|
|
|
|
getFolderInboxName,
|
2020-10-25 20:50:26 +08:00
|
|
|
getFolderFromCacheList
|
2016-08-22 05:30:34 +08:00
|
|
|
} from 'Common/Cache';
|
|
|
|
|
|
|
|
import {
|
2019-07-05 03:19:24 +08:00
|
|
|
mailBox,
|
|
|
|
root,
|
|
|
|
openPgpWorkerJs,
|
2020-03-11 19:55:03 +08:00
|
|
|
openPgpJs
|
2016-08-22 05:30:34 +08:00
|
|
|
} from 'Common/Links';
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { getNotification, i18n } from 'Common/Translator';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
|
|
|
import { NotificationUserStore } from 'Stores/User/Notification';
|
|
|
|
import { AccountUserStore } from 'Stores/User/Account';
|
|
|
|
import { ContactUserStore } from 'Stores/User/Contact';
|
2021-02-17 21:40:21 +08:00
|
|
|
import { IdentityUserStore } from 'Stores/User/Identity';
|
2021-03-11 05:41:35 +08:00
|
|
|
import { FolderUserStore } from 'Stores/User/Folder';
|
|
|
|
import { PgpUserStore } from 'Stores/User/Pgp';
|
|
|
|
import { MessageUserStore } from 'Stores/User/Message';
|
2021-02-17 03:12:23 +08:00
|
|
|
import { ThemeStore } from 'Stores/Theme';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2016-06-17 07:23:49 +08:00
|
|
|
import * as Local from 'Storage/Client';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { EmailModel } from 'Model/Email';
|
|
|
|
import { AccountModel } from 'Model/Account';
|
|
|
|
import { IdentityModel } from 'Model/Identity';
|
|
|
|
import { OpenPgpKeyModel } from 'Model/OpenPgpKey';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { LoginUserScreen } from 'Screen/User/Login';
|
|
|
|
import { MailBoxUserScreen } from 'Screen/User/MailBox';
|
|
|
|
import { SettingsUserScreen } from 'Screen/User/Settings';
|
2016-07-07 07:11:13 +08:00
|
|
|
|
2021-08-31 22:17:20 +08:00
|
|
|
import { startScreens, showScreenPopup, arePopupsVisible } from 'Knoin/Knoin';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { AbstractApp } from 'App/Abstract';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
import { ComposePopupView } from 'View/Popup/Compose';
|
|
|
|
import { FolderSystemPopupView } from 'View/Popup/FolderSystem';
|
|
|
|
import { AskPopupView } from 'View/Popup/Ask';
|
2020-09-17 06:02:35 +08:00
|
|
|
|
2021-07-19 20:26:32 +08:00
|
|
|
import { timeToNode } from 'Common/Momentor';
|
|
|
|
|
2021-03-18 20:52:56 +08:00
|
|
|
// Every 5 minutes
|
|
|
|
const refreshFolders = 300000;
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
class AppUser extends AbstractApp {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
2015-11-19 01:32:29 +08:00
|
|
|
super(Remote);
|
2014-04-09 00:08:16 +08:00
|
|
|
|
2016-06-28 04:54:38 +08:00
|
|
|
this.moveCache = {};
|
|
|
|
|
2020-07-30 03:49:41 +08:00
|
|
|
this.moveOrDeleteResponseHelper = this.moveOrDeleteResponseHelper.bind(this);
|
2013-12-15 19:02:50 +08:00
|
|
|
|
2020-08-19 02:24:17 +08:00
|
|
|
this.messagesMoveTrigger = this.messagesMoveTrigger.debounce(500);
|
|
|
|
|
2020-07-17 01:49:56 +08:00
|
|
|
// wakeUp
|
2020-08-14 04:58:41 +08:00
|
|
|
const interval = 3600000; // 60m
|
2020-09-04 23:07:35 +08:00
|
|
|
var lastTime = Date.now();
|
2020-07-17 01:49:56 +08:00
|
|
|
setInterval(() => {
|
2020-09-04 23:07:35 +08:00
|
|
|
const currentTime = Date.now();
|
2020-07-17 01:49:56 +08:00
|
|
|
if (currentTime > (lastTime + interval + 1000)) {
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('Version',
|
|
|
|
iError => (100 < iError) && this.reload(),
|
|
|
|
{ Version: Settings.app('version') }
|
|
|
|
);
|
2020-07-17 01:49:56 +08:00
|
|
|
}
|
|
|
|
lastTime = currentTime;
|
|
|
|
}, interval);
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2021-03-03 00:39:02 +08:00
|
|
|
const fn = (ev=>$htmlCL.toggle('rl-ctrl-key-pressed', ev.ctrlKey)).debounce(500);
|
|
|
|
['keydown','keyup'].forEach(t => doc.addEventListener(t, fn));
|
2021-02-17 21:40:21 +08:00
|
|
|
|
2021-03-16 23:06:16 +08:00
|
|
|
shortcuts.add('escape,enter', '', Scope.All, () => rl.Dropdowns.detectVisibility());
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
2016-05-22 20:27:50 +08:00
|
|
|
reload() {
|
2020-09-04 20:36:24 +08:00
|
|
|
(Settings.app('inIframe') ? parent : window).location.reload();
|
2016-05-22 20:27:50 +08:00
|
|
|
}
|
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
reloadFlagsCurrentMessageListAndMessageFromCache() {
|
2021-03-12 23:54:37 +08:00
|
|
|
MessageUserStore.list.forEach(message =>
|
2020-10-25 20:50:26 +08:00
|
|
|
MessageFlagsCache.initMessage(message)
|
|
|
|
);
|
2021-03-11 05:41:35 +08:00
|
|
|
MessageFlagsCache.initMessage(MessageUserStore.message());
|
2021-03-12 23:54:37 +08:00
|
|
|
MessageUserStore.messageViewTrigger(!MessageUserStore.messageViewTrigger());
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
|
|
|
* @param {boolean=} bDropPagePosition = false
|
|
|
|
* @param {boolean=} bDropCurrenFolderCache = false
|
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
reloadMessageList(bDropPagePosition = false, bDropCurrenFolderCache = false) {
|
2021-03-12 23:54:37 +08:00
|
|
|
let iOffset = (MessageUserStore.listPage() - 1) * SettingsUserStore.messagesPerPage();
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (bDropCurrenFolderCache) {
|
2021-11-30 17:19:43 +08:00
|
|
|
setFolderHash(FolderUserStore.currentFolderFullName(), '');
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (bDropPagePosition) {
|
2021-03-12 23:54:37 +08:00
|
|
|
MessageUserStore.listPage(1);
|
|
|
|
MessageUserStore.listPageBeforeThread(1);
|
2014-08-20 23:03:12 +08:00
|
|
|
iOffset = 0;
|
2015-04-22 05:01:29 +08:00
|
|
|
|
2020-09-17 02:35:29 +08:00
|
|
|
rl.route.setHash(
|
2019-07-05 03:19:24 +08:00
|
|
|
mailBox(
|
2021-03-11 05:41:35 +08:00
|
|
|
FolderUserStore.currentFolderFullNameHash(),
|
2021-03-12 23:54:37 +08:00
|
|
|
MessageUserStore.listPage(),
|
|
|
|
MessageUserStore.listSearch(),
|
|
|
|
MessageUserStore.listThreadUid()
|
2019-07-05 03:19:24 +08:00
|
|
|
),
|
|
|
|
true,
|
|
|
|
true
|
|
|
|
);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
2021-03-12 23:54:37 +08:00
|
|
|
MessageUserStore.listLoading(true);
|
2021-03-16 16:46:23 +08:00
|
|
|
MessageUserStore.listError('');
|
2017-06-25 03:26:27 +08:00
|
|
|
Remote.messageList(
|
2021-03-16 16:46:23 +08:00
|
|
|
(iError, oData, bCached) => {
|
2021-03-18 19:33:13 +08:00
|
|
|
if (iError) {
|
|
|
|
if (Notification.RequestAborted !== iError) {
|
|
|
|
MessageUserStore.list([]);
|
|
|
|
MessageUserStore.listError(getNotification(iError));
|
|
|
|
}
|
|
|
|
} else {
|
2021-03-11 05:41:35 +08:00
|
|
|
MessageUserStore.setMessageList(oData, bCached);
|
2017-06-25 03:26:27 +08:00
|
|
|
}
|
2021-03-16 16:46:23 +08:00
|
|
|
MessageUserStore.listLoading(false);
|
2017-06-25 03:26:27 +08:00
|
|
|
},
|
2021-03-26 22:07:14 +08:00
|
|
|
{
|
2021-11-30 17:19:43 +08:00
|
|
|
Folder: FolderUserStore.currentFolderFullName(),
|
2021-03-26 22:07:14 +08:00
|
|
|
Offset: iOffset,
|
|
|
|
Limit: SettingsUserStore.messagesPerPage(),
|
|
|
|
Search: MessageUserStore.listSearch(),
|
2021-03-30 15:10:43 +08:00
|
|
|
ThreadUid: MessageUserStore.listThreadUid()
|
2021-03-26 22:07:14 +08:00
|
|
|
}
|
2017-06-25 03:26:27 +08:00
|
|
|
);
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-05-13 16:29:36 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
messagesMoveTrigger() {
|
2021-03-11 05:41:35 +08:00
|
|
|
const sTrashFolder = FolderUserStore.trashFolder(),
|
|
|
|
sSpamFolder = FolderUserStore.spamFolder();
|
2020-08-19 02:24:17 +08:00
|
|
|
|
2021-11-01 18:24:11 +08:00
|
|
|
forEachObjectValue(this.moveCache, item => {
|
2020-08-19 02:24:17 +08:00
|
|
|
const isSpam = sSpamFolder === item.To,
|
|
|
|
isTrash = sTrashFolder === item.To,
|
|
|
|
isHam = !isSpam && sSpamFolder === item.From && getFolderInboxName() === item.To;
|
|
|
|
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('MessageMove',
|
2020-08-19 02:24:17 +08:00
|
|
|
this.moveOrDeleteResponseHelper,
|
2021-12-03 06:15:24 +08:00
|
|
|
{
|
|
|
|
FromFolder: item.From,
|
|
|
|
ToFolder: item.To,
|
|
|
|
Uids: item.Uid.join(','),
|
|
|
|
MarkAsRead: (isSpam || isTrash) ? 1 : 0,
|
|
|
|
Learning: isSpam ? 'SPAM' : isHam ? 'HAM' : ''
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
'',
|
|
|
|
['MessageList']
|
2020-08-19 02:24:17 +08:00
|
|
|
);
|
|
|
|
});
|
2014-03-20 00:18:28 +08:00
|
|
|
|
2020-08-19 02:24:17 +08:00
|
|
|
this.moveCache = {};
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
|
2021-11-30 17:19:43 +08:00
|
|
|
messagesMoveHelper(fromFolderFullName, toFolderFullName, uidsForMove) {
|
|
|
|
const hash = '$$' + fromFolderFullName + '$$' + toFolderFullName + '$$';
|
2019-07-05 03:19:24 +08:00
|
|
|
if (!this.moveCache[hash]) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.moveCache[hash] = {
|
2021-11-30 17:19:43 +08:00
|
|
|
From: fromFolderFullName,
|
|
|
|
To: toFolderFullName,
|
2016-04-21 01:12:51 +08:00
|
|
|
Uid: []
|
2014-08-20 23:03:12 +08:00
|
|
|
};
|
2014-03-20 00:18:28 +08:00
|
|
|
}
|
|
|
|
|
2020-10-03 05:54:15 +08:00
|
|
|
this.moveCache[hash].Uid = this.moveCache[hash].Uid.concat(uidsForMove).unique();
|
2014-08-20 23:03:12 +08:00
|
|
|
this.messagesMoveTrigger();
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-05-13 16:29:36 +08:00
|
|
|
|
2021-11-30 17:19:43 +08:00
|
|
|
messagesCopyHelper(sFromFolderFullName, sToFolderFullName, aUidForCopy) {
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('MessageCopy', this.moveOrDeleteResponseHelper, {
|
|
|
|
FromFolder: sFromFolderFullName,
|
|
|
|
ToFolder: sToFolderFullName,
|
|
|
|
Uids: aUidForCopy.join(',')
|
|
|
|
});
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2021-11-30 17:19:43 +08:00
|
|
|
messagesDeleteHelper(sFromFolderFullName, aUidForRemove) {
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('MessageDelete',
|
|
|
|
this.moveOrDeleteResponseHelper,
|
|
|
|
{
|
|
|
|
Folder: sFromFolderFullName,
|
|
|
|
Uids: aUidForRemove.join(',')
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
'',
|
|
|
|
['MessageList']
|
|
|
|
);
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
|
2021-03-16 16:46:23 +08:00
|
|
|
moveOrDeleteResponseHelper(iError, oData) {
|
2021-03-18 19:33:13 +08:00
|
|
|
if (iError) {
|
2021-11-30 17:19:43 +08:00
|
|
|
setFolderHash(FolderUserStore.currentFolderFullName(), '');
|
2021-03-18 19:33:13 +08:00
|
|
|
alert(getNotification(iError));
|
|
|
|
} else if (FolderUserStore.currentFolder()) {
|
2021-07-22 03:34:17 +08:00
|
|
|
if (2 === arrayLength(oData.Result)) {
|
2016-08-22 05:30:34 +08:00
|
|
|
setFolderHash(oData.Result[0], oData.Result[1]);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2021-11-30 17:19:43 +08:00
|
|
|
setFolderHash(FolderUserStore.currentFolderFullName(), '');
|
2014-04-09 00:08:16 +08:00
|
|
|
}
|
2021-03-12 23:54:37 +08:00
|
|
|
this.reloadMessageList(!MessageUserStore.list.length);
|
2014-03-20 00:18:28 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-03-20 00:18:28 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2021-11-30 17:19:43 +08:00
|
|
|
* @param {string} sFromFolderFullName
|
2014-08-20 23:03:12 +08:00
|
|
|
* @param {Array} aUidForRemove
|
|
|
|
*/
|
2021-11-30 17:19:43 +08:00
|
|
|
deleteMessagesFromFolderWithoutCheck(sFromFolderFullName, aUidForRemove) {
|
|
|
|
this.messagesDeleteHelper(sFromFolderFullName, aUidForRemove);
|
|
|
|
MessageUserStore.removeMessagesFromList(sFromFolderFullName, aUidForRemove);
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {number} iDeleteType
|
2021-11-30 17:19:43 +08:00
|
|
|
* @param {string} sFromFolderFullName
|
2014-08-20 23:03:12 +08:00
|
|
|
* @param {Array} aUidForRemove
|
|
|
|
* @param {boolean=} bUseFolder = true
|
|
|
|
*/
|
2021-11-30 17:19:43 +08:00
|
|
|
deleteMessagesFromFolder(iDeleteType, sFromFolderFullName, aUidForRemove, bUseFolder) {
|
2019-07-05 03:19:24 +08:00
|
|
|
let oMoveFolder = null,
|
2016-06-30 08:02:45 +08:00
|
|
|
nSetSystemFoldersNotification = null;
|
2014-03-20 00:18:28 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
switch (iDeleteType) {
|
2016-06-07 05:57:52 +08:00
|
|
|
case FolderType.Spam:
|
2021-03-11 05:41:35 +08:00
|
|
|
oMoveFolder = getFolderFromCacheList(FolderUserStore.spamFolder());
|
2016-06-07 05:57:52 +08:00
|
|
|
nSetSystemFoldersNotification = SetSystemFoldersNotification.Spam;
|
2014-08-20 23:03:12 +08:00
|
|
|
break;
|
2016-06-07 05:57:52 +08:00
|
|
|
case FolderType.NotSpam:
|
2016-08-22 05:30:34 +08:00
|
|
|
oMoveFolder = getFolderFromCacheList(getFolderInboxName());
|
2014-08-20 23:03:12 +08:00
|
|
|
break;
|
2016-06-07 05:57:52 +08:00
|
|
|
case FolderType.Trash:
|
2021-03-11 05:41:35 +08:00
|
|
|
oMoveFolder = getFolderFromCacheList(FolderUserStore.trashFolder());
|
2016-06-07 05:57:52 +08:00
|
|
|
nSetSystemFoldersNotification = SetSystemFoldersNotification.Trash;
|
2014-08-20 23:03:12 +08:00
|
|
|
break;
|
2016-06-07 05:57:52 +08:00
|
|
|
case FolderType.Archive:
|
2021-03-11 05:41:35 +08:00
|
|
|
oMoveFolder = getFolderFromCacheList(FolderUserStore.archiveFolder());
|
2016-06-07 05:57:52 +08:00
|
|
|
nSetSystemFoldersNotification = SetSystemFoldersNotification.Archive;
|
2014-08-20 23:03:12 +08:00
|
|
|
break;
|
2016-06-30 08:02:45 +08:00
|
|
|
// no default
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-07-30 03:49:41 +08:00
|
|
|
bUseFolder = undefined === bUseFolder ? true : !!bUseFolder;
|
2019-07-05 03:19:24 +08:00
|
|
|
if (bUseFolder) {
|
|
|
|
if (
|
2021-03-11 05:41:35 +08:00
|
|
|
(FolderType.Spam === iDeleteType && UNUSED_OPTION_VALUE === FolderUserStore.spamFolder()) ||
|
|
|
|
(FolderType.Trash === iDeleteType && UNUSED_OPTION_VALUE === FolderUserStore.trashFolder()) ||
|
|
|
|
(FolderType.Archive === iDeleteType && UNUSED_OPTION_VALUE === FolderUserStore.archiveFolder())
|
2019-07-05 03:19:24 +08:00
|
|
|
) {
|
2014-08-20 23:03:12 +08:00
|
|
|
bUseFolder = false;
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (!oMoveFolder && bUseFolder) {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(FolderSystemPopupView, [nSetSystemFoldersNotification]);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else if (
|
|
|
|
!bUseFolder ||
|
|
|
|
(FolderType.Trash === iDeleteType &&
|
2021-11-30 17:19:43 +08:00
|
|
|
(sFromFolderFullName === FolderUserStore.spamFolder()
|
|
|
|
|| sFromFolderFullName === FolderUserStore.trashFolder()))
|
2019-07-05 03:19:24 +08:00
|
|
|
) {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(AskPopupView, [
|
2019-07-05 03:19:24 +08:00
|
|
|
i18n('POPUPS_ASK/DESC_WANT_DELETE_MESSAGES'),
|
|
|
|
() => {
|
2021-11-30 17:19:43 +08:00
|
|
|
this.messagesDeleteHelper(sFromFolderFullName, aUidForRemove);
|
|
|
|
MessageUserStore.removeMessagesFromList(sFromFolderFullName, aUidForRemove);
|
2019-07-05 03:19:24 +08:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
} else if (oMoveFolder) {
|
2021-11-30 17:19:43 +08:00
|
|
|
this.messagesMoveHelper(sFromFolderFullName, oMoveFolder.fullName, aUidForRemove);
|
|
|
|
MessageUserStore.removeMessagesFromList(sFromFolderFullName, aUidForRemove, oMoveFolder.fullName);
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
/**
|
2021-11-30 17:19:43 +08:00
|
|
|
* @param {string} sFromFolderFullName
|
2014-08-20 23:03:12 +08:00
|
|
|
* @param {Array} aUidForMove
|
2021-11-30 17:19:43 +08:00
|
|
|
* @param {string} sToFolderFullName
|
2014-08-20 23:03:12 +08:00
|
|
|
* @param {boolean=} bCopy = false
|
|
|
|
*/
|
2021-11-30 17:19:43 +08:00
|
|
|
moveMessagesToFolder(sFromFolderFullName, aUidForMove, sToFolderFullName, bCopy) {
|
|
|
|
if (sFromFolderFullName !== sToFolderFullName && arrayLength(aUidForMove)) {
|
|
|
|
const oFromFolder = getFolderFromCacheList(sFromFolderFullName),
|
|
|
|
oToFolder = getFolderFromCacheList(sToFolderFullName);
|
2014-03-13 06:29:33 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (oFromFolder && oToFolder) {
|
2020-07-30 03:49:41 +08:00
|
|
|
if (undefined === bCopy ? false : !!bCopy) {
|
2021-11-23 04:01:30 +08:00
|
|
|
this.messagesCopyHelper(oFromFolder.fullName, oToFolder.fullName, aUidForMove);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2021-11-23 04:01:30 +08:00
|
|
|
this.messagesMoveHelper(oFromFolder.fullName, oToFolder.fullName, aUidForMove);
|
2014-03-21 07:47:13 +08:00
|
|
|
}
|
2014-03-13 06:29:33 +08:00
|
|
|
|
2021-11-23 04:01:30 +08:00
|
|
|
MessageUserStore.removeMessagesFromList(oFromFolder.fullName, aUidForMove, oToFolder.fullName, bCopy);
|
2014-08-20 23:03:12 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-05-13 16:29:36 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
return false;
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {Function=} callback = null
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
foldersReload(callback = null) {
|
2021-03-03 00:39:02 +08:00
|
|
|
Remote.foldersReload(callback);
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
foldersPromisesActionHelper(promise, errorDefCode) {
|
2020-09-15 01:40:56 +08:00
|
|
|
Remote.abort('Folders')
|
2015-03-17 22:12:19 +08:00
|
|
|
.fastResolve(true)
|
2015-11-19 01:32:29 +08:00
|
|
|
.then(() => promise)
|
2019-07-05 03:19:24 +08:00
|
|
|
.then(
|
2021-03-22 22:20:59 +08:00
|
|
|
() => Remote.foldersReloadWithTimeout(),
|
2021-08-25 18:00:50 +08:00
|
|
|
error => {
|
|
|
|
FolderUserStore.folderListError(getNotification(error.code, '', errorDefCode) + '.\n' + error.message);
|
2021-03-03 00:39:02 +08:00
|
|
|
Remote.foldersReloadWithTimeout();
|
2019-07-05 03:19:24 +08:00
|
|
|
}
|
|
|
|
);
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
reloadOpenPgpKeys() {
|
2021-03-11 05:41:35 +08:00
|
|
|
if (PgpUserStore.capaOpenPGP()) {
|
2019-07-05 03:19:24 +08:00
|
|
|
const keys = [],
|
2016-08-17 06:01:20 +08:00
|
|
|
email = new EmailModel(),
|
2021-03-11 05:41:35 +08:00
|
|
|
openpgpKeyring = PgpUserStore.openpgpKeyring,
|
2016-08-17 06:01:20 +08:00
|
|
|
openpgpKeys = openpgpKeyring ? openpgpKeyring.getAllKeys() : [];
|
2014-05-13 16:29:36 +08:00
|
|
|
|
2020-07-22 20:49:18 +08:00
|
|
|
openpgpKeys.forEach((oItem, iIndex) => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (oItem && oItem.primaryKey) {
|
|
|
|
const aEmails = [],
|
2016-04-07 02:26:29 +08:00
|
|
|
aUsers = [],
|
2016-08-17 06:01:20 +08:00
|
|
|
primaryUser = oItem.getPrimaryUser(),
|
2019-07-05 03:19:24 +08:00
|
|
|
user =
|
|
|
|
primaryUser && primaryUser.user
|
|
|
|
? primaryUser.user.userId.userid
|
|
|
|
: oItem.users && oItem.users[0]
|
|
|
|
? oItem.users[0].userId.userid
|
|
|
|
: '';
|
|
|
|
|
|
|
|
if (oItem.users) {
|
2020-07-22 20:49:18 +08:00
|
|
|
oItem.users.forEach(item => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (item.userId) {
|
2016-08-17 06:01:20 +08:00
|
|
|
email.clear();
|
2017-09-28 01:58:15 +08:00
|
|
|
email.parse(item.userId.userid);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (email.validate()) {
|
2016-08-17 06:01:20 +08:00
|
|
|
aEmails.push(email.email);
|
2016-05-24 01:33:01 +08:00
|
|
|
aUsers.push(item.userId.userid);
|
|
|
|
}
|
2016-04-07 02:26:29 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-05-13 16:29:36 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (aEmails.length) {
|
|
|
|
keys.push(
|
|
|
|
new OpenPgpKeyModel(
|
|
|
|
iIndex,
|
|
|
|
oItem.primaryKey.getFingerprint(),
|
|
|
|
oItem.primaryKey
|
|
|
|
.getKeyId()
|
|
|
|
.toHex()
|
|
|
|
.toLowerCase(),
|
2020-07-23 22:06:16 +08:00
|
|
|
oItem.getKeyIds()
|
|
|
|
.map(item => (item && item.toHex ? item.toHex() : null))
|
2020-10-03 05:54:15 +08:00
|
|
|
.validUnique(),
|
2019-07-05 03:19:24 +08:00
|
|
|
aUsers,
|
|
|
|
aEmails,
|
|
|
|
oItem.isPrivate(),
|
|
|
|
oItem.armor(),
|
|
|
|
user
|
|
|
|
)
|
2014-08-20 23:03:12 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
delegateRunOnDestroy(PgpUserStore.openpgpkeys());
|
|
|
|
PgpUserStore.openpgpkeys(keys);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2020-08-15 02:35:39 +08:00
|
|
|
accountsAndIdentities() {
|
2021-03-11 05:41:35 +08:00
|
|
|
AccountUserStore.loading(true);
|
2021-02-17 21:40:21 +08:00
|
|
|
IdentityUserStore.loading(true);
|
2014-05-13 16:29:36 +08:00
|
|
|
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('AccountsAndIdentities', (iError, oData) => {
|
2021-03-11 05:41:35 +08:00
|
|
|
AccountUserStore.loading(false);
|
2021-02-17 21:40:21 +08:00
|
|
|
IdentityUserStore.loading(false);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-03-18 21:48:21 +08:00
|
|
|
if (!iError) {
|
2021-12-02 18:12:21 +08:00
|
|
|
const
|
|
|
|
// counts = {},
|
2021-11-15 17:56:52 +08:00
|
|
|
accounts = oData.Result.Accounts,
|
|
|
|
mainEmail = SettingsGet('MainEmail');
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-11-15 17:56:52 +08:00
|
|
|
if (isArray(accounts)) {
|
2021-12-02 18:12:21 +08:00
|
|
|
// AccountUserStore.accounts.forEach(oAccount => counts[oAccount.email] = oAccount.count());
|
2014-12-18 04:53:46 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
delegateRunOnDestroy(AccountUserStore.accounts());
|
2014-12-18 04:53:46 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
AccountUserStore.accounts(
|
2021-11-15 17:56:52 +08:00
|
|
|
accounts.map(
|
2021-12-02 18:12:21 +08:00
|
|
|
sValue => new AccountModel(sValue/*, counts[sValue]*/)
|
2019-07-05 03:19:24 +08:00
|
|
|
)
|
|
|
|
);
|
2021-11-15 17:56:52 +08:00
|
|
|
// accounts.length &&
|
2021-12-02 18:12:21 +08:00
|
|
|
AccountUserStore.accounts.unshift(new AccountModel(mainEmail/*, counts[mainEmail]*/, false));
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-03-16 23:49:14 +08:00
|
|
|
if (isArray(oData.Result.Identities)) {
|
2021-02-17 21:40:21 +08:00
|
|
|
delegateRunOnDestroy(IdentityUserStore());
|
2015-01-29 05:24:58 +08:00
|
|
|
|
2021-02-17 21:40:21 +08:00
|
|
|
IdentityUserStore(
|
2020-07-23 02:09:31 +08:00
|
|
|
oData.Result.Identities.map(identityData => {
|
2021-11-15 17:56:52 +08:00
|
|
|
const identity = new IdentityModel(
|
|
|
|
pString(identityData.Id),
|
|
|
|
pString(identityData.Email)
|
|
|
|
);
|
2013-12-07 06:45:46 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
identity.name(pString(identityData.Name));
|
|
|
|
identity.replyTo(pString(identityData.ReplyTo));
|
|
|
|
identity.bcc(pString(identityData.Bcc));
|
|
|
|
identity.signature(pString(identityData.Signature));
|
|
|
|
identity.signatureInsertBefore(!!identityData.SignatureInsertBefore);
|
2013-12-07 06:45:46 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
return identity;
|
|
|
|
})
|
|
|
|
);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {string} folder
|
|
|
|
* @param {Array=} list = []
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
folderInformation(folder, list) {
|
2020-07-30 03:49:41 +08:00
|
|
|
if (folder && folder.trim()) {
|
2019-07-05 03:19:24 +08:00
|
|
|
Remote.folderInformation(
|
2021-03-16 16:46:23 +08:00
|
|
|
(iError, data) => {
|
2021-08-17 18:08:09 +08:00
|
|
|
if (!iError && data.Result) {
|
|
|
|
const result = data.Result,
|
|
|
|
hash = getFolderHash(result.Folder),
|
|
|
|
folderFromCache = getFolderFromCacheList(result.Folder);
|
2021-03-16 16:46:23 +08:00
|
|
|
if (folderFromCache) {
|
2021-03-18 20:52:56 +08:00
|
|
|
folderFromCache.expires = Date.now();
|
2021-03-16 16:46:23 +08:00
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
setFolderHash(result.Folder, result.Hash);
|
2013-12-16 01:16:25 +08:00
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
folderFromCache.messageCountAll(result.MessageCount);
|
2019-07-05 03:19:24 +08:00
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
let unreadCountChange = (folderFromCache.messageCountUnread() !== result.MessageUnseenCount);
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
folderFromCache.messageCountUnread(result.MessageUnseenCount);
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2021-03-16 16:46:23 +08:00
|
|
|
if (unreadCountChange) {
|
2021-11-23 04:01:30 +08:00
|
|
|
MessageFlagsCache.clearFolder(folderFromCache.fullName);
|
2021-03-16 16:46:23 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
if (result.Flags.length) {
|
|
|
|
result.Flags.forEach(flags =>
|
2021-11-23 04:01:30 +08:00
|
|
|
MessageFlagsCache.storeByFolderAndUid(folderFromCache.fullName, flags.Uid.toString(), [
|
2021-08-17 00:10:45 +08:00
|
|
|
!!flags.IsUnseen,
|
|
|
|
!!flags.IsFlagged,
|
|
|
|
!!flags.IsAnswered,
|
|
|
|
!!flags.IsForwarded,
|
|
|
|
!!flags.IsReadReceipt
|
2021-08-17 18:08:09 +08:00
|
|
|
])
|
|
|
|
);
|
2019-07-05 03:19:24 +08:00
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
this.reloadFlagsCurrentMessageListAndMessageFromCache();
|
2021-03-16 16:46:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageUserStore.initUidNextAndNewMessages(
|
2021-11-23 04:01:30 +08:00
|
|
|
folderFromCache.fullName,
|
2021-08-17 18:08:09 +08:00
|
|
|
result.UidNext,
|
|
|
|
result.NewMessages
|
2021-03-16 16:46:23 +08:00
|
|
|
);
|
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
if (!hash || unreadCountChange || result.Hash !== hash) {
|
2021-11-30 17:19:43 +08:00
|
|
|
if (folderFromCache.fullName === FolderUserStore.currentFolderFullName()) {
|
2021-03-16 16:46:23 +08:00
|
|
|
this.reloadMessageList();
|
2021-11-23 04:01:30 +08:00
|
|
|
} else if (getFolderInboxName() === folderFromCache.fullName) {
|
2021-11-13 16:45:06 +08:00
|
|
|
Remote.messageList(null, {Folder: getFolderInboxName()}, true);
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2013-12-16 01:16:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-05 03:19:24 +08:00
|
|
|
},
|
|
|
|
folder,
|
|
|
|
list
|
|
|
|
);
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2016-04-21 01:12:51 +08:00
|
|
|
}
|
2013-12-16 01:16:25 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {boolean=} boot = false
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
folderInformationMultiply(boot = false) {
|
2021-03-18 20:52:56 +08:00
|
|
|
const folders = FolderUserStore.getNextFolderNames(refreshFolders);
|
2021-07-22 03:34:17 +08:00
|
|
|
if (arrayLength(folders)) {
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('FolderInformationMultiply', (iError, oData) => {
|
2021-10-31 07:06:32 +08:00
|
|
|
if (!iError && arrayLength(oData.Result)) {
|
2021-03-16 16:46:23 +08:00
|
|
|
const utc = Date.now();
|
2021-10-31 07:06:32 +08:00
|
|
|
oData.Result.forEach(item => {
|
2021-03-16 16:46:23 +08:00
|
|
|
const hash = getFolderHash(item.Folder),
|
|
|
|
folder = getFolderFromCacheList(item.Folder);
|
|
|
|
|
|
|
|
if (folder) {
|
2021-03-18 20:52:56 +08:00
|
|
|
folder.expires = utc;
|
2021-03-16 16:46:23 +08:00
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
setFolderHash(item.Folder, item.Hash);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
folder.messageCountAll(item.MessageCount);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
let unreadCountChange = folder.messageCountUnread() !== item.MessageUnseenCount;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-08-17 18:08:09 +08:00
|
|
|
folder.messageCountUnread(item.MessageUnseenCount);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-03-16 16:46:23 +08:00
|
|
|
if (unreadCountChange) {
|
2021-11-23 04:01:30 +08:00
|
|
|
MessageFlagsCache.clearFolder(folder.fullName);
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
|
2021-03-16 16:46:23 +08:00
|
|
|
if (!hash || item.Hash !== hash) {
|
2021-11-30 17:19:43 +08:00
|
|
|
if (folder.fullName === FolderUserStore.currentFolderFullName()) {
|
2021-03-16 16:46:23 +08:00
|
|
|
this.reloadMessageList();
|
|
|
|
}
|
|
|
|
} else if (unreadCountChange
|
2021-11-30 17:19:43 +08:00
|
|
|
&& folder.fullName === FolderUserStore.currentFolderFullName()
|
2021-03-16 16:46:23 +08:00
|
|
|
&& MessageUserStore.list.length) {
|
2021-11-23 04:01:30 +08:00
|
|
|
this.folderInformation(folder.fullName, MessageUserStore.list());
|
2021-03-16 16:46:23 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2021-03-16 16:46:23 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (boot) {
|
|
|
|
setTimeout(() => this.folderInformationMultiply(true), 2000);
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-03 06:15:24 +08:00
|
|
|
}, {
|
|
|
|
Folders: folders
|
|
|
|
});
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2016-04-21 01:12:51 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-03-06 08:42:40 +08:00
|
|
|
/**
|
2021-11-30 17:19:43 +08:00
|
|
|
* @param {string} sFolderFullName
|
2015-03-06 08:42:40 +08:00
|
|
|
* @param {number} iSetAction
|
2016-08-17 06:01:20 +08:00
|
|
|
* @param {Array=} messages = null
|
2015-03-06 08:42:40 +08:00
|
|
|
*/
|
2021-11-30 17:19:43 +08:00
|
|
|
messageListAction(sFolderFullName, iSetAction, messages) {
|
2021-12-03 06:15:24 +08:00
|
|
|
messages = messages || MessageUserStore.listChecked();
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
let folder = null,
|
2016-08-17 06:01:20 +08:00
|
|
|
alreadyUnread = 0,
|
2021-12-03 06:15:24 +08:00
|
|
|
rootUids = messages.map(oMessage => oMessage && oMessage.uid ? oMessage.uid : null)
|
|
|
|
.validUnique(),
|
|
|
|
length = rootUids.length;
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2021-12-03 06:15:24 +08:00
|
|
|
if (sFolderFullName && length) {
|
2019-07-05 03:19:24 +08:00
|
|
|
switch (iSetAction) {
|
2016-06-07 05:57:52 +08:00
|
|
|
case MessageSetAction.SetSeen:
|
2021-12-03 06:15:24 +08:00
|
|
|
length = 0;
|
|
|
|
// fallthrough is intentionally
|
2016-06-07 05:57:52 +08:00
|
|
|
case MessageSetAction.UnsetSeen:
|
2020-10-25 20:50:26 +08:00
|
|
|
rootUids.forEach(sSubUid =>
|
2021-11-30 17:19:43 +08:00
|
|
|
alreadyUnread += MessageFlagsCache.storeBySetAction(sFolderFullName, sSubUid, iSetAction)
|
2020-10-25 20:50:26 +08:00
|
|
|
);
|
2015-03-06 08:42:40 +08:00
|
|
|
|
2021-11-30 17:19:43 +08:00
|
|
|
folder = getFolderFromCacheList(sFolderFullName);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (folder) {
|
2021-12-03 06:15:24 +08:00
|
|
|
folder.messageCountUnread(folder.messageCountUnread() - alreadyUnread + length);
|
2015-03-06 08:42:40 +08:00
|
|
|
}
|
|
|
|
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('MessageSetSeen', null, {
|
|
|
|
Folder: sFolderFullName,
|
|
|
|
Uids: rootUids.join(','),
|
|
|
|
SetAction: iSetAction == MessageSetAction.SetSeen ? 1 : 0
|
|
|
|
});
|
2015-03-06 08:42:40 +08:00
|
|
|
break;
|
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
case MessageSetAction.SetFlag:
|
|
|
|
case MessageSetAction.UnsetFlag:
|
2020-10-25 20:50:26 +08:00
|
|
|
rootUids.forEach(sSubUid =>
|
2021-11-30 17:19:43 +08:00
|
|
|
MessageFlagsCache.storeBySetAction(sFolderFullName, sSubUid, iSetAction)
|
2020-10-25 20:50:26 +08:00
|
|
|
);
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('MessageSetFlagged', null, {
|
|
|
|
Folder: sFolderFullName,
|
|
|
|
Uids: rootUids.join(','),
|
|
|
|
SetAction: iSetAction == MessageSetAction.SetFlag ? 1 : 0
|
|
|
|
});
|
2015-03-06 08:42:40 +08:00
|
|
|
break;
|
2016-06-30 08:02:45 +08:00
|
|
|
// no default
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
this.reloadFlagsCurrentMessageListAndMessageFromCache();
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {string} query
|
2016-07-02 06:49:59 +08:00
|
|
|
* @param {Function} autocompleteCallback
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2016-07-02 06:49:59 +08:00
|
|
|
getAutocomplete(query, autocompleteCallback) {
|
2021-03-16 16:46:23 +08:00
|
|
|
Remote.suggestions((iError, data) => {
|
2021-03-18 21:48:21 +08:00
|
|
|
if (!iError && isArray(data.Result)) {
|
2019-07-05 03:19:24 +08:00
|
|
|
autocompleteCallback(
|
2020-10-03 05:54:15 +08:00
|
|
|
data.Result.map(item => (item && item[0] ? new EmailModel(item[0], item[1]) : null)).filter(v => v)
|
2019-07-05 03:19:24 +08:00
|
|
|
);
|
2021-03-18 19:33:13 +08:00
|
|
|
} else if (Notification.RequestAborted !== iError) {
|
2016-07-02 06:49:59 +08:00
|
|
|
autocompleteCallback([]);
|
2014-08-22 23:08:56 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}, query);
|
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
/**
|
|
|
|
* @param {string} sFullNameHash
|
|
|
|
* @param {boolean} bExpanded
|
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
setExpandedFolder(sFullNameHash, bExpanded) {
|
2016-06-07 05:57:52 +08:00
|
|
|
let aExpandedList = Local.get(ClientSideKeyName.ExpandedFolders);
|
2021-03-16 23:49:14 +08:00
|
|
|
if (!isArray(aExpandedList)) {
|
2014-08-22 23:08:56 +08:00
|
|
|
aExpandedList = [];
|
|
|
|
}
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (bExpanded) {
|
2020-07-23 22:06:16 +08:00
|
|
|
if (!aExpandedList.includes(sFullNameHash))
|
|
|
|
aExpandedList.push(sFullNameHash);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2020-07-23 22:06:16 +08:00
|
|
|
aExpandedList = aExpandedList.filter(value => value !== sFullNameHash);
|
2014-08-22 23:08:56 +08:00
|
|
|
}
|
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
Local.set(ClientSideKeyName.ExpandedFolders, aExpandedList);
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
|
|
|
|
2021-03-25 17:54:40 +08:00
|
|
|
/**
|
|
|
|
* @param {string} link
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
download(link) {
|
|
|
|
if (ThemeStore.isMobile()) {
|
|
|
|
open(link, '_self');
|
|
|
|
focus();
|
|
|
|
} else {
|
|
|
|
const oLink = createElement('a');
|
|
|
|
oLink.href = link;
|
|
|
|
doc.body.appendChild(oLink).click();
|
|
|
|
oLink.remove();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
logout() {
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('Logout', () => rl.logoutReload());
|
2016-04-21 01:12:51 +08:00
|
|
|
}
|
2015-02-19 03:52:52 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
bootstart() {
|
|
|
|
super.bootstart();
|
2014-05-13 16:29:36 +08:00
|
|
|
|
2021-03-05 23:46:40 +08:00
|
|
|
addEventListener('resize', () => leftPanelDisabled(ThemeStore.isMobile() || 1000 > innerWidth));
|
2021-08-31 22:21:40 +08:00
|
|
|
addEventListener('beforeunload', event => {
|
|
|
|
if (arePopupsVisible()) {
|
|
|
|
event.preventDefault();
|
|
|
|
return event.returnValue = "Are you sure you want to exit?";
|
|
|
|
}
|
|
|
|
}, {capture: true});
|
2021-11-01 18:24:11 +08:00
|
|
|
}
|
2021-03-05 23:46:40 +08:00
|
|
|
|
2021-11-01 18:24:11 +08:00
|
|
|
start() {
|
2021-03-10 18:44:48 +08:00
|
|
|
if (SettingsGet('Auth')) {
|
2021-04-13 01:15:33 +08:00
|
|
|
rl.setWindowTitle(i18n('GLOBAL/LOADING'));
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2021-09-23 20:24:06 +08:00
|
|
|
NotificationUserStore.enableSoundNotification(!!SettingsGet('SoundNotification'));
|
|
|
|
NotificationUserStore.enableDesktopNotification(!!SettingsGet('DesktopNotifications'));
|
|
|
|
|
|
|
|
AccountUserStore.email(SettingsGet('Email'));
|
|
|
|
|
2021-11-19 19:44:53 +08:00
|
|
|
SettingsUserStore.init();
|
2021-11-24 15:36:27 +08:00
|
|
|
ContactUserStore.init();
|
2021-11-19 19:44:53 +08:00
|
|
|
|
2021-04-13 01:15:33 +08:00
|
|
|
this.foldersReload(value => {
|
|
|
|
try {
|
|
|
|
if (value) {
|
2021-09-23 20:24:06 +08:00
|
|
|
value = pString(SettingsGet('StartupUrl'));
|
|
|
|
value && rl.route.setHash(root(value), true);
|
2013-12-16 01:16:25 +08:00
|
|
|
|
2021-04-13 01:15:33 +08:00
|
|
|
startScreens([
|
|
|
|
MailBoxUserScreen,
|
2021-09-23 17:05:19 +08:00
|
|
|
SettingsUserScreen
|
2021-04-13 01:15:33 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
setInterval(() => {
|
2021-11-30 17:19:43 +08:00
|
|
|
const cF = FolderUserStore.currentFolderFullName(),
|
2021-04-13 01:15:33 +08:00
|
|
|
iF = getFolderInboxName();
|
|
|
|
this.folderInformation(iF);
|
|
|
|
if (iF !== cF) {
|
|
|
|
this.folderInformation(cF);
|
|
|
|
}
|
|
|
|
this.folderInformationMultiply();
|
|
|
|
}, refreshFolders);
|
2014-10-29 06:05:50 +08:00
|
|
|
|
2021-04-13 01:15:33 +08:00
|
|
|
// Every 15 minutes
|
2021-11-01 23:26:07 +08:00
|
|
|
setInterval(()=>this.foldersReload(), 900000);
|
2014-10-29 06:05:50 +08:00
|
|
|
|
2021-09-23 20:24:06 +08:00
|
|
|
ContactUserStore.init();
|
2014-10-29 06:05:50 +08:00
|
|
|
|
2021-11-13 16:46:59 +08:00
|
|
|
this.accountsAndIdentities();
|
2015-02-19 03:52:52 +08:00
|
|
|
|
2021-04-13 01:15:33 +08:00
|
|
|
setTimeout(() => {
|
2021-11-30 17:19:43 +08:00
|
|
|
const cF = FolderUserStore.currentFolderFullName();
|
2021-04-13 01:15:33 +08:00
|
|
|
if (getFolderInboxName() !== cF) {
|
|
|
|
this.folderInformation(cF);
|
|
|
|
}
|
2021-11-03 09:28:01 +08:00
|
|
|
FolderUserStore.hasCapability('LIST-STATUS') || this.folderInformationMultiply(true);
|
2021-04-13 01:15:33 +08:00
|
|
|
}, 1000);
|
|
|
|
|
2021-12-03 06:15:24 +08:00
|
|
|
setTimeout(() => Remote.request('AppDelayStart'), 35000);
|
2021-04-13 01:15:33 +08:00
|
|
|
|
|
|
|
// When auto-login is active
|
|
|
|
if (
|
2021-09-23 20:24:06 +08:00
|
|
|
SettingsGet('AccountSignMe') &&
|
2021-09-17 19:58:49 +08:00
|
|
|
navigator.registerProtocolHandler
|
2021-04-13 01:15:33 +08:00
|
|
|
) {
|
2020-10-13 01:46:41 +08:00
|
|
|
setTimeout(() => {
|
2021-04-13 01:15:33 +08:00
|
|
|
try {
|
|
|
|
navigator.registerProtocolHandler(
|
|
|
|
'mailto',
|
|
|
|
location.protocol + '//' + location.host + location.pathname + '?mailto&to=%s',
|
|
|
|
(SettingsGet('Title') || 'SnappyMail')
|
|
|
|
);
|
|
|
|
} catch (e) {} // eslint-disable-line no-empty
|
|
|
|
|
2021-09-23 20:24:06 +08:00
|
|
|
value = SettingsGet('MailToEmail');
|
|
|
|
value && mailToHelper(value);
|
2021-04-13 01:15:33 +08:00
|
|
|
}, 500);
|
|
|
|
}
|
2015-03-04 08:30:37 +08:00
|
|
|
|
2021-04-13 01:15:33 +08:00
|
|
|
['touchstart','mousedown','mousemove','keydown'].forEach(
|
|
|
|
t => doc.addEventListener(t, SettingsUserStore.delayLogout, {passive:true})
|
|
|
|
);
|
|
|
|
SettingsUserStore.delayLogout();
|
2021-03-18 23:12:24 +08:00
|
|
|
|
2021-11-13 16:46:59 +08:00
|
|
|
// initLeftSideLayoutResizer
|
|
|
|
setTimeout(() => {
|
|
|
|
const left = elementById('rl-left'),
|
|
|
|
right = elementById('rl-right'),
|
|
|
|
fToggle = () =>
|
|
|
|
setLayoutResizer(left, right, ClientSideKeyName.FolderListSize,
|
|
|
|
(ThemeStore.isMobile() || leftPanelDisabled()) ? 0 : 'Width');
|
|
|
|
if (left && right) {
|
|
|
|
fToggle();
|
|
|
|
leftPanelDisabled.subscribe(fToggle);
|
|
|
|
}
|
|
|
|
}, 1);
|
2021-09-23 20:24:06 +08:00
|
|
|
|
|
|
|
setInterval(this.reloadTime(), 60000);
|
|
|
|
|
|
|
|
if (window.crypto && crypto.getRandomValues && Settings.capa(Capa.OpenPGP)) {
|
|
|
|
const script = createElement('script', {src:openPgpJs()});
|
|
|
|
script.onload = () => {
|
|
|
|
PgpUserStore.openpgp = openpgp;
|
|
|
|
if (window.Worker) {
|
|
|
|
try {
|
|
|
|
PgpUserStore.openpgp.initWorker({ path: openPgpWorkerJs() });
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PgpUserStore.openpgpKeyring = new openpgp.Keyring();
|
|
|
|
PgpUserStore.capaOpenPGP(true);
|
|
|
|
this.reloadOpenPgpKeys();
|
|
|
|
};
|
|
|
|
script.onerror = () => console.error(script.src);
|
|
|
|
doc.head.append(script);
|
|
|
|
}
|
2021-04-13 01:15:33 +08:00
|
|
|
} else {
|
|
|
|
this.logout();
|
2015-04-08 00:39:43 +08:00
|
|
|
}
|
2021-04-13 01:15:33 +08:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
});
|
2014-10-30 05:08:53 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2020-10-13 01:46:41 +08:00
|
|
|
startScreens([LoginUserScreen]);
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2021-07-19 20:26:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
reloadTime()
|
|
|
|
{
|
|
|
|
setTimeout(() =>
|
2021-09-23 20:24:06 +08:00
|
|
|
doc.querySelectorAll('time').forEach(element => timeToNode(element))
|
2021-07-19 20:26:32 +08:00
|
|
|
, 1)
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2021-01-26 05:00:13 +08:00
|
|
|
|
2021-03-10 18:43:23 +08:00
|
|
|
showMessageComposer(params = [])
|
2021-01-26 05:00:13 +08:00
|
|
|
{
|
2021-09-17 19:58:49 +08:00
|
|
|
showScreenPopup(ComposePopupView, params);
|
2021-01-26 05:00:13 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
export default new AppUser();
|