MCPcopy Index your code
hub / github.com/mailvelope/mailvelope / parseMIME

Function parseMIME

src/modules/mime.js:29–71  ·  view source on GitHub ↗
(raw, encoding)

Source from the content-addressed store, hash-verified

27}
28
29async function parseMIME(raw, encoding) {
30 let message = '';
31 const attachments = [];
32 const parsed = mailreader.parse([{raw}]);
33 if (parsed?.length) {
34 const htmlParts = [];
35 const textParts = [];
36 if (encoding === 'html') {
37 filterBodyParts(parsed, 'html', htmlParts);
38 if (htmlParts.length) {
39 message = await mvelo.util.sanitizeHTML(htmlParts.map(part => part.content).join('\n<hr>\n'));
40 } else {
41 filterBodyParts(parsed, 'text', textParts);
42 if (textParts.length) {
43 message = await mvelo.util.text2autoLinkHtml(textParts.map(part => part.content).join('\n<hr>\n'));
44 }
45 }
46 } else if (encoding === 'text') {
47 filterBodyParts(parsed, 'text', textParts);
48 if (textParts.length) {
49 message = textParts.map(part => part.content).join('\n\n');
50 } else {
51 filterBodyParts(parsed, 'html', htmlParts);
52 if (htmlParts.length) {
53 message = htmlParts.map(part => html2text(part.content)).join('\n\n');
54 }
55 }
56 }
57 filterBodyParts(parsed, 'attachment', attachments);
58 for (const part of attachments) {
59 part.filename = encodeHTML(part.filename);
60 part.content = ab2str(part.content.buffer);
61 }
62
63 // prepend subject line using i18n label
64 const subject = parsed[0].subject;
65 if (subject) {
66 const subjectLabel = l10n.get('editor_label_subject');
67 message = `<strong>${subjectLabel}: </strong>${encodeHTML(subject)}\n<hr>\n${message}`;
68 }
69 }
70 return {message, attachments, parsed};
71}
72
73async function parseInline(raw, encoding) {
74 // raw is a JS binary string of UTF-8 bytes — decode to a display-ready Unicode string once here.

Callers 3

parseMessageFunction · 0.85
parseSignedMessageFunction · 0.85
parseFunction · 0.85

Calls 5

html2textFunction · 0.90
encodeHTMLFunction · 0.90
ab2strFunction · 0.90
filterBodyPartsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected