mail_full_headers placeholder added. see #713

This commit is contained in:
mic 2026-04-10 23:33:15 +02:00
parent 9c50345127
commit 7c984dc74d
4 changed files with 29 additions and 4 deletions

View file

@ -668,6 +668,10 @@
"message": "Mail headers", "message": "Mail headers",
"description": "" "description": ""
}, },
"placeholder_mail_full_headers": {
"message": "All mail headers",
"description": ""
},
"placeholder_selected_text": { "placeholder_selected_text": {
"message": "Selected text", "message": "Selected text",
"description": "" "description": ""

View file

@ -43,6 +43,7 @@ Example in a prompt: `"Summarize this email: {%mail_text_body_or_selected%}"`
| `identity_signature` | Current identity signature | 0 | | `identity_signature` | Current identity signature | 0 |
| `additional_text[id]` | User input field (dynamic, shows input in popup) | 0 | | `additional_text[id]` | User input field (dynamic, shows input in popup) | 0 |
| `mail_header:name` | Any email header by name (dynamic) | 1 | | `mail_header:name` | Any email header by name (dynamic) | 1 |
| `mail_full_headers` | All mail headers (key: value format, newline-separated) | 1 |
## Dynamic Placeholders ## Dynamic Placeholders

View file

@ -127,6 +127,15 @@ const defaultPlaceholders = [
is_dynamic: "1", is_dynamic: "1",
enabled: 1, enabled: 1,
}, },
{
id: 'mail_full_headers',
name: "__MSG_placeholder_mail_full_headers__",
default_value: "",
type: 1,
is_default: "1",
is_dynamic: "0",
enabled: 1,
},
{ {
id: 'selected_text', id: 'selected_text',
name: "__MSG_placeholder_selected_text__", name: "__MSG_placeholder_selected_text__",
@ -568,6 +577,9 @@ export const placeholdersUtils = {
case 'mail_headers': case 'mail_headers':
finalSubs['mail_headers:' + currPH.custom_value] = placeholdersUtils.failSafePlaceholders(sanitizeMailHeaders(await getMailHeader(curr_message, currPH.custom_value))); finalSubs['mail_headers:' + currPH.custom_value] = placeholdersUtils.failSafePlaceholders(sanitizeMailHeaders(await getMailHeader(curr_message, currPH.custom_value)));
break; break;
case 'mail_full_headers':
finalSubs['mail_full_headers'] = placeholdersUtils.failSafePlaceholders(sanitizeMailHeaders(await getMailHeader(curr_message)));
break;
case 'selected_text': case 'selected_text':
finalSubs['selected_text'] = placeholdersUtils.failSafePlaceholders(selection_text); finalSubs['selected_text'] = placeholdersUtils.failSafePlaceholders(selection_text);
break; break;

View file

@ -215,14 +215,22 @@ export async function replaceBody(tabId, replyHtml) {
await messenger.compose.setComposeDetails(tabId, {body: fullBody}); await messenger.compose.setComposeDetails(tabId, {body: fullBody});
} }
export async function getMailHeader(curr_message, mail_header_id) { export async function getMailHeader(curr_message, mail_header_id = false) {
let mail_header_value = ""; let mail_header_value = "";
let full_message = await browser.messages.getFull(curr_message.id); let full_message = await browser.messages.getFull(curr_message.id);
// console.log(">>>>>>>>>>>> getMailHeader full_message: " + JSON.stringify(full_message)); // console.log(">>>>>>>>>>>> getMailHeader full_message: " + JSON.stringify(full_message));
if(full_message.hasOwnProperty("headers") && Object.keys(full_message.headers).some(header => header.toLowerCase() === mail_header_id.toLowerCase())){ if(full_message.hasOwnProperty("headers")) {
if(mail_header_id) {
if(Object.keys(full_message.headers).some(header => header.toLowerCase() === mail_header_id.toLowerCase())){
const raw_value = full_message.headers[Object.keys(full_message.headers).find(header => header.toLowerCase() === mail_header_id.toLowerCase())]; const raw_value = full_message.headers[Object.keys(full_message.headers).find(header => header.toLowerCase() === mail_header_id.toLowerCase())];
mail_header_value = Array.isArray(raw_value) ? raw_value.join(", ") : raw_value; mail_header_value = Array.isArray(raw_value) ? raw_value.join(", ") : raw_value;
} }
} else {
mail_header_value = Object.entries(full_message.headers)
.map(([key, value]) => key + ": " + (Array.isArray(value) ? value.join(", ") : value))
.join("\n");
}
}
// console.log(">>>>>>>>>>>> getMailHeader mail_header_value: " + mail_header_value) // console.log(">>>>>>>>>>>> getMailHeader mail_header_value: " + mail_header_value)
return mail_header_value; return mail_header_value;
} }