diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9340f3b3..133cc365 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@
[All APIs] In the API WebChat is now possibile to select a part of the answer and use only that [#356].
[All APIs] Setting the "Max prompt length" to zero on the options page will disable the length check when sending a prompt to the AI. [#380].
[All APIs] Added a button to the options page to reset the 'Max prompt length' value to its default.
+ [All APIs] Adding tags automatically or with the context menu will now use also tags not created by ThunderAI [#390].
Fix: in the Spamfilter page the unsaved changes warning is now correctly shown.
Fix: The default keyboard shortcut is no longer enforced at every Thunderbird startup [#384].
Fix: Incoming email processing now works correctly when auto-tagging is enabled and the full tagging feature is subsequently disabled.
diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index 1b7df299..22d88aa8 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -1116,7 +1116,7 @@
"description": ""
},
"prefs_OptionText_add_tags_auto_force_existing": {
- "message": "Force existing tags when autotagging",
+ "message": "Force existing tags when autotagging or using the context menu",
"description": ""
},
"prefs_OptionText_add_tags_auto_force_existing_Info": {
diff --git a/js/mzta-addatags-exclusion-list.js b/js/mzta-addatags-exclusion-list.js
index ae44eaba..06a103bd 100644
--- a/js/mzta-addatags-exclusion-list.js
+++ b/js/mzta-addatags-exclusion-list.js
@@ -16,8 +16,9 @@
* along with this program. If not, see .
*/
-// These methods are also defined in the file /js/mzta-compose-script.js
+
+// These methods are also defined in the file /js/mzta-compose-script.js
export async function addTags_getExclusionList() {
let prefs_excluded_tags = await browser.storage.local.get({add_tags_exclusions: []});
return prefs_excluded_tags.add_tags_exclusions;
diff --git a/js/mzta-utils.js b/js/mzta-utils.js
index 12904797..b044d2db 100644
--- a/js/mzta-utils.js
+++ b/js/mzta-utils.js
@@ -350,21 +350,66 @@ export async function createTag(tag) {
}
}
-export function checkIfTagExists(tag, tags_list) {
- return tags_list.hasOwnProperty("$ta-" + sanitizeString(tag));
+// export function checkIfTagExists(tag, tags_list) {
+// console.log(">>>>>>>>>>> checkIfTagExists tags_list: " + JSON.stringify(tags_list));
+// console.log(">>>>>>>>>>> checkIfTagExists tag: " + tag);
+// return tags_list.hasOwnProperty("$ta-" + sanitizeString(tag));
+// }
+
+export function checkIfTagLabelExists(tag_label, tags_list) {
+ // console.log(">>>>>>>>>>> checkIfTagExists tags_list: " + JSON.stringify(tags_list));
+ // console.log(">>>>>>>>>>> checkIfTagExists tag_label: " + tag_label);
+ const lowerTagLabel = tag_label.toLowerCase();
+ return Object.values(tags_list).some(label => label.tag.toLowerCase() === lowerTagLabel);
}
+// export async function assignTagsToMessage(messageId, tags) {
+// console.log(">>>>>>>>>>> assignTagsToMessage messageId: tags: " + JSON.stringify(tags));
+// tags = tags.map(tag => `$ta-${sanitizeString(tag)}`);
+// let msg_prop = await browser.messages.get(messageId);
+// tags = tags.concat(msg_prop.tags || []);
+// try {
+// return browser.messages.update(messageId, {tags: tags});
+// } catch (error) {
+// console.error('[ThunderAI] Error assigning tag [messageId: ', messageId, ' - tag: ', tag, ']:', error);
+// }
+// }
+
export async function assignTagsToMessage(messageId, tags) {
- tags = tags.map(tag => `$ta-${sanitizeString(tag)}`);
+ // console.log(">>>>>>>>>>> assignTagsToMessage tags: " + JSON.stringify(tags));
+ let all_tags_list = await getTagsList();
+ all_tags_list = all_tags_list[1];
+ tags = getTagsKeyFromLabel(tags, all_tags_list);
+ // console.log(">>>>>>>>>>> assignTagsToMessage tags after conversion: " + JSON.stringify(tags));
let msg_prop = await browser.messages.get(messageId);
+ // console.log(">>>>>>>>>>> assignTagsToMessage msg_prop.tags: " + JSON.stringify(msg_prop.tags));
tags = tags.concat(msg_prop.tags || []);
+ tags = [...new Set(tags)];
+ // console.log(">>>>>>>>>>> assignTagsToMessage tags after concat: " + JSON.stringify(tags));
try {
- return browser.messages.update(messageId, {tags: tags});
+ await browser.messages.update(messageId, {tags: tags});
+ return tags; // Return the updated tags for confirmation
} catch (error) {
console.error('[ThunderAI] Error assigning tag [messageId: ', messageId, ' - tag: ', tag, ']:', error);
}
}
+function getTagsKeyFromLabel(tag_names, all_tags_list) {
+ const result = [];
+
+ tag_names.forEach(name => {
+ const lowerName = name.toLowerCase();
+ const match = Object.entries(all_tags_list).find(
+ ([, value]) => value.tag.toLowerCase() === lowerName
+ );
+ if (match) {
+ result.push(match[0]);
+ }
+ });
+
+ return result;
+}
+
function sanitizeString(input) {
input = input.toLowerCase();
// Define the regex to match valid characters
diff --git a/mzta-background.js b/mzta-background.js
index 27b24601..da9e1fbf 100644
--- a/mzta-background.js
+++ b/mzta-background.js
@@ -20,12 +20,13 @@ import { mzta_script } from './js/mzta-chatgpt.js';
import { prefs_default } from './options/mzta-options-default.js';
import { mzta_Menus } from './js/mzta-menus.js';
import { taLogger } from './js/mzta-logger.js';
-import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage, getGPTWebModelString, getTagsList, createTag, assignTagsToMessage, checkIfTagExists, getActiveSpecialPromptsIDs, checkSparksPresence, getMessages, getMailBody, extractJsonObject, contextMenuID_AddTags, contextMenuID_Spamfilter, sanitizeChatGPTModelData, sanitizeChatGPTWebCustomData, stripHtmlKeepLines } from './js/mzta-utils.js';
+import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage, getGPTWebModelString, getTagsList, createTag, assignTagsToMessage, checkIfTagLabelExists, getActiveSpecialPromptsIDs, checkSparksPresence, getMessages, getMailBody, extractJsonObject, contextMenuID_AddTags, contextMenuID_Spamfilter, sanitizeChatGPTModelData, sanitizeChatGPTWebCustomData, stripHtmlKeepLines } from './js/mzta-utils.js';
import { taPromptUtils } from './js/mzta-utils-prompt.js';
import { mzta_specialCommand } from './js/mzta-special-commands.js';
import { getSpamFilterPrompt } from './js/mzta-prompts.js';
import { taSpamReport } from './js/mzta-spamreport.js';
import { taWorkingStatus } from './js/mzta-working-status.js';
+import { addTags_getExclusionList } from './js/mzta-addatags-exclusion-list.js';
browser.runtime.onInstalled.addListener(({ reason, previousVersion }) => {
// console.log(">>>>>>>>>>> onInstalled: " + JSON.stringify(reason) + ", previousVersion: " + previousVersion);
@@ -160,16 +161,26 @@ async function _assign_tags(_data, create_new_tags = true) {
// console.log(">>>>>>>>>>>>>>> all_tags_list: " + JSON.stringify(all_tags_list));
taLog.log("assign_tags data: " + JSON.stringify(_data));
let new_tags = [];
- for (const tag of _data.tags) {
- // console.log(">>>>>>>>>>>>>>> tag: " + tag);
- if (create_new_tags && !checkIfTagExists(tag, all_tags_list)) {
+ let add_tags_exclusions_list = await addTags_getExclusionList();
+ taLog.log("add_tags_exclusions_list: " + JSON.stringify(add_tags_exclusions_list));
+ const tags_final = _data.tags.filter(tag =>
+ !add_tags_exclusions_list.some(exclusion =>
+ tag.toLowerCase().includes(exclusion.toLowerCase())
+ )
+ );
+ if(!create_new_tags){
+ taLog.log("Not creating new tags, only assigning existing ones...");
+ }
+ for (const tag of tags_final) {
+ // console.log(">>>>>>>>>>>>>>> tag: " + JSON.stringify(tag));
+ if (create_new_tags && !checkIfTagLabelExists(tag, all_tags_list)) {
taLog.log("Creating tag: " + tag);
await createTag(tag);
}
new_tags.push(tag);
}
- await assignTagsToMessage(_data.messageId, new_tags);
- taLog.log("Assigned tags: " + JSON.stringify(new_tags));
+ let added_tags = await assignTagsToMessage(_data.messageId, new_tags);
+ taLog.log("Assigned tags: " + JSON.stringify(added_tags));
}
messenger.runtime.onMessage.addListener((message, sender, sendResponse) => {
diff --git a/options/mzta-release-notes.html b/options/mzta-release-notes.html
index 02e9565f..2253161e 100644
--- a/options/mzta-release-notes.html
+++ b/options/mzta-release-notes.html
@@ -15,6 +15,7 @@
[All APIs] In the API WebChat is now possibile to select a part of the answer and use only that [#356].
[All APIs] Setting the "Max prompt length" to zero on the options page will disable the length check when sending a prompt to the AI. [#380].
[All APIs] Added a button to the options page to reset the 'Max prompt length' value to its default.
+ [All APIs] Adding tags automatically or with the context menu will now use also tags not created by ThunderAI [#390].
Fix: In the Spamfilter page the unsaved changes warning is now correctly shown.
Fix: The default keyboard shortcut is no longer enforced at every Thunderbird startup [#384].
Fix: Incoming email processing now works correctly when auto-tagging is enabled and the full tagging feature is subsequently disabled.
diff --git a/pages/addtags/mzta-add-tags.css b/pages/addtags/mzta-add-tags.css
index fc254dc4..198b6896 100644
--- a/pages/addtags/mzta-add-tags.css
+++ b/pages/addtags/mzta-add-tags.css
@@ -43,7 +43,7 @@
justify-content: space-between;
}
-#addtags_info_additional_statements, #add_tags_auto_force_existing_tr, #add_tags_auto_only_inbox_tr{
+#addtags_info_additional_statements, #add_tags_auto_only_inbox_tr{
display: none;
}
diff --git a/pages/addtags/mzta-add-tags.html b/pages/addtags/mzta-add-tags.html
index 18f20d48..451100e7 100644
--- a/pages/addtags/mzta-add-tags.html
+++ b/pages/addtags/mzta-add-tags.html
@@ -59,15 +59,6 @@
-
- | __MSG_prefs_OptionText_add_tags_auto_force_existing__ |
-
-
- |
-
| __MSG_prefs_OptionText_add_tags_auto_only_inbox__ |
@@ -86,6 +77,15 @@
|
+
+ | __MSG_prefs_OptionText_add_tags_auto_force_existing__ |
+
+
+ |
+
__MSG_AddTags_prompt_text_title__ __MSG_customPrompts_unsaved_changes__
diff --git a/pages/addtags/mzta-add-tags.js b/pages/addtags/mzta-add-tags.js
index 6e8662b2..50a6bd61 100644
--- a/pages/addtags/mzta-add-tags.js
+++ b/pages/addtags/mzta-add-tags.js
@@ -54,17 +54,14 @@ document.addEventListener('DOMContentLoaded', async () => {
});
let add_tags_auto_el = document.getElementById('add_tags_auto');
- let add_tags_auto_force_existing_tr = document.getElementById('add_tags_auto_force_existing_tr');
let add_tags_auto_only_inbox_tr = document.getElementById('add_tags_auto_only_inbox_tr');
let account_selector_container = document.getElementById('account_selector_container');
let add_tags_auto_infoline = document.getElementById('add_tags_auto_infoline');
add_tags_auto_el.addEventListener('click', (event) => {
- add_tags_auto_force_existing_tr.style.display = event.target.checked ? 'table-row' : 'none';
add_tags_auto_only_inbox_tr.style.display = event.target.checked ? 'table-row' : 'none';
account_selector_container.style.display = event.target.checked ? 'block' : 'none';
add_tags_auto_infoline.style.display = event.target.checked ? 'inline' : 'none';
});
- add_tags_auto_force_existing_tr.style.display = add_tags_auto_el.checked ? 'table-row' : 'none';
add_tags_auto_only_inbox_tr.style.display = add_tags_auto_el.checked ? 'table-row' : 'none';
account_selector_container.style.display = add_tags_auto_el.checked ? 'block' : 'none';
add_tags_auto_infoline.style.display = add_tags_auto_el.checked ? 'inline' : 'none';