email-forward-parser 1.0.9 → 1.0.14

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 IM SARL
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
package/README.md CHANGED
@@ -24,7 +24,7 @@ _👋 You use this library and you want to be listed there? [Contact us](https:/
24
24
  ## Features
25
25
 
26
26
  This library is used at [Crisp](https://crisp.chat/) everyday with around 1 million inbound emails.
27
- * 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
28
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
29
29
 
30
30
  ## Usage
@@ -51,17 +51,32 @@ const EmailForwardParser = require("email-forward-parser");
51
51
 
52
52
  const result = new EmailForwardParser().read(MY_EMAIL_STRING, MY_SUBJECT_STRING);
53
53
 
54
- console.log(result.forwarded);
55
- // true
56
-
57
- console.log(result.email.from);
58
- // { email: "john.doe@acme.com", name: "John Doe" }
59
-
60
- console.log(result.email.body);
61
- // "Aenean quis diam urna..."
62
-
63
- console.log(result.message);
64
- // "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
+ // }
65
80
  ```
66
81
 
67
82
  ## How does it work?
@@ -75,6 +90,7 @@ Client | Detectable via subject | Detectable via separator | Subject localized |
75
90
  Apple Mail | Yes | Yes | Yes | Yes | Yes | Yes | --
76
91
  Gmail | Yes | Yes | No | No | Yes | Only some parts | --
77
92
  Outlook Live | Yes | Yes | Yes | No | Yes | No | --
93
+ Outlook 2013 | Yes | No | ? | -- | ? | ? | --
78
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
79
95
  New Outlook 2019 | Yes | No | Yes | -- | Yes | Yes | --
80
96
  Yahoo Mail | Yes | Yes | No | Yes | Yes | Yes | The original information are all stuck to each other, without line breaks
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
@@ -18,22 +18,22 @@ var REGEXES = {
18
18
  byte_order_mark : /[\uFEFF]/gm, // Outlook 2019
19
19
 
20
20
  subject : [
21
- /^Fw:(.+)/m, // Outlook Live (cs, en, hr, hu, sk), Yahoo Mail (all locales)
22
- /^VS:(.+)/m, // Outlook Live (da), New Outlook 2019 (da)
23
- /^WG:(.+)/m, // Outlook Live (de), New Outlook 2019 (de)
24
- /^RV:(.+)/m, // Outlook Live (es), New Outlook 2019 (es)
25
- /^TR:(.+)/m, // Outlook Live (fr), New Outlook 2019 (fr)
26
- /^I:(.+)/m, // Outlook Live (it), New Outlook 2019 (it)
27
- /^FW:(.+)/m, // Outlook Live (nl, pt), New Outlook 2019 (cs, en, hu, nl, pt, ru, sk), Outlook 2019 (all locales)
28
- /^Vs:(.+)/m, // Outlook Live (no)
29
- /^PD:(.+)/m, // Outlook Live (pl), New Outlook 2019 (pl)
30
- /^ENC:(.+)/m, // Outlook Live (pt-br), New Outlook 2019 (pt-br)
31
- /^Redir.:(.+)/m, // Outlook Live (ro)
32
- /^VB:(.+)/m, // Outlook Live (sv), New Outlook 2019 (sv)
33
- /^VL:(.+)/m, // New Outlook 2019 (fi)
34
- /^Videresend:(.+)/m, // New Outlook 2019 (no)
35
- /^İLT:(.+)/m, // New Outlook 2019 (tr)
36
- /^Fwd:(.+)/m // Gmail (all locales), Thunderbird (all locales)
21
+ /^Fw:(.*)/m, // Outlook Live (cs, en, hr, hu, sk), Yahoo Mail (all locales)
22
+ /^VS:(.*)/m, // Outlook Live (da), New Outlook 2019 (da)
23
+ /^WG:(.*)/m, // Outlook Live (de), New Outlook 2019 (de)
24
+ /^RV:(.*)/m, // Outlook Live (es), New Outlook 2019 (es)
25
+ /^TR:(.*)/m, // Outlook Live (fr), New Outlook 2019 (fr)
26
+ /^I:(.*)/m, // Outlook Live (it), New Outlook 2019 (it)
27
+ /^FW:(.*)/m, // Outlook Live (nl, pt), New Outlook 2019 (cs, en, hu, nl, pt, ru, sk), Outlook 2019 (all locales)
28
+ /^Vs:(.*)/m, // Outlook Live (no)
29
+ /^PD:(.*)/m, // Outlook Live (pl), New Outlook 2019 (pl)
30
+ /^ENC:(.*)/m, // Outlook Live (pt-br), New Outlook 2019 (pt-br)
31
+ /^Redir.:(.*)/m, // Outlook Live (ro)
32
+ /^VB:(.*)/m, // Outlook Live (sv), New Outlook 2019 (sv)
33
+ /^VL:(.*)/m, // New Outlook 2019 (fi)
34
+ /^Videresend:(.*)/m, // New Outlook 2019 (no)
35
+ /^İLT:(.*)/m, // New Outlook 2019 (tr)
36
+ /^Fwd:(.*)/m // Gmail (all locales), Thunderbird (all locales)
37
37
  ],
38
38
 
39
39
  separator : [
@@ -59,8 +59,8 @@ var REGEXES = {
59
59
  /^>?\s*Vidarebefordrat mejl\s?:/m, // Apple Mail (sv)
60
60
  /^>?\s*İleti başlangıcı\s?:/m, // Apple Mail (tr)
61
61
  /^>?\s*Початок листа, що пересилається\s?:/m, // Apple Mail (uk)
62
- /^\s*-{1,20}\s*Forwarded message\s*-{1,20}\s*/m, // Gmail (all locales)
63
- /^\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)
64
64
  /^\s?Dne\s?(?<date>.+)\,\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?napsal\(a\)\s?:/m, // Outlook 2019 (cz)
65
65
  /^\s?D.\s?(?<date>.+)\s?skrev\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?:/m, // Outlook 2019 (da)
66
66
  /^\s?Am\s?(?<date>.+)\s?schrieb\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?:/m, // Outlook 2019 (de)
@@ -326,8 +326,9 @@ var REGEXES = {
326
326
  ],
327
327
 
328
328
  name_address : [
329
- /^\"(.+)\"\s?\n?\s*[\[|<](.+)[\]|>]$/, // ""Walter Sheltan" <walter.sheltan@acme.com>" or ""walter.sheltan@acme.com" <walter.sheltan@acme.com>"
330
- /^(.+)\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>"
331
332
  /^(.?)\s?\n?\s*[\[|<](.+)[\]|>]$/, // "<walter.sheltan@acme.com>"
332
333
  /(.?)\s?\n?\s*[\[|<](.+)[\]|>]/ // "<walter.sheltan@acme.com>" (lax)
333
334
  ]
@@ -358,7 +359,9 @@ class Parser {
358
359
  var _match = loopRegexes(this.__regexes.subject, subject);
359
360
 
360
361
  if (_match && _match.length > 1) {
361
- 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]) || "";
362
365
  }
363
366
 
364
367
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "email-forward-parser",
3
- "version": "1.0.9",
3
+ "version": "1.0.14",
4
4
  "description": "Parses forwarded emails and extract content",
5
5
  "author": "Eliott Vincent <eliott@crisp.chat>",
6
6
  "main": "lib/index.js",
package/test.js CHANGED
@@ -2,6 +2,24 @@ const EmailForwardParser = require("./");
2
2
  const fs = require("fs");
3
3
 
4
4
  MY_EMAIL_STRING = fs.readFileSync("./test.txt", "utf-8");
5
- const result = new EmailForwardParser().read(MY_EMAIL_STRING);
5
+ // MY_EMAIL_STRING = fs.readFileSync("./test_working.txt", "utf-8");
6
+ // const result = new EmailForwardParser().read(MY_EMAIL_STRING, "FW: FC-701 Contact Request by Gleam.io");
7
+ const result = new EmailForwardParser().read(MY_EMAIL_STRING, "Fwd:");
6
8
 
7
- console.log(result.forwarded);
9
+ console.log(result.forwarded);
10
+ console.log(result);
11
+ // console.log(result.email.to);
12
+ // console.log(result.email.cc);
13
+
14
+ // {
15
+ // forwarded: false,
16
+ // message: null,
17
+ // email: {
18
+ // body: undefined,
19
+ // from: { address: undefined, name: undefined },
20
+ // to: undefined,
21
+ // cc: undefined,
22
+ // subject: undefined,
23
+ // date: undefined
24
+ // }
25
+ // }
package/test.txt CHANGED
@@ -1,21 +1,14 @@
1
1
 
2
-
3
- Envoyé de mon iPhone
4
-
5
- Début du message transféré :
6
-
7
- > From: Dotan Brown <dotan@prizepicks.com>
8
- > Date: 12 January 2022 at 14:22:12 CET
9
- > To: Eliott <eliott@crisp.chat>
10
- > Subject: Daily image quota
11
- >
12
- > 
13
- > Good morning,
14
- >
15
- >
16
- > Could we please get a reset on our daily image quota for the day?
17
- >
18
- >
19
- > Thanks in advance,
20
- >
21
- > Dotan-PrizePicks
2
+ Camille Le Bruchec
3
+ Head of Customer Success - Crisp
4
+ https://calendly.com/camille-crisp/30min-1
5
+ camille@crisp.chat
6
+
7
+ > Début du message réexpédié :
8
+ >
9
+ > De: Camille Le Bruchec <camille.lebruchec@icloud.com>
10
+ > Date: 19 avril 2022 à 16:38:24 UTC+2
11
+ > À: Camille Le Bruchec <camille@crisp.chat>
12
+ >
13
+ >
14
+ > Hello test 4
@@ -1,40 +0,0 @@
1
- on: [push, pull_request]
2
-
3
- name: Test and Build
4
-
5
- jobs:
6
- test:
7
- strategy:
8
- matrix:
9
- os: [ubuntu-latest]
10
- node-version: [10.x, 12.x, 14.x, 16.x]
11
- fail-fast: false
12
-
13
- runs-on: ${{ matrix.os }}
14
-
15
- steps:
16
- - name: Checkout code
17
- uses: actions/checkout@v2
18
-
19
- - name: Install NodeJS
20
- uses: actions/setup-node@v1
21
- with:
22
- node-version: ${{ matrix.node-version }}
23
-
24
- - name: Verify versions
25
- run: node --version && npm --version && node -p process.versions.v8
26
-
27
- - name: Cache build artifacts
28
- id: cache-node
29
- uses: actions/cache@v2
30
- with:
31
- path: |
32
- ~/.npm
33
- node_modules
34
- key: ${{ runner.os }}-node-${{ matrix.node-version }}
35
-
36
- - name: Install dependencies
37
- run: npm install
38
-
39
- - name: Run tests
40
- run: npm test