From b8cb3adfc69ee1dbc2ae4758d20b357d7e48d351 Mon Sep 17 00:00:00 2001 From: Mic Date: Mon, 1 Sep 2025 23:40:00 +0200 Subject: [PATCH] filtering tags in autotagging. see #289 --- js/mzta-utils-prompt.js | 6 +++++- mzta-background.js | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/js/mzta-utils-prompt.js b/js/mzta-utils-prompt.js index 60c9076b..5c3a8c59 100644 --- a/js/mzta-utils-prompt.js +++ b/js/mzta-utils-prompt.js @@ -126,7 +126,7 @@ export const taPromptUtils = { * For backwords compatibility, if the response text is not a valid JSON, * it will try to split the text by commas and return the resulting array. */ - getTagsFromResponse(response_text){ + getTagsFromResponse(response_text, filter_tags = false, filter_tags_list = ''){ let tags = []; if(response_text && response_text.length > 0){ try { @@ -143,6 +143,10 @@ export const taPromptUtils = { tags = response_text.split(/,\s*/).map(tag => tag.trim()); } } + if(filter_tags && filter_tags_list && filter_tags_list.length > 0){ + const allowedTags = filter_tags_list.split(',').map(tag => tag.trim().toLowerCase()).filter(tag => tag.length > 0); + tags = tags.filter(tag => allowedTags.includes(tag.toLowerCase())); + } return tags; } }; \ No newline at end of file diff --git a/mzta-background.js b/mzta-background.js index b82438e1..03c705e7 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -973,6 +973,8 @@ async function processEmails(messages, addTagsAuto, spamFilter) { add_tags_auto_force_existing: prefs_default.add_tags_auto_force_existing, add_tags_enabled_accounts: prefs_default.add_tags_enabled_accounts, add_tags_exclusions_exact_match: prefs_default.add_tags_exclusions_exact_match, + add_tags_auto_uselist: prefs_default.add_tags_auto_uselist, + add_tags_auto_uselist_list: prefs_default.add_tags_auto_uselist_list, spamfilter_enabled_accounts: prefs_default.spamfilter_enabled_accounts, }); @@ -1020,7 +1022,7 @@ async function processEmails(messages, addTagsAuto, spamFilter) { await cmd_addTags.initWorker(); let tags_current_email = []; try { - tags_current_email = taPromptUtils.getTagsFromResponse(await cmd_addTags.sendPrompt()); + tags_current_email = taPromptUtils.getTagsFromResponse(await cmd_addTags.sendPrompt(), prefs_aats.add_tags_auto_uselist, prefs_aats.add_tags_auto_uselist_list); } catch (err) { console.error("[ThunderAI | Auto add_tags] Error getting tags: ", err); }