Skip to content

Commit

Permalink
v1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Jan 15, 2021
1 parent 7ca5e9e commit dac5b74
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ parser.parse(email) -> Promise
Where
- **email** is the rfc822 formatted email. Either a string, an ArrayBuffer or a Blob object
- **email** is the rfc822 formatted email. Either a string, an ArrayBuffer, a Blob object or a Node.js Buffer
> **NB** you can call `parse()` only once. If you need to parse another message, create a new _PostalMime_ object.
Expand Down
16 changes: 16 additions & 0 deletions example/node-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* globals globalThis, require, Buffer */

globalThis.Blob = require('cross-blob');
const PostalMime = require('../dist/node').postalMime.default;

new PostalMime()
.parse(
Buffer.from(
`Subject: test
From: andris@kreata.ee
To: andris@ethereal.email
Hello world`
)
)
.then(res => console.log(res));
109 changes: 102 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postal-mime",
"version": "1.0.6",
"version": "1.0.7",
"description": "Email parser for browser environments",
"main": "dist/postal-mime.js",
"scripts": {
Expand All @@ -16,6 +16,7 @@
"author": "Andris Reinman",
"license": "AGPL-3.0-or-later",
"devDependencies": {
"cross-blob": "^2.0.0",
"eslint": "7.17.0",
"eslint-cli": "1.1.1",
"webpack": "5.11.1",
Expand Down
8 changes: 8 additions & 0 deletions src/postal-mime.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ export default class PostalMime {
}
this.started = true;

// should it thrown on empty value instead?
buf = buf || ArrayBuffer(0);

if (typeof buf === 'string') {
// cast string input to ArrayBuffer
buf = textEncoder.encode(buf);
Expand All @@ -210,6 +213,11 @@ export default class PostalMime {
buf = await blobToArrayBuffer(buf);
}

if (buf.buffer instanceof ArrayBuffer) {
// Node.js Buffer object or Uint8Array
buf = new Uint8Array(buf).buffer;
}

this.buf = buf;
this.av = new Uint8Array(buf);
this.readPos = 0;
Expand Down

0 comments on commit dac5b74

Please sign in to comment.