From 0df321bcd309bb2d391e51390d2dec5817bfa4b2 Mon Sep 17 00:00:00 2001 From: wooferguy Date: Tue, 14 Feb 2023 23:22:01 +1300 Subject: [PATCH] XOAUTH2 POP3 Added checking for authentication type to allow XOauth2 tokens to be sent to POP server. Turned off UI restrictions for this functionality. --- social/email/61-email.html | 4 ---- social/email/61-email.js | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/social/email/61-email.html b/social/email/61-email.html index ac48ddd3..f486d896 100644 --- a/social/email/61-email.html +++ b/social/email/61-email.html @@ -230,8 +230,6 @@ $(".node-input-disposition").show(); $(".node-input-criteria").show(); } else { - $("#node-input-authtype").val("BASIC"); - $("#node-input-authtype").change(); $(".node-input-autotls").hide(); $(".node-input-box").hide(); $(".node-input-disposition").hide(); @@ -250,8 +248,6 @@ $(".node-input-password").hide(); $(".node-input-saslformat").show(); $(".node-input-token").show(); - $("#node-input-protocol").val("IMAP"); //Remove when POP lib updated - $("#node-input-protocol").change(); $("#node-input-fetch").val("trigger"); $("#node-input-fetch").change(); } diff --git a/social/email/61-email.js b/social/email/61-email.js index f51c6710..41a21d58 100644 --- a/social/email/61-email.js +++ b/social/email/61-email.js @@ -205,7 +205,6 @@ module.exports = function(RED) { if (this.authtype !== "BASIC") { this.inputs = 1; this.repeat = 0; - this.protocol = "IMAP"; } var flag = false; @@ -275,6 +274,7 @@ module.exports = function(RED) { // the messages from the server. async function checkPOP3(msg,send,done) { var tout = (node.repeat > 0) ? node.repeat - 500 : 15000; + var saslxoauth2 = ""; var currentMessage = 1; var maxMessage = 0; var nextMessage; @@ -288,9 +288,23 @@ module.exports = function(RED) { try { node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"}); await pop3.connect(); + if(node.authtype == "XOAUTH2") { + var value = RED.util.getMessageProperty(msg,node.token); + if (value !== undefined) { + if(node.saslformat) { + //Make base64 string for access - compatible with outlook365 and gmail + saslxoauth2 = Buffer.from("user="+node.userid+"\x01auth=Bearer "+value+"\x01\x01").toString('base64'); + } else { + saslxoauth2 = value; + } + } + await pop3.command('AUTH', "XOAUTH2"); + await pop3.command(saslxoauth2); + } else if(node.authtype == "BASIC") { await pop3.command('USER', node.userid); await pop3.command('PASS', node.password); + } } catch(err) { node.error(err.message,err); node.status({fill:"red",shape:"ring",text:"email.status.connecterror"});