RealRaven2000 / SmartTemplates

Thunderbird Add-on: SmartTemplates
http://smarttemplates.quickfolders.org/
Other
25 stars 15 forks source link

Feature request: `%tags%` Variable #320

Open infinitelyintrigued opened 1 week ago

infinitelyintrigued commented 1 week ago

I use Thunderbird tags to categorize emails. I would like to see a variable (e.g., %tags%) to embed assigned tag names in templates (e.g., tag1,tag2,....)

It would also be great if the variable can do pattern matching optionally (e.g, %tags("pattern")% for matching and %tags("^pattern") non-matching) to include and exclude some tags.

I use the same tag names in other applications that have their own email addresses. Being able to tag reply and forward messages will be a great time-saver.

Thank you

RealRaven2000 commented 1 week ago

Maybe something like this

%tags()%                 -- (return all tags - comma separated)
%tags(matchPattern)%        -- returns matching tags (regular expression)
%tags(matchPattern,excludePattern)%   -- returns matching tags, exluding matches of 2nd expression
%tags(matchPattern,excludePattern,toclipboard)%  --literal parameter to copy the list to the clipboard.

I think it could also be useful to optionally restrict to just one tag somehow, if there was some processing or a field that couldn't take multiple tags?

infinitelyintrigued commented 1 week ago

Looks good to me. I can't wait to see this new feature!

RealRaven2000 commented 4 days ago

Here is a first test version. Currently only supports 2 uses %tags% and %tags(color)% [this one only makes sense in HTML emails, just a little thing I added for better visibblity] - try it out!

smartTemplate-fx-4.8.2pre24.zip


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)

infinitelyintrigued commented 4 days ago

Yes, it works. Very nice. This will help me a lot!

I have one more request if you don't mind. Could you also provide an option to format each tag name? Some applications I use automatically recognize a text as a tag when it's prefixed with a special character such as "#". For example, %tags produces "tag1,tag2,tag3,..." and %tags(format:"#\0")% produces "#tag1,#tag2,#tag3"?

RealRaven2000 commented 4 days ago

I have one more request if you don't mind. Could you also provide an option to format each tag name? Some applications I use automatically recognize a text as a tag when it's prefixed with a special character such as "#". For example, %tags produces "tag1,tag2,tag3,..." and %tags(format:"#\0")% produces "#tag1,#tag2,#tag3"?

I will look into it. At the moment I am just wrapping the whole lot like this:

      for (let t of tags) {
        const labelObject = `<span style="color:${t.color}; border: 1px solid ${t.color};border-radius: 0.2em; padding: 0.05em 0.1em;">${t.label}</span>`;
        labelAtoms.push(labelObject);
      }

I already thought to myself that the formatting string (which is now hard coded) could be somehow configurable in a global preferences somewhere.

infinitelyintrigued commented 4 days ago

Thank you. I'll be looking forward to it. The current implementation is very helpful as it is. I can feel my workflow is smoother.

RealRaven2000 commented 4 days ago

I think this might be a good candidate to tie to one of the license levels either SmartTemplates Pro only or at least ST Standard with some restrictions. Simply making it a Pro feature would be my preference, as it is a little outside the wheel house of the ordinary user. I have to make sure that I convert a few more users to licensees as I am putting a lot of work in which isn't currently reflected in sales. Partly a problem of it being too complex of course, but that's to be addressed in a different topic.

infinitelyintrigued commented 3 days ago

I think it makes sense to make it a pro-only feature.

RealRaven2000 commented 1 day ago

Here is a new version with more features:

smartTemplate-fx-4.8.2pre36.zip

you can add the following parameters:

color this will use a preset format with colored labels (as before) delimiter="-" what to put in between the tags. If this is not given as parameters it defaults to , (a single comma followed by a single space) format="formatString" how to format each tag label toclipboard copies the result to the clipboard instead of inserting it

formatString can contain single or multiple instances of $label$ and $color$

$label$ placeholder for the tag text $color$ 6 digit hex value of the tag's color

Example:

%tags(color,delimiter=" ")%

result (used in a standard quote header with small font): image


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

RealRaven2000 commented 1 day ago

Had to edit the previous comment, because MarkDown messed with my $label$ and $color$ parameters (by removing the $ signs and turning them into italic text instead).

RealRaven2000 commented 1 day ago

I have one more request if you don't mind. Could you also provide an option to format each tag name? Some applications I use automatically recognize a text as a tag when it's prefixed with a special character such as "#". For example, %tags produces "tag1,tag2,tag3,..." and %tags(format:"#\0")% produces "#tag1,#tag2,#tag3"?

with the latest version I linked above, please try:

  %tags(format="#$label$",delimiter=",")%
infinitelyintrigued commented 1 day ago

I have this code in my template. (I copied/pasted your sample code.)

<b>Tags</b>: %tags(format="#$label$",delimiter=",")%

The tags are rendered like this:

#tag1#tag2#tag3

without the comma delimiter.

I also could not get the color parameter to work right. Could you show me a sample code with the format and delimiter parameters?

But I'm already very excited about this release!

RealRaven2000 commented 1 day ago

The tags are rendered like this:

#tag1#tag2#tag3

without the comma delimiter.

Looks like there is a problem with the comma (it is swallowed by the parser that breaks up the parameters, which are also delimited by commas. Had to write a fix and you will also have to escape the comma with a \ backslash. Like below; I also tried the second way with some color to stress test it, and had to make it more robust because of the "=" within the second format string:

%tags(format="#$label$",delimiter="\,")%
or
%tags(format="<span style='background-color:$color$;color:white;border-radius:0.2em;'>#$label$</span>",delimiter="\,")%

the second one looks like this: image

New version. [Make sure to put \, instead of , for the delimiter]:

smartTemplate-fx-4.8.2pre41.zip


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

infinitelyintrigued commented 1 day ago

I got the first example (the comma delimiter) to work correctly. This makes a big difference.

The second color example turned out to be tricky. I use Visual Studio code to edit templates. The Prettier formatter is turned on by default. This formatting engine breaks up a long line into multiple lines. The second color example is a long line. The Prettier broke it up into multiple lines when the template was saved. This also broke %tags%. I edited the template in another text editor and restored it into a single line. Then %tags% worked.

Another thing I noticed was that my Thunderbird (128.2.1esr (64-bit) on Pop!_OS 22.04) could not render the colors. Consequently, the result was the same as the first example's. However, Firefox was able to render correctly after I saved the rendered message as an HTML file and opened it in Firefox.

RealRaven2000 commented 49 minutes ago

Another thing I noticed was that my Thunderbird (128.2.1esr (64-bit) on Pop!_OS 22.04) could not render the colors. Consequently, the result was the same as the first example's. However, Firefox was able to render correctly after I saved the rendered message as an HTML file and opened it in Firefox.

I am wondering if you have plain text only emails enabled? The HTML (with inline CSS) should display everything as expected as long as you are editing in HTML mode. Although even if I have the command in my account template and force replying in plain text (holding down Shift while clicking Reply) I still see the tags in color`, albeit with monospaced font:

image

so it's a little strange, can you look at the generated markup in Composer (I use ThunderHTMLEdit)? you can also investigate the HTML in Composer by highlighting portions of the text (best more than a line or across tag boundaries) and selecting insert >> html from the menu - this will display the HTML of the selected text:

image

In the meantime I also added support for the [[optional section]] syntax for tags, with this Composer can leave out a line if there are no tags in the replied / follow-up email. For instance:

[[<p> Tags: %tags(color)% </p>]]

This will make a paragraph with tags but only if at least on exists. otherwise it will not insert the paragraph. I have similar functionality for all address headers, such as cc, bcc, which can generate nicer, more concise quote headers.

smartTemplate-fx-4.8.2pre44.zip


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

RealRaven2000 commented 19 minutes ago

And I also added an optional text transformation parameter (use one of uppercase,lowercase,capitalize,camelcase) for the tag labels.

smartTemplate-fx-4.8.2pre46.zip

Example:

[[<p> Tags: %tags(format="<span style='font-size:0.8em;background-color:$color$;color:white;border-radius:0.2em;padding-inline:0.1em;'>$label$</span>",delimiter=" ",uppercase)% </p>]]

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