mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix email node repeat send, add to, cc, bcc fields, and ability to select inbox.
This commit is contained in:
parent
6927f10f8f
commit
1014abe92f
@ -135,9 +135,13 @@
|
|||||||
<input type="text" id="node-input-userid">
|
<input type="text" id="node-input-userid">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
|
<label for="node-input-password"><i class="fa fa-lock"></i> Password</label>
|
||||||
<input type="password" id="node-input-password">
|
<input type="password" id="node-input-password">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-box"><i class="fa fa-inbox"></i> Folder</label>
|
||||||
|
<input type="text" id="node-input-box">
|
||||||
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||||
@ -151,6 +155,7 @@
|
|||||||
<p>Repeatedly gets a <b>single email</b> from an IMAP server and forwards on as a msg if not already seen.</p>
|
<p>Repeatedly gets a <b>single email</b> from an IMAP server and forwards on as a msg if not already seen.</p>
|
||||||
<p>The subject is loaded into <b>msg.topic</b> and <b>msg.payload</b> is the plain text body.
|
<p>The subject is loaded into <b>msg.topic</b> and <b>msg.payload</b> is the plain text body.
|
||||||
If there is text/html then that is returned in <b>msg.html</b>. <b>msg.from</b> and <b>msg.date</b> are also set if you need them.</p>
|
If there is text/html then that is returned in <b>msg.html</b>. <b>msg.from</b> and <b>msg.date</b> are also set if you need them.</p>
|
||||||
|
<p>Additionally <b>msg.to</b>, <b>msg.cc</b>, <b>msg.bcc</b> may exist and contain arrays of relevant email addresses.</p>
|
||||||
<p>Uses the imap module.</p>
|
<p>Uses the imap module.</p>
|
||||||
<p><b>Note:</b> this node <i>only</i> gets the most recent single email from the inbox, so set the repeat (polling) time appropriately.</p>
|
<p><b>Note:</b> this node <i>only</i> gets the most recent single email from the inbox, so set the repeat (polling) time appropriately.</p>
|
||||||
</script>
|
</script>
|
||||||
@ -161,10 +166,11 @@
|
|||||||
category: 'social-input',
|
category: 'social-input',
|
||||||
color:"#c7e9c0",
|
color:"#c7e9c0",
|
||||||
defaults: {
|
defaults: {
|
||||||
repeat: {value:"300",required:true},
|
name: {value:""},
|
||||||
server: {value:"imap.gmail.com",required:true},
|
server: {value:"imap.gmail.com",required:true},
|
||||||
port: {value:"993",required:true},
|
port: {value:"993",required:true},
|
||||||
name: {value:""}
|
box: {value:"INBOX"},
|
||||||
|
repeat: {value:"300",required:true}
|
||||||
},
|
},
|
||||||
credentials: {
|
credentials: {
|
||||||
userid: {type:"text"},
|
userid: {type:"text"},
|
||||||
@ -186,6 +192,10 @@
|
|||||||
} else {
|
} else {
|
||||||
$('#node-tip').hide();
|
$('#node-tip').hide();
|
||||||
};
|
};
|
||||||
|
if (typeof this.box === 'undefined') {
|
||||||
|
$("#node-input-box").val("INBOX");
|
||||||
|
this.box = "INBOX";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@ -121,6 +121,7 @@ module.exports = function(RED) {
|
|||||||
this.repeat = n.repeat * 1000 || 300000;
|
this.repeat = n.repeat * 1000 || 300000;
|
||||||
this.inserver = n.server || globalkeys.server || "imap.gmail.com";
|
this.inserver = n.server || globalkeys.server || "imap.gmail.com";
|
||||||
this.inport = n.port || globalkeys.port || "993";
|
this.inport = n.port || globalkeys.port || "993";
|
||||||
|
this.box = n.box || "INBOX";
|
||||||
var flag = false;
|
var flag = false;
|
||||||
|
|
||||||
if (this.credentials && this.credentials.hasOwnProperty("userid")) {
|
if (this.credentials && this.credentials.hasOwnProperty("userid")) {
|
||||||
@ -173,9 +174,9 @@ module.exports = function(RED) {
|
|||||||
imap.once('ready', function() {
|
imap.once('ready', function() {
|
||||||
node.status({fill:"blue",shape:"dot",text:"fetching"});
|
node.status({fill:"blue",shape:"dot",text:"fetching"});
|
||||||
var pay = {};
|
var pay = {};
|
||||||
imap.openBox('INBOX', false, function(err, box) {
|
imap.openBox(node.box, false, function(err, box) {
|
||||||
if (box.messages.total > 0) {
|
if (box.messages.total > 0) {
|
||||||
var f = imap.seq.fetch(box.messages.total + ':*', { markSeen:true, bodies: ['HEADER.FIELDS (FROM SUBJECT DATE)','TEXT'] });
|
var f = imap.seq.fetch(box.messages.total + ':*', { markSeen:true, bodies: ['HEADER.FIELDS (FROM SUBJECT DATE TO CC BCC)','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 + ') ';
|
||||||
@ -186,9 +187,14 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
stream.on('end', function() {
|
stream.on('end', function() {
|
||||||
if (info.which !== 'TEXT') {
|
if (info.which !== 'TEXT') {
|
||||||
pay.from = Imap.parseHeader(buffer).from[0];
|
var head = Imap.parseHeader(buffer);
|
||||||
pay.topic = Imap.parseHeader(buffer).subject[0];
|
if (RED.settings.verbose) { node.log(head); }
|
||||||
pay.date = Imap.parseHeader(buffer).date[0];
|
pay.from = head.from[0];
|
||||||
|
pay.topic = head.subject[0];
|
||||||
|
pay.date = head.date[0];
|
||||||
|
if (head.hasOwnProperty("to")) { pay.to = head.to; }
|
||||||
|
if (head.hasOwnProperty("cc")) { pay.cc = head.cc; }
|
||||||
|
if (head.hasOwnProperty("bcc")) { pay.bcc = head.bcc; }
|
||||||
} else {
|
} else {
|
||||||
var parts = buffer.split("Content-Type");
|
var parts = buffer.split("Content-Type");
|
||||||
for (var p = 0; p < parts.length; p++) {
|
for (var p = 0; p < parts.length; p++) {
|
||||||
@ -212,9 +218,10 @@ module.exports = function(RED) {
|
|||||||
node.status({fill:"red",shape:"ring",text:"fetch error"});
|
node.status({fill:"red",shape:"ring",text:"fetch error"});
|
||||||
});
|
});
|
||||||
f.on('end', function() {
|
f.on('end', function() {
|
||||||
|
delete(pay._msgid);
|
||||||
if (JSON.stringify(pay) !== oldmail) {
|
if (JSON.stringify(pay) !== oldmail) {
|
||||||
node.send(pay);
|
|
||||||
oldmail = JSON.stringify(pay);
|
oldmail = JSON.stringify(pay);
|
||||||
|
node.send(pay);
|
||||||
node.log('received new email: '+pay.topic);
|
node.log('received new email: '+pay.topic);
|
||||||
}
|
}
|
||||||
else { node.log('duplicate not sent: '+pay.topic); }
|
else { node.log('duplicate not sent: '+pay.topic); }
|
||||||
|
Loading…
Reference in New Issue
Block a user