postal-mime 2.1.1-patch.1 → 2.1.2
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 +8 -0
- package/README.md +127 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.1.2](https://github.com/postalsys/postal-mime/compare/v2.1.1...v2.1.2) (2024-02-29)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **git:** re-renamed git repo ([29d235e](https://github.com/postalsys/postal-mime/commit/29d235ece222844dc59858d9e991cc85f65733e2))
|
|
9
|
+
* **git:** Renamed git repository ([829e537](https://github.com/postalsys/postal-mime/commit/829e5371602f87fe114d87130c6e9953d50872b4))
|
|
10
|
+
|
|
3
11
|
## [2.1.1](https://github.com/postalsys/postal-mime/compare/v2.1.0...v2.1.1) (2024-02-26)
|
|
4
12
|
|
|
5
13
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,130 @@
|
|
|
1
1
|
# postal-mime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Email parser for browser environments.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
PostalMime can be run in the main web thread or from Web Workers.
|
|
6
|
+
|
|
7
|
+
## Source
|
|
8
|
+
|
|
9
|
+
Source code is available from [Github](https://github.com/postalsys/postal-mime).
|
|
10
|
+
|
|
11
|
+
## Demo
|
|
12
|
+
|
|
13
|
+
See this [example](https://kreata.ee/postal-mime/example/).
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
First install the module from npm:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
$ npm install postal-mime
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
next import the PostalMime class into your script:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import PostalMime from './node_modules/postal-mime/src/postal-mime.js';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or when using from a Node.js app
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import PostalMime from 'postal-mime';
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Promises
|
|
36
|
+
|
|
37
|
+
All postal-mime methods use Promises, so you need to wait using `await` or wait for the `then()` method to fire until you get the response.
|
|
38
|
+
|
|
39
|
+
#### Browser
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import PostalMime from './node_modules/postal-mime/src/postal-mime.js';
|
|
43
|
+
|
|
44
|
+
const parser = new PostalMime();
|
|
45
|
+
const email = await parser.parse(`Subject: My awesome email 🤓
|
|
46
|
+
Content-Type: text/html; charset=utf-8
|
|
47
|
+
|
|
48
|
+
<p>Hello world 😵💫</p>`);
|
|
49
|
+
|
|
50
|
+
console.log(email.subject);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Node.js
|
|
54
|
+
|
|
55
|
+
It is pretty much the same as in the browser.
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import PostalMime from 'postal-mime';
|
|
59
|
+
import util from 'node:util';
|
|
60
|
+
|
|
61
|
+
const parser = new PostalMime();
|
|
62
|
+
const email = await parser.parse(`Subject: My awesome email 🤓
|
|
63
|
+
Content-Type: text/html; charset=utf-8
|
|
64
|
+
|
|
65
|
+
<p>Hello world 😵💫</p>`);
|
|
66
|
+
|
|
67
|
+
console.log(util.inspect(email, false, 22, true));
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Cloudflare [Email Workers](https://developers.cloudflare.com/email-routing/email-workers/)
|
|
71
|
+
|
|
72
|
+
Pretty much the same as in Node.js. Use `message.raw` as the raw message for parsing.
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
import PostalMime from 'postal-mime';
|
|
76
|
+
|
|
77
|
+
export default {
|
|
78
|
+
async email(message, env, ctx) {
|
|
79
|
+
const parser = new PostalMime();
|
|
80
|
+
const email = await parser.parse(message.raw);
|
|
81
|
+
|
|
82
|
+
console.log('Subject: ', email.subject);
|
|
83
|
+
console.log('HTML: ', email.html);
|
|
84
|
+
console.log('Text: ', email.text);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### parser.parse()
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
parser.parse(email) -> Promise
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Where
|
|
96
|
+
|
|
97
|
+
- **email** is the rfc822 formatted email. Either a string, an ArrayBuffer, a Blob object or a Node.js Buffer
|
|
98
|
+
|
|
99
|
+
> **NB** you can call `parse()` only once. If you need to parse another message, create a new _PostalMime_ object.
|
|
100
|
+
|
|
101
|
+
This method parses an email message into a structured object with the following properties:
|
|
102
|
+
|
|
103
|
+
- **headers** is an array of headers in the same order as found from the message (topmost headers first).
|
|
104
|
+
- **headers[].key** is lowercase key of the header line, eg. `"dkim-signature"`
|
|
105
|
+
- **headers[].value** is the unprocessed value of the header line
|
|
106
|
+
- **from**, **sender**, **replyTo** includes a processed object for the corresponding headers
|
|
107
|
+
- **from.name** is decoded name (empty string if not set)
|
|
108
|
+
- **from.address** is the email address
|
|
109
|
+
- **deliveredTo**, **returnPath** is the email address from the corresponding header
|
|
110
|
+
- **to**, **cc**, **bcc** includes an array of processed objects for the corresponding headers
|
|
111
|
+
- **to[].name** is decoded name (empty string if not set)
|
|
112
|
+
- **to[].address** is the email address
|
|
113
|
+
- **subject** is the email subject line
|
|
114
|
+
- **messageId**, **inReplyTo**, **references** includes the value as found from the corresponding header without any processing
|
|
115
|
+
- **date** is the email sending time formatted as an ISO date string (unless parsing failed and in this case the original value is used)
|
|
116
|
+
- **html** is the HTML content of the message as a string
|
|
117
|
+
- **text** is the plaintext content of the message as a string
|
|
118
|
+
- **attachments** is an array that includes message attachments
|
|
119
|
+
- **attachment[].filename** is the file name if provided
|
|
120
|
+
- **attachment[].mimeType** is the MIME type of the attachment
|
|
121
|
+
- **attachment[].disposition** is either "attachment", "inline" or `null` if disposition was not provided
|
|
122
|
+
- **attachment[].related** is a boolean value that indicats if this attachment should be treated as embedded image
|
|
123
|
+
- **attachment[].contentId** is the ID from Content-ID header
|
|
124
|
+
- **attachment[].content** is an ArrayBuffer that contains the attachment file
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
© 2021-2023 Andris Reinman
|
|
129
|
+
|
|
130
|
+
`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.1.
|
|
3
|
+
"version": "2.1.2",
|
|
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.22",
|
|
31
31
|
"cross-blob": "3.0.2",
|
|
32
32
|
"cross-env": "7.0.3",
|
|
33
33
|
"eslint": "8.57.0",
|