-
Notifications
You must be signed in to change notification settings - Fork 8
/
attachment_reminder.js
executable file
·91 lines (61 loc) · 1.81 KB
/
attachment_reminder.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
/* Attachment Reminder plugin script */
/* TODO: Prompt on keypress , show matched keyword , localization
*/
function rcmail_get_compose_message()
{
if (window.tinyMCE && (ed = tinyMCE.get(rcmail.env.composebody)))
{
msg = ed.getContent();
msg = msg.replace(/<blockquote[^>]*>(.|[\r\n])*<\/blockquote>/gmi, '');
}
else
{
if(document.getElementById("compose-body"))
msg = document.getElementById("compose-body").value;
else
msg = document.getElementById("composebody").value;
msg = msg.replace(/^\s*>.*$/gmi, '');
}
return msg;
}
function rcmail_check_message( msg )
{
keyword = rcmail.gettext('keywords', 'attachment_reminder').split(",").concat([".doc", ".pdf"]);
for (var i = 0; i < keyword.length; i++) {
var rg = new RegExp(keyword[i],'i');
if( msg.search(rg) != -1 ){
return true;
}
}
return false;
}
function rcmail_have_attachments()
{
if (rcmail.env.attachments){
var list = rcmail.gui_objects.attachmentlist.getElementsByTagName("li");
if( list.length > 0){
return true;
}
}
return false;
}
if (window.rcmail) {
rcmail.addEventListener('beforesend', function(evt) {
//Get value
msg = rcmail_get_compose_message();
subject = document.getElementById("compose-subject").value;
//Check attachment
have_attachment = rcmail_have_attachments();
contain_key_word = rcmail_check_message(msg) || rcmail_check_message(subject);
if( !have_attachment && contain_key_word ){
//Confirm
var attach_now = confirm(rcmail.gettext('forgotattachment', 'attachment_reminder'));
if (attach_now) {
//Show upload dialog.
rcmail_ui.show_popup('uploadmenu', true);
return false;
}
}
//TODO: prompt on typing
});
}