- commit
- 881d283b0cc941c867037c8d57d02f9b073bc681
- parent
- 84d066dd6942ea827761d873431ce80980fce664
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-09-15 07:45
tb128: use new APIs to get message body
Diffstat
| M | content/js/body.js | 19 | ++++++++++++++++--- |
| M | content/js/util.js | 22 | ---------------------- |
| M | experiment-api/api.js | 11 | ----------- |
| M | experiment-api/schema.json | 8 | -------- |
4 files changed, 16 insertions, 44 deletions
diff --git a/content/js/body.js b/content/js/body.js
@@ -79,11 +79,24 @@ export default function(msg) {
79 79 var pre = document.createElement('pre');
80 80 pre.className = 'message__body';
81 81 wrapper.append(pre);
82 -1 browser.xi.getFull(msg.id).then(util.getBody).then(([body, isEncrypted]) => {
83 -1 if (isEncrypted) {
-1 82 browser.messages.listInlineTextParts(msg.id).then(async parts => {
-1 83 var body = '';
-1 84 if (parts.some(p => p.contentType.startsWith('text/plain'))) {
-1 85 body = parts
-1 86 .filter(p => p.contentType.startsWith('text/plain'))
-1 87 .map(p => p.content)
-1 88 .join('\n\n');
-1 89 } else if (parts.some(p => p.contentType.startsWith('text/html'))) {
-1 90 var html = parts.find(p => p.contentType.startsWith('text/html')).content;
-1 91 body = await browser.messengerUtilities.convertToPlainText(html);
-1 92 } else if (parts.length) {
-1 93 body = parts[0].content;
-1 94 }
-1 95
-1 96 if (msg.full.decryptionStatus !== 'none') {
84 97 wrapper.prepend(util.createAlert(browser.i18n.getMessage('encrypted'), 'lock', 'info'));
85 98 }
86 -1 renderBody(pre, body || msg.body || browser.i18n.getMessage('emptyBody'));
-1 99 renderBody(pre, body || browser.i18n.getMessage('emptyBody'));
87 100 });
88 101
89 102 return wrapper;
diff --git a/content/js/util.js b/content/js/util.js
@@ -16,28 +16,6 @@ export var getParams = function() {
16 16 return params;
17 17 };
18 18
19 -1 export var getBody = function(msgPart) {
20 -1 if (msgPart.body && msgPart.contentType.startsWith('text/plain')) {
21 -1 return [msgPart.body, msgPart.isEncrypted];
22 -1 } else if (msgPart.parts) {
23 -1 var bodies = [];
24 -1 var encrypted = (
25 -1 msgPart.isEncrypted
26 -1 && !msgPart.contentType.startsWith('multipart/signed')
27 -1 );
28 -1 for (var part of msgPart.parts) {
29 -1 var [body, e] = getBody(part);
30 -1 if (body) {
31 -1 bodies.push(body);
32 -1 encrypted |= e;
33 -1 }
34 -1 }
35 -1 return [bodies.join('\n\n'), encrypted];
36 -1 } else {
37 -1 return ['', false];
38 -1 }
39 -1 };
40 -1
41 19 export var h = function(tag, attrs, children) {
42 20 var el = document.createElement(tag);
43 21 for (let attr in attrs) {
diff --git a/experiment-api/api.js b/experiment-api/api.js
@@ -3,7 +3,6 @@ 3 3 var {ExtensionCommon} = ChromeUtils.import('resource://gre/modules/ExtensionCommon.jsm'); 4 4 var {Gloda} = ChromeUtils.import('resource:///modules/gloda/GlodaPublic.jsm'); 5 5 var {GlodaConstants} = ChromeUtils.import('resource:///modules/gloda/GlodaConstants.jsm');6 -1 var {MsgHdrToMimeMessage} = ChromeUtils.import('resource:///modules/gloda/MimeMessage.jsm');7 6 var {MailServices} = ChromeUtils.import('resource:///modules/MailServices.jsm'); 8 7 9 8 var unique = function(l, keyFn) { @@ -78,16 +77,6 @@ var xi = class extends ExtensionCommon.ExtensionAPI { 78 77 // https://bugzilla.mozilla.org/show_bug.cgi?id=1665676 79 78 return getConversation(ids).then(results => results.map(glodaMsg2msg)); 80 79 },81 -1 getFull(id) {82 -1 // the original getFull() is restricted to these fields:83 -1 // body, contentType, headers, name partName, size84 -1 var msgHdr = context.extension.messageManager.get(id);85 -1 return new Promise(resolve => {86 -1 MsgHdrToMimeMessage(msgHdr, null, (aMsgHdr, aMimeMsg) => {87 -1 resolve(aMimeMsg);88 -1 }, false, {examineEncryptedParts: true});89 -1 });90 -1 },91 80 viewSource(id) { 92 81 var win = Services.wm.getMostRecentWindow('mail:3pane'); 93 82 var msgHdr = context.extension.messageManager.get(id);
diff --git a/experiment-api/schema.json b/experiment-api/schema.json
@@ -12,14 +12,6 @@ 12 12 } 13 13 }] 14 14 }, {15 -1 "name": "getFull",16 -1 "type": "function",17 -1 "async": true,18 -1 "parameters": [{19 -1 "name": "id",20 -1 "type": "integer"21 -1 }]22 -1 }, {23 15 "name": "viewSource", 24 16 "type": "function", 25 17 "async": false,