postal-mime 2.0.1 → 2.1.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/.prettierrc.cjs +8 -0
- package/CHANGELOG.md +20 -0
- package/README.md +19 -0
- package/package.json +6 -5
- package/postal-mime.d.ts +1 -1
- package/src/address-parser.js +8 -0
- package/src/postal-mime.js +29 -0
- /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
package/.prettierrc.cjs
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.1.0](https://github.com/postalsys/postal-mime/compare/v2.0.2...v2.1.0) (2024-02-22)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **workers:** Support Cloudflare Email Workers out of the box ([4904708](https://github.com/postalsys/postal-mime/commit/49047089bf779931dacb4a7b31816b48d1b00840))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **module:** add types to module exports ([#23](https://github.com/postalsys/postal-mime/issues/23)) ([1ee4a42](https://github.com/postalsys/postal-mime/commit/1ee4a427643d71f6a4bda0db0ebe0b5b280e52ae))
|
|
14
|
+
|
|
15
|
+
## [2.0.2](https://github.com/postalsys/postal-mime/compare/v2.0.1...v2.0.2) (2023-12-08)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **test:** Added a tests runner and some tests ([8c6f7fb](https://github.com/postalsys/postal-mime/commit/8c6f7fb495b0158756fc11482a717e8081cede86))
|
|
21
|
+
* **test:** Added test action ([c43c086](https://github.com/postalsys/postal-mime/commit/c43c0865dae74a7f20e32885a5860d8654f0c932))
|
|
22
|
+
|
|
3
23
|
## [2.0.1](https://github.com/postalsys/postal-mime/compare/v2.0.0...v2.0.1) (2023-11-05)
|
|
4
24
|
|
|
5
25
|
|
package/README.md
CHANGED
|
@@ -67,6 +67,25 @@ Content-Type: text/html; charset=utf-8
|
|
|
67
67
|
console.log(util.inspect(email, false, 22, true));
|
|
68
68
|
```
|
|
69
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
|
+
|
|
70
89
|
#### parser.parse()
|
|
71
90
|
|
|
72
91
|
```js
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postal-mime",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Email parser for browser environments",
|
|
5
5
|
"main": "./src/postal-mime.js",
|
|
6
6
|
"exports": {
|
|
7
|
-
"import": "./src/postal-mime.js"
|
|
7
|
+
"import": "./src/postal-mime.js",
|
|
8
|
+
"types": "./postal-mime.d.ts"
|
|
8
9
|
},
|
|
9
10
|
"type": "module",
|
|
10
11
|
"types": "postal-mime.d.ts",
|
|
11
12
|
"scripts": {
|
|
12
|
-
"test": "eslint",
|
|
13
|
+
"test": "eslint && node --test",
|
|
13
14
|
"update": "rm -rf node_modules package-lock.json && ncu -u && npm install"
|
|
14
15
|
},
|
|
15
16
|
"keywords": [
|
|
@@ -27,9 +28,9 @@
|
|
|
27
28
|
"license": "MIT-0",
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"cross-blob": "3.0.2",
|
|
30
|
-
"eslint": "8.
|
|
31
|
+
"eslint": "8.56.0",
|
|
31
32
|
"eslint-cli": "1.1.1",
|
|
32
|
-
"iframe-resizer": "4.3.
|
|
33
|
+
"iframe-resizer": "4.3.9",
|
|
33
34
|
"cross-env": "7.0.3"
|
|
34
35
|
}
|
|
35
36
|
}
|
package/postal-mime.d.ts
CHANGED
package/src/address-parser.js
CHANGED
|
@@ -109,6 +109,14 @@ function _handleAddress(tokens) {
|
|
|
109
109
|
data.text = data.text.join(' ');
|
|
110
110
|
data.address = data.address.join(' ');
|
|
111
111
|
|
|
112
|
+
if (!data.address && /^=\?[^=]+?=$/.test(data.text.trim())) {
|
|
113
|
+
// try to extract words from text content
|
|
114
|
+
const parsedSubAddresses = addressParser(decodeWords(data.text));
|
|
115
|
+
if (parsedSubAddresses && parsedSubAddresses.length) {
|
|
116
|
+
return parsedSubAddresses;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
112
120
|
if (!data.address && isGroup) {
|
|
113
121
|
return [];
|
|
114
122
|
} else {
|
package/src/postal-mime.js
CHANGED
|
@@ -287,12 +287,41 @@ export default class PostalMime {
|
|
|
287
287
|
this.textContent = textContent;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
+
async resolveStream(stream) {
|
|
291
|
+
let chunkLen = 0;
|
|
292
|
+
let chunks = [];
|
|
293
|
+
const reader = stream.getReader();
|
|
294
|
+
|
|
295
|
+
while (true) {
|
|
296
|
+
const { done, value } = await reader.read();
|
|
297
|
+
if (done) {
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
chunks.push(value);
|
|
301
|
+
chunkLen += value.length;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const result = new Uint8Array(chunkLen);
|
|
305
|
+
let chunkPointer = 0;
|
|
306
|
+
for (let chunk of chunks) {
|
|
307
|
+
result.set(chunk, chunkPointer);
|
|
308
|
+
chunkPointer += chunk.length;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return result;
|
|
312
|
+
}
|
|
313
|
+
|
|
290
314
|
async parse(buf) {
|
|
291
315
|
if (this.started) {
|
|
292
316
|
throw new Error('Can not reuse parser, create a new PostalMime object');
|
|
293
317
|
}
|
|
294
318
|
this.started = true;
|
|
295
319
|
|
|
320
|
+
// check if the input is a readable stream and resolve it into an ArrayBuffer
|
|
321
|
+
if (buf && typeof buf.getReader === 'function') {
|
|
322
|
+
buf = await this.resolveStream(buf);
|
|
323
|
+
}
|
|
324
|
+
|
|
296
325
|
// should it thrown on empty value instead?
|
|
297
326
|
buf = buf || ArrayBuffer(0);
|
|
298
327
|
|
|
File without changes
|