handle bad user ids in mail ui better

This commit is contained in:
Kevin Froman 2020-10-14 22:28:56 +00:00
parent e0f59784b1
commit c2b7246048
3 changed files with 23 additions and 9 deletions

View File

@ -1,5 +1,5 @@
{
"name" : "pms",
"version" : "0.1.1",
"version" : "0.1.2",
"author" : "onionr"
}

View File

@ -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

View File

@ -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){
let getInstances = function(string, word) {
return string.split(word).length - 1;
}
if(getInstances(to.value, '-') != 15){
if (to.value.length != 56 && to.value.length != 52){
PNotify.error({
text: 'User ID is not valid'
})
return false
}
}
else{
sendMail(to.value, messageContent.value, subject.value)
}
return false
}