Skip to content

Conversation

@gdkrmr
Copy link

@gdkrmr gdkrmr commented Jan 2, 2026

Adds an option to the context menu to summarize single emails and email threads and allows the user to chat with them.

  • Customizable templates
  • No icon for the context menu yet
  • The default prompts probably need some fine tuning
  • There are probably still some bugs.
  • It fails silently for email threads that are too long; the limit can be changed in the options, but it is reached easily for long conversations.

Context menu:

context menu

Summary:

hpspam

Asking questions:

hpspamask

export const contextMenuIconsPath = {
[contextMenuID_AddTags]: 'moz-extension:images/autotags.png',
[contextMenuID_Spamfilter]: 'moz-extension:images/spamfilter.png',
// [contextMenuID_Summarize]: 'moz-extension:images/summarize.png',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no icon yet. If you have a good idea, go ahead and add one.

@micz
Copy link
Owner

micz commented Jan 2, 2026

Thank you Guido for your PR!
It will fit also for #580. I think I'll add an option to let the user choose between automatic summary or manually via the context menu.
Don't worry for the icon, I'll add it.

I'm currently working on version 3.8.0 in this branch that simplifies a lot how special prompts work in regard of the different integration APIs and the default settings.

May you rebase this PR to that branch?
Thank you again!

@micz
Copy link
Owner

micz commented Jan 2, 2026

What do you think about adding the summary directly in the mail body, as PR #579 does?
Your PR is opening the webchat collecting a list of emails, I was thinking about summarizing a single message, waiting for #152 to be implemented for a real thread summarization.

@gdkrmr
Copy link
Author

gdkrmr commented Jan 2, 2026

It will fit also for #580. I think I'll add an option to let the user choose between automatic summary or manually via the context menu.

What do you think about adding the summary directly in the mail body, as PR #579 does?

I think the automatic summary inside of the email (#579/#580) sounds very cool. Both options can be useful, and the user should be able to use both. I am personally more interested in the ability to summarize threads and ask questions about them, so the ability to select more than one email is important to me, but this does not mean that won't appreciate automatic summaries when opening emails.

Regarding #152 : You can already get this by "context menu" -> "open" -> "open message in conversation". There you can just collapse the thread and then use "context menu" -> "summarize" from my PR. It is a couple of more clicks but also gives a bit more control in case you want to exclude an email.

I'm currently working on version 3.8.0 in this branch that simplifies a lot how special prompts work in regard of the different integration APIs and the default settings.

May you rebase this PR to that branch?

👍

@gdkrmr gdkrmr marked this pull request as draft January 2, 2026 22:06
@micz
Copy link
Owner

micz commented Jan 3, 2026

Regarding #152 : You can already get this by "context menu" -> "open" -> "open message in conversation". There you can just collapse the thread and then use "context menu" -> "summarize" from my PR. It is a couple of more clicks but also gives a bit more control in case you want to exclude an email.

You are right, this gives a workaround waiting for that feature in the Thunderbird API.

@gdkrmr gdkrmr force-pushed the gk/thread_summary branch from b057c31 to 81c626a Compare January 3, 2026 11:37
@micz
Copy link
Owner

micz commented Jan 3, 2026

You should also change the PR base to be the branch v3.8.0.
If you want I can do it for you.

@gdkrmr gdkrmr changed the base branch from main to v3.8.0 January 4, 2026 11:31
@gdkrmr
Copy link
Author

gdkrmr commented Jan 4, 2026

Question: Currently I have separators between emails in both the prompt as well as in concatenation. Where should they go?

https://github.com/gdkrmr/ThunderAI/blob/5fdbce06487d2315a5468723e47200da103fb3d8/mzta-background.js#L1062

Translations are auto generated, right?

I think you can review the PR now.

@gdkrmr gdkrmr marked this pull request as ready for review January 4, 2026 11:37
@micz
Copy link
Owner

micz commented Jan 4, 2026

You need to prepare also the final prompt, to handle placeholders.

For the concatenation, I'd like to have an option in the special prompt page to define it. The default value should be a translated string and not something hardcoded, so that the user can define it.

For the translation, do not worry, there is no need to add it to the PR, I manage the translation on weblate.

@gdkrmr
Copy link
Author

gdkrmr commented Jan 7, 2026

  • All prompts handle placeholders now
  • there is a third prompt field for a separator between emails

One issue I see is that placeholders that do not exist, e.g. emails without attachments, don't get replaced:

Attachments:
{%mail_attachments_info%}

It doesn't really matter for the LLM but it would probably be better to replace them with a default value (e.g. "none") but I don't think this should be part of this PR.

When loading ThunderAI, I get the following error message, not sure if it is my fault:

image

@micz
Copy link
Owner

micz commented Jan 9, 2026

* there is a third prompt field for a separator between emails

I was thinking about using a parameter, but a dedicated prompt might be more flexible.

May you handle the enable and disable of the button in the option page, like the tag and spamfilter ones?

One issue I see is that placeholders that do not exist, e.g. emails without attachments, don't get replaced:

Attachments:
{%mail_attachments_info%}

With the "Placeholders: use default value" option selected it should use an empty string instead of the placeholder tag. do you have that option active?

When loading ThunderAI, I get the following error message, not sure if it is my fault:
image

This is my fault. I fixed it in aa0fd97, thank you!

@micz
Copy link
Owner

micz commented Jan 9, 2026

Could you also add descriptions for the three prompts on the management page to explain their purpose?

@gdkrmr gdkrmr force-pushed the gk/thread_summary branch from f0773d8 to 51c8141 Compare January 10, 2026 22:00
@gdkrmr
Copy link
Author

gdkrmr commented Jan 10, 2026

This is my fault. I fixed it in aa0fd97, thank you!

Rebased onto v3.8.0, error is gone. 👍

I was thinking about using a parameter, but a dedicated prompt might be more flexible.

Let me know if you want me to change it, see also comment at the end. Folding this one into the other two prompts is possible and decreases the amount of code.

May you handle the enable and disable of the button in the option page, like the tag and spamfilter ones?

Ahh, didn't notice this one before, thanks! I only require messagesRead permissions, right? Should work now.

With the "Placeholders: use default value" option selected it should use an empty string instead of the placeholder tag. do you have that option active?

Option was unchecked. Works as intended, thanks!

Could you also add descriptions for the three prompts on the management page to explain their purpose?

Done, please let me know if they are not clear enough.

Also:

  • When reloading the addon, sometimes I get the following error. I have the suspicion that this happens after I change something in the code regarding the options but I am not quite sure:
image
  • Here are two minor issues:
    • In the AI chat, there are quite a lot of stray quotes.
    • The actual email address is missing from the From: field if the email is of the form Name <[email protected]>.
image
  • We should think about final forms of the actual prompts, I like the following suggestion by ChatGPT:
You are an assistant that summarizes email conversations.

Given an email thread, produce a concise, accurate summary that captures:

The main topic or purpose of the conversation

Key decisions, conclusions, or agreements

Important questions, requests, or action items

Who is responsible for each action item (if stated)

Omit greetings, signatures, quoted text, and redundant back-and-forth.
Do not add assumptions or information not present in the emails.

Write the summary in clear, neutral language suitable for a busy professional.


EMAIL THREAD
------------

[Email 1]
From: Alice Johnson <[email protected]>
To: Bob Smith <[email protected]>
Date: 2025-01-03 09:14
Subject: Project timeline update

Body:
The client approved the revised timeline.
We can move the delivery to March 15.

---

[Email 2]
From: Bob Smith <[email protected]>
To: Alice Johnson <[email protected]>
Date: 2025-01-03 10:02
Subject: Re: Project timeline update

Body:
Great. I’ll notify the engineering team and update the roadmap.
  • finally: Is there a way to strip footers, legal disclaimers, quoted replies (only makes sense if reply is not inline), etc. These will mostly increase token count and have a chance of confusing the LLM.


// Add Context menu: Summarize
if(prefs_init.summarize && prefs_init.summarize_context_menu && checkAPIIntegration(prefs_init.connection_type && prefs_init.summarize_use_specific_integration, prefs_init.summarize_connection_type)) {
console.log("adding summarize to context menu")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed before merging.

summarize_el.addEventListener('click', (event) => {
async function _summarize_el_change() {
if (event.target.checked) {
let granted = await messenger.permissions.request({ permissions: ["messagesRead"] });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

messageRead is not an optional permission, so you can't ask for it here. The permission is mandatory to install ThunderAI. See the mainfest.json file.
In the logs there is this error: "Uncaught (in promise) Error: Cannot request permission messagesRead since it was not declared in optional_permissions"

spamfilter_context_menu: true,
spamfilter_enabled_accounts: [],
summarize: false,
summarize_context_menu: true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have added this option that is used in the mzta-background script, but there is no way for the user to change it. I use a similar option for add_tags and spamfilter, but I'm thiking about removing it and always show the menuitem when the user has activated the feature. I think you could remove it and always show the context menu when the summurize feature is activated.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed issue #609

@micz
Copy link
Owner

micz commented Jan 11, 2026

You need to add these to the en locale file:

prompt_summarize_email_template_full_text
prompt_summarize_email_separator_full_text

You are using prompt_summarize_email_template and prompt_summarize_email_separator as the full text, but this one should be only the prompt name. Also fix the reset buttons on click methods on the summirize page.

let getting = await browser.storage.sync.get(prefs_default);

let specialPrompts = await getSpecialPrompts();
let addtags_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_add_tags');
Copy link
Owner

@micz micz Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to update for summarize this code pasted from add_tags.

@micz
Copy link
Owner

micz commented Jan 11, 2026

I was thinking about using a parameter, but a dedicated prompt might be more flexible.

Let me know if you want me to change it, see also comment at the end. Folding this one into the other two prompts is possible and decreases the amount of code.

I think we can keep it this way.

Also:

When reloading the addon, sometimes I get the following error. I have the suspicion that this happens after I change something in the code regarding the options but I am not quite sure:

image

In your actual code at that line there is no call that uses prefs.
If it happens again, check the new line number and share it. Thanks.

In the AI chat, there are quite a lot of stray quotes.

The problem is in the preparePrompt method: when there are no placeholders it uses the mail_body.
If the mail_body is empty you see the "".

You need to change line 53 of mzta-utils-prompt.js with:

fullPrompt = curr_prompt.text + (String(curr_prompt.need_signature) == "1" ? " " + await taPromptUtils.getDefaultSignature():"") + " " + chatgpt_lang + ((selection_text!='' || body_text != '')? " \"" + (selection_text=='' ? body_text : selection_text) + "\" " : '');

This has to be tested against all the other prompts if they continue to work.

The actual email address is missing from the From: field if the email is of the form Name <[email protected]>.

I think this happens when the mail body is converted from html to text.
May you check it?

We should think about final forms of the actual prompts, I like the following suggestion by ChatGPT:

Find a generic prompt that for you is working ok and we can use it as standard.

finally: Is there a way to strip footers, legal disclaimers, quoted replies (only makes sense if reply is not inline), etc. These will mostly increase token count and have a chance of confusing the LLM.

I checked it in the past, but there is no standard about it, so it's not possibile to be sure to strip the correct part of the email.

Thank you for all the work you are putting in adding this feature!!
I'm going to release version 3.8.0 in the next few days, then I usually wait some days to fix any bug and then I'll start working on the next major version where we can add this one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants