From 5fbead1fcc45162f52fe9ca4112d84d097d859f4 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 9 Feb 2025 22:45:09 +0100 Subject: [PATCH] getMailBody method added. see #237 --- js/mzta-utils.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/js/mzta-utils.js b/js/mzta-utils.js index d9b995c7..17b70de4 100644 --- a/js/mzta-utils.js +++ b/js/mzta-utils.js @@ -83,6 +83,29 @@ export async function getMailSubject(tab){ } } +export async function getMailBody(fullMessage){ + let text = ''; + let html = ''; + + if (fullMessage.contentType.trim().toLowerCase() === "text/plain") { + text = fullMessage.body; + } + if (fullMessage.contentType.trim().toLowerCase() === "text/html") { + html = fullMessage.body; + } + + for (let part of fullMessage.parts) { + if (part.contentType.trim().toLowerCase() === "text/plain") { + text = part.body; + } + if (part.contentType.trim().toLowerCase() === "text/html") { + html = part.body; + } + } + + return {text, html}; +} + export async function reloadBody(tabId){ let composeDetails = await messenger.compose.getComposeDetails(tabId); let originalHtmlBody = composeDetails.body + " ";