iobroker.imap 0.2.1 → 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 +71 -58
- 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 +48 -9
- package/io-package.json +27 -27
- package/lib/helper.js +40 -6
- package/lib/imap_event.js +156 -58
- package/lib/translator.js +78 -0
- package/main.js +237 -216
- package/package.json +15 -17
- 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,11 +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];
|
|
533
|
+
let nextuid = this.diffArray(uidNext, new_mail, 2, client);
|
|
505
534
|
this.clientsRaw[client][inbox] = new_mail;
|
|
506
|
-
if (nextuid.length === 0) {
|
|
535
|
+
if (nextuid === 0 || nextuid.length === 0) {
|
|
507
536
|
nextuid = [box.uidnext];
|
|
508
537
|
}
|
|
538
|
+
this.log_translator("debug", "logs", `nextuid: ${nextuid}`);
|
|
509
539
|
if (this.clients[client].serverSupports("SORT")) {
|
|
510
540
|
this.newMails(client, nextuid, "new", true);
|
|
511
541
|
} else {
|
|
@@ -530,13 +560,15 @@ module.exports = {
|
|
|
530
560
|
/**
|
|
531
561
|
* Arrival new Mail and capability SORT == false -> Use nextuid
|
|
532
562
|
* Arrival new Mail and capability SORT == true
|
|
563
|
+
*
|
|
533
564
|
* @param {string} client device id
|
|
534
565
|
* @param {object} uid
|
|
535
566
|
* @param {string} what new mail or update
|
|
536
567
|
* @param {boolean} sort Implementation in the next release
|
|
537
568
|
*/
|
|
538
569
|
newMails(client, uid, what, sort) {
|
|
539
|
-
this.
|
|
570
|
+
this.log_translator("debug", "logs", `sort: ${sort}`);
|
|
571
|
+
this.log_translator("debug", "logs", `newMail: ${JSON.stringify(uid)}`);
|
|
540
572
|
for (const uids of uid) {
|
|
541
573
|
let attrs;
|
|
542
574
|
let header_mail;
|
|
@@ -544,11 +576,11 @@ module.exports = {
|
|
|
544
576
|
bodies: ["TEXT"],
|
|
545
577
|
struct: true,
|
|
546
578
|
});
|
|
547
|
-
f.on("message",
|
|
548
|
-
msg.once("attributes",
|
|
579
|
+
f.on("message", msg => {
|
|
580
|
+
msg.once("attributes", att => {
|
|
549
581
|
attrs = att;
|
|
550
582
|
});
|
|
551
|
-
msg.on("body", async
|
|
583
|
+
msg.on("body", async stream => {
|
|
552
584
|
header_mail = stream;
|
|
553
585
|
stream.resume();
|
|
554
586
|
});
|
|
@@ -569,14 +601,14 @@ module.exports = {
|
|
|
569
601
|
this.all_seqno[client].push(seqno);
|
|
570
602
|
this.all_seqno[client].sort((a, b) => b - a);
|
|
571
603
|
let new_attrs;
|
|
572
|
-
next_msg.once("attributes",
|
|
604
|
+
next_msg.once("attributes", att => {
|
|
573
605
|
new_attrs = att;
|
|
574
606
|
});
|
|
575
607
|
next_msg.on("body", async (stream, info) => {
|
|
576
608
|
let mail;
|
|
577
609
|
try {
|
|
578
610
|
mail = await simpleParser(stream, this.clientsRaw[client].node_option);
|
|
579
|
-
} catch
|
|
611
|
+
} catch {
|
|
580
612
|
mail = this.current_date(client);
|
|
581
613
|
}
|
|
582
614
|
const att = {
|
|
@@ -587,7 +619,7 @@ module.exports = {
|
|
|
587
619
|
let mail_header;
|
|
588
620
|
try {
|
|
589
621
|
mail_header = await simpleParser(header_mail, this.clientsRaw[client].node_option);
|
|
590
|
-
} catch
|
|
622
|
+
} catch {
|
|
591
623
|
mail_header = this.current_date(client);
|
|
592
624
|
}
|
|
593
625
|
mail.text = mail_header.text;
|
|
@@ -596,18 +628,20 @@ module.exports = {
|
|
|
596
628
|
}
|
|
597
629
|
mail.attachments = all_att.attach;
|
|
598
630
|
mail.attachments_info = all_att.attach_info;
|
|
599
|
-
if (mail.headerLines)
|
|
631
|
+
if (mail.headerLines) {
|
|
632
|
+
mail.headerLines = [];
|
|
633
|
+
}
|
|
600
634
|
this.updatejson(mail, seqno, att, info, client, what);
|
|
601
635
|
stream.resume();
|
|
602
636
|
});
|
|
603
637
|
});
|
|
604
|
-
e.once("error",
|
|
638
|
+
e.once("error", error => {
|
|
605
639
|
if (error) {
|
|
606
640
|
this.log_translator("error", "Error", client, error);
|
|
607
641
|
}
|
|
608
642
|
});
|
|
609
643
|
});
|
|
610
|
-
f.once("error",
|
|
644
|
+
f.once("error", error => {
|
|
611
645
|
if (error) {
|
|
612
646
|
this.log_translator("error", "Error", client, error);
|
|
613
647
|
}
|
|
@@ -622,7 +656,7 @@ module.exports = {
|
|
|
622
656
|
*/
|
|
623
657
|
diffArray(arr1, arr2, from, client) {
|
|
624
658
|
try {
|
|
625
|
-
const diff = (a, b) => a.filter(
|
|
659
|
+
const diff = (a, b) => a.filter(item => b.indexOf(item) === -1);
|
|
626
660
|
if (from === 1) {
|
|
627
661
|
return diff(arr1, arr2);
|
|
628
662
|
}
|
|
@@ -632,7 +666,7 @@ module.exports = {
|
|
|
632
666
|
const diff1 = diff(arr1, arr2);
|
|
633
667
|
const diff2 = diff(arr2, arr1);
|
|
634
668
|
return [].concat(diff1, diff2);
|
|
635
|
-
} catch
|
|
669
|
+
} catch {
|
|
636
670
|
this.log_translator(
|
|
637
671
|
"warn",
|
|
638
672
|
"Error",
|
|
@@ -651,7 +685,7 @@ module.exports = {
|
|
|
651
685
|
if (sort) {
|
|
652
686
|
this.all_seqno[client] = seqno;
|
|
653
687
|
} else {
|
|
654
|
-
const isRange = this.all_seqno[client].findIndex(
|
|
688
|
+
const isRange = this.all_seqno[client].findIndex(number => number == seqno);
|
|
655
689
|
if (isRange != -1) {
|
|
656
690
|
this.all_seqno[client][isRange] = seqno;
|
|
657
691
|
}
|
|
@@ -659,12 +693,13 @@ module.exports = {
|
|
|
659
693
|
},
|
|
660
694
|
/**
|
|
661
695
|
* Event when message metadata (e.g. flags) changes externally
|
|
696
|
+
*
|
|
662
697
|
* @param {number} seqno
|
|
663
698
|
* @param {object} info
|
|
664
699
|
* @param {string} client device id
|
|
665
700
|
*/
|
|
666
701
|
onUpdate(seqno, info, client) {
|
|
667
|
-
const isRange = this.all_seqno[client].findIndex(
|
|
702
|
+
const isRange = this.all_seqno[client].findIndex(number => number == seqno);
|
|
668
703
|
if (isRange != -1 && (isRange < this.clientsRaw[client].max || isRange == this.clientsRaw[client].max)) {
|
|
669
704
|
this.log_translator("info", "Start Update", seqno, client, JSON.stringify(info));
|
|
670
705
|
info["seqno"] = seqno;
|
|
@@ -679,7 +714,7 @@ module.exports = {
|
|
|
679
714
|
* @param {object} attrs
|
|
680
715
|
*/
|
|
681
716
|
async updateattachments(attrs) {
|
|
682
|
-
return new Promise(
|
|
717
|
+
return new Promise(resolve => {
|
|
683
718
|
const all_att = [];
|
|
684
719
|
let counter_att = 0;
|
|
685
720
|
if (attrs && attrs.struct) {
|
|
@@ -744,11 +779,11 @@ module.exports = {
|
|
|
744
779
|
bodies: ["TEXT"],
|
|
745
780
|
struct: true,
|
|
746
781
|
});
|
|
747
|
-
f.on("message",
|
|
748
|
-
msg.once("attributes",
|
|
782
|
+
f.on("message", msg => {
|
|
783
|
+
msg.once("attributes", att => {
|
|
749
784
|
attrs = att;
|
|
750
785
|
});
|
|
751
|
-
msg.on("body", async
|
|
786
|
+
msg.on("body", async stream => {
|
|
752
787
|
header_mail = stream;
|
|
753
788
|
stream.resume();
|
|
754
789
|
});
|
|
@@ -766,14 +801,14 @@ module.exports = {
|
|
|
766
801
|
});
|
|
767
802
|
e.on("message", (next_msg, seqno) => {
|
|
768
803
|
let new_attrs;
|
|
769
|
-
next_msg.once("attributes",
|
|
804
|
+
next_msg.once("attributes", att => {
|
|
770
805
|
new_attrs = att;
|
|
771
806
|
});
|
|
772
807
|
next_msg.on("body", async (stream, info) => {
|
|
773
808
|
let mail;
|
|
774
809
|
try {
|
|
775
810
|
mail = await simpleParser(stream, this.clientsRaw[client].node_option);
|
|
776
|
-
} catch
|
|
811
|
+
} catch {
|
|
777
812
|
mail = this.current_date(client);
|
|
778
813
|
}
|
|
779
814
|
const att = {
|
|
@@ -784,7 +819,7 @@ module.exports = {
|
|
|
784
819
|
let mail_header;
|
|
785
820
|
try {
|
|
786
821
|
mail_header = await simpleParser(header_mail, this.clientsRaw[client].node_option);
|
|
787
|
-
} catch
|
|
822
|
+
} catch {
|
|
788
823
|
mail_header = this.current_date(client);
|
|
789
824
|
}
|
|
790
825
|
mail.text = mail_header.text;
|
|
@@ -793,18 +828,20 @@ module.exports = {
|
|
|
793
828
|
}
|
|
794
829
|
mail.attachments = all_att.attach;
|
|
795
830
|
mail.attachments_info = all_att.attach_info;
|
|
796
|
-
if (mail.headerLines)
|
|
831
|
+
if (mail.headerLines) {
|
|
832
|
+
mail.headerLines = [];
|
|
833
|
+
}
|
|
797
834
|
this.updatejson(mail, seqno, att, info, client, what);
|
|
798
835
|
stream.resume();
|
|
799
836
|
});
|
|
800
837
|
});
|
|
801
|
-
e.once("error",
|
|
838
|
+
e.once("error", error => {
|
|
802
839
|
if (error) {
|
|
803
840
|
this.log_translator("error", "Error", client, error);
|
|
804
841
|
}
|
|
805
842
|
});
|
|
806
843
|
});
|
|
807
|
-
f.once("error",
|
|
844
|
+
f.once("error", error => {
|
|
808
845
|
if (error) {
|
|
809
846
|
this.log_translator("error", "Error", client, error);
|
|
810
847
|
}
|
|
@@ -813,8 +850,64 @@ module.exports = {
|
|
|
813
850
|
this.log_translator("error", "Error", client, error);
|
|
814
851
|
}
|
|
815
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
|
+
},
|
|
816
908
|
/**
|
|
817
909
|
* set, add, del: Flags, Labels, Keyword, move or copy
|
|
910
|
+
*
|
|
818
911
|
* @param {string} client device id
|
|
819
912
|
* @param {string} event
|
|
820
913
|
* @param {number|object} uid
|
|
@@ -822,7 +915,7 @@ module.exports = {
|
|
|
822
915
|
*/
|
|
823
916
|
change_events(client, event, uid, flags) {
|
|
824
917
|
try {
|
|
825
|
-
this.clients[client][event](uid, flags,
|
|
918
|
+
this.clients[client][event](uid, flags, err => {
|
|
826
919
|
if (!err) {
|
|
827
920
|
this.log_translator(
|
|
828
921
|
"info",
|
|
@@ -843,7 +936,9 @@ module.exports = {
|
|
|
843
936
|
* @param {any} folder
|
|
844
937
|
*/
|
|
845
938
|
changeFolder(client, folder) {
|
|
846
|
-
if (folder == this.clientsRaw[client].inbox_activ)
|
|
939
|
+
if (folder == this.clientsRaw[client].inbox_activ) {
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
847
942
|
if (folder && folder != "") {
|
|
848
943
|
this.clientsRaw[client].inbox_activ = folder;
|
|
849
944
|
this.getStatus(folder, client);
|
|
@@ -895,9 +990,10 @@ module.exports = {
|
|
|
895
990
|
},
|
|
896
991
|
/**
|
|
897
992
|
*
|
|
993
|
+
* @param {string} client
|
|
898
994
|
*/
|
|
899
995
|
loadUnseenSeqno(client) {
|
|
900
|
-
return new Promise(
|
|
996
|
+
return new Promise(resolve => {
|
|
901
997
|
this.clients[client].search(["UNSEEN"], async (error, results) => {
|
|
902
998
|
if (error) {
|
|
903
999
|
this.emit("error", error, this.client);
|
|
@@ -909,6 +1005,7 @@ module.exports = {
|
|
|
909
1005
|
},
|
|
910
1006
|
/**
|
|
911
1007
|
* Blockly Call
|
|
1008
|
+
*
|
|
912
1009
|
* @param {string} client device id
|
|
913
1010
|
* @param {object} obj
|
|
914
1011
|
*/
|
|
@@ -962,6 +1059,7 @@ module.exports = {
|
|
|
962
1059
|
},
|
|
963
1060
|
/**
|
|
964
1061
|
* Blockly Call from message event
|
|
1062
|
+
*
|
|
965
1063
|
* @param {string} client device id
|
|
966
1064
|
* @param {number|object} read_mail
|
|
967
1065
|
* @param {object} obj
|
|
@@ -985,7 +1083,7 @@ module.exports = {
|
|
|
985
1083
|
readAllMails(client, result, obj, count) {
|
|
986
1084
|
const all_mails = [];
|
|
987
1085
|
let counter = 0;
|
|
988
|
-
return new Promise(
|
|
1086
|
+
return new Promise(resolve => {
|
|
989
1087
|
try {
|
|
990
1088
|
const f = this.clients[client].fetch(result, {
|
|
991
1089
|
bodies: "",
|
|
@@ -993,7 +1091,7 @@ module.exports = {
|
|
|
993
1091
|
});
|
|
994
1092
|
f.on("message", (msg, seqno) => {
|
|
995
1093
|
let attrs;
|
|
996
|
-
msg.on("attributes",
|
|
1094
|
+
msg.on("attributes", att => {
|
|
997
1095
|
attrs = att;
|
|
998
1096
|
});
|
|
999
1097
|
msg.on("body", async (stream, info) => {
|
|
@@ -1015,7 +1113,7 @@ module.exports = {
|
|
|
1015
1113
|
}
|
|
1016
1114
|
});
|
|
1017
1115
|
});
|
|
1018
|
-
f.once("error",
|
|
1116
|
+
f.once("error", error => {
|
|
1019
1117
|
if (error) {
|
|
1020
1118
|
this.log_translator("error", "Error", client, error);
|
|
1021
1119
|
}
|