iobroker.imap 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -60
- package/admin/blockly.js +1 -1
- package/admin/i18n/de/translations.json +4 -4
- package/admin/i18n/en/translations.json +4 -4
- package/admin/jsonConfig.json +17 -1
- package/io-package.json +14 -14
- package/lib/helper.js +40 -6
- package/lib/imap_event.js +154 -58
- package/lib/translator.js +78 -0
- package/main.js +235 -214
- package/package.json +6 -8
- package/admin/index_m.html +0 -40
- package/lib/Connection.js +0 -1583
package/lib/imap_event.js
CHANGED
|
@@ -45,6 +45,7 @@ module.exports = {
|
|
|
45
45
|
},
|
|
46
46
|
/**
|
|
47
47
|
* Read Mail with search criteria and capability SORT == true
|
|
48
|
+
*
|
|
48
49
|
* @param {string} client client id
|
|
49
50
|
*/
|
|
50
51
|
readMailsSort(client) {
|
|
@@ -59,7 +60,9 @@ module.exports = {
|
|
|
59
60
|
this.all_seqno[client] = [];
|
|
60
61
|
results.sort((a, b) => b - a);
|
|
61
62
|
for (const result of results) {
|
|
62
|
-
if (count > this.clientsRaw[client].max)
|
|
63
|
+
if (count > this.clientsRaw[client].max) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
63
66
|
if (this.clientsRaw[client].att) {
|
|
64
67
|
await this.findmail(client, result, count, all, true);
|
|
65
68
|
} else {
|
|
@@ -74,6 +77,7 @@ module.exports = {
|
|
|
74
77
|
},
|
|
75
78
|
/**
|
|
76
79
|
* Read Mail with search criteria and capability SORT == false
|
|
80
|
+
*
|
|
77
81
|
* @param {string} client client id
|
|
78
82
|
*/
|
|
79
83
|
readMails(client) {
|
|
@@ -94,7 +98,9 @@ module.exports = {
|
|
|
94
98
|
this.all_seqno[client] = [];
|
|
95
99
|
results.sort((a, b) => b - a);
|
|
96
100
|
for (const result of results) {
|
|
97
|
-
if (count > this.clientsRaw[client].max)
|
|
101
|
+
if (count > this.clientsRaw[client].max) {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
98
104
|
if (this.clientsRaw[client].att) {
|
|
99
105
|
await this.findmail(client, result, count, all, false);
|
|
100
106
|
} else {
|
|
@@ -115,7 +121,7 @@ module.exports = {
|
|
|
115
121
|
* @param {boolean} sort
|
|
116
122
|
*/
|
|
117
123
|
async findmail_wo_att(client, result, counter, all, sort) {
|
|
118
|
-
return new Promise(
|
|
124
|
+
return new Promise(resolve => {
|
|
119
125
|
try {
|
|
120
126
|
let attrs;
|
|
121
127
|
let header_mail;
|
|
@@ -123,11 +129,11 @@ module.exports = {
|
|
|
123
129
|
bodies: ["TEXT"],
|
|
124
130
|
struct: true,
|
|
125
131
|
});
|
|
126
|
-
f.on("message",
|
|
127
|
-
msg.once("attributes",
|
|
132
|
+
f.on("message", msg => {
|
|
133
|
+
msg.once("attributes", att => {
|
|
128
134
|
attrs = att;
|
|
129
135
|
});
|
|
130
|
-
msg.on("body", async
|
|
136
|
+
msg.on("body", async stream => {
|
|
131
137
|
header_mail = stream;
|
|
132
138
|
stream.resume();
|
|
133
139
|
});
|
|
@@ -145,14 +151,14 @@ module.exports = {
|
|
|
145
151
|
});
|
|
146
152
|
e.on("message", (next_msg, seqno) => {
|
|
147
153
|
let new_attrs;
|
|
148
|
-
next_msg.once("attributes",
|
|
154
|
+
next_msg.once("attributes", att => {
|
|
149
155
|
new_attrs = att;
|
|
150
156
|
});
|
|
151
157
|
next_msg.on("body", async (stream, info) => {
|
|
152
158
|
let mail;
|
|
153
159
|
try {
|
|
154
160
|
mail = await simpleParser(stream, this.clientsRaw[client].node_option);
|
|
155
|
-
} catch
|
|
161
|
+
} catch {
|
|
156
162
|
mail = this.current_date(client);
|
|
157
163
|
}
|
|
158
164
|
const att = {
|
|
@@ -163,7 +169,7 @@ module.exports = {
|
|
|
163
169
|
let mail_header;
|
|
164
170
|
try {
|
|
165
171
|
mail_header = await simpleParser(header_mail, this.clientsRaw[client].node_option);
|
|
166
|
-
} catch
|
|
172
|
+
} catch {
|
|
167
173
|
header_mail = this.current_date(client);
|
|
168
174
|
}
|
|
169
175
|
mail.text = mail_header.text != null ? mail_header.text : "";
|
|
@@ -172,20 +178,22 @@ module.exports = {
|
|
|
172
178
|
}
|
|
173
179
|
mail.attachments = all_att.attach;
|
|
174
180
|
mail.attachments_info = all_att.attach_info;
|
|
175
|
-
if (mail.headerLines)
|
|
181
|
+
if (mail.headerLines) {
|
|
182
|
+
mail.headerLines = [];
|
|
183
|
+
}
|
|
176
184
|
this.setMail(mail, seqno, att, info, client, counter, all, sort);
|
|
177
185
|
stream.resume();
|
|
178
186
|
resolve(true);
|
|
179
187
|
});
|
|
180
188
|
});
|
|
181
|
-
e.once("error",
|
|
189
|
+
e.once("error", error => {
|
|
182
190
|
if (error) {
|
|
183
191
|
this.log_translator("error", "Error", client, error);
|
|
184
192
|
}
|
|
185
193
|
resolve(false);
|
|
186
194
|
});
|
|
187
195
|
});
|
|
188
|
-
f.once("error",
|
|
196
|
+
f.once("error", error => {
|
|
189
197
|
if (error) {
|
|
190
198
|
this.log_translator("error", "Error", client, error);
|
|
191
199
|
}
|
|
@@ -205,7 +213,7 @@ module.exports = {
|
|
|
205
213
|
* @param {boolean} sort
|
|
206
214
|
*/
|
|
207
215
|
async findmail(client, result, counter, all, sort) {
|
|
208
|
-
return new Promise(
|
|
216
|
+
return new Promise(resolve => {
|
|
209
217
|
try {
|
|
210
218
|
const f = this.clients[client].fetch(result, {
|
|
211
219
|
bodies: "",
|
|
@@ -214,26 +222,28 @@ module.exports = {
|
|
|
214
222
|
f.on("message", (msg, seqno) => {
|
|
215
223
|
let attrs;
|
|
216
224
|
this.all_seqno[client].push(seqno);
|
|
217
|
-
msg.on("attributes",
|
|
225
|
+
msg.on("attributes", att => {
|
|
218
226
|
attrs = att;
|
|
219
227
|
});
|
|
220
228
|
msg.on("body", async (stream, info) => {
|
|
221
229
|
let mail;
|
|
222
230
|
try {
|
|
223
231
|
mail = await simpleParser(stream, this.clientsRaw[client].node_option);
|
|
224
|
-
} catch
|
|
232
|
+
} catch {
|
|
225
233
|
mail = this.current_date(client);
|
|
226
234
|
}
|
|
227
235
|
const all_att = await this.updateattachments(attrs);
|
|
228
236
|
mail.attachments = all_att.attach;
|
|
229
237
|
mail.attachments_info = all_att.attach_info;
|
|
230
|
-
if (mail.headerLines)
|
|
238
|
+
if (mail.headerLines) {
|
|
239
|
+
mail.headerLines = [];
|
|
240
|
+
}
|
|
231
241
|
this.setMail(mail, seqno, attrs, info, client, counter, all, sort);
|
|
232
242
|
stream.resume();
|
|
233
243
|
resolve(true);
|
|
234
244
|
});
|
|
235
245
|
});
|
|
236
|
-
f.once("error",
|
|
246
|
+
f.once("error", error => {
|
|
237
247
|
if (error) {
|
|
238
248
|
this.log_translator("error", "Error", client, error);
|
|
239
249
|
}
|
|
@@ -279,7 +289,7 @@ module.exports = {
|
|
|
279
289
|
* @param {string} client client id
|
|
280
290
|
*/
|
|
281
291
|
subscribeBox(mailboxname, client) {
|
|
282
|
-
this.clients[client].subscribeBox(mailboxname,
|
|
292
|
+
this.clients[client].subscribeBox(mailboxname, error => {
|
|
283
293
|
if (error) {
|
|
284
294
|
this.log_translator("error", "Error", client, error);
|
|
285
295
|
} else {
|
|
@@ -289,11 +299,12 @@ module.exports = {
|
|
|
289
299
|
},
|
|
290
300
|
/**
|
|
291
301
|
* Event for delete or move
|
|
302
|
+
*
|
|
292
303
|
* @param {number} seqno
|
|
293
304
|
* @param {string} client client id
|
|
294
305
|
*/
|
|
295
306
|
onExpunge(seqno, client) {
|
|
296
|
-
const isRange = this.all_seqno[client].findIndex(
|
|
307
|
+
const isRange = this.all_seqno[client].findIndex(number => number == seqno);
|
|
297
308
|
if (isRange != -1 && (isRange < this.clientsRaw[client].max || isRange == this.clientsRaw[client].max)) {
|
|
298
309
|
this.log_translator("info", "EMail deleted in scope", client, seqno);
|
|
299
310
|
this.clientsRaw[client].isonExpunge = true;
|
|
@@ -334,6 +345,7 @@ module.exports = {
|
|
|
334
345
|
},
|
|
335
346
|
/**
|
|
336
347
|
* Event if UIDs in this mailbox have changed since the last time this mailbox was opened.
|
|
348
|
+
*
|
|
337
349
|
* @param {number} uidvalidity
|
|
338
350
|
* @param {string} client client id
|
|
339
351
|
*/
|
|
@@ -342,6 +354,7 @@ module.exports = {
|
|
|
342
354
|
},
|
|
343
355
|
/**
|
|
344
356
|
* Event with value total, new, unseen
|
|
357
|
+
*
|
|
345
358
|
* @param {object} message
|
|
346
359
|
* @param {string} client client id
|
|
347
360
|
*/
|
|
@@ -378,6 +391,7 @@ module.exports = {
|
|
|
378
391
|
/**
|
|
379
392
|
* @param {string|object} err
|
|
380
393
|
* @param {string} clientID client id
|
|
394
|
+
* @param {string} where
|
|
381
395
|
*/
|
|
382
396
|
onErrorImap(err, clientID, where) {
|
|
383
397
|
let level = "warn";
|
|
@@ -393,6 +407,7 @@ module.exports = {
|
|
|
393
407
|
},
|
|
394
408
|
/**
|
|
395
409
|
* Status current folder (total and unseen)
|
|
410
|
+
*
|
|
396
411
|
* @param {string} folder
|
|
397
412
|
* @param {string} client client id
|
|
398
413
|
*/
|
|
@@ -419,14 +434,18 @@ module.exports = {
|
|
|
419
434
|
* @param {boolean} [second=false]
|
|
420
435
|
*/
|
|
421
436
|
loadAllSeqno(client, inbox, second) {
|
|
422
|
-
return new Promise(
|
|
437
|
+
return new Promise(resolve => {
|
|
423
438
|
this.clients[client].search(["ALL"], async (error, results) => {
|
|
424
439
|
if (error) {
|
|
425
440
|
this.log_translator("error", "Error", client, error);
|
|
426
|
-
if (!second)
|
|
441
|
+
if (!second) {
|
|
442
|
+
this.clientsRaw[client][inbox] = [];
|
|
443
|
+
}
|
|
427
444
|
resolve([]);
|
|
428
445
|
}
|
|
429
|
-
if (!second)
|
|
446
|
+
if (!second) {
|
|
447
|
+
this.clientsRaw[client][inbox] = results;
|
|
448
|
+
}
|
|
430
449
|
resolve(results);
|
|
431
450
|
});
|
|
432
451
|
});
|
|
@@ -434,6 +453,7 @@ module.exports = {
|
|
|
434
453
|
/**
|
|
435
454
|
* Read all uids from active mailbox
|
|
436
455
|
* Return total and unread
|
|
456
|
+
*
|
|
437
457
|
* @param {string} client device id
|
|
438
458
|
* @param {string} inbox folder name
|
|
439
459
|
*/
|
|
@@ -443,25 +463,26 @@ module.exports = {
|
|
|
443
463
|
let count_all = 0;
|
|
444
464
|
try {
|
|
445
465
|
count_unseen = unseen.length;
|
|
446
|
-
} catch
|
|
466
|
+
} catch {
|
|
447
467
|
count_unseen = 0;
|
|
448
468
|
}
|
|
449
469
|
try {
|
|
450
470
|
count_all = this.clientsRaw[client][inbox].length;
|
|
451
|
-
} catch
|
|
471
|
+
} catch {
|
|
452
472
|
count_all = 0;
|
|
453
473
|
}
|
|
454
|
-
await this.
|
|
474
|
+
await this.setState(`${client}.total`, {
|
|
455
475
|
val: count_all,
|
|
456
476
|
ack: true,
|
|
457
477
|
});
|
|
458
|
-
await this.
|
|
478
|
+
await this.setState(`${client}.total_unread`, {
|
|
459
479
|
val: count_unseen,
|
|
460
480
|
ack: true,
|
|
461
481
|
});
|
|
462
482
|
},
|
|
463
483
|
/**
|
|
464
484
|
* Event when new mail arrives in the currently open mailbox
|
|
485
|
+
*
|
|
465
486
|
* @param {object} box
|
|
466
487
|
* @param {object} info
|
|
467
488
|
* @param {object} curReq
|
|
@@ -478,8 +499,10 @@ module.exports = {
|
|
|
478
499
|
},
|
|
479
500
|
/**
|
|
480
501
|
* Event when new mail arrives in the currently open mailbox
|
|
502
|
+
*
|
|
481
503
|
* @param {object} box
|
|
482
504
|
* @param {object} info
|
|
505
|
+
* @param {string} state
|
|
483
506
|
* @param {string} client device id
|
|
484
507
|
*/
|
|
485
508
|
async onNew(box, info, state, client) {
|
|
@@ -487,6 +510,7 @@ module.exports = {
|
|
|
487
510
|
},
|
|
488
511
|
/**
|
|
489
512
|
* Event when new mail arrives in the currently open mailbox
|
|
513
|
+
*
|
|
490
514
|
* @param {number} count counter new mail
|
|
491
515
|
* @param {object} box
|
|
492
516
|
* @param {object} info
|
|
@@ -501,12 +525,17 @@ module.exports = {
|
|
|
501
525
|
this.setUpdate(client, { flags: [], new_mail: count }, "new mail");
|
|
502
526
|
const inbox = this.clientsRaw[client].inbox_activ;
|
|
503
527
|
const new_mail = await this.loadAllSeqno(client, inbox, true);
|
|
504
|
-
|
|
528
|
+
this.log_translator("debug", "logs", `inbox: ${inbox}`);
|
|
529
|
+
this.log_translator("debug", "logs", `clientsRaw: ${this.clientsRaw[client][inbox]}`);
|
|
530
|
+
this.log_translator("debug", "logs", `uidnext: ${box.uidnext}`);
|
|
531
|
+
this.log_translator("debug", "logs", `new_mail: ${new_mail}`);
|
|
532
|
+
const uidNext = this.clientsRaw[client][inbox] != null ? this.clientsRaw[client][inbox] : [box.uidnext - 1];
|
|
505
533
|
let nextuid = this.diffArray(uidNext, new_mail, 2, client);
|
|
506
534
|
this.clientsRaw[client][inbox] = new_mail;
|
|
507
535
|
if (nextuid === 0 || nextuid.length === 0) {
|
|
508
536
|
nextuid = [box.uidnext];
|
|
509
537
|
}
|
|
538
|
+
this.log_translator("debug", "logs", `nextuid: ${nextuid}`);
|
|
510
539
|
if (this.clients[client].serverSupports("SORT")) {
|
|
511
540
|
this.newMails(client, nextuid, "new", true);
|
|
512
541
|
} else {
|
|
@@ -531,14 +560,15 @@ module.exports = {
|
|
|
531
560
|
/**
|
|
532
561
|
* Arrival new Mail and capability SORT == false -> Use nextuid
|
|
533
562
|
* Arrival new Mail and capability SORT == true
|
|
563
|
+
*
|
|
534
564
|
* @param {string} client device id
|
|
535
565
|
* @param {object} uid
|
|
536
566
|
* @param {string} what new mail or update
|
|
537
567
|
* @param {boolean} sort Implementation in the next release
|
|
538
568
|
*/
|
|
539
569
|
newMails(client, uid, what, sort) {
|
|
540
|
-
this.
|
|
541
|
-
this.
|
|
570
|
+
this.log_translator("debug", "logs", `sort: ${sort}`);
|
|
571
|
+
this.log_translator("debug", "logs", `newMail: ${JSON.stringify(uid)}`);
|
|
542
572
|
for (const uids of uid) {
|
|
543
573
|
let attrs;
|
|
544
574
|
let header_mail;
|
|
@@ -546,11 +576,11 @@ module.exports = {
|
|
|
546
576
|
bodies: ["TEXT"],
|
|
547
577
|
struct: true,
|
|
548
578
|
});
|
|
549
|
-
f.on("message",
|
|
550
|
-
msg.once("attributes",
|
|
579
|
+
f.on("message", msg => {
|
|
580
|
+
msg.once("attributes", att => {
|
|
551
581
|
attrs = att;
|
|
552
582
|
});
|
|
553
|
-
msg.on("body", async
|
|
583
|
+
msg.on("body", async stream => {
|
|
554
584
|
header_mail = stream;
|
|
555
585
|
stream.resume();
|
|
556
586
|
});
|
|
@@ -571,14 +601,14 @@ module.exports = {
|
|
|
571
601
|
this.all_seqno[client].push(seqno);
|
|
572
602
|
this.all_seqno[client].sort((a, b) => b - a);
|
|
573
603
|
let new_attrs;
|
|
574
|
-
next_msg.once("attributes",
|
|
604
|
+
next_msg.once("attributes", att => {
|
|
575
605
|
new_attrs = att;
|
|
576
606
|
});
|
|
577
607
|
next_msg.on("body", async (stream, info) => {
|
|
578
608
|
let mail;
|
|
579
609
|
try {
|
|
580
610
|
mail = await simpleParser(stream, this.clientsRaw[client].node_option);
|
|
581
|
-
} catch
|
|
611
|
+
} catch {
|
|
582
612
|
mail = this.current_date(client);
|
|
583
613
|
}
|
|
584
614
|
const att = {
|
|
@@ -589,7 +619,7 @@ module.exports = {
|
|
|
589
619
|
let mail_header;
|
|
590
620
|
try {
|
|
591
621
|
mail_header = await simpleParser(header_mail, this.clientsRaw[client].node_option);
|
|
592
|
-
} catch
|
|
622
|
+
} catch {
|
|
593
623
|
mail_header = this.current_date(client);
|
|
594
624
|
}
|
|
595
625
|
mail.text = mail_header.text;
|
|
@@ -598,18 +628,20 @@ module.exports = {
|
|
|
598
628
|
}
|
|
599
629
|
mail.attachments = all_att.attach;
|
|
600
630
|
mail.attachments_info = all_att.attach_info;
|
|
601
|
-
if (mail.headerLines)
|
|
631
|
+
if (mail.headerLines) {
|
|
632
|
+
mail.headerLines = [];
|
|
633
|
+
}
|
|
602
634
|
this.updatejson(mail, seqno, att, info, client, what);
|
|
603
635
|
stream.resume();
|
|
604
636
|
});
|
|
605
637
|
});
|
|
606
|
-
e.once("error",
|
|
638
|
+
e.once("error", error => {
|
|
607
639
|
if (error) {
|
|
608
640
|
this.log_translator("error", "Error", client, error);
|
|
609
641
|
}
|
|
610
642
|
});
|
|
611
643
|
});
|
|
612
|
-
f.once("error",
|
|
644
|
+
f.once("error", error => {
|
|
613
645
|
if (error) {
|
|
614
646
|
this.log_translator("error", "Error", client, error);
|
|
615
647
|
}
|
|
@@ -624,7 +656,7 @@ module.exports = {
|
|
|
624
656
|
*/
|
|
625
657
|
diffArray(arr1, arr2, from, client) {
|
|
626
658
|
try {
|
|
627
|
-
const diff = (a, b) => a.filter(
|
|
659
|
+
const diff = (a, b) => a.filter(item => b.indexOf(item) === -1);
|
|
628
660
|
if (from === 1) {
|
|
629
661
|
return diff(arr1, arr2);
|
|
630
662
|
}
|
|
@@ -634,7 +666,7 @@ module.exports = {
|
|
|
634
666
|
const diff1 = diff(arr1, arr2);
|
|
635
667
|
const diff2 = diff(arr2, arr1);
|
|
636
668
|
return [].concat(diff1, diff2);
|
|
637
|
-
} catch
|
|
669
|
+
} catch {
|
|
638
670
|
this.log_translator(
|
|
639
671
|
"warn",
|
|
640
672
|
"Error",
|
|
@@ -653,7 +685,7 @@ module.exports = {
|
|
|
653
685
|
if (sort) {
|
|
654
686
|
this.all_seqno[client] = seqno;
|
|
655
687
|
} else {
|
|
656
|
-
const isRange = this.all_seqno[client].findIndex(
|
|
688
|
+
const isRange = this.all_seqno[client].findIndex(number => number == seqno);
|
|
657
689
|
if (isRange != -1) {
|
|
658
690
|
this.all_seqno[client][isRange] = seqno;
|
|
659
691
|
}
|
|
@@ -661,12 +693,13 @@ module.exports = {
|
|
|
661
693
|
},
|
|
662
694
|
/**
|
|
663
695
|
* Event when message metadata (e.g. flags) changes externally
|
|
696
|
+
*
|
|
664
697
|
* @param {number} seqno
|
|
665
698
|
* @param {object} info
|
|
666
699
|
* @param {string} client device id
|
|
667
700
|
*/
|
|
668
701
|
onUpdate(seqno, info, client) {
|
|
669
|
-
const isRange = this.all_seqno[client].findIndex(
|
|
702
|
+
const isRange = this.all_seqno[client].findIndex(number => number == seqno);
|
|
670
703
|
if (isRange != -1 && (isRange < this.clientsRaw[client].max || isRange == this.clientsRaw[client].max)) {
|
|
671
704
|
this.log_translator("info", "Start Update", seqno, client, JSON.stringify(info));
|
|
672
705
|
info["seqno"] = seqno;
|
|
@@ -681,7 +714,7 @@ module.exports = {
|
|
|
681
714
|
* @param {object} attrs
|
|
682
715
|
*/
|
|
683
716
|
async updateattachments(attrs) {
|
|
684
|
-
return new Promise(
|
|
717
|
+
return new Promise(resolve => {
|
|
685
718
|
const all_att = [];
|
|
686
719
|
let counter_att = 0;
|
|
687
720
|
if (attrs && attrs.struct) {
|
|
@@ -746,11 +779,11 @@ module.exports = {
|
|
|
746
779
|
bodies: ["TEXT"],
|
|
747
780
|
struct: true,
|
|
748
781
|
});
|
|
749
|
-
f.on("message",
|
|
750
|
-
msg.once("attributes",
|
|
782
|
+
f.on("message", msg => {
|
|
783
|
+
msg.once("attributes", att => {
|
|
751
784
|
attrs = att;
|
|
752
785
|
});
|
|
753
|
-
msg.on("body", async
|
|
786
|
+
msg.on("body", async stream => {
|
|
754
787
|
header_mail = stream;
|
|
755
788
|
stream.resume();
|
|
756
789
|
});
|
|
@@ -768,14 +801,14 @@ module.exports = {
|
|
|
768
801
|
});
|
|
769
802
|
e.on("message", (next_msg, seqno) => {
|
|
770
803
|
let new_attrs;
|
|
771
|
-
next_msg.once("attributes",
|
|
804
|
+
next_msg.once("attributes", att => {
|
|
772
805
|
new_attrs = att;
|
|
773
806
|
});
|
|
774
807
|
next_msg.on("body", async (stream, info) => {
|
|
775
808
|
let mail;
|
|
776
809
|
try {
|
|
777
810
|
mail = await simpleParser(stream, this.clientsRaw[client].node_option);
|
|
778
|
-
} catch
|
|
811
|
+
} catch {
|
|
779
812
|
mail = this.current_date(client);
|
|
780
813
|
}
|
|
781
814
|
const att = {
|
|
@@ -786,7 +819,7 @@ module.exports = {
|
|
|
786
819
|
let mail_header;
|
|
787
820
|
try {
|
|
788
821
|
mail_header = await simpleParser(header_mail, this.clientsRaw[client].node_option);
|
|
789
|
-
} catch
|
|
822
|
+
} catch {
|
|
790
823
|
mail_header = this.current_date(client);
|
|
791
824
|
}
|
|
792
825
|
mail.text = mail_header.text;
|
|
@@ -795,18 +828,20 @@ module.exports = {
|
|
|
795
828
|
}
|
|
796
829
|
mail.attachments = all_att.attach;
|
|
797
830
|
mail.attachments_info = all_att.attach_info;
|
|
798
|
-
if (mail.headerLines)
|
|
831
|
+
if (mail.headerLines) {
|
|
832
|
+
mail.headerLines = [];
|
|
833
|
+
}
|
|
799
834
|
this.updatejson(mail, seqno, att, info, client, what);
|
|
800
835
|
stream.resume();
|
|
801
836
|
});
|
|
802
837
|
});
|
|
803
|
-
e.once("error",
|
|
838
|
+
e.once("error", error => {
|
|
804
839
|
if (error) {
|
|
805
840
|
this.log_translator("error", "Error", client, error);
|
|
806
841
|
}
|
|
807
842
|
});
|
|
808
843
|
});
|
|
809
|
-
f.once("error",
|
|
844
|
+
f.once("error", error => {
|
|
810
845
|
if (error) {
|
|
811
846
|
this.log_translator("error", "Error", client, error);
|
|
812
847
|
}
|
|
@@ -815,8 +850,64 @@ module.exports = {
|
|
|
815
850
|
this.log_translator("error", "Error", client, error);
|
|
816
851
|
}
|
|
817
852
|
},
|
|
853
|
+
/**
|
|
854
|
+
* @param {string} client device id
|
|
855
|
+
* @param {string} folder
|
|
856
|
+
*/
|
|
857
|
+
addBox(client, folder) {
|
|
858
|
+
if (!folder || folder == "") {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
this.clients[client].addBox(folder, err => {
|
|
862
|
+
if (!err) {
|
|
863
|
+
this.log_translator("info", "addBox", `addBox ${folder} success`, client);
|
|
864
|
+
this.setFolder(client);
|
|
865
|
+
} else {
|
|
866
|
+
this.log_translator("error", "Error", client, err);
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
},
|
|
870
|
+
/**
|
|
871
|
+
* @param {string} client device id
|
|
872
|
+
* @param {string} folder
|
|
873
|
+
*/
|
|
874
|
+
deleteBox(client, folder) {
|
|
875
|
+
if (!folder || folder == "") {
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
this.clients[client].delBox(folder, err => {
|
|
879
|
+
if (!err) {
|
|
880
|
+
this.log_translator("info", "delBox", `deleteBox ${folder} success`, client);
|
|
881
|
+
this.setFolder(client);
|
|
882
|
+
} else {
|
|
883
|
+
this.log_translator("error", "Error", client, err);
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
},
|
|
887
|
+
/**
|
|
888
|
+
* @param {string} client device id
|
|
889
|
+
* @param {string} oldname
|
|
890
|
+
* @param {string} newname
|
|
891
|
+
*/
|
|
892
|
+
rename(client, oldname, newname) {
|
|
893
|
+
if (!oldname || oldname == "") {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
if (!newname || newname == "") {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
this.clients[client].renameBox(oldname, newname, err => {
|
|
900
|
+
if (!err) {
|
|
901
|
+
this.log_translator("info", "renameBox", `renameBox ${oldname} with ${newname} success`, client);
|
|
902
|
+
this.setFolder(client);
|
|
903
|
+
} else {
|
|
904
|
+
this.log_translator("error", "Error", client, err);
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
},
|
|
818
908
|
/**
|
|
819
909
|
* set, add, del: Flags, Labels, Keyword, move or copy
|
|
910
|
+
*
|
|
820
911
|
* @param {string} client device id
|
|
821
912
|
* @param {string} event
|
|
822
913
|
* @param {number|object} uid
|
|
@@ -824,7 +915,7 @@ module.exports = {
|
|
|
824
915
|
*/
|
|
825
916
|
change_events(client, event, uid, flags) {
|
|
826
917
|
try {
|
|
827
|
-
this.clients[client][event](uid, flags,
|
|
918
|
+
this.clients[client][event](uid, flags, err => {
|
|
828
919
|
if (!err) {
|
|
829
920
|
this.log_translator(
|
|
830
921
|
"info",
|
|
@@ -845,7 +936,9 @@ module.exports = {
|
|
|
845
936
|
* @param {any} folder
|
|
846
937
|
*/
|
|
847
938
|
changeFolder(client, folder) {
|
|
848
|
-
if (folder == this.clientsRaw[client].inbox_activ)
|
|
939
|
+
if (folder == this.clientsRaw[client].inbox_activ) {
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
849
942
|
if (folder && folder != "") {
|
|
850
943
|
this.clientsRaw[client].inbox_activ = folder;
|
|
851
944
|
this.getStatus(folder, client);
|
|
@@ -897,9 +990,10 @@ module.exports = {
|
|
|
897
990
|
},
|
|
898
991
|
/**
|
|
899
992
|
*
|
|
993
|
+
* @param {string} client
|
|
900
994
|
*/
|
|
901
995
|
loadUnseenSeqno(client) {
|
|
902
|
-
return new Promise(
|
|
996
|
+
return new Promise(resolve => {
|
|
903
997
|
this.clients[client].search(["UNSEEN"], async (error, results) => {
|
|
904
998
|
if (error) {
|
|
905
999
|
this.emit("error", error, this.client);
|
|
@@ -911,6 +1005,7 @@ module.exports = {
|
|
|
911
1005
|
},
|
|
912
1006
|
/**
|
|
913
1007
|
* Blockly Call
|
|
1008
|
+
*
|
|
914
1009
|
* @param {string} client device id
|
|
915
1010
|
* @param {object} obj
|
|
916
1011
|
*/
|
|
@@ -964,6 +1059,7 @@ module.exports = {
|
|
|
964
1059
|
},
|
|
965
1060
|
/**
|
|
966
1061
|
* Blockly Call from message event
|
|
1062
|
+
*
|
|
967
1063
|
* @param {string} client device id
|
|
968
1064
|
* @param {number|object} read_mail
|
|
969
1065
|
* @param {object} obj
|
|
@@ -987,7 +1083,7 @@ module.exports = {
|
|
|
987
1083
|
readAllMails(client, result, obj, count) {
|
|
988
1084
|
const all_mails = [];
|
|
989
1085
|
let counter = 0;
|
|
990
|
-
return new Promise(
|
|
1086
|
+
return new Promise(resolve => {
|
|
991
1087
|
try {
|
|
992
1088
|
const f = this.clients[client].fetch(result, {
|
|
993
1089
|
bodies: "",
|
|
@@ -995,7 +1091,7 @@ module.exports = {
|
|
|
995
1091
|
});
|
|
996
1092
|
f.on("message", (msg, seqno) => {
|
|
997
1093
|
let attrs;
|
|
998
|
-
msg.on("attributes",
|
|
1094
|
+
msg.on("attributes", att => {
|
|
999
1095
|
attrs = att;
|
|
1000
1096
|
});
|
|
1001
1097
|
msg.on("body", async (stream, info) => {
|
|
@@ -1017,7 +1113,7 @@ module.exports = {
|
|
|
1017
1113
|
}
|
|
1018
1114
|
});
|
|
1019
1115
|
});
|
|
1020
|
-
f.once("error",
|
|
1116
|
+
f.once("error", error => {
|
|
1021
1117
|
if (error) {
|
|
1022
1118
|
this.log_translator("error", "Error", client, error);
|
|
1023
1119
|
}
|