Import/export or retrieve Thunderbird tags from IMAP server

I'm still very interested in an answer to my first question, but regarding my second question, I found out that the tags are actually saved in the "prefs.js" file, which is in the Thunderbird profile folder. Example for the tag "Important":

user_pref("mailnews.tags.$label1.color", "#FF0000");
user_pref("mailnews.tags.$label1.tag", "Important");

(User-defined tags are also found in that file; not just predefined tags.)

So saving this file is probably a good way to easily make a backup of the tags that have been defined in Thunderbird. As for restoring those tags in another profile, I have not tested it, but maybe simply copying those lines in the file (when TB is not running) would do the trick.

Edit: I now have tested it and can confirm that it works.

Also, as mentionned by @Hovestar in their answer, the tags can be put inside a user.js file instead of editing the prefs.js directly (which isn't recommended). The content of the user.js file will be copied to prefs.js when Thunderbird launches.

It should be noted that this only works one way. Tags created in Thunderbird will not automatically be copied into user.js. So this method is useful to import tags into Thunderbird, but you cannot rely on this file to export your tags.

Also, I ran into a small encoding problem when using this approach: special characters (such as "é") in user.js appeared as "é" in prefs.js. (This was only visible in the file itself, not in the Thunderbird interface.) But saving the prefs.js file with UTF-8 encoding was enough to solve this problem.