Ability to insert attachments into a script
In a script, I need to insert an attachment whose name varies according to criteria calculated in this script. For example, the script will determine that the attachment named "Order_4525.pdf" or "Quotation_2512.pdf" or "Invoice_8852.pdf" must be sent. I can't find a solution to insert the attachment from the script. Is there a solution ?
Quicktext v6 will support that. Before I send you to the pre-release I need one more piece of information. Where is the data (the binary content) for the attachment coming from? Is it pulled in via a REST API call?
In my use case, the PDF file would most often come from a call like "https://myprestashop.site/index.php?controller=pdf-invoice&secure_key=84d39cccc6ba7dd61e994bbe3fc3b878&id_order=11420"
It would also be desirable to be able to attach a file from a local drive or a network share.
Ok, here is some information about the pre-release: https://github.com/jobisoft/quicktext/issues/439#issue-2941411864
Access to local files or mounted network files is possible, but more complicated. The easy part is pulling the data via fetch. A script could look like so:
let response = await fetch(url);
let buffer = await response.arrayBuffer();
let file = new File([buffer], "filename", { type: "application/pdf"});
await this.compose.addAttachment({ file });
Quicktext v6 exposes some of the WebExtension APIs to scripts. To see what is available, do a console.log(this). At the moment some methods from the compose API, the messages API and the identities API are exposed. The methods in this.compose.* differ a bit from the official WebExtension APIs, as they do not require the first tabId parameter, they use the correct one for you automatically.
Documentation for addAttachment:
https://webextension-api.thunderbird.net/en/stable/compose.html#addattachment-tabid-attachment
There is one issue though: The server you are pulling the PDF from needs to accept CORS requests. If that is not the case, you need to use the alternative approach and use an external script instead of an internal script (which is the old "normal" script defined directly in Quicktext's script input box). I gave some explanations about external scripts here: https://github.com/jobisoft/quicktext/issues/439#issuecomment-2770711121
The external script will be inside a custom add-on, and that add-on can request the "<all_urls>" permission, which bypasses CORS limitations. That add-on can also include an Experiment to allow file system access, which Quicktext as a pure WebExtension can no longer do. Examples of external script add-ons:
- custom script addon: https://github.com/jobisoft/quicktext/issues/432#issuecomment-2771676171
- community script addon: https://github.com/jobisoft/quicktext/releases/download/v6.3.2/quicktext-community-scripts_1_1.xpi
Would be interested in feedback, once you got it working.