-
Notifications
You must be signed in to change notification settings - Fork 58
Description
Quicktext v6 has reached its second milestone in being converted to the WebExtension technology. The ultimate goals of this effort are described in the announcement for the first milestone. Everything mentioned there is still important, so if you have not read that, please do so soon.
One major change in v6 is the new script engine. Quicktext v5 executed scripts with system privileges and just like Quicktext itself, scripts had full access to the user's computer and could do everything. This is no longer the case for Quicktext v6.
TL;DR - What changed?
The following properties have been moved:
this.mVariables->this.quicktext.variablesthis.mQuicktext.get_<tag>([...])->await this.quicktext.getTag("<tag>", ...)
Example:
let rcpt = await this.quicktext.getTag('to', 'lastname');`
The following property has been removed:
this.mWindow
Quicktext scripts now run with reduced privileges and can no longer use core functions of the compose window, or access its DOM elements. Most things formaly done via this.mWindow.* can still be achieved via this.compose.* (internal scripts) or via messenger.compose.* (external scripts).
Internal scripts
These scripts are how we used to define scripts in the "Scripts" tab of the Quicktext Manager UI. Internal scripts run with minimal privileges, but Quicktext exposes a subset of the official WebExtension APIs:
this.compose.*-> compose APIthis.messages.*-> messages APIthis.identities.*-> identities API
The methods of this.compose.* differ from the methods of the official compose API: The first tabId parameter must not be specified, as the methods available to internal scripts will always act on the current compose window.
Note: The WebExtension APIs are used by add-on developers, are well documented and aim to be stable. That means scripts will not break anymore when a new version of Thunderbird is released.
To see everything that is available to internal scripts, use the following script and check the result printed to the error comsole:
console.log(this)
Currently, this will return something like the following:
Example
The AddRecipients community script now has to look like this:
let type = this.quicktext.variables[0];
let adresses = this.quicktext.variables[1].split(';');
if (!type || !["to", "cc", "bcc", "reply-to"].includes(type)) {
return;
}
if (type == "reply-to") {
type = "replyTo";
}
let details = await this.compose.getComposeDetails();
let recipients = new Set([...details[type], ...adresses].map(e => e.trim()));
await this.compose.setComposeDetails({
[type]: Array.from(recipients)
});
Scripts no longer manipulate the compose fields directly, but can use getComposeDetails() to pull information from the composer and setComposeDetails() to update properties of the composer.
External scripts
There will be cases, where the API methods available to internal scripts will be insufficient. Furthermore, there might even be cases where scripts still need to do everything. Both scenarios can be solved by external scripts.
An external script is shipped in a separate add-on. Since it can be executed natively, it can use all WebExtension APIs. For advanced use-cases, such an external script add-on can even include an Experiment and have full access to the user's system again.
We created the Quicktext Community Scripts Add-on which provides most of the former community scripts. This does not only serve as a blueprint for custom script add-ons, but is intended to provide script support for the most common use-cases. Instead of manually maintaining scripts, users can install the Community Script Add-on.
If the Quicktext Community Script Add-on is installed, any of its stored scripts can be used in Quicktext via the CSCRIPT tag. Its first parameter is the name of the requested script, followed by variables passed into the script. The tag to execute its AddRecipients script has to look as follows:
[[CSCRIPT=AddRecipients|to|user@inter.net]]
In order to execute scripts of a custom script add-on, Quicktext needs to know the add-on's id. This is accomplished through the ESCRIPT tag. Since the id of the Community Script Add-on is quicktext.scripts@community.jobisoft.de, its AddRecipients script can also be executed via:
[[ESCRIPT=quicktext.scripts@community.jobisoft.de|AddRecipients|to|user@inter.net]]
The first parameter is the id of the script add-on, the second parameter is the name of the requested script, followed by variables passed into the script.
Need more help?
The converted community scripts shipped with the Quicktext Community Scripts Add-on should give you an idea how to convert your scripts.
