-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzimbra.sender.addresses.user.js
144 lines (124 loc) · 5.03 KB
/
zimbra.sender.addresses.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// ==UserScript==
// @name Zimbra webclient improvement: Sender addresses
// @namespace http://thomas-rosenau.de
// @description Add a context menu entry to folders that provides a list of all mail sender addresses from that folder
// @include INSERT.URL.HERE
// @version 1
// @grant none
// ==/UserScript==
/*!
Copyright 2015 SEITENBAU GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function (main) {
if (window == window.top && !document.querySelector('.LoginScreen')) {
// http://stackoverflow.com/a/5006952/27862
var script = document.createElement('script');
script.textContent = 'try{(' + main + ')();}catch(e){console.log(e);}';
document.body.appendChild(script).parentNode.removeChild(script);
}
})(function () {
var pagesize = 1000; // server-side limit == 1000
var zimbraOpKey = 'SOME_UID' + +new Date();
// i18n
ZmMsg.showSenderAddresses = 'List sender addresses';
// register export operation
ZmOperation.registerOp(zimbraOpKey, {
textKey: 'showSenderAddresses',
image: 'DuplicateCOS' // well, the icon is appropriate
});
// add export operation to tree context menu
ZmFolderTreeController.prototype._getActionMenuOps = (function (original) {
var actionMenuOps = null;
return function () {
if (!actionMenuOps) {
actionMenuOps = original();
actionMenuOps.push(zimbraOpKey);
// we also register the operation listener here, since it's too late to modify the constructor function
this._listeners[zimbraOpKey] = (function (evt) {
var searchTerm = this._getActionedOrganizer(evt).createQuery();
runSearch(searchTerm, function (addresses) {
display(addresses.join(','), 'Sender addresses from ' + searchTerm.replace(/^[^:]+:/, ''));
});
}).bind(this);
}
return actionMenuOps;
};
})(ZmFolderTreeController.prototype._getActionMenuOps);
// do not hide context menu entry in system folders
ZmFolderTreeController.prototype.resetOperations = (function (original) {
return function (parent, type, id) {
original.apply(this, arguments);
parent.enable(zimbraOpKey, true);
};
})(ZmFolderTreeController.prototype.resetOperations);
// search emails in folder
// @param {string} searchTerm
// @param {function} callback
var runSearch = function (searchTerm, callback) {
var page = 0;
var addresses = [];
// internal callback for search
// @param {ZmCsfeResult} result
var cb = function (result) {
var response = result.getResponse();
response.getResults().getVector().foreach(function (msg) {
var sender = msg.getMsgSender(); // '[email protected]'
// var sender = msg.getAddress(AjxEmailAddress.FROM).toString(); // '"John Doe" <[email protected]>'
if (sender && addresses.indexOf(sender) < 0) {
addresses.push(sender);
}
});
if (response.getAttribute('more')) {
// paginate
page++;
request(cb);
} else {
// pagination done
callback(addresses);
}
};
// do search request
var request = function (callback) {
if (!callback.isAjxCallback) {
callback = new AjxCallback(callback);
}
appCtxt.getSearchController().search(new ZmSearch({
searchFor: ZmId.SEARCH_MAIL,
query: searchTerm,
offset: page * pagesize,
limit: pagesize,
callback: callback,
noRender: true,
noUpdateOverview: true,
skipUpdateSearchToolbar: true
}));
};
request(cb);
};
// display a string in a dialog box
// @param {String} str
// @param {String} title
var display = function (str, title) {
var dialog = new DwtDialog({
parent: appCtxt.getShell(),
title: title,
standardButtons: [DwtDialog.DISMISS_BUTTON]
});
dialog.setContent('<textarea cols="60" rows="10">' + str + '</textarea>');
var area = dialog._getContentDiv().firstChild;
area.addEventListener('focus', function () {
area.select();
}, false);
dialog.popup();
area.focus();
};
});