XOAUTH2 POP3

Added checking for authentication type to allow XOauth2 tokens to be sent to POP server. Turned off UI restrictions for this functionality.
This commit is contained in:
wooferguy 2023-02-14 23:22:01 +13:00
parent 7964a1e7e3
commit 0df321bcd3
2 changed files with 15 additions and 5 deletions

View File

@ -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();
}

View File

@ -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"});