diff --git a/README.md b/README.md index f278197..3e68f7a 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,8 @@ Where: - **email**: The RFC822 formatted email. This can be a string, an ArrayBuffer/Uint8Array, a Blob object, a Node.js Buffer, or a [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream). - **options**: An optional object containing configuration options. - - **rfc822Attachments**: A boolean (defaults to `false`). If set to `true`, it treats `Message/RFC822` attachments without a Content-Disposition declaration as attachments. By default, these messages are treated as inline values. + - **rfc822Attachments**: A boolean (defaults to `false`). If set to `true`, then treats `message/rfc822` attachments without a Content-Disposition declaration as attachments. By default, these messages are treated as inline values. + - **forceRfc822Attachments**: A boolean (defaults to `false`). If set to `true`, then treats all `message/rfc822` nodes as attachments. This method parses an email message into a structured object with the following properties: diff --git a/postal-mime.d.ts b/postal-mime.d.ts index 170e45f..b202190 100644 --- a/postal-mime.d.ts +++ b/postal-mime.d.ts @@ -53,7 +53,8 @@ declare function decodeWords ( ): string; declare type PostalMimeOptions = { - rfc822Attachments?: boolean + rfc822Attachments?: boolean, + forceRfc822Attachments?: boolean } declare class PostalMime { diff --git a/src/postal-mime.js b/src/postal-mime.js index 09b8914..37b293d 100644 --- a/src/postal-mime.js +++ b/src/postal-mime.js @@ -339,6 +339,10 @@ export default class PostalMime { // Check if this is a specially crafted report email where message/rfc822 content should not be inlined forceRfc822Attachments() { + if (this.options.forceRfc822Attachments) { + return true; + } + let forceRfc822Attachments = false; let walk = node => { if (!node.contentType.multipart) { diff --git a/test/postal-mime-test.js b/test/postal-mime-test.js index cdf6f87..1a5216b 100644 --- a/test/postal-mime-test.js +++ b/test/postal-mime-test.js @@ -91,6 +91,15 @@ test('Parse mimetorture email', async t => { assert.strictEqual(email.attachments.length, 9); }); +test('Parse mimetorture email as attachments', async t => { + const mail = await readFile(Path.join(process.cwd(), 'test', 'fixtures', 'mimetorture.eml')); + + const parser = new PostalMime({ forceRfc822Attachments: true }); + const email = await parser.parse(mail); + + assert.strictEqual(email.attachments.length, 10); +}); + test('Parse calendar email', async t => { const mail = await readFile(Path.join(process.cwd(), 'test', 'fixtures', 'calendar-event.eml'));