@5minds/node-red-contrib-processcube-tools 1.0.3 → 1.0.5-develop-ad29fd-mfwgxhe0
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.
|
@@ -2,6 +2,17 @@ module.exports = function (RED) {
|
|
|
2
2
|
const Imap = require('node-imap');
|
|
3
3
|
const mailparser = require('mailparser');
|
|
4
4
|
|
|
5
|
+
function toBoolean(val, defaultValue = false) {
|
|
6
|
+
if (typeof val === "boolean") return val; // schon korrekt
|
|
7
|
+
if (typeof val === "number") return val !== 0; // 0 = false, sonst true
|
|
8
|
+
if (typeof val === "string") {
|
|
9
|
+
const v = val.trim().toLowerCase();
|
|
10
|
+
if (["true", "1", "yes", "on"].includes(v)) return true;
|
|
11
|
+
if (["false", "0", "no", "off"].includes(v)) return false;
|
|
12
|
+
}
|
|
13
|
+
return defaultValue; // fallback
|
|
14
|
+
}
|
|
15
|
+
|
|
5
16
|
function EmailReceiverNode(config) {
|
|
6
17
|
RED.nodes.createNode(this, config);
|
|
7
18
|
const node = this;
|
|
@@ -36,10 +47,10 @@ module.exports = function (RED) {
|
|
|
36
47
|
folders: Array.isArray(imap_folder)
|
|
37
48
|
? imap_folder
|
|
38
49
|
: imap_folder
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
markSeen: imap_markSeen,
|
|
50
|
+
.split(',')
|
|
51
|
+
.map((f) => f.trim())
|
|
52
|
+
.filter((f) => f.length > 0),
|
|
53
|
+
markSeen: toBoolean(imap_markSeen, true),
|
|
43
54
|
connTimeout: msg.imap_connTimeout || 10000,
|
|
44
55
|
authTimeout: msg.imap_authTimeout || 5000,
|
|
45
56
|
keepalive: msg.imap_keepalive !== undefined ? msg.imap_keepalive : true,
|
|
@@ -161,7 +172,7 @@ module.exports = function (RED) {
|
|
|
161
172
|
|
|
162
173
|
state.totalMails += results.length;
|
|
163
174
|
|
|
164
|
-
const fetch = imap.fetch(results, { bodies: '' });
|
|
175
|
+
const fetch = imap.fetch(results, { bodies: '', markSeen: markSeen });
|
|
165
176
|
|
|
166
177
|
fetch.on('message', (msg) => {
|
|
167
178
|
msg.on('body', (stream) => {
|
|
@@ -232,8 +243,12 @@ module.exports = function (RED) {
|
|
|
232
243
|
node.log('IMAP connection ended.');
|
|
233
244
|
});
|
|
234
245
|
|
|
235
|
-
|
|
236
|
-
|
|
246
|
+
try {
|
|
247
|
+
updateStatus('yellow', 'Connecting to IMAP...');
|
|
248
|
+
imap.connect();
|
|
249
|
+
} catch (err) {
|
|
250
|
+
updateStatus('red', 'Connection error: ' + err.message);
|
|
251
|
+
}
|
|
237
252
|
};
|
|
238
253
|
|
|
239
254
|
fetchEmails(finalConfig, (mail) => {
|