From 5fdd47dd62f3296910252f5e126a87f0228c9ff2 Mon Sep 17 00:00:00 2001 From: mic Date: Fri, 13 Dec 2024 00:10:14 +0100 Subject: [PATCH] mail_tags and full_tags_list placeholders added. see #197 and #198 --- _locales/en/messages.json | 8 ++++++++ js/mzta-menus.js | 10 +++++++++- js/mzta-placeholders.js | 14 ++++++++++++++ js/mzta-utils.js | 31 +++++++++++++++++++++++++++++++ manifest.json | 1 + 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 1e71de0f..cb3f3238 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -758,5 +758,13 @@ "prompt_add_tags_full_text": { "message": "Analyze the following email text and generate a comma-separated list of tags that summarize its content. Use themes, key topics, and relevant descriptors as tags. Ensure the tags are concise and relevant to the email's content.\nEmail text: {%mail_text_body%}\nConsider the following details for context:\n- Sender: {%author%}\n- Recipients: {%recipients%}\n- CC list: {%cc_list%}\n- Email subject: {%mail_subject%}\nPlease base your tags on the email's text and context, ignoring unnecessary information or trivial details.", "description": "" + }, + "placeholder_mail_tags": { + "message": "Mail tags", + "description": "" + }, + "placeholder_full_tags_list": { + "message": "Existing tags", + "description": "" } } \ No newline at end of file diff --git a/js/mzta-menus.js b/js/mzta-menus.js index 43343dc1..2c761f5e 100644 --- a/js/mzta-menus.js +++ b/js/mzta-menus.js @@ -19,7 +19,7 @@ // Some original methods are derived from https://github.com/ali-raheem/Aify/blob/cfadf52f576b7be3720b5b73af7c8d3129c054da/plugin/html/actions.js import { getPrompts } from './mzta-prompts.js'; -import { getLanguageDisplayName, getMenuContextCompose, getMenuContextDisplay, i18nConditionalGet, getMailSubject } from './mzta-utils.js' +import { getLanguageDisplayName, getMenuContextCompose, getMenuContextDisplay, i18nConditionalGet, getMailSubject, getTagsList, transformTagsLabels } from './mzta-utils.js' import { taLogger } from './mzta-logger.js'; import { placeholdersUtils } from './mzta-placeholders.js'; import { mzta_specialCommand_AddTags } from './special_commands/mzta-add-tags.js'; @@ -115,6 +115,7 @@ export class mzta_Menus { } let fullPrompt = ''; + let full_tags_list = await getTagsList(); if(!placeholdersUtils.hasPlaceholder(curr_prompt.text)){ // no placeholders, do as usual fullPrompt = curr_prompt.text + (String(curr_prompt.need_signature) == "1" ? " " + await this.getDefaultSignature():"") + " " + chatgpt_lang + " \"" + (selection_text=='' ? body_text : selection_text) + "\" "; @@ -152,6 +153,13 @@ export class mzta_Menus { case 'junk_score': finalSubs['junk_score'] = curr_message.junkScore; break; + case 'mail_tags': + let mail_tags_array = await transformTagsLabels(curr_message.tags, full_tags_list[1]); + finalSubs['mail_tags'] = mail_tags_array.join(", "); + break; + case 'full_tags_list': + finalSubs['full_tags_list'] = full_tags_list[0]; + break; default: // TODO Manage custom placeholders https://github.com/micz/ThunderAI/issues/156 break; } diff --git a/js/mzta-placeholders.js b/js/mzta-placeholders.js index 5c1fbff8..f799f930 100644 --- a/js/mzta-placeholders.js +++ b/js/mzta-placeholders.js @@ -96,6 +96,20 @@ const defaultPlaceholders = [ type: 0, is_default: "1", }, + { + id: 'mail_tags', + name: "__MSG_placeholder_mail_tags__", + default_value: "", + type: 0, + is_default: "1", + }, + { + id: 'full_tags_list', + name: "__MSG_placeholder_full_tags_list__", + default_value: "", + type: 0, + is_default: "1", + }, ]; diff --git a/js/mzta-utils.js b/js/mzta-utils.js index e7974246..7070698a 100644 --- a/js/mzta-utils.js +++ b/js/mzta-utils.js @@ -176,6 +176,37 @@ export function generateCallID(length = 10) { return result; } +export async function getTagsList(){ + let messageTags = {}; + if(isThunderbird128OrGreater()) { + messageTags = await browser.messages.tags.list(); + } else { + messageTags = await browser.messages.listTags(); + } + const output = messageTags.map(tag => tag.tag).join(', '); + + const output2 = messageTags.reduce((acc, messageTag) => { + acc[messageTag.key] = { + tag: messageTag.tag, + color: messageTag.color, + key: messageTag.key, + ordinal: messageTag.ordinal, + }; + return acc; + }, {}); + + return [output, output2]; // Return the list of tags and the list of tags objects as an array +} + +export async function transformTagsLabels(labels, tags_list) { + console.log(">>>>>>>>> transformTagsLabels labels: " + labels); + console.log(">>>>>>>>> transformTagsLabels tags_list: " + tags_list); + let output = []; + for(let label of labels) { + output.push(tags_list[label].tag); + } + return output; +} // The following methods are a modified version derived from https://github.com/ali-raheem/Aify/blob/13ff87583bc520fb80f555ab90a90c5c9df797a7/plugin/content_scripts/compose.js diff --git a/manifest.json b/manifest.json index c931b144..c4525c21 100644 --- a/manifest.json +++ b/manifest.json @@ -31,6 +31,7 @@ "activeTab", "accountsRead", "downloads", + "messagesTagsList", "https://*.chatgpt.com/*" ], "background": {