jobisoft / quicktext

An extension for Thunderbird that lets you create templates that can be easily inserted into your own emails.
Mozilla Public License 2.0
187 stars 53 forks source link

Match "is not a function" #328

Closed jtoddv closed 2 years ago

jtoddv commented 2 years ago

Has worked for over a year, but today it seems to have stopped working. I see that the last update of the extension was on Sept 10th, 2022 (v5.2) running in Thunderbird 102.2.2 (64-bit).

I have a Quicktext script GetName that used str.match(regex) to parse out the name from a submitted email. This same script now errors out with the following:

There was an error in your Quicktext script: GetName TypeError: paragraph.match is not a function Line 4: let found = paragraph.match(regex);

Here is the code of the two functions used to get the name:

GetMailBody Script:

var editor = this.mWindow.gMsgCompose.editor;
var text = editor.outputToString('text/plain', 8);
return text;

GetName Script:

const paragraph = this.mQuicktext.get_script(["GetMailBody"]);
const regex = /Name:\s(.*?)\s/smi;
let found = paragraph.match(regex);
return found[1];

Any help on why this stopped working would be appreciated.

SamuelPlentz commented 2 years ago

This is related to: #271 and #320

Try to add await like this:

GetMailBody Script

var editor = this.mWindow.gMsgCompose.editor;
var text = editor.outputToString('text/plain', 8);
return text;

GetName Script

const paragraph = await this.mQuicktext.get_script(["GetMailBody"]);
const regex = /Name:\s(.*?)\s/smi;
let found = paragraph.match(regex);
if (found == null) return "no match found"; // aditionally i would add a line like that
return found[1];
SamuelPlentz commented 2 years ago

IMO close.

jtoddv commented 2 years ago

Thanks, Samuel! Worked.