postal-mime 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/LICENSE.txt +1 -1
- package/README.md +16 -19
- package/package.json +2 -2
- package/src/postal-mime.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.2.0](https://github.com/postalsys/postal-mime/compare/v2.1.2...v2.2.0) (2024-03-26)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **interface:** Added statis parse() method to simplify usage (`await PostalMime.parse(email)`) ([c2faa27](https://github.com/postalsys/postal-mime/commit/c2faa276520d6551df640abe008986eebc6d99d3))
|
|
9
|
+
|
|
10
|
+
## [2.1.2](https://github.com/postalsys/postal-mime/compare/v2.1.1...v2.1.2) (2024-02-29)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **git:** re-renamed git repo ([29d235e](https://github.com/postalsys/postal-mime/commit/29d235ece222844dc59858d9e991cc85f65733e2))
|
|
16
|
+
* **git:** Renamed git repository ([829e537](https://github.com/postalsys/postal-mime/commit/829e5371602f87fe114d87130c6e9953d50872b4))
|
|
17
|
+
|
|
3
18
|
## [2.1.1](https://github.com/postalsys/postal-mime/compare/v2.1.0...v2.1.1) (2024-02-26)
|
|
4
19
|
|
|
5
20
|
|
package/LICENSE.txt
CHANGED
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# postal-mime
|
|
2
2
|
|
|
3
|
-
Email parser for browser environments.
|
|
3
|
+
Email parser for browser and serverless environments.
|
|
4
4
|
|
|
5
|
-
PostalMime can be run in the main web thread or from Web Workers.
|
|
5
|
+
PostalMime can be run in the main web thread or from Web Workers. It can also used in serverless functions.
|
|
6
6
|
|
|
7
7
|
## Source
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
The source code is available from [Github](https://github.com/postalsys/postal-mime).
|
|
10
10
|
|
|
11
11
|
## Demo
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ See this [example](https://kreata.ee/postal-mime/example/).
|
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
|
-
First install the module from npm:
|
|
17
|
+
First, install the module from npm:
|
|
18
18
|
|
|
19
19
|
```
|
|
20
20
|
$ npm install postal-mime
|
|
@@ -26,7 +26,7 @@ next import the PostalMime class into your script:
|
|
|
26
26
|
import PostalMime from './node_modules/postal-mime/src/postal-mime.js';
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
or when using from a Node.js app
|
|
29
|
+
or when using from a Node.js app or in a serverless function:
|
|
30
30
|
|
|
31
31
|
```js
|
|
32
32
|
import PostalMime from 'postal-mime';
|
|
@@ -34,15 +34,14 @@ import PostalMime from 'postal-mime';
|
|
|
34
34
|
|
|
35
35
|
### Promises
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
PostalMime methods use Promises, so you need to wait using `await` or wait for the `then()` method to fire until you get the response.
|
|
38
38
|
|
|
39
39
|
#### Browser
|
|
40
40
|
|
|
41
41
|
```js
|
|
42
42
|
import PostalMime from './node_modules/postal-mime/src/postal-mime.js';
|
|
43
43
|
|
|
44
|
-
const
|
|
45
|
-
const email = await parser.parse(`Subject: My awesome email 🤓
|
|
44
|
+
const email = await PostalMime.parse(`Subject: My awesome email 🤓
|
|
46
45
|
Content-Type: text/html; charset=utf-8
|
|
47
46
|
|
|
48
47
|
<p>Hello world 😵💫</p>`);
|
|
@@ -58,8 +57,7 @@ It is pretty much the same as in the browser.
|
|
|
58
57
|
import PostalMime from 'postal-mime';
|
|
59
58
|
import util from 'node:util';
|
|
60
59
|
|
|
61
|
-
const
|
|
62
|
-
const email = await parser.parse(`Subject: My awesome email 🤓
|
|
60
|
+
const email = await PostalMime.parse(`Subject: My awesome email 🤓
|
|
63
61
|
Content-Type: text/html; charset=utf-8
|
|
64
62
|
|
|
65
63
|
<p>Hello world 😵💫</p>`);
|
|
@@ -76,8 +74,7 @@ import PostalMime from 'postal-mime';
|
|
|
76
74
|
|
|
77
75
|
export default {
|
|
78
76
|
async email(message, env, ctx) {
|
|
79
|
-
const
|
|
80
|
-
const email = await parser.parse(message.raw);
|
|
77
|
+
const email = await PostalMime.parse(message.raw);
|
|
81
78
|
|
|
82
79
|
console.log('Subject: ', email.subject);
|
|
83
80
|
console.log('HTML: ', email.html);
|
|
@@ -86,17 +83,17 @@ export default {
|
|
|
86
83
|
};
|
|
87
84
|
```
|
|
88
85
|
|
|
89
|
-
####
|
|
86
|
+
#### PostalMime.parse()
|
|
87
|
+
|
|
88
|
+
`parse(email)` is a static class method to parse emails
|
|
90
89
|
|
|
91
90
|
```js
|
|
92
|
-
|
|
91
|
+
PostalMime.parse(email) -> Promise
|
|
93
92
|
```
|
|
94
93
|
|
|
95
94
|
Where
|
|
96
95
|
|
|
97
|
-
- **email** is the rfc822 formatted email. Either a string, an ArrayBuffer, a Blob object
|
|
98
|
-
|
|
99
|
-
> **NB** you can call `parse()` only once. If you need to parse another message, create a new _PostalMime_ object.
|
|
96
|
+
- **email** is the rfc822 formatted email. Either a string, an ArrayBuffer/Uint8Array value, a Blob object, a Node.js Buffer, or a [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream)
|
|
100
97
|
|
|
101
98
|
This method parses an email message into a structured object with the following properties:
|
|
102
99
|
|
|
@@ -121,10 +118,10 @@ This method parses an email message into a structured object with the following
|
|
|
121
118
|
- **attachment[].disposition** is either "attachment", "inline" or `null` if disposition was not provided
|
|
122
119
|
- **attachment[].related** is a boolean value that indicats if this attachment should be treated as embedded image
|
|
123
120
|
- **attachment[].contentId** is the ID from Content-ID header
|
|
124
|
-
- **attachment[].content** is an
|
|
121
|
+
- **attachment[].content** is an Uint8Array value that contains the attachment file
|
|
125
122
|
|
|
126
123
|
## License
|
|
127
124
|
|
|
128
|
-
© 2021-
|
|
125
|
+
© 2021-2024 Andris Reinman
|
|
129
126
|
|
|
130
127
|
`postal-mime` is licensed under the **MIT No Attribution license**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postal-mime",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Email parser for browser environments",
|
|
5
5
|
"main": "./src/postal-mime.js",
|
|
6
6
|
"exports": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"author": "Andris Reinman",
|
|
28
28
|
"license": "MIT-0",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/node": "20.11.
|
|
30
|
+
"@types/node": "20.11.30",
|
|
31
31
|
"cross-blob": "3.0.2",
|
|
32
32
|
"cross-env": "7.0.3",
|
|
33
33
|
"eslint": "8.57.0",
|
package/src/postal-mime.js
CHANGED
|
@@ -4,6 +4,11 @@ import addressParser from './address-parser.js';
|
|
|
4
4
|
import { decodeWords, textEncoder, blobToArrayBuffer } from './decode-strings.js';
|
|
5
5
|
|
|
6
6
|
export default class PostalMime {
|
|
7
|
+
static parse(buf) {
|
|
8
|
+
const parser = new PostalMime();
|
|
9
|
+
return parser.parse(buf);
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
constructor() {
|
|
8
13
|
this.root = this.currentNode = new MimeNode({
|
|
9
14
|
postalMime: this
|