postal-mime 2.2.0 → 2.2.1

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.1](https://github.com/postalsys/postal-mime/compare/v2.2.0...v2.2.1) (2024-03-31)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **parser:** Reply-To value must be an array, not a single address object ([280bd8d](https://github.com/postalsys/postal-mime/commit/280bd8dc1626315e1a43f35641415453c434716e))
9
+
3
10
  ## [2.2.0](https://github.com/postalsys/postal-mime/compare/v2.1.2...v2.2.0) (2024-03-26)
4
11
 
5
12
 
package/README.md CHANGED
@@ -4,6 +4,9 @@ Email parser for browser and serverless environments.
4
4
 
5
5
  PostalMime can be run in the main web thread or from Web Workers. It can also used in serverless functions.
6
6
 
7
+ > [!TIP]
8
+ > PostalMime is developed by the makers of **[EmailEngine](https://emailengine.app/?utm_source=github&utm_campaign=imapflow&utm_medium=readme-link)** – a self-hosted email gateway that allows making **REST requests against IMAP and SMTP servers**. EmailEngine also sends webhooks whenever something changes on the registered accounts.
9
+
7
10
  ## Source
8
11
 
9
12
  The source code is available from [Github](https://github.com/postalsys/postal-mime).
@@ -100,11 +103,11 @@ This method parses an email message into a structured object with the following
100
103
  - **headers** is an array of headers in the same order as found from the message (topmost headers first).
101
104
  - **headers[].key** is lowercase key of the header line, eg. `"dkim-signature"`
102
105
  - **headers[].value** is the unprocessed value of the header line
103
- - **from**, **sender**, **replyTo** includes a processed object for the corresponding headers
106
+ - **from**, **sender** includes a processed object for the corresponding headers
104
107
  - **from.name** is decoded name (empty string if not set)
105
108
  - **from.address** is the email address
106
109
  - **deliveredTo**, **returnPath** is the email address from the corresponding header
107
- - **to**, **cc**, **bcc** includes an array of processed objects for the corresponding headers
110
+ - **to**, **cc**, **bcc**, **replyTo** includes an array of processed objects for the corresponding headers
108
111
  - **to[].name** is decoded name (empty string if not set)
109
112
  - **to[].address** is the email address
110
113
  - **subject** is the email subject line
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postal-mime",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Email parser for browser environments",
5
5
  "main": "./src/postal-mime.js",
6
6
  "exports": {
package/postal-mime.d.ts CHANGED
@@ -37,6 +37,7 @@ export type Email = {
37
37
  };
38
38
 
39
39
  declare class PostalMime {
40
+ static parse(email: RawEmail): Promise<Email>;
40
41
  parse(email: RawEmail): Promise<Email>;
41
42
  }
42
43
 
@@ -358,32 +358,33 @@ export default class PostalMime {
358
358
 
359
359
  await this.processNodeTree();
360
360
 
361
- let message = {
361
+ const message = {
362
362
  headers: this.root.headers.map(entry => ({ key: entry.key, value: entry.value })).reverse()
363
363
  };
364
364
 
365
- for (let key of ['from', 'sender', 'reply-to']) {
366
- let addressHeader = this.root.headers.find(line => line.key === key);
365
+ for (const key of ['from', 'sender']) {
366
+ const addressHeader = this.root.headers.find(line => line.key === key);
367
367
  if (addressHeader && addressHeader.value) {
368
- let addresses = addressParser(addressHeader.value);
368
+ const addresses = addressParser(addressHeader.value);
369
369
  if (addresses && addresses.length) {
370
- message[key.replace(/\-(.)/g, (o, c) => c.toUpperCase())] = addresses[0];
370
+ message[key] = addresses[0];
371
371
  }
372
372
  }
373
373
  }
374
374
 
375
- for (let key of ['delivered-to', 'return-path']) {
376
- let addressHeader = this.root.headers.find(line => line.key === key);
375
+ for (const key of ['delivered-to', 'return-path']) {
376
+ const addressHeader = this.root.headers.find(line => line.key === key);
377
377
  if (addressHeader && addressHeader.value) {
378
- let addresses = addressParser(addressHeader.value);
378
+ const addresses = addressParser(addressHeader.value);
379
379
  if (addresses && addresses.length && addresses[0].address) {
380
- message[key.replace(/\-(.)/g, (o, c) => c.toUpperCase())] = addresses[0].address;
380
+ const camelKey = key.replace(/\-(.)/g, (o, c) => c.toUpperCase());
381
+ message[camelKey] = addresses[0].address;
381
382
  }
382
383
  }
383
384
  }
384
385
 
385
- for (let key of ['to', 'cc', 'bcc']) {
386
- let addressHeaders = this.root.headers.filter(line => line.key === key);
386
+ for (const key of ['to', 'cc', 'bcc', 'reply-to']) {
387
+ const addressHeaders = this.root.headers.filter(line => line.key === key);
387
388
  let addresses = [];
388
389
 
389
390
  addressHeaders
@@ -392,14 +393,16 @@ export default class PostalMime {
392
393
  .forEach(parsed => (addresses = addresses.concat(parsed || [])));
393
394
 
394
395
  if (addresses && addresses.length) {
395
- message[key] = addresses;
396
+ const camelKey = key.replace(/\-(.)/g, (o, c) => c.toUpperCase());
397
+ message[camelKey] = addresses;
396
398
  }
397
399
  }
398
400
 
399
- for (let key of ['subject', 'message-id', 'in-reply-to', 'references']) {
400
- let header = this.root.headers.find(line => line.key === key);
401
+ for (const key of ['subject', 'message-id', 'in-reply-to', 'references']) {
402
+ const header = this.root.headers.find(line => line.key === key);
401
403
  if (header && header.value) {
402
- message[key.replace(/\-(.)/g, (o, c) => c.toUpperCase())] = decodeWords(header.value);
404
+ const camelKey = key.replace(/\-(.)/g, (o, c) => c.toUpperCase());
405
+ message[camelKey] = decodeWords(header.value);
403
406
  }
404
407
  }
405
408