From c2b72460483c72d7d51a37294efe6a23525af19d Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 14 Oct 2020 22:28:56 +0000 Subject: [PATCH] handle bad user ids in mail ui better --- static-data/default-plugins/pms/info.json | 2 +- static-data/default-plugins/pms/main.py | 2 +- .../default-plugins/pms/web/sendmail.js | 28 ++++++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/static-data/default-plugins/pms/info.json b/static-data/default-plugins/pms/info.json index d654f11e..72ce2b39 100755 --- a/static-data/default-plugins/pms/info.json +++ b/static-data/default-plugins/pms/info.json @@ -1,5 +1,5 @@ { "name" : "pms", - "version" : "0.1.1", + "version" : "0.1.2", "author" : "onionr" } diff --git a/static-data/default-plugins/pms/main.py b/static-data/default-plugins/pms/main.py index c9a80a92..4d2219f2 100755 --- a/static-data/default-plugins/pms/main.py +++ b/static-data/default-plugins/pms/main.py @@ -31,7 +31,7 @@ import notifier locale.setlocale(locale.LC_ALL, '') plugin_name = 'pms' -PLUGIN_VERSION = '0.1.1' +PLUGIN_VERSION = '0.1.2' sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) import sentboxdb, mailapi, loadinbox # import after path insert diff --git a/static-data/default-plugins/pms/web/sendmail.js b/static-data/default-plugins/pms/web/sendmail.js index b69d36db..dd7c44ff 100755 --- a/static-data/default-plugins/pms/web/sendmail.js +++ b/static-data/default-plugins/pms/web/sendmail.js @@ -62,7 +62,16 @@ function sendMail(toData, message, subject){ headers: { "content-type": "application/json", "token": webpass - }}) + }}).then(function(resp){ + if (!resp.ok){ + PNotify.error({ + text: 'Malformed input' + }) + sendForm.style.display = 'block' + throw new Error("Malformed input in sendmail") + } + return resp + }) .then((resp) => resp.text()) // Transform the data into text .then(function(data) { sendForm.style.display = 'block' @@ -83,13 +92,18 @@ friendPicker.onchange = function(){ } sendForm.onsubmit = function(){ - if (! to.value.includes("-") && to.value.length !== 56 && to.value.length !== 52){ - PNotify.error({ - text: 'User ID is not valid' - }) + let getInstances = function(string, word) { + return string.split(word).length - 1; } - else{ - sendMail(to.value, messageContent.value, subject.value) + + if(getInstances(to.value, '-') != 15){ + if (to.value.length != 56 && to.value.length != 52){ + PNotify.error({ + text: 'User ID is not valid' + }) + return false + } } + sendMail(to.value, messageContent.value, subject.value) return false }