-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc.js
More file actions
147 lines (110 loc) · 3.64 KB
/
Copy pathfunc.js
File metadata and controls
147 lines (110 loc) · 3.64 KB
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
const ipc = require('electron').ipcRenderer;
var dataset = [];
var old_selected = -1 ;
/*
document.getElementById('select_folder_btn').addEventListener('click', () => {
ipc.send('selectbox_event', );
});*/
document.getElementById('valid_folder_btn').addEventListener('click', () => {
ipc.send('loadfile', document.getElementById('filename_chose').value);
});
function format_infos(from, froma, to, toa, date){
txt = "<b>From :</b> " + from + " ("+ froma +")" ;
txt += "<br><b>To :</b> " + to + " ("+ toa +")" ;
txt += "<br><b>Date :</b> " + date;
return txt ;
}
function load_display(data){
var html_list = document.getElementById("msglist");
html_list.innerHTML = "";
for(var i = 0 ; i < data.length ; i++){
{
var d = JSON.parse(data[i]);
row = {
"id":i,
"subject":d.subject,
"sender":d.sender,
"size": d.size
};
var item = document.createElement("div");
var item_name = document.createElement("div");
var item_subject = document.createElement("div");
var item_size = document.createElement("div");
item.className = "item-list";
item_name.className = "item-list-name";
item_size.className = "item-list-size";
item_subject.className = "item-list-subject";
item_name.innerHTML = '♟ '+ row["sender"];
item_size.innerHTML = '⚖ : ' + row['size'] + ' bytes';
item_subject.innerHTML = '✉ ' + row["subject"];
item.setAttribute("id", i);
item.addEventListener('click', function(){
ipc.send('request_msg',this.id);
this.style.backgroundColor = "#404040";
});
item.appendChild(item_name);
item.appendChild(item_subject);
item.appendChild(item_size);
html_list.appendChild(item);
dataset[i] = row;
}
}
}
ipc.on('folder', (event, arg) => {
console.log("choosed", arg);
document.getElementById("filename_chose").innerHTML = arg[0];
});
ipc.on('dataset', (event, arg) => {
load_display(JSON.parse(arg));
});
ipc.on('mail_read', (event, arg) => {
row = {
"date": arg.date,
"from_mail": arg.from.email,
"from_name": arg.from.name,
"subject": arg.subject,
"text": arg.text,
"attachments": arg.attachments
};
if(!arg.to){
row['to_mail'] = "Unknow";
row['to_name'] = "(Unknow)";
}
else {
row['to_mail'] = arg.to.email ;
row['to_name'] = arg.to.name ;
}
console.log("Reading message");
console.log(arg);
document.getElementById('mailinfos_sub').innerHTML = row['subject'][0].toUpperCase() + row['subject'].substring(1);
document.getElementById('mailinfos').innerHTML = format_infos(row["from_name"],row["from_mail"],row["to_name"],row["to_mail"],row["date"]);
lMCsf = document.getElementById('mailcontent');
lMCsf.innerHTML = "" ;
if(row.attachments){
lMCsf.innerHTML += "Attached file(s) :";
for(var i = 0; i < row.attachments.length;i++){
try {
var filetype = row.attachments[i].contentType.split(';')[0] ;
} catch(e){
var filetype = "text/ascii";
}
var att = document.createElement("div");
att.className = "msg_attachment";
var link = document.createElement("a");
link.className = "a_attachment";
if(row.attachments[i] && row.attachments[i].name)
link.download = row.attachments[i].name;
else row.attachments[i].name= "undef_file";
link.href= 'data:'+filetype+';base64,' + row.attachments[i].data;
link.innerHTML = row.attachments[i].name;
link.innerHTML += ' (' + filetype + ')';
link.innerHTML += ' - ' + (row.attachments[i].data.length) + ' bytes';
att.appendChild(link);
lMCsf.appendChild(att);
}
var sep = document.createElement("hr");
sep.className = "attachment_sep";
lMCsf.appendChild(sep);
}
lMCsf.innerHTML += '<p><pre>' + row.text + '</pre></p>' ;
});