mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
parent
2ca330fcb8
commit
2c8e4780e1
@ -121,9 +121,16 @@
|
||||
|
||||
|
||||
<script type="text/x-red" data-template-name="e-mail in">
|
||||
<div class="form-row node-input-repeat">
|
||||
<label for="node-input-repeat"><i class="fa fa-repeat"></i> <span data-i18n="email.label.repeat"></span></label>
|
||||
<input type="text" id="node-input-repeat" style="width: 80px"> <span data-i18n="email.label.seconds">seconds</span>
|
||||
<div class="form-row">
|
||||
<label for="node-input-fetch"><i class="fa fa-hourglass-half"></i> <span data-i18n="email.label.getmail"></span></label>
|
||||
<select type="text" id="node-input-fetch" style="width:130px;">
|
||||
<option value="auto" data-i18n="email.label.auto"></option>
|
||||
<option value="trigger" data-i18n="email.label.trigger"></option>
|
||||
</select>
|
||||
<span id="node-repeatTime">
|
||||
<span style="margin-left:20px;" data-i18n="email.label.repeat"></span>
|
||||
<input type="text" id="node-input-repeat" style="width:80px"> <span data-i18n="email.label.seconds">seconds</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-protocol"><i class="fa fa-envelope"></i> <span data-i18n="email.label.protocol"></span></label>
|
||||
@ -182,8 +189,8 @@
|
||||
};
|
||||
|
||||
$("#node-input-useSSL").change(function(x, y) {
|
||||
console.log("useSSL: x="+ JSON.stringify(x) + ", y=" + y);
|
||||
console.log("Value: " + $("#node-input-useSSL").prop("checked"));
|
||||
// console.log("useSSL: x="+ JSON.stringify(x) + ", y=" + y);
|
||||
// console.log("Value: " + $("#node-input-useSSL").prop("checked"));
|
||||
checkPorts();
|
||||
});
|
||||
|
||||
@ -245,15 +252,17 @@
|
||||
port: {value:"993",required:true},
|
||||
box: {value:"INBOX"}, // For IMAP, The mailbox to process
|
||||
disposition: { value: "Read" }, // For IMAP, the disposition of the read email
|
||||
repeat: {value:"300",required:true}
|
||||
repeat: {value:"300",required:true},
|
||||
fetch: {value:"auto"},
|
||||
inputs: {value:0}
|
||||
},
|
||||
credentials: {
|
||||
userid: {type:"text"},
|
||||
password: {type: "password"},
|
||||
global: { type:"boolean"}
|
||||
},
|
||||
inputs:0,
|
||||
outputs:1,
|
||||
inputs: 0,
|
||||
outputs: 1,
|
||||
icon: "envelope.png",
|
||||
paletteLabel: function() {
|
||||
return this._("email.email");
|
||||
@ -265,6 +274,7 @@
|
||||
return (this.name)?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var that = this;
|
||||
if (this.credentials.global) {
|
||||
$('#node-tip').show();
|
||||
} else {
|
||||
@ -274,6 +284,17 @@
|
||||
$("#node-input-box").val("INBOX");
|
||||
this.box = "INBOX";
|
||||
}
|
||||
if ($("#node-input-fetch").val() === null) { $("#node-input-fetch").val("auto"); }
|
||||
$("#node-input-fetch").change(function() {
|
||||
if ($("#node-input-fetch").val() === "trigger") {
|
||||
$('#node-repeatTime').hide();
|
||||
that.inputs = 1;
|
||||
}
|
||||
else {
|
||||
$('#node-repeatTime').show();
|
||||
that.inputs = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
@ -146,12 +146,14 @@ module.exports = function(RED) {
|
||||
|
||||
RED.nodes.createNode(this,n);
|
||||
this.name = n.name;
|
||||
this.inputs = n.inputs;
|
||||
this.repeat = n.repeat * 1000 || 300000;
|
||||
if (this.repeat > 2147483647) {
|
||||
// setTimeout/Interval has a limit of 2**31-1 Milliseconds
|
||||
this.repeat = 2147483647;
|
||||
this.error(RED._("email.errors.refreshtoolarge"));
|
||||
}
|
||||
if (this.inputs === 1) { this.repeat = 0; }
|
||||
this.inserver = n.server || (globalkeys && globalkeys.server) || "imap.gmail.com";
|
||||
this.inport = n.port || (globalkeys && globalkeys.port) || "993";
|
||||
this.box = n.box || "INBOX";
|
||||
@ -315,10 +317,12 @@ module.exports = function(RED) {
|
||||
// checkIMAP
|
||||
//
|
||||
// Check the email sever using the IMAP protocol for new messages.
|
||||
var s = true;
|
||||
function checkIMAP(msg) {
|
||||
//node.log("Checking IMAP for new messages");
|
||||
// We get back a 'ready' event once we have connected to imap
|
||||
imap.once("ready", function() {
|
||||
s = true;
|
||||
node.status({fill:"blue", shape:"dot", text:"email.status.fetching"});
|
||||
//console.log("> ready");
|
||||
// Open the inbox folder
|
||||
@ -328,6 +332,7 @@ module.exports = function(RED) {
|
||||
//console.log("> Inbox err : %j", err);
|
||||
//console.log("> Inbox open: %j", box);
|
||||
if (err) {
|
||||
s = false;
|
||||
node.status({fill:"red", shape:"ring", text:"email.status.foldererror"});
|
||||
node.error(RED._("email.errors.fetchfail", {folder:node.box}),err);
|
||||
imap.end();
|
||||
@ -337,6 +342,7 @@ module.exports = function(RED) {
|
||||
else {
|
||||
imap.search([ 'UNSEEN' ], function(err, results) {
|
||||
if (err) {
|
||||
s = false;
|
||||
node.status({fill:"red", shape:"ring", text:"email.status.foldererror"});
|
||||
node.error(RED._("email.errors.fetchfail", {folder:node.box}),err);
|
||||
imap.end();
|
||||
@ -347,6 +353,7 @@ module.exports = function(RED) {
|
||||
//console.log("> search - err=%j, results=%j", err, results);
|
||||
if (results.length === 0) {
|
||||
//console.log(" [X] - Nothing to fetch");
|
||||
s = true;
|
||||
node.status({});
|
||||
imap.end();
|
||||
setInputRepeatTimeout();
|
||||
@ -386,6 +393,7 @@ module.exports = function(RED) {
|
||||
|
||||
// When we have fetched all the messages, we don't need the imap connection any more.
|
||||
fetch.on('end', function() {
|
||||
s = true;
|
||||
node.status({});
|
||||
var cleanup = function() {
|
||||
imap.end();
|
||||
@ -409,6 +417,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
}); // End of imap->openInbox
|
||||
}); // End of imap->ready
|
||||
s = false;
|
||||
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"});
|
||||
imap.connect();
|
||||
} // End of checkIMAP
|
||||
@ -416,10 +425,13 @@ module.exports = function(RED) {
|
||||
|
||||
// Perform a check of the email inboxes using either POP3 or IMAP
|
||||
function checkEmail(msg) {
|
||||
console.log("STAT",s);
|
||||
if (node.protocol === "POP3") {
|
||||
checkPOP3(msg);
|
||||
} else if (node.protocol === "IMAP") {
|
||||
checkIMAP(msg);
|
||||
if (s !== false) {
|
||||
checkIMAP(msg);
|
||||
}
|
||||
}
|
||||
} // End of checkEmail
|
||||
|
||||
@ -437,8 +449,10 @@ module.exports = function(RED) {
|
||||
imap.on('error', function(err) {
|
||||
if (err.errno !== "ECONNRESET") {
|
||||
node.log(err);
|
||||
s = true;
|
||||
node.status({fill:"red",shape:"ring",text:"email.status.connecterror"});
|
||||
}
|
||||
setInputRepeatTimeout()
|
||||
});
|
||||
}
|
||||
|
||||
@ -462,7 +476,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
}
|
||||
|
||||
node.emit("input",{});
|
||||
if (this.inputs !== 1) { node.emit("input",{}); }
|
||||
}
|
||||
|
||||
RED.nodes.registerType("e-mail in",EmailInNode,{
|
||||
|
@ -2,13 +2,16 @@
|
||||
"email": {
|
||||
"email": "email",
|
||||
"label": {
|
||||
"getmail":"Get mail",
|
||||
"auto": "automatically",
|
||||
"trigger": "when triggered",
|
||||
"to": "To",
|
||||
"server": "Server",
|
||||
"port": "Port",
|
||||
"useSecureConnection": "Use secure connection.",
|
||||
"userid": "Userid",
|
||||
"password": "Password",
|
||||
"repeat": "Refresh",
|
||||
"repeat": "every",
|
||||
"seconds": "seconds",
|
||||
"folder": "Folder",
|
||||
"protocol": "Protocol",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-red-node-email",
|
||||
"version": "1.0.7",
|
||||
"version": "1.1.0",
|
||||
"description": "Node-RED nodes to send and receive simple emails",
|
||||
"dependencies": {
|
||||
"imap": "^0.8.19",
|
||||
|
Loading…
Reference in New Issue
Block a user