2016-09-23 23:17:25 +02:00
|
|
|
/* -*- Mode: js; indent-tabs-mode: nil; js-indent-level: 2; -*- */
|
2015-05-06 04:06:13 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2018-11-13 20:59:09 +01:00
|
|
|
MailboxesController.$inject = ['$scope', '$state', '$transitions', '$timeout', '$window', '$mdUtil', '$mdMedia', '$mdSidenav', '$mdDialog', '$mdToast', 'sgConstant', 'sgFocus', 'encodeUriFilter', 'Dialog', 'sgSettings', 'sgHotkeys', 'Account', 'Mailbox', 'VirtualMailbox', 'User', 'Preferences', 'stateAccounts'];
|
|
|
|
function MailboxesController($scope, $state, $transitions, $timeout, $window, $mdUtil, $mdMedia, $mdSidenav, $mdDialog, $mdToast, sgConstant, focus, encodeUriFilter, Dialog, Settings, sgHotkeys, Account, Mailbox, VirtualMailbox, User, Preferences, stateAccounts) {
|
2015-07-13 21:22:58 +02:00
|
|
|
var vm = this,
|
|
|
|
account,
|
2016-09-27 21:19:24 +02:00
|
|
|
mailbox,
|
|
|
|
hotkeys = [];
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.$onInit = function () {
|
|
|
|
this.service = Mailbox;
|
|
|
|
this.accounts = stateAccounts;
|
|
|
|
|
|
|
|
// Advanced search options
|
|
|
|
this.currentSearchParam = '';
|
|
|
|
this.search = {
|
|
|
|
options: {'': '', // no placeholder when no criteria is active
|
|
|
|
subject: l('Enter Subject'),
|
|
|
|
from: l('Enter From'),
|
|
|
|
to: l('Enter To'),
|
|
|
|
cc: l('Enter Cc'),
|
|
|
|
body: l('Enter Body')
|
|
|
|
},
|
|
|
|
subfolders: 1,
|
|
|
|
match: 'AND',
|
|
|
|
params: []
|
|
|
|
};
|
2016-09-27 21:19:24 +02:00
|
|
|
|
2017-06-01 19:46:57 +02:00
|
|
|
this.showSubscribedOnly = Preferences.defaults.SOGoMailShowSubscribedFoldersOnly;
|
2016-09-14 21:57:49 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.refreshUnseenCount();
|
2016-08-04 23:34:29 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
_registerHotkeys(hotkeys);
|
2016-09-27 21:19:24 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
// Deregister hotkeys
|
|
|
|
_.forEach(hotkeys, function(key) {
|
|
|
|
sgHotkeys.deregisterHotkey(key);
|
|
|
|
});
|
2016-09-27 21:19:24 +02:00
|
|
|
});
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2016-09-27 21:19:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
function _registerHotkeys(keys) {
|
2017-06-14 19:37:13 +02:00
|
|
|
_.forEach(['backspace', 'delete'], function(hotkey) {
|
|
|
|
keys.push(sgHotkeys.createHotkey({
|
|
|
|
key: hotkey,
|
|
|
|
description: l('Delete selected message or folder'),
|
|
|
|
callback: function() {
|
2020-06-16 18:57:17 +02:00
|
|
|
if (Mailbox.selectedFolderController &&
|
|
|
|
Mailbox.selectedFolder &&
|
|
|
|
Mailbox.selectedFolder.$isEditable &&
|
|
|
|
!Mailbox.selectedFolder.hasSelectedMessage() &&
|
|
|
|
Mailbox.selectedFolder.$selectedCount() === 0)
|
2017-06-14 19:37:13 +02:00
|
|
|
Mailbox.selectedFolderController.confirmDelete(Mailbox.selectedFolder);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
});
|
2016-09-27 21:19:24 +02:00
|
|
|
|
|
|
|
// Register the hotkeys
|
|
|
|
_.forEach(keys, function(key) {
|
|
|
|
sgHotkeys.registerHotkey(key);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.hideAdvancedSearch = function() {
|
|
|
|
vm.service.$virtualPath = false;
|
2015-09-10 22:38:30 +02:00
|
|
|
vm.service.$virtualMode = false;
|
|
|
|
|
|
|
|
account = vm.accounts[0];
|
|
|
|
mailbox = vm.searchPreviousMailbox;
|
|
|
|
$state.go('mail.account.mailbox', { accountId: account.id, mailboxId: encodeUriFilter(mailbox.path) });
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2015-09-10 22:38:30 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.toggleAdvancedSearch = function() {
|
2015-09-15 03:35:34 +02:00
|
|
|
if (Mailbox.selectedFolder.$isLoading) {
|
2015-10-02 21:43:02 +02:00
|
|
|
// Stop search
|
2015-09-15 03:35:34 +02:00
|
|
|
vm.virtualMailbox.stopSearch();
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-10-02 21:43:02 +02:00
|
|
|
// Start search
|
2015-09-15 03:35:34 +02:00
|
|
|
var root, mailboxes = [],
|
|
|
|
_visit = function(folders) {
|
2016-03-03 19:38:54 +01:00
|
|
|
_.forEach(folders, function(o) {
|
2018-06-15 04:20:24 +02:00
|
|
|
if (!o.isNoSelect())
|
|
|
|
mailboxes.push(o);
|
2015-09-15 03:35:34 +02:00
|
|
|
if (o.children && o.children.length > 0) {
|
|
|
|
_visit(o.children);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
vm.virtualMailbox = new VirtualMailbox(vm.accounts[0]);
|
|
|
|
|
|
|
|
// Don't set the previous selected mailbox if we're in virtual mode
|
|
|
|
// That allows users to do multiple advanced search but return
|
|
|
|
// correctly to the previously selected mailbox once done.
|
|
|
|
if (!Mailbox.$virtualMode)
|
|
|
|
vm.searchPreviousMailbox = Mailbox.selectedFolder;
|
|
|
|
|
|
|
|
Mailbox.selectedFolder = vm.virtualMailbox;
|
|
|
|
Mailbox.$virtualMode = true;
|
|
|
|
|
2018-06-15 04:20:24 +02:00
|
|
|
if (Mailbox.$virtualPath.length) {
|
2017-05-18 21:31:38 +02:00
|
|
|
root = vm.accounts[0].$getMailboxByPath(Mailbox.$virtualPath);
|
2015-09-15 03:35:34 +02:00
|
|
|
mailboxes.push(root);
|
|
|
|
if (vm.search.subfolders && root.children.length)
|
|
|
|
_visit(root.children);
|
|
|
|
}
|
|
|
|
else {
|
2018-06-15 04:20:24 +02:00
|
|
|
mailboxes = _.filter(vm.accounts[0].$flattenMailboxes({ all: true }), function(mailbox) {
|
|
|
|
return !mailbox.isNoSelect();
|
|
|
|
});
|
2015-09-15 03:35:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
vm.virtualMailbox.setMailboxes(mailboxes);
|
|
|
|
vm.virtualMailbox.startSearch(vm.search.match, vm.search.params);
|
2017-05-18 21:31:38 +02:00
|
|
|
if ($state.$current.name != 'mail.account.virtualMailbox')
|
|
|
|
$state.go('mail.account.virtualMailbox', { accountId: vm.accounts[0].id });
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2015-09-10 22:38:30 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.addSearchParam = function(v) {
|
2018-06-28 16:45:11 +02:00
|
|
|
this.currentSearchParam = v;
|
2015-09-15 03:35:34 +02:00
|
|
|
focus('advancedSearch');
|
2015-10-02 21:43:02 +02:00
|
|
|
return false;
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2015-09-10 22:38:30 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.newSearchParam = function(pattern) {
|
2018-06-28 16:45:11 +02:00
|
|
|
if (pattern.length && this.currentSearchParam.length) {
|
|
|
|
var n = 0, searchParam = this.currentSearchParam;
|
2015-10-02 21:43:02 +02:00
|
|
|
if (pattern.startsWith("!")) {
|
2015-09-10 22:38:30 +02:00
|
|
|
n = 1;
|
2015-10-02 21:43:02 +02:00
|
|
|
pattern = pattern.substring(1).trim();
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
2018-06-28 16:45:11 +02:00
|
|
|
this.currentSearchParam = '';
|
2015-10-02 21:43:02 +02:00
|
|
|
return { searchBy: searchParam, searchInput: pattern, negative: n };
|
2015-09-10 22:38:30 +02:00
|
|
|
}
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2015-09-10 22:38:30 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.toggleAccountState = function (account) {
|
2016-05-26 21:48:15 +02:00
|
|
|
account.$expanded = !account.$expanded;
|
2018-11-13 20:59:09 +01:00
|
|
|
if (!this.debounceSaveState) {
|
|
|
|
this.debounceSaveState = $mdUtil.debounce(function () {
|
|
|
|
account.$flattenMailboxes({ reload: true, saveState: true });
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
this.debounceSaveState();
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2016-05-26 21:48:15 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.subscribe = function(account) {
|
2016-09-14 21:57:49 +02:00
|
|
|
$mdDialog.show({
|
|
|
|
templateUrl: account.id + '/subscribe',
|
|
|
|
controller: SubscriptionsDialogController,
|
|
|
|
controllerAs: 'subscriptions',
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
escapeToClose: true,
|
|
|
|
locals: {
|
|
|
|
srcAccount: account
|
|
|
|
}
|
|
|
|
}).finally(function() {
|
|
|
|
account.$getMailboxes({reload: true});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2017-02-20 03:13:44 +01:00
|
|
|
SubscriptionsDialogController.$inject = ['$scope', '$mdDialog', 'srcAccount'];
|
|
|
|
function SubscriptionsDialogController($scope, $mdDialog, srcAccount) {
|
2016-09-14 21:57:49 +02:00
|
|
|
var vm = this;
|
|
|
|
|
2016-09-30 18:02:46 +02:00
|
|
|
vm.loading = true;
|
|
|
|
vm.filter = { name: '' };
|
|
|
|
vm.account = new Account({
|
|
|
|
id: srcAccount.id,
|
|
|
|
name: srcAccount.name
|
|
|
|
});
|
2016-09-14 21:57:49 +02:00
|
|
|
vm.close = close;
|
|
|
|
|
2016-11-08 21:20:41 +01:00
|
|
|
vm.account.$getMailboxes({ reload: true, all: true }).then(function() {
|
2016-09-30 18:02:46 +02:00
|
|
|
vm.loading = false;
|
|
|
|
});
|
|
|
|
|
2016-09-14 21:57:49 +02:00
|
|
|
function close() {
|
2017-05-18 21:31:38 +02:00
|
|
|
$mdDialog.hide();
|
2016-09-14 21:57:49 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2016-09-14 21:57:49 +02:00
|
|
|
|
2018-06-15 04:20:24 +02:00
|
|
|
this.showAdvancedSearch = function() {
|
|
|
|
Mailbox.$virtualPath = '';
|
|
|
|
// Close sidenav on small devices
|
|
|
|
if (!$mdMedia(sgConstant['gt-md']))
|
|
|
|
$mdSidenav('left').close();
|
|
|
|
};
|
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.newFolder = function(parentFolder) {
|
2016-10-21 16:55:59 +02:00
|
|
|
Dialog.prompt(l('New Folder...'),
|
|
|
|
l('Enter the new name of your folder'))
|
2015-05-06 04:06:13 +02:00
|
|
|
.then(function(name) {
|
2015-07-02 22:11:11 +02:00
|
|
|
parentFolder.$newMailbox(parentFolder.id, name)
|
|
|
|
.then(function() {
|
|
|
|
// success
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('An error occured while creating the mailbox "%{0}".', name),
|
|
|
|
l(data.error));
|
|
|
|
});
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2015-07-13 21:22:58 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.delegate = function(account) {
|
2015-07-04 02:40:06 +02:00
|
|
|
$mdDialog.show({
|
|
|
|
templateUrl: account.id + '/delegation', // UI/Templates/MailerUI/UIxMailUserDelegation.wox
|
|
|
|
controller: MailboxDelegationController,
|
|
|
|
controllerAs: 'delegate',
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
escapeToClose: true,
|
|
|
|
locals: {
|
|
|
|
User: User,
|
2015-07-04 13:51:20 +02:00
|
|
|
account: account
|
2015-07-04 02:40:06 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-07-04 13:51:20 +02:00
|
|
|
MailboxDelegationController.$inject = ['$scope', '$mdDialog', 'User', 'account'];
|
|
|
|
function MailboxDelegationController($scope, $mdDialog, User, account) {
|
2015-07-04 02:40:06 +02:00
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
vm.users = account.delegates;
|
|
|
|
vm.account = account;
|
|
|
|
vm.userToAdd = '';
|
|
|
|
vm.searchText = '';
|
|
|
|
vm.userFilter = userFilter;
|
|
|
|
vm.closeModal = closeModal;
|
|
|
|
vm.removeUser = removeUser;
|
|
|
|
vm.addUser = addUser;
|
|
|
|
|
|
|
|
function userFilter($query) {
|
|
|
|
return User.$filter($query, account.delegates);
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeModal() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeUser(user) {
|
2015-08-03 20:40:18 +02:00
|
|
|
account.$removeDelegate(user.uid).catch(function(data, status) {
|
2019-02-27 15:51:43 +01:00
|
|
|
Dialog.alert(l('Warning'), l('An error occured, please try again.'));
|
2015-07-04 02:40:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addUser(data) {
|
|
|
|
if (data) {
|
|
|
|
account.$addDelegate(data).then(function() {
|
|
|
|
vm.userToAdd = '';
|
|
|
|
vm.searchText = '';
|
|
|
|
}, function(error) {
|
|
|
|
Dialog.alert(l('Warning'), error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-18 21:31:38 +02:00
|
|
|
}; // delegate
|
2015-07-13 21:22:58 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.refreshUnseenCount = function() {
|
2019-03-22 16:57:57 +01:00
|
|
|
var unseenCountFolders, refreshViewCheck;
|
2015-07-31 19:32:14 +02:00
|
|
|
|
2019-03-22 16:57:57 +01:00
|
|
|
if (Preferences.defaults.SOGoMailFetchAllUnseenCountFolders === 1)
|
|
|
|
unseenCountFolders = [];
|
|
|
|
else
|
|
|
|
unseenCountFolders = $window.unseenCountFolders;
|
2015-07-31 19:32:14 +02:00
|
|
|
|
2019-03-22 16:57:57 +01:00
|
|
|
_.forEach(vm.accounts, function(account) {
|
|
|
|
if (Preferences.defaults.SOGoMailFetchAllUnseenCountFolders === 1) {
|
|
|
|
// Include all mailboxes
|
|
|
|
_.forEach(account.$$flattenMailboxes, function(mailbox) {
|
2015-07-31 19:32:14 +02:00
|
|
|
unseenCountFolders.push(mailbox.id);
|
2019-03-22 16:57:57 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Always include the INBOX
|
|
|
|
if (!_.includes(unseenCountFolders, account.id + '/folderINBOX'))
|
|
|
|
unseenCountFolders.push(account.id + '/folderINBOX');
|
|
|
|
|
|
|
|
_.forEach(account.$$flattenMailboxes, function(mailbox) {
|
|
|
|
if (angular.isDefined(mailbox.unseenCount) &&
|
|
|
|
!_.includes(unseenCountFolders, mailbox.id))
|
|
|
|
unseenCountFolders.push(mailbox.id);
|
|
|
|
});
|
|
|
|
}
|
2015-07-31 19:32:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
Account.$$resource.post('', 'unseenCount', {mailboxes: unseenCountFolders}).then(function(data) {
|
|
|
|
_.forEach(vm.accounts, function(account) {
|
2015-07-31 20:31:38 +02:00
|
|
|
_.forEach(account.$$flattenMailboxes, function(mailbox) {
|
2020-08-04 22:16:09 +02:00
|
|
|
if (data[mailbox.id]) {
|
2015-07-31 19:32:14 +02:00
|
|
|
mailbox.unseenCount = data[mailbox.id];
|
2020-08-04 22:16:09 +02:00
|
|
|
}
|
2015-07-31 19:32:14 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-01 19:46:57 +02:00
|
|
|
refreshViewCheck = Preferences.defaults.SOGoRefreshViewCheck;
|
|
|
|
if (refreshViewCheck && refreshViewCheck != 'manually')
|
|
|
|
$timeout(vm.refreshUnseenCount, refreshViewCheck.timeInterval()*1000);
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2015-07-31 19:32:14 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.isDroppableFolder = function(srcFolder, dstFolder) {
|
2016-08-04 23:34:29 +02:00
|
|
|
return (dstFolder.id != srcFolder.id) && !dstFolder.isNoSelect();
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2016-08-04 23:34:29 +02:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
this.dragSelectedMessages = function(srcFolder, dstFolder, mode) {
|
2016-08-04 23:34:29 +02:00
|
|
|
var dstId, messages, uids, clearMessageView, promise, success;
|
|
|
|
|
|
|
|
dstId = '/' + dstFolder.id;
|
|
|
|
messages = srcFolder.$selectedMessages();
|
|
|
|
if (messages.length === 0)
|
|
|
|
messages = [srcFolder.$selectedMessage()];
|
|
|
|
uids = _.map(messages, 'uid');
|
|
|
|
clearMessageView = (srcFolder.selectedMessage && uids.indexOf(srcFolder.selectedMessage) >= 0);
|
|
|
|
|
|
|
|
if (mode == 'copy') {
|
|
|
|
promise = srcFolder.$copyMessages(messages, dstId);
|
|
|
|
success = l('%{0} message(s) copied', messages.length);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
promise = srcFolder.$moveMessages(messages, dstId);
|
|
|
|
success = l('%{0} message(s) moved', messages.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
promise.then(function() {
|
|
|
|
if (clearMessageView)
|
|
|
|
$state.go('mail.account.mailbox');
|
|
|
|
$mdToast.show(
|
|
|
|
$mdToast.simple()
|
2020-08-04 22:16:09 +02:00
|
|
|
.textContent(success)
|
2016-08-04 23:34:29 +02:00
|
|
|
.position('top right')
|
|
|
|
.hideDelay(2000));
|
|
|
|
});
|
2017-05-18 21:31:38 +02:00
|
|
|
};
|
2016-08-04 23:34:29 +02:00
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
2016-08-04 23:34:29 +02:00
|
|
|
.module('SOGo.MailerUI')
|
|
|
|
.controller('MailboxesController', MailboxesController);
|
2015-05-06 04:06:13 +02:00
|
|
|
})();
|
|
|
|
|