* Extract and base64-decode the body of a specific MIME part identified by its * Content-Type prefix (e.g. `text/plain`, `text/html`). Returns the decoded * UTF-8 string.
(mime: string, contentTypePrefix: string)
| 21 | * UTF-8 string. |
| 22 | */ |
| 23 | function decodePart(mime: string, contentTypePrefix: string): string { |
| 24 | const partRegex = new RegExp( |
| 25 | `Content-Type: ${contentTypePrefix}[^\\n]*\\nContent-Transfer-Encoding: base64\\n\\n([\\s\\S]*?)\\n\\n--` |
| 26 | ) |
| 27 | const match = mime.match(partRegex) |
| 28 | if (!match) throw new Error(`No ${contentTypePrefix} part found`) |
| 29 | return Buffer.from(match[1].replace(/\n/g, ''), 'base64').toString('utf-8') |
| 30 | } |
| 31 | |
| 32 | describe('encodeRfc2047', () => { |
| 33 | it('returns ASCII text unchanged', () => { |
no test coverage detected