Skip to content

Sandbox script: Support reading async variables without parameters (e.g. %from%) within script #329

Closed

Description

@RealRaven2000

In the following example we try to read the %identity% variable and do something within the script:

%{%
  (async () => {
  let val = await identity;
  switch(val) {
    case 'email1@acme.com':
      return "<p>The parameter email1@acme.com was read from Clipboard.</p>";
    default:
      return `<p>Other value retrieved from Clipboard: ${val}</p>`;
  }
})()
%}%

Expected behavior: identity should retrieve the same string that %identity% would. The problem here is that the function isn't fully executed. Instead it returns an empty function or throws "ERR: TypeError: can't convert val to string ". The workaround would be to add parentheses, like this:

(async () => {
  let val = await identity();
})()

But this returns the string %identity% - because by design an empty parameter list was not allowed.

As an acceptable workaround I tried supplying an empty string as argument, like this:

(async () => {
  let val = await identity("");
})()

Interestingly, this returns an empty string at the moment. Let's implement this to work so that it returns the variable value like this:

await from("")   =>  %from%
await identity("")   =>  %identity%
await clipboard("")   =>  %clipboard%

Activity

  1. changed the title [-]Sandbox script: variables without parameters cannot be evaluated within script[/-] [+]Sandbox script: Support reading variables without parameters (e.g. %from%) within script[/+] on Oct 26, 2024
  2. RealRaven2000 commented on Oct 26, 2024

    @RealRaven2000
    OwnerAuthor

    While testing, I also encountered an interesting behavior of the %clipboard()% function: It will preferably return html as format, so if we copy an email address from composer in the editing area, it will return a string like:

    <html><body>
    <!--StartFragment-->thunderbirddaily@gmail.com<!--EndFragment-->
    </body>
    </html>

    so we will need a way of dealing with this, maybe by forcing plain text through a parameter. See new issue #330

  3. RealRaven2000 commented on Oct 26, 2024

    @RealRaven2000
    OwnerAuthor

    Preview version:

    smartTemplate-fx-4.9pre82.zip

    this one supports using empty parentheses to return data without passing parameters, in order to get the result string %from% like this:

    var t = await from();

    To install version above download zip file and drag the file into Thunderbird Add-ons Manager (do not extract contents, it won't install like that)

  4. added a commit that references this issue on Oct 26, 2024
  5. changed the title [-]Sandbox script: Support reading variables without parameters (e.g. %from%) within script[/-] [+]Sandbox script: Support reading variables without parameters (e.g. `%from%`) within script[/+] on Oct 31, 2024
  6. changed the title [-]Sandbox script: Support reading variables without parameters (e.g. `%from%`) within script[/-] [+]Sandbox script: Support reading async variables without parameters (e.g. `%from%`) within script[/+] on Oct 31, 2024
  7. RealRaven2000 commented on Nov 11, 2024

    @RealRaven2000
    OwnerAuthor

    Implemented in 4.9 - published 11/11/2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions