This repository has been archived by the owner on Nov 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
markasjunk2.js
executable file
·181 lines (150 loc) · 6.01 KB
/
markasjunk2.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* MarkAsJunk2 plugin script
*/
if (window.rcmail) {
rcmail.addEventListener('init', function(evt) {
// register command (directly enable in message view mode)
rcmail.register_command('plugin.markasjunk2', rcmail_markasjunk2, rcmail.env.uid);
rcmail.register_command('plugin.markasnotjunk2', rcmail_markasnotjunk2, rcmail.env.uid);
if (rcmail.message_list && rcmail.env.junk_mailbox) {
rcmail.message_list.addEventListener('select', function(list) {
rcmail.enable_command('plugin.markasjunk2', list.get_selection().length > 0);
rcmail.enable_command('plugin.markasnotjunk2', list.get_selection().length > 0);
});
}
})
}
function rcmail_markasjunk2(prop) {
if (!rcmail.env.uid && (!rcmail.message_list || !rcmail.message_list.get_selection().length))
return;
if (!prop)
prop = 'markasjunk2';
var prev_sel = null;
// also select childs of (collapsed) threads
if (rcmail.message_list) {
if (rcmail.env.uid) {
if (rcmail.message_list.rows[rcmail.env.uid].has_children && !rcmail.message_list.rows[rcmail.env.uid].expanded) {
if (!rcmail.message_list.in_selection(rcmail.env.uid)) {
prev_sel = rcmail.message_list.get_selection();
rcmail.message_list.select_row(rcmail.env.uid);
}
rcmail.message_list.select_childs(rcmail.env.uid);
rcmail.env.uid = null;
}
else if (rcmail.message_list.get_single_selection() == rcmail.env.uid) {
rcmail.env.uid = null;
}
}
else {
selection = rcmail.message_list.get_selection();
for (var i in selection)
rcmail.message_list.select_childs(selection[i]);
}
}
var uids = rcmail.env.uid ? rcmail.env.uid : rcmail.message_list.get_selection().join(',');
rcmail.set_busy(true, 'loading');
rcmail.http_post('plugin.' + prop, '_uid='+uids+'&_mbox='+urlencode(rcmail.env.mailbox), true);
if (prev_sel) {
rcmail.message_list.clear_selection();
for (var i in prev_sel)
rcmail.message_list.select_row(prev_sel[i], CONTROL_KEY);
}
}
function rcmail_markasnotjunk2(prop) {
rcmail_markasjunk2('markasnotjunk2');
}
rcmail.rcmail_markasjunk2_move = function(mbox, uid) {
var prev_uid = rcmail.env.uid;
var prev_sel = null;
var a_uids = uid.split(",");
if (rcmail.message_list && a_uids.length == 1 && !rcmail.message_list.in_selection(a_uids[0])) {
rcmail.env.uid = a_uids[0];
rcmail.message_list.remove_row(rcmail.env.uid, false);
}
else if (rcmail.message_list && !rcmail.message_list.in_selection(a_uids[0])) {
prev_sel = rcmail.message_list.get_selection();
rcmail.message_list.clear_selection();
for (var i in a_uids)
rcmail.message_list.select_row(a_uids[i], CONTROL_KEY);
}
if (mbox)
rcmail.move_messages(mbox);
else
rcmail.delete_messages();
rcmail.env.uid = prev_uid;
if (prev_sel) {
rcmail.message_list.clear_selection();
for (var i in prev_sel)
rcmail.message_list.select_row(prev_sel[i], CONTROL_KEY);
}
}
function rcmail_markasjunk2_init() {
if (window.rcm_contextmenu_register_command) {
rcm_contextmenu_register_command('markasjunk2', 'rcmail_markasjunk2', ' ' + rcmail.gettext('markasjunk2.markasjunk'), 'reply', null, true);
rcm_contextmenu_register_command('markasnotjunk2', 'rcmail_markasnotjunk2', ' ' + rcmail.gettext('markasjunk2.markasnotjunk'), 'reply', null, true);
if (rcmail.env.junk_mailbox && rcmail.env.mailbox == rcmail.env.junk_mailbox) {
$('#rcmContextMenu li.markasjunk2').hide();
$('#rcmContextMenu li.markasnotjunk2').show();
}
else {
$('#rcmContextMenu li.markasjunk2').show();
$('#rcmContextMenu li.markasnotjunk2').hide();
}
$('#rcmContextMenu li.unflagged').removeClass('separator_below');
$('#rcmContextMenu li.reply').addClass('separator_above');
}
}
function rcmail_markasjunk2_update() {
var spamobj = $('#' + rcmail.buttons['plugin.markasjunk2'][0].id);
var hamobj = $('#' + rcmail.buttons['plugin.markasnotjunk2'][0].id);
if (spamobj.parent('li').length > 0) {
spamobj = spamobj.parent();
hamobj = hamobj.parent();
}
if (rcmail.env.junk_mailbox && rcmail.env.mailbox != rcmail.env.junk_mailbox) {
$('#rcmContextMenu li.markasjunk2').show();
$('#rcmContextMenu li.markasnotjunk2').hide();
spamobj.show();
hamobj.hide();
}
else {
$('#rcmContextMenu li.markasjunk2').hide();
$('#rcmContextMenu li.markasnotjunk2').show();
spamobj.hide();
hamobj.show();
}
}
function rcmail_markasjunk2_status(command) {
switch (command) {
case 'beforedelete':
if (!rcmail.env.flag_for_deletion && rcmail.env.trash_mailbox &&
rcmail.env.mailbox != rcmail.env.trash_mailbox &&
(rcmail.message_list && !rcmail.message_list.shiftkey))
rcmail.enable_command('plugin.markasjunk2', 'plugin.markasnotjunk2', false);
break;
case 'beforemove':
case 'beforemoveto':
rcmail.enable_command('plugin.markasjunk2', 'plugin.markasnotjunk2', false);
break;
case 'aftermove':
case 'aftermoveto':
if (rcmail.env.action == 'show')
rcmail.enable_command('plugin.markasjunk2', 'plugin.markasnotjunk2', true);
break;
case 'afterpurge':
case 'afterexpunge':
if (!rcmail.env.messagecount && rcmail.task == 'mail')
rcmail.enable_command('plugin.markasjunk2', 'plugin.markasnotjunk2', false);
break;
}
}
rcmail.add_onload('rcmail_markasjunk2_init()');
rcmail.addEventListener('listupdate', function(props) { rcmail_markasjunk2_update(); } );
// update button activation after external events
rcmail.addEventListener('beforedelete', function(props) { rcmail_markasjunk2_status('beforedelete'); } );
rcmail.addEventListener('beforemove', function(props) { rcmail_markasjunk2_status('beforemove'); } );
rcmail.addEventListener('beforemoveto', function(props) { rcmail_markasjunk2_status('beforemoveto'); } );
rcmail.addEventListener('aftermove', function(props) { rcmail_markasjunk2_status('aftermove'); } );
rcmail.addEventListener('aftermoveto', function(props) { rcmail_markasjunk2_status('aftermoveto'); } );
rcmail.addEventListener('afterpurge', function(props) { rcmail_markasjunk2_status('afterpurge'); } );
rcmail.addEventListener('afterexpunge', function(props) { rcmail_markasjunk2_status('afterexpunge'); } );