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 +1 -1
- package/README.md +28 -12
- package/lib/index.js +1 -1
- package/lib/parser.js +24 -21
- package/package.json +1 -1
- package/test.js +20 -2
- package/test.txt +13 -20
- package/.github/workflows/test.yml +0 -40
package/LICENSE
CHANGED
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
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// "Aenean quis diam urna
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// "
|
|
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:(
|
|
22
|
-
/^VS:(
|
|
23
|
-
/^WG:(
|
|
24
|
-
/^RV:(
|
|
25
|
-
/^TR:(
|
|
26
|
-
/^I:(
|
|
27
|
-
/^FW:(
|
|
28
|
-
/^Vs:(
|
|
29
|
-
/^PD:(
|
|
30
|
-
/^ENC:(
|
|
31
|
-
/^Redir.:(
|
|
32
|
-
/^VB:(
|
|
33
|
-
/^VL:(
|
|
34
|
-
/^Videresend:(
|
|
35
|
-
/^İLT:(
|
|
36
|
-
/^Fwd:(
|
|
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*-{
|
|
63
|
-
/^\s*_{
|
|
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
|
-
|
|
330
|
-
|
|
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
|
|
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
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
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
>
|
|
8
|
-
>
|
|
9
|
-
>
|
|
10
|
-
>
|
|
11
|
-
>
|
|
12
|
-
>
|
|
13
|
-
>
|
|
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
|