email-forward-parser 1.0.7 → 1.0.13

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Crisp
3
+ Copyright (c) 2021 Crisp IM SAS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,11 +1,13 @@
1
- # email-forward-parser
1
+ # Email Forward Parser
2
2
 
3
- [![NPM](https://img.shields.io/npm/v/email-forward-parser.svg)](https://www.npmjs.com/package/email-forward-parser) [![Downloads](https://img.shields.io/npm/dt/email-forward-parser.svg)](https://www.npmjs.com/package/email-forward-parser)
3
+ [![Test and Build](https://github.com/crisp-oss/email-forward-parser/workflows/Test%20and%20Build/badge.svg?branch=master)](https://github.com/crisp-oss/email-forward-parser/actions?query=workflow%3A%22Test+and+Build%22) [![NPM](https://img.shields.io/npm/v/email-forward-parser.svg)](https://www.npmjs.com/package/email-forward-parser) [![Downloads](https://img.shields.io/npm/dt/email-forward-parser.svg)](https://www.npmjs.com/package/email-forward-parser)
4
4
 
5
5
  Parses forwarded emails and extracts original content.
6
6
 
7
7
  This library supports most common email clients and locales.
8
8
 
9
+ **😘 Maintainer**: [@eliottvincent](https://github.com/eliottvincent)
10
+
9
11
  ## Who uses it?
10
12
 
11
13
  <table>
@@ -22,7 +24,7 @@ _👋 You use this library and you want to be listed there? [Contact us](https:/
22
24
  ## Features
23
25
 
24
26
  This library is used at [Crisp](https://crisp.chat/) everyday with around 1 million inbound emails.
25
- * Supported clients: Apple Mail, Gmail, Outlook Live, Outlook 2019, New Outlook 2019, Yahoo Mail, Thunderbird
27
+ * Supported clients: Apple Mail, Gmail, Outlook Live, Outlook 2013, Outlook 2019, New Outlook 2019, Yahoo Mail, Thunderbird
26
28
  * Supported locales: Croatian, Czech, Danish, Dutch, English, French, Finnish, German, Hungarian, Italian, Norwegian, Polish, Portuguese (Brazil), Portuguese (Portugal), Romanian, Russian, Slovak, Spanish, Swedish, Turkish, Ukrainian
27
29
 
28
30
  ## Usage
@@ -49,17 +51,32 @@ const EmailForwardParser = require("email-forward-parser");
49
51
 
50
52
  const result = new EmailForwardParser().read(MY_EMAIL_STRING, MY_SUBJECT_STRING);
51
53
 
52
- console.log(result.forwarded);
53
- // true
54
-
55
- console.log(result.email.from);
56
- // { email: "john.doe@acme.com", name: "John Doe" }
57
-
58
- console.log(result.email.body);
59
- // "Aenean quis diam urna..."
60
-
61
- console.log(result.message);
62
- // "Praesent suscipit egestas hendrerit..."
54
+ console.log(result);
55
+ // {
56
+ // forwarded: true,
57
+ //
58
+ // message: "Praesent suscipit egestas hendrerit.",
59
+ //
60
+ // email: {
61
+ // body: "Aenean quis diam urna.",
62
+ //
63
+ // from: {
64
+ // address: "john.doe@acme.com",
65
+ // name: "John Doe"
66
+ // },
67
+ // to: [{
68
+ // address: "bessie.berry@acme.com",
69
+ // name: "Bessie Berry"
70
+ // }],
71
+ // cc: [{
72
+ // address: "walter.sheltan@acme.com",
73
+ // name: "Walter Sheltan"
74
+ // }],
75
+ //
76
+ // subject: "Integer consequat non purus",
77
+ // date: "25 October 2021 at 11:17:21 EEST"
78
+ // }
79
+ // }
63
80
  ```
64
81
 
65
82
  ## How does it work?
@@ -73,6 +90,7 @@ Client | Detectable via subject | Detectable via separator | Subject localized |
73
90
  Apple Mail | Yes | Yes | Yes | Yes | Yes | Yes | --
74
91
  Gmail | Yes | Yes | No | No | Yes | Only some parts | --
75
92
  Outlook Live | Yes | Yes | Yes | No | Yes | No | --
93
+ Outlook 2013 | Yes | No | ? | -- | ? | ? | --
76
94
  Outlook 2019 | Yes | Yes | No | Yes | No | Yes | The From and Date parts (only original information available) are embedded in the separator, rather than the body itself
77
95
  New Outlook 2019 | Yes | No | Yes | -- | Yes | Yes | --
78
96
  Yahoo Mail | Yes | Yes | No | Yes | Yes | Yes | The original information are all stuck to each other, without line breaks
@@ -90,5 +108,4 @@ npm test
90
108
 
91
109
  ## License
92
110
 
93
- email-forward-parser is released under the MIT License. See the bundled LICENSE
94
- file for details.
111
+ email-forward-parser is released under the MIT License. See the bundled LICENSE file for details.
package/lib/index.js CHANGED
@@ -33,7 +33,7 @@ class EmailForwardParser {
33
33
  _subject = this.parser.parseSubject(subject);
34
34
  }
35
35
 
36
- var _forwarded = ((subject && _subject) && true) || false;
36
+ var _forwarded = ((subject && _subject !== null) && true) || false;
37
37
 
38
38
  // Check if email was forwarded or not (via the body)
39
39
  if (!subject || _forwarded) {
package/lib/parser.js CHANGED
@@ -44,6 +44,7 @@ var REGEXES = {
44
44
  /^>?\s*Inicio del mensaje reenviado\s?:/m, // Apple Mail (es)
45
45
  /^>?\s*Välitetty viesti alkaa\s?:/m, // Apple Mail (fi)
46
46
  /^>?\s*Début du message réexpédié\s?:/m, // Apple Mail (fr)
47
+ /^>?\s*Début du message transféré\s?:/m, // Apple Mail iOS (fr)
47
48
  /^>?\s*Započni proslijeđenu poruku\s?:/m, // Apple Mail (hr)
48
49
  /^>?\s*Továbbított levél kezdete\s?:/m, // Apple Mail (hu)
49
50
  /^>?\s*Inizio messaggio inoltrato\s?:/m, // Apple Mail (it)
@@ -58,8 +59,8 @@ var REGEXES = {
58
59
  /^>?\s*Vidarebefordrat mejl\s?:/m, // Apple Mail (sv)
59
60
  /^>?\s*İleti başlangıcı\s?:/m, // Apple Mail (tr)
60
61
  /^>?\s*Початок листа, що пересилається\s?:/m, // Apple Mail (uk)
61
- /^\s*-{1,20}\s*Forwarded message\s*-{1,20}\s*/m, // Gmail (all locales)
62
- /^\s*_{20,40}\s*$/m, // Outlook Live (all locales)
62
+ /^\s*-{8,10}\s*Forwarded message\s*-{8,10}\s*/m, // Gmail (all locales)
63
+ /^\s*_{32}\s*$/m, // Outlook Live (all locales)
63
64
  /^\s?Dne\s?(?<date>.+)\,\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?napsal\(a\)\s?:/m, // Outlook 2019 (cz)
64
65
  /^\s?D.\s?(?<date>.+)\s?skrev\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?:/m, // Outlook 2019 (da)
65
66
  /^\s?Am\s?(?<date>.+)\s?schrieb\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?:/m, // Outlook 2019 (de)
@@ -325,8 +326,9 @@ var REGEXES = {
325
326
  ],
326
327
 
327
328
  name_address : [
328
- /^\"(.+)\"\s?\n?\s*[\[|<](.+)[\]|>]$/, // ""Walter Sheltan" <walter.sheltan@acme.com>" or ""walter.sheltan@acme.com" <walter.sheltan@acme.com>"
329
- /^(.+)\s?\n?\s*[\[|<](.+)[\]|>]$/, // "Walter Sheltan <walter.sheltan@acme.com>" or "walter.sheltan@acme.com <walter.sheltan@acme.com>"
329
+ /^(.+)\s?\n?\s*[\[|<]mailto\:(.+)[\]|>]$/, // "Walter Sheltan <mailto:walter.sheltan@acme.com>" or "Walter Sheltan [mailto:walter.sheltan@acme.com]" or "walter.sheltan@acme.com <mailto:walter.sheltan@acme.com>"
330
+ /^\"(.+)\"\s?\n?\s*[\[|<](.+)[\]|>]$/, // ""Walter Sheltan" <walter.sheltan@acme.com>" or ""Walter Sheltan" [walter.sheltan@acme.com]" or ""walter.sheltan@acme.com" <walter.sheltan@acme.com>"
331
+ /^(.+)\s?\n?\s*[\[|<](.+)[\]|>]$/, // "Walter Sheltan <walter.sheltan@acme.com>" or "Walter Sheltan [walter.sheltan@acme.com]" or "walter.sheltan@acme.com <walter.sheltan@acme.com>"
330
332
  /^(.?)\s?\n?\s*[\[|<](.+)[\]|>]$/, // "<walter.sheltan@acme.com>"
331
333
  /(.?)\s?\n?\s*[\[|<](.+)[\]|>]/ // "<walter.sheltan@acme.com>" (lax)
332
334
  ]
@@ -357,7 +359,9 @@ class Parser {
357
359
  var _match = loopRegexes(this.__regexes.subject, subject);
358
360
 
359
361
  if (_match && _match.length > 1) {
360
- return trimString(_match[1]);
362
+ // Notice: return an empty string if the detected subject is empty \
363
+ // (e.g. 'Fwd: ')
364
+ return trimString(_match[1]) || "";
361
365
  }
362
366
 
363
367
  return null;
@@ -393,9 +397,9 @@ class Parser {
393
397
 
394
398
  // Attempt second method?
395
399
  // Notice: as this second method is more uncertain (we split via the From \
396
- // From part, without further verification), we have to be sure we can \
397
- // attempt it. The `forwarded` boolean gives the confirmation that the
398
- // email was indeed forwarded (detected from the Subject part)
400
+ // part, without further verification), we have to be sure we can \
401
+ // attempt it. The `forwarded` boolean gives the confirmation that the \
402
+ // email was indeed forwarded (detected from the Subject part)
399
403
  if (forwarded === true) {
400
404
  // Second method: split via the Form part (New Outlook 2019)
401
405
  _match = loopRegexes(this.__regexes.original_from, _body, "split");
@@ -481,7 +485,7 @@ class Parser {
481
485
  __parseOriginalBody(text) {
482
486
  var _match = null;
483
487
 
484
- // First method: extract the text after the Cc, To or Reply-To part
488
+ // First method: extract the text after the Cc, To or Reply-To part \
485
489
  // (Apple Mail, Gmail) or after the Subject part (Outlook Live)
486
490
  var _regexes = [
487
491
  this.__regexes.original_subject,
@@ -500,7 +504,7 @@ class Parser {
500
504
  }
501
505
  }
502
506
 
503
- // Second method: extract the text after the Subject part
507
+ // Second method: extract the text after the Subject part \
504
508
  // (New Outlook 2019, Yahoo Mail)
505
509
  _match = loopRegexes(
506
510
  this.__regexes.original_subject.concat(
@@ -647,7 +651,7 @@ class Parser {
647
651
  * @return {object} The parsed carbon-copy recipient(s)
648
652
  */
649
653
  __parseOriginalCc(text) {
650
- // First method: extract the carbon-copy recipient(s) via the Cc part
654
+ // First method: extract the carbon-copy recipient(s) via the Cc part \
651
655
  // (Apple Mail, Gmail, Outlook Live, New Outlook 2019, Thunderbird)
652
656
  var _recipients = this.__parseMailbox(
653
657
  this.__regexes.original_cc,
@@ -764,7 +768,7 @@ class Parser {
764
768
  * @return {string} The parsed subject
765
769
  */
766
770
  __parseOriginalSubject(text) {
767
- // First method: extract the subject via the Subject part (Apple Mail,
771
+ // First method: extract the subject via the Subject part (Apple Mail, \
768
772
  // Gmail, Outlook Live, New Outlook 2019, Thunderbird)
769
773
  var _match = loopRegexes(this.__regexes.original_subject, text);
770
774
 
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "email-forward-parser",
3
- "version": "1.0.7",
3
+ "version": "1.0.13",
4
4
  "description": "Parses forwarded emails and extract content",
5
5
  "author": "Eliott Vincent <eliott@crisp.chat>",
6
6
  "main": "lib/index.js",
7
+ "homepage": "https://github.com/crisp-oss/email-forward-parser",
7
8
  "repository": {
8
9
  "type": "git",
9
- "url": "git://github.com/crisp-dev/email-forward-parser"
10
+ "url": "git://github.com/crisp-oss/email-forward-parser"
10
11
  },
11
12
  "bugs": {
12
- "url": "https://github.com/crisp-dev/email-forward-parser/issues"
13
+ "url": "https://github.com/crisp-oss/email-forward-parser/issues"
13
14
  },
14
15
  "scripts": {
15
16
  "test": "nodeunit ./test/index.js"