Skip to content

Commit

Permalink
fix(message/rfc822): Added option 'forceRfc822Attachments' to handle …
Browse files Browse the repository at this point in the history
…all message/rfc822 nodes as attachments instead of inline content
  • Loading branch information
andris9 committed Sep 23, 2024
1 parent 9aa543a commit bf47621
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion postal-mime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ declare function decodeWords (
): string;

declare type PostalMimeOptions = {
rfc822Attachments?: boolean
rfc822Attachments?: boolean,
forceRfc822Attachments?: boolean
}

declare class PostalMime {
Expand Down
4 changes: 4 additions & 0 deletions src/postal-mime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions test/postal-mime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down

0 comments on commit bf47621

Please sign in to comment.