(raw, encoding)
| 27 | } |
| 28 | |
| 29 | async 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 | |
| 73 | async function parseInline(raw, encoding) { |
| 74 | // raw is a JS binary string of UTF-8 bytes — decode to a display-ready Unicode string once here. |
no test coverage detected