mail_full_headers placeholder added. see #713
This commit is contained in:
parent
9c50345127
commit
7c984dc74d
4 changed files with 29 additions and 4 deletions
|
|
@ -668,6 +668,10 @@
|
|||
"message": "Mail headers",
|
||||
"description": ""
|
||||
},
|
||||
"placeholder_mail_full_headers": {
|
||||
"message": "All mail headers",
|
||||
"description": ""
|
||||
},
|
||||
"placeholder_selected_text": {
|
||||
"message": "Selected text",
|
||||
"description": ""
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ Example in a prompt: `"Summarize this email: {%mail_text_body_or_selected%}"`
|
|||
| `identity_signature` | Current identity signature | 0 |
|
||||
| `additional_text[id]` | User input field (dynamic, shows input in popup) | 0 |
|
||||
| `mail_header:name` | Any email header by name (dynamic) | 1 |
|
||||
| `mail_full_headers` | All mail headers (key: value format, newline-separated) | 1 |
|
||||
|
||||
## Dynamic Placeholders
|
||||
|
||||
|
|
|
|||
|
|
@ -127,6 +127,15 @@ const defaultPlaceholders = [
|
|||
is_dynamic: "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',
|
||||
name: "__MSG_placeholder_selected_text__",
|
||||
|
|
@ -568,6 +577,9 @@ export const placeholdersUtils = {
|
|||
case 'mail_headers':
|
||||
finalSubs['mail_headers:' + currPH.custom_value] = placeholdersUtils.failSafePlaceholders(sanitizeMailHeaders(await getMailHeader(curr_message, currPH.custom_value)));
|
||||
break;
|
||||
case 'mail_full_headers':
|
||||
finalSubs['mail_full_headers'] = placeholdersUtils.failSafePlaceholders(sanitizeMailHeaders(await getMailHeader(curr_message)));
|
||||
break;
|
||||
case 'selected_text':
|
||||
finalSubs['selected_text'] = placeholdersUtils.failSafePlaceholders(selection_text);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -215,13 +215,21 @@ export async function replaceBody(tabId, replyHtml) {
|
|||
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 full_message = await browser.messages.getFull(curr_message.id);
|
||||
// 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())){
|
||||
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;
|
||||
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())];
|
||||
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)
|
||||
return mail_header_value;
|
||||
|
|
|
|||
Loading…
Reference in a new issue