mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix for IMAP node - inbox 0 error.
This commit is contained in:
parent
0b516a83db
commit
2a0491542d
@ -57,51 +57,56 @@ function ImapNode(n) {
|
|||||||
imap.once('ready', function() {
|
imap.once('ready', function() {
|
||||||
var pay = {};
|
var pay = {};
|
||||||
openInbox(function(err, box) {
|
openInbox(function(err, box) {
|
||||||
//if (err) throw err;
|
if (box.messages.total > 0) {
|
||||||
var f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM SUBJECT DATE)','TEXT'] });
|
var f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM SUBJECT DATE)','TEXT'] });
|
||||||
f.on('message', function(msg, seqno) {
|
f.on('message', function(msg, seqno) {
|
||||||
node.log('message: #'+ seqno);
|
node.log('message: #'+ seqno);
|
||||||
var prefix = '(#' + seqno + ') ';
|
var prefix = '(#' + seqno + ') ';
|
||||||
msg.on('body', function(stream, info) {
|
msg.on('body', function(stream, info) {
|
||||||
var buffer = '';
|
var buffer = '';
|
||||||
stream.on('data', function(chunk) {
|
stream.on('data', function(chunk) {
|
||||||
buffer += chunk.toString('utf8');
|
buffer += chunk.toString('utf8');
|
||||||
});
|
});
|
||||||
stream.on('end', function() {
|
stream.on('end', function() {
|
||||||
if (info.which !== 'TEXT') {
|
if (info.which !== 'TEXT') {
|
||||||
pay.from = Imap.parseHeader(buffer).from[0];
|
pay.from = Imap.parseHeader(buffer).from[0];
|
||||||
pay.topic = Imap.parseHeader(buffer).subject[0];
|
pay.topic = Imap.parseHeader(buffer).subject[0];
|
||||||
pay.date = Imap.parseHeader(buffer).date[0];
|
pay.date = Imap.parseHeader(buffer).date[0];
|
||||||
} else {
|
} else {
|
||||||
var parts = buffer.split("Content-Type");
|
var parts = buffer.split("Content-Type");
|
||||||
for (var p in parts) {
|
for (var p in parts) {
|
||||||
if (parts[p].indexOf("text/plain") >= 0) {
|
if (parts[p].indexOf("text/plain") >= 0) {
|
||||||
pay.payload = parts[p].split("\n").slice(1,-2).join("\n").trim();
|
pay.payload = parts[p].split("\n").slice(1,-2).join("\n").trim();
|
||||||
}
|
}
|
||||||
if (parts[p].indexOf("text/html") >= 0) {
|
if (parts[p].indexOf("text/html") >= 0) {
|
||||||
pay.html = parts[p].split("\n").slice(1,-2).join("\n").trim();
|
pay.html = parts[p].split("\n").slice(1,-2).join("\n").trim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
//pay.body = buffer;
|
||||||
}
|
}
|
||||||
//pay.body = buffer;
|
});
|
||||||
}
|
});
|
||||||
|
msg.on('end', function() {
|
||||||
|
//node.log('Finished: '+prefix);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
msg.on('end', function() {
|
f.on('error', function(err) {
|
||||||
//node.log('Finished: '+prefix);
|
node.warn('fetch error: ' + err);
|
||||||
});
|
});
|
||||||
});
|
f.on('end', function() {
|
||||||
f.on('error', function(err) {
|
if (JSON.stringify(pay) !== oldmail) {
|
||||||
node.warn('fetch error: ' + err);
|
node.send(pay);
|
||||||
});
|
oldmail = JSON.stringify(pay);
|
||||||
f.on('end', function() {
|
node.log('sent new message: '+pay.topic);
|
||||||
if (JSON.stringify(pay) !== oldmail) {
|
}
|
||||||
node.send(pay);
|
else { node.log('duplicate not sent: '+pay.topic); }
|
||||||
oldmail = JSON.stringify(pay);
|
imap.end();
|
||||||
node.log('sent new message: '+pay.topic);
|
});
|
||||||
}
|
}
|
||||||
else { node.log('duplicate not sent: '+pay.topic); }
|
else {
|
||||||
|
// node.log("you have achieved inbox zero");
|
||||||
imap.end();
|
imap.end();
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
imap.connect();
|
imap.connect();
|
||||||
|
Loading…
Reference in New Issue
Block a user