email-forward-parser 1.0.15 → 1.0.18
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/README.md +3 -2
- package/lib/parser.js +72 -50
- package/package.json +1 -1
- package/result+1.txt +0 -51
- package/test-regex.js +0 -123
- package/test.js +0 -25
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 2013, Outlook 2019, New Outlook 2019, Yahoo Mail, Thunderbird
|
|
27
|
+
* Supported clients: Apple Mail, Gmail, Outlook Live / 365, Outlook 2013, Outlook 2019, New Outlook 2019, Yahoo Mail, Thunderbird, Missive
|
|
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
|
|
@@ -89,12 +89,13 @@ Client | Detectable via subject | Detectable via separator | Subject localized |
|
|
|
89
89
|
--- | --- | --- | --- | --- | --- | --- | ---
|
|
90
90
|
Apple Mail | Yes | Yes | Yes | Yes | Yes | Yes | --
|
|
91
91
|
Gmail | Yes | Yes | No | No | Yes | Only some parts | --
|
|
92
|
-
Outlook Live | Yes | Yes | Yes | No | Yes | No | --
|
|
92
|
+
Outlook Live / 365 | Yes | Yes | Yes | No | Yes | No | --
|
|
93
93
|
Outlook 2013 | Yes | No | ? | -- | ? | ? | --
|
|
94
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
|
|
95
95
|
New Outlook 2019 | Yes | No | Yes | -- | Yes | Yes | --
|
|
96
96
|
Yahoo Mail | Yes | Yes | No | Yes | Yes | Yes | The original information are all stuck to each other, without line breaks
|
|
97
97
|
Thunderbird | Yes | Yes | No | Yes | Yes | Yes | --
|
|
98
|
+
Missive | Yes | Yes | No | No | Yes | No | --
|
|
98
99
|
|
|
99
100
|
## Contributing
|
|
100
101
|
|
package/lib/parser.js
CHANGED
|
@@ -7,7 +7,7 @@ var { loopRegexes, trimString } = require("./utils");
|
|
|
7
7
|
|
|
8
8
|
var MAILBOXES_SEPARATORS = [
|
|
9
9
|
",", // Apple Mail, Gmail, New Outlook 2019, Thunderbird
|
|
10
|
-
";" // Outlook Live, Yahoo Mail
|
|
10
|
+
";" // Outlook Live / 365, Yahoo Mail
|
|
11
11
|
];
|
|
12
12
|
|
|
13
13
|
var REGEXES = {
|
|
@@ -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)
|
|
21
|
+
/^Fw:(.*)/m, // Outlook Live / 365 (cs, en, hr, hu, sk), Yahoo Mail (all locales)
|
|
22
|
+
/^VS:(.*)/m, // Outlook Live / 365 (da), New Outlook 2019 (da)
|
|
23
|
+
/^WG:(.*)/m, // Outlook Live / 365 (de), New Outlook 2019 (de)
|
|
24
|
+
/^RV:(.*)/m, // Outlook Live / 365 (es), New Outlook 2019 (es)
|
|
25
|
+
/^TR:(.*)/m, // Outlook Live / 365 (fr), New Outlook 2019 (fr)
|
|
26
|
+
/^I:(.*)/m, // Outlook Live / 365 (it), New Outlook 2019 (it)
|
|
27
|
+
/^FW:(.*)/m, // Outlook Live / 365 (nl, pt), New Outlook 2019 (cs, en, hu, nl, pt, ru, sk), Outlook 2019 (all locales)
|
|
28
|
+
/^Vs:(.*)/m, // Outlook Live / 365 (no)
|
|
29
|
+
/^PD:(.*)/m, // Outlook Live / 365 (pl), New Outlook 2019 (pl)
|
|
30
|
+
/^ENC:(.*)/m, // Outlook Live / 365 (pt-br), New Outlook 2019 (pt-br)
|
|
31
|
+
/^Redir.:(.*)/m, // Outlook Live / 365 (ro)
|
|
32
|
+
/^VB:(.*)/m, // Outlook Live / 365 (sv), New Outlook 2019 (sv)
|
|
33
33
|
/^VL:(.*)/m, // New Outlook 2019 (fi)
|
|
34
34
|
/^Videresend:(.*)/m, // New Outlook 2019 (no)
|
|
35
35
|
/^İLT:(.*)/m, // New Outlook 2019 (tr)
|
|
36
|
-
/^Fwd:(.*)/m // Gmail (all locales), Thunderbird (all locales)
|
|
36
|
+
/^Fwd:(.*)/m // Gmail (all locales), Thunderbird (all locales), Missive (en)
|
|
37
37
|
],
|
|
38
38
|
|
|
39
39
|
separator : [
|
|
@@ -59,25 +59,25 @@ 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*-{8,10}\s*Forwarded message\s*-{8,10}\s*/m, // Gmail (all locales)
|
|
63
|
-
/^\s*_{32}\s*$/m, // Outlook Live (all locales)
|
|
64
|
-
/^\s?Dne\s
|
|
65
|
-
/^\s?D.\s
|
|
66
|
-
/^\s?Am\s
|
|
67
|
-
/^\s?On\s
|
|
68
|
-
/^\s?El\s
|
|
69
|
-
/^\s?Le\s
|
|
70
|
-
/^\s
|
|
71
|
-
/^\s
|
|
72
|
-
/^\s?Il giorno\s
|
|
73
|
-
/^\s?Op\s
|
|
74
|
-
/^\s
|
|
75
|
-
/^\s?Dnia\s
|
|
76
|
-
/^\s?Em\s
|
|
77
|
-
/^\s
|
|
78
|
-
/^\s
|
|
79
|
-
/^\s?Den\s
|
|
80
|
-
/^\s?\"
|
|
62
|
+
/^\s*-{8,10}\s*Forwarded message\s*-{8,10}\s*/m, // Gmail (all locales), Missive (en)
|
|
63
|
+
/^\s*_{32}\s*$/m, // Outlook Live / 365 (all locales)
|
|
64
|
+
/^\s?Dne\s?.+\,\s?.+\s*[\[|<].+[\]|>]\s?napsal\(a\)\s?:/m, // Outlook 2019 (cz)
|
|
65
|
+
/^\s?D.\s?.+\s?skrev\s?\".+\"\s*[\[|<].+[\]|>]\s?:/m, // Outlook 2019 (da)
|
|
66
|
+
/^\s?Am\s?.+\s?schrieb\s?\".+\"\s*[\[|<].+[\]|>]\s?:/m, // Outlook 2019 (de)
|
|
67
|
+
/^\s?On\s?.+\,\s?\".+\"\s*[\[|<].+[\]|>]\s?wrote\s?:/m, // Outlook 2019 (en)
|
|
68
|
+
/^\s?El\s?.+\,\s?\".+\"\s*[\[|<].+[\]|>]\s?escribió\s?:/m, // Outlook 2019 (es)
|
|
69
|
+
/^\s?Le\s?.+\,\s?«.+»\s*[\[|<].+[\]|>]\s?a écrit\s?:/m, // Outlook 2019 (fr)
|
|
70
|
+
/^\s?.+\s*[\[|<].+[\]|>]\s?kirjoitti\s?.+\s?:/m, // Outlook 2019 (fi)
|
|
71
|
+
/^\s?.+\s?időpontban\s?.+\s*[\[|<|(].+[\]|>|)]\s?ezt írta\s?:/m, // Outlook 2019 (hu)
|
|
72
|
+
/^\s?Il giorno\s?.+\s?\".+\"\s*[\[|<].+[\]|>]\s?ha scritto\s?:/m, // Outlook 2019 (it)
|
|
73
|
+
/^\s?Op\s?.+\s?heeft\s?.+\s*[\[|<].+[\]|>]\s?geschreven\s?:/m, // Outlook 2019 (nl)
|
|
74
|
+
/^\s?.+\s*[\[|<].+[\]|>]\s?skrev følgende den\s?.+\s?:/m, // Outlook 2019 (no)
|
|
75
|
+
/^\s?Dnia\s?.+\s?„.+”\s*[\[|<].+[\]|>]\s?napisał\s?:/m, // Outlook 2019 (pl)
|
|
76
|
+
/^\s?Em\s?.+\,\s?\".+\"\s*[\[|<].+[\]|>]\s?escreveu\s?:/m, // Outlook 2019 (pt)
|
|
77
|
+
/^\s?.+\s?пользователь\s?\".+\"\s*[\[|<].+[\]|>]\s?написал\s?:/m, // Outlook 2019 (ru)
|
|
78
|
+
/^\s?.+\s?používateľ\s?.+\s*\([\[|<].+[\]|>]\)\s?napísal\s?:/m, // Outlook 2019 (sk)
|
|
79
|
+
/^\s?Den\s?.+\s?skrev\s?\".+\"\s*[\[|<].+[\]|>]\s?följande\s?:/m, // Outlook 2019 (sv)
|
|
80
|
+
/^\s?\".+\"\s*[\[|<].+[\]|>]\,\s?.+\s?tarihinde şunu yazdı\s?:/m, // Outlook 2019 (tr)
|
|
81
81
|
/\s*-{5,8} Přeposlaná zpráva -{5,8}\s*/m, // Yahoo Mail (cs), Thunderbird (cs)
|
|
82
82
|
/\s*-{5,8} Videresendt meddelelse -{5,8}\s*/m, // Yahoo Mail (da), Thunderbird (da)
|
|
83
83
|
/\s*-{5,8} Weitergeleitete Nachricht -{5,8}\s*/m, // Yahoo Mail (de), Thunderbird (de)
|
|
@@ -109,8 +109,28 @@ var REGEXES = {
|
|
|
109
109
|
/\s*-{8} Переслане повідомлення -{8}\s*/m // Thunderbird (uk)
|
|
110
110
|
],
|
|
111
111
|
|
|
112
|
+
separator_with_information : [
|
|
113
|
+
/^\s?Dne\s?(?<date>.+)\,\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?napsal\(a\)\s?:/m, // Outlook 2019 (cz)
|
|
114
|
+
/^\s?D.\s?(?<date>.+)\s?skrev\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?:/m, // Outlook 2019 (da)
|
|
115
|
+
/^\s?Am\s?(?<date>.+)\s?schrieb\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?:/m, // Outlook 2019 (de)
|
|
116
|
+
/^\s?On\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?wrote\s?:/m, // Outlook 2019 (en)
|
|
117
|
+
/^\s?El\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?escribió\s?:/m, // Outlook 2019 (es)
|
|
118
|
+
/^\s?Le\s?(?<date>.+)\,\s?«(?<from_name>.+)»\s*[\[|<](?<from_address>.+)[\]|>]\s?a écrit\s?:/m, // Outlook 2019 (fr)
|
|
119
|
+
/^\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?kirjoitti\s?(?<date>.+)\s?:/m, // Outlook 2019 (fi)
|
|
120
|
+
/^\s?(?<date>.+)\s?időpontban\s?(?<from_name>.+)\s*[\[|<|(](?<from_address>.+)[\]|>|)]\s?ezt írta\s?:/m, // Outlook 2019 (hu)
|
|
121
|
+
/^\s?Il giorno\s?(?<date>.+)\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?ha scritto\s?:/m, // Outlook 2019 (it)
|
|
122
|
+
/^\s?Op\s?(?<date>.+)\s?heeft\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?geschreven\s?:/m, // Outlook 2019 (nl)
|
|
123
|
+
/^\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?skrev følgende den\s?(?<date>.+)\s?:/m, // Outlook 2019 (no)
|
|
124
|
+
/^\s?Dnia\s?(?<date>.+)\s?„(?<from_name>.+)”\s*[\[|<](?<from_address>.+)[\]|>]\s?napisał\s?:/m, // Outlook 2019 (pl)
|
|
125
|
+
/^\s?Em\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?escreveu\s?:/m, // Outlook 2019 (pt)
|
|
126
|
+
/^\s?(?<date>.+)\s?пользователь\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?написал\s?:/m, // Outlook 2019 (ru)
|
|
127
|
+
/^\s?(?<date>.+)\s?používateľ\s?(?<from_name>.+)\s*\([\[|<](?<from_address>.+)[\]|>]\)\s?napísal\s?:/m, // Outlook 2019 (sk)
|
|
128
|
+
/^\s?Den\s?(?<date>.+)\s?skrev\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?följande\s?:/m, // Outlook 2019 (sv)
|
|
129
|
+
/^\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\,\s?(?<date>.+)\s?tarihinde şunu yazdı\s?:/m // Outlook 2019 (tr)
|
|
130
|
+
],
|
|
131
|
+
|
|
112
132
|
original_subject : [
|
|
113
|
-
/^Subject\s?:(.+)/im, // Apple Mail (en), Gmail (all locales), Outlook Live (all locales), New Outlook 2019 (en), Thunderbird (da, en)
|
|
133
|
+
/^Subject\s?:(.+)/im, // Apple Mail (en), Gmail (all locales), Outlook Live / 365 (all locales), New Outlook 2019 (en), Thunderbird (da, en), Missive (en)
|
|
114
134
|
/^Předmět\s?:(.+)/im, // Apple Mail (cs), New Outlook 2019 (cs), Thunderbird (cs)
|
|
115
135
|
/^Emne\s?:(.+)/im, // Apple Mail (da, no), New Outlook 2019 (da), Thunderbird (no)
|
|
116
136
|
/^Betreff\s?:(.+)/im, // Apple Mail (de), New Outlook 2019 (de), Thunderbird (de)
|
|
@@ -152,7 +172,7 @@ var REGEXES = {
|
|
|
152
172
|
],
|
|
153
173
|
|
|
154
174
|
original_from : [
|
|
155
|
-
/^(\s*From\s?:(.+))$/m, // Apple Mail (en), Outlook Live (all locales), New Outlook 2019 (en), Thunderbird (da, en)
|
|
175
|
+
/^(\s*From\s?:(.+))$/m, // Apple Mail (en), Outlook Live / 365 (all locales), New Outlook 2019 (en), Thunderbird (da, en), Missive (en)
|
|
156
176
|
/^(\s*Od\s?:(.+))$/m, // Apple Mail (cs, pl, sk), Gmail (cs, pl, sk), New Outlook 2019 (cs, pl, sk), Thunderbird (cs, sk)
|
|
157
177
|
/^(\s*Fra\s?:(.+))$/m, // Apple Mail (da, no), Gmail (da, no), New Outlook 2019 (da), Thunderbird (no)
|
|
158
178
|
/^(\s*Von\s?:(.+))$/m, // Apple Mail (de), Gmail (de), New Outlook 2019 (de), Thunderbird (de)
|
|
@@ -195,7 +215,7 @@ var REGEXES = {
|
|
|
195
215
|
],
|
|
196
216
|
|
|
197
217
|
original_to : [
|
|
198
|
-
/^\s*To\s?:(.+)$/m, // Apple Mail (en), Gmail (all locales), Outlook Live (all locales), Thunderbird (da, en)
|
|
218
|
+
/^\s*To\s?:(.+)$/m, // Apple Mail (en), Gmail (all locales), Outlook Live / 365 (all locales), Thunderbird (da, en), Missive (en)
|
|
199
219
|
/^\s*Komu\s?:(.+)$/m, // Apple Mail (cs), New Outlook 2019 (cs, sk), Thunderbird (cs)
|
|
200
220
|
/^\s*Til\s?:(.+)$/m, // Apple Mail (da, no), New Outlook 2019 (da), Thunderbird (no)
|
|
201
221
|
/^\s*An\s?:(.+)$/m, // Apple Mail (de), New Outlook 2019 (de), Thunderbird (de)
|
|
@@ -258,7 +278,7 @@ var REGEXES = {
|
|
|
258
278
|
],
|
|
259
279
|
|
|
260
280
|
original_cc : [
|
|
261
|
-
/^\s*Cc\s?:(.+)$/m, // Apple Mail (en, da, es, fr, hr, it, pt, pt-br, ro, sk), Gmail (all locales), Outlook Live (all locales), New Outlook 2019 (da, de, en, fr, it, pt-br)
|
|
281
|
+
/^\s*Cc\s?:(.+)$/m, // Apple Mail (en, da, es, fr, hr, it, pt, pt-br, ro, sk), Gmail (all locales), Outlook Live / 365 (all locales), New Outlook 2019 (da, de, en, fr, it, pt-br), Missive (en)
|
|
262
282
|
/^\s*CC\s?:(.+)$/m, // New Outlook 2019 (es, nl, pt), Thunderbird (da, en, es, fi, hr, hu, it, nl, no, pt, pt-br, ro, tr, uk)
|
|
263
283
|
/^\s*Kopie\s?:(.+)$/m, // Apple Mail (cs, de, nl), New Outlook 2019 (cs), Thunderbird (cs)
|
|
264
284
|
/^\s*Kopio\s?:(.+)$/m, // Apple Mail (fi), New Outlook 2019 (es)
|
|
@@ -291,7 +311,7 @@ var REGEXES = {
|
|
|
291
311
|
],
|
|
292
312
|
|
|
293
313
|
original_date : [
|
|
294
|
-
/^\s*Date\s?:(.+)$/m, // Apple Mail (en, fr), Gmail (all locales), New Outlook 2019 (en, fr), Thunderbird (da, en, fr)
|
|
314
|
+
/^\s*Date\s?:(.+)$/m, // Apple Mail (en, fr), Gmail (all locales), New Outlook 2019 (en, fr), Thunderbird (da, en, fr), Missive (en)
|
|
295
315
|
/^\s*Datum\s?:(.+)$/m, // Apple Mail (cs, de, hr, nl, sv), New Outlook 2019 (cs, de, nl, sv), Thunderbird (cs, de, hr, nl, sv)
|
|
296
316
|
/^\s*Dato\s?:(.+)$/m, // Apple Mail (da, no), New Outlook 2019 (da), Thunderbird (no)
|
|
297
317
|
/^\s*Fecha\s?:(.+)$/m, // Apple Mail (es), New Outlook 2019 (es), Thunderbird (es)
|
|
@@ -301,7 +321,7 @@ var REGEXES = {
|
|
|
301
321
|
/^\s*Dată\s?:(.+)$/m, // Apple Mail (ro), Thunderbird (ro)
|
|
302
322
|
/^\s*Дата\s?:(.+)$/m, // Apple Mail (ru, uk), New Outlook 2019 (ru), Thunderbird (ru, uk)
|
|
303
323
|
/^\s*Tarih\s?:(.+)$/m, // Apple Mail (tr), Thunderbird (tr)
|
|
304
|
-
/^\s*Sent\s?:(.+)$/m, // Outlook Live (all locales)
|
|
324
|
+
/^\s*Sent\s?:(.+)$/m, // Outlook Live / 365 (all locales)
|
|
305
325
|
/^\s*Päiväys\s?:(.+)$/m // Thunderbird (fi)
|
|
306
326
|
],
|
|
307
327
|
|
|
@@ -326,6 +346,8 @@ var REGEXES = {
|
|
|
326
346
|
],
|
|
327
347
|
|
|
328
348
|
mailbox : [
|
|
349
|
+
/^\s?\n?\s*<.+?<mailto\:(.+?)>>/, // "<walter.sheltan@acme.com<mailto:walter.sheltan@acme.com>>"
|
|
350
|
+
/^(.+?)\s?\n?\s*<.+?<mailto\:(.+?)>>/, // "Walter Sheltan <walter.sheltan@acme.com<mailto:walter.sheltan@acme.com>>"
|
|
329
351
|
/^(.+?)\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
352
|
/^\'(.+?)\'\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
353
|
/^\"\'(.+?)\'\"\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>"
|
|
@@ -384,8 +406,8 @@ class Parser {
|
|
|
384
406
|
// Remove Byte Order Mark
|
|
385
407
|
_body = _body.replace(this.__regexes.byte_order_mark, "");
|
|
386
408
|
|
|
387
|
-
// First method: split via the separator (Apple Mail, Gmail,
|
|
388
|
-
// Outlook 2019, Yahoo Mail, Thunderbird)
|
|
409
|
+
// First method: split via the separator (Apple Mail, Gmail, \
|
|
410
|
+
// Outlook Live / 365, Outlook 2019, Yahoo Mail, Thunderbird)
|
|
389
411
|
var _match = loopRegexes(this.__regexes.separator, _body, "split");
|
|
390
412
|
|
|
391
413
|
if (_match && _match.length > 1) {
|
|
@@ -393,7 +415,7 @@ class Parser {
|
|
|
393
415
|
body : _body,
|
|
394
416
|
|
|
395
417
|
message : trimString(_match[0]),
|
|
396
|
-
email : trimString(_match[
|
|
418
|
+
email : trimString(_match[1])
|
|
397
419
|
};
|
|
398
420
|
}
|
|
399
421
|
|
|
@@ -488,7 +510,7 @@ class Parser {
|
|
|
488
510
|
var _match = null;
|
|
489
511
|
|
|
490
512
|
// First method: extract the text after the Cc, To or Reply-To part \
|
|
491
|
-
// (Apple Mail, Gmail) or after the Subject part (Outlook Live)
|
|
513
|
+
// (Apple Mail, Gmail) or after the Subject part (Outlook Live / 365)
|
|
492
514
|
var _regexes = [
|
|
493
515
|
this.__regexes.original_subject,
|
|
494
516
|
this.__regexes.original_cc,
|
|
@@ -540,7 +562,7 @@ class Parser {
|
|
|
540
562
|
var _name = null;
|
|
541
563
|
|
|
542
564
|
// First method: extract the author via the From part (Apple Mail, Gmail, \
|
|
543
|
-
// Outlook Live, New Outlook 2019, Thunderbird)
|
|
565
|
+
// Outlook Live / 365, New Outlook 2019, Thunderbird)
|
|
544
566
|
var _author = this.__parseMailbox(this.__regexes.original_from, text);
|
|
545
567
|
|
|
546
568
|
// Author found?
|
|
@@ -549,7 +571,7 @@ class Parser {
|
|
|
549
571
|
}
|
|
550
572
|
|
|
551
573
|
// Second method: extract the author via the separator (Outlook 2019)
|
|
552
|
-
var _match = loopRegexes(this.__regexes.
|
|
574
|
+
var _match = loopRegexes(this.__regexes.separator_with_information, body);
|
|
553
575
|
|
|
554
576
|
if (_match && _match.length === 4 && _match.groups) {
|
|
555
577
|
// Notice: the order of parts may change depending on the localization, \
|
|
@@ -598,7 +620,7 @@ class Parser {
|
|
|
598
620
|
*/
|
|
599
621
|
__parseOriginalTo(text) {
|
|
600
622
|
// First method: extract the primary recipient(s) via the To part \
|
|
601
|
-
// (Apple Mail, Gmail, Outlook Live, New Outlook 2019, Thunderbird)
|
|
623
|
+
// (Apple Mail, Gmail, Outlook Live / 365, New Outlook 2019, Thunderbird)
|
|
602
624
|
var _recipients = this.__parseMailbox(
|
|
603
625
|
this.__regexes.original_to,
|
|
604
626
|
|
|
@@ -654,7 +676,7 @@ class Parser {
|
|
|
654
676
|
*/
|
|
655
677
|
__parseOriginalCc(text) {
|
|
656
678
|
// First method: extract the carbon-copy recipient(s) via the Cc part \
|
|
657
|
-
// (Apple Mail, Gmail, Outlook Live, New Outlook 2019, Thunderbird)
|
|
679
|
+
// (Apple Mail, Gmail, Outlook Live / 365, New Outlook 2019, Thunderbird)
|
|
658
680
|
var _recipients = this.__parseMailbox(
|
|
659
681
|
this.__regexes.original_cc,
|
|
660
682
|
|
|
@@ -795,7 +817,7 @@ class Parser {
|
|
|
795
817
|
*/
|
|
796
818
|
__parseOriginalSubject(text) {
|
|
797
819
|
// First method: extract the subject via the Subject part (Apple Mail, \
|
|
798
|
-
// Gmail, Outlook Live, New Outlook 2019, Thunderbird)
|
|
820
|
+
// Gmail, Outlook Live / 365, New Outlook 2019, Thunderbird)
|
|
799
821
|
var _match = loopRegexes(this.__regexes.original_subject, text);
|
|
800
822
|
|
|
801
823
|
if (_match && _match.length > 0) {
|
|
@@ -823,7 +845,7 @@ class Parser {
|
|
|
823
845
|
*/
|
|
824
846
|
__parseOriginalDate(text, body) {
|
|
825
847
|
// First method: extract the date via the Date part (Apple Mail, Gmail, \
|
|
826
|
-
// Outlook Live, New Outlook 2019, Thunderbird)
|
|
848
|
+
// Outlook Live / 365, New Outlook 2019, Thunderbird)
|
|
827
849
|
var _match = loopRegexes(this.__regexes.original_date, text);
|
|
828
850
|
|
|
829
851
|
if (_match && _match.length > 0) {
|
|
@@ -831,7 +853,7 @@ class Parser {
|
|
|
831
853
|
}
|
|
832
854
|
|
|
833
855
|
// Second method: extract the date via the separator (Outlook 2019)
|
|
834
|
-
_match = loopRegexes(this.__regexes.
|
|
856
|
+
_match = loopRegexes(this.__regexes.separator_with_information, body);
|
|
835
857
|
|
|
836
858
|
if (_match && _match.length === 4 && _match.groups) {
|
|
837
859
|
// Notice: the order of parts may change depending on the localization, \
|
package/package.json
CHANGED
package/result+1.txt
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
--
|
|
3
|
-
|
|
4
|
-
Baptiste Jamin
|
|
5
|
-
CEO, Crisp <https://crisp.im/> - Connect your customers to your team.
|
|
6
|
-
|
|
7
|
-
> Begin forwarded message:
|
|
8
|
-
>
|
|
9
|
-
> From: "Grant, Jordan" <Jordan.Grant@slam.nhs.uk>
|
|
10
|
-
> Subject: Re: [ACTION REQUIRED] Your Crisp subscription is about to be cancelled
|
|
11
|
-
> Date: 9 May 2022 at 14:09:04 CEST
|
|
12
|
-
> To: "'billing@crisp.chat'" <billing@crisp.chat>, "'baptiste@crisp.chat'" <baptiste@crisp.chat>
|
|
13
|
-
> Cc: "Winter, Helen" <Helen.Winter@slam.nhs.uk>, "Pollard, Clair" <Clair.Pollard@slam.nhs.uk>, "Wilson, Hannah" <Hannah.Wilson2@slam.nhs.uk>
|
|
14
|
-
>
|
|
15
|
-
> Hi Billings team,
|
|
16
|
-
>
|
|
17
|
-
> My name is Jordan Grant and I am emailing on behalf of Helen winter in regards to the CRISP subscription.
|
|
18
|
-
>
|
|
19
|
-
> We still would like to continue this subscription but will need more time to make payment. As we have a process we need to go through on our side.
|
|
20
|
-
>
|
|
21
|
-
> Apologies for the delay in getting back you sooner.
|
|
22
|
-
>
|
|
23
|
-
> Helen, we could not renew your subscriptions.
|
|
24
|
-
> We are still awaiting for the payment due on your Crisp account.
|
|
25
|
-
> Please check your unpaid invoices in your Crisp settings, and proceed the manual payment if you did not do so yet.
|
|
26
|
-
> Provider:
|
|
27
|
-
> WIRE
|
|
28
|
-
> Payment Details:
|
|
29
|
-
> GB 1234XXX
|
|
30
|
-
> Expiration:
|
|
31
|
-
> 05/22
|
|
32
|
-
> Review my billing settings <https://hooks.crisp.chat/email/link/notification/?user_id=4f8a3219-b77d-47fd-b754-0b9d39fd3bb7&type=billing_charge_error&link_url=https%3A%2F%2Fapp.crisp.chat%2Fsettings%2Fbilling%2F&signature=72098c797340a00>
|
|
33
|
-
> Note that if we do not receive the funds within a week, we will have to cancel your subscription. If you need more time, you can still contact us and ask us to extend the payment delay.
|
|
34
|
-
> You receive this email because we could not renew some active subscriptions on Crisp.
|
|
35
|
-
> Crisp website <https://crisp.chat/>
|
|
36
|
-
> Documentation <https://help.crisp.chat/>
|
|
37
|
-
> Unsubscribe from emails <https://app.crisp.chat/settings/notifications/>
|
|
38
|
-
>
|
|
39
|
-
> We run on
|
|
40
|
-
>
|
|
41
|
-
>
|
|
42
|
-
>
|
|
43
|
-
>
|
|
44
|
-
>
|
|
45
|
-
> Jordan Grant
|
|
46
|
-
> Business Manager, Corporate Psychology and Psychotherapy
|
|
47
|
-
> South London and Maudsley NHS Foundation Trust
|
|
48
|
-
> The Maudsley Hospital
|
|
49
|
-
> Email: jordan.grant@slam.nhs.uk <mailto:jordan.grant@slam.nhs.uk>
|
|
50
|
-
> 020 3228 6000 The switchboard number for SLaM
|
|
51
|
-
|
package/test-regex.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
var RE2 = require("re2");
|
|
2
|
-
var { loopRegexes, trimString } = require("./lib/utils");
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var MAILBOXES_SEPARATORS = [
|
|
6
|
-
",", // Apple Mail, Gmail, New Outlook 2019, Thunderbird
|
|
7
|
-
";" // Outlook Live, Yahoo Mail
|
|
8
|
-
];
|
|
9
|
-
|
|
10
|
-
this.__regexes = [];
|
|
11
|
-
|
|
12
|
-
var REGEXES = {
|
|
13
|
-
mailbox : [
|
|
14
|
-
/(.+?)\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>"
|
|
15
|
-
/\'(.+?)\'\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>"
|
|
16
|
-
/\"\'(.+?)\'\"\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>"
|
|
17
|
-
/\"(.+?)\"\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>"
|
|
18
|
-
/([^\,\;]+?)\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>"
|
|
19
|
-
/(.?)\s?\n?\s*[\[|<](.+?)[\]|>]/, // "<walter.sheltan@acme.com>" or "[walter.sheltan@acme.com]"
|
|
20
|
-
/([^\s@]+@[^\s@]+\.[^\s@,]+)/ // "walter.sheltan@acme.com"
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
for (var _key in REGEXES) {
|
|
25
|
-
var _entry = REGEXES[_key];
|
|
26
|
-
|
|
27
|
-
if (Array.isArray(_entry)) {
|
|
28
|
-
this.__regexes[_key] = [];
|
|
29
|
-
|
|
30
|
-
for (var _i = 0; _i < _entry.length; _i++) {
|
|
31
|
-
this.__regexes[_key].push(new RE2(_entry[_i]));
|
|
32
|
-
}
|
|
33
|
-
} else {
|
|
34
|
-
this.__regexes[_key] = new RE2(_entry);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Parses mailboxes(s)
|
|
41
|
-
* @private
|
|
42
|
-
* @param {object} regexes
|
|
43
|
-
* @param {string} text
|
|
44
|
-
* @param {boolean} [force_array]
|
|
45
|
-
* @return {object} The parsed mailboxes(s)
|
|
46
|
-
*/
|
|
47
|
-
var __parseMailbox = (regexes, text, force_array=false) => {
|
|
48
|
-
var _mailboxesLine = trimString("walter.sheltan@acme.com, Nicholas <nicholas@globex.corp>");
|
|
49
|
-
// var _mailboxesLine = trimString("bessie.berry@acme.com, suzanne@globex.corp");
|
|
50
|
-
// var _mailboxesLine = trimString("Walter Sheltan <walter.sheltan@acme.com>, Nicholas <nicholas@globex.corp>");
|
|
51
|
-
|
|
52
|
-
if (_mailboxesLine) {
|
|
53
|
-
var _mailboxes = [];
|
|
54
|
-
|
|
55
|
-
while (_mailboxesLine) {
|
|
56
|
-
var _mailboxMatch = loopRegexes(
|
|
57
|
-
this.__regexes.mailbox,
|
|
58
|
-
_mailboxesLine
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
// Name and address available?
|
|
62
|
-
if (_mailboxMatch && _mailboxMatch.length > 0) {
|
|
63
|
-
var _address = null;
|
|
64
|
-
var _name = null;
|
|
65
|
-
|
|
66
|
-
// Only address available?
|
|
67
|
-
if (_mailboxMatch.length === 2) {
|
|
68
|
-
_address = trimString(_mailboxMatch[1]);
|
|
69
|
-
} else {
|
|
70
|
-
_address = trimString(_mailboxMatch[2]);
|
|
71
|
-
_name = trimString(_mailboxMatch[1]);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
_mailboxes.push({
|
|
75
|
-
address : _address,
|
|
76
|
-
|
|
77
|
-
// Some clients fill the name with the address \
|
|
78
|
-
// ("bessie.berry@acme.com <bessie.berry@acme.com>")
|
|
79
|
-
name : (_address !== _name) ? _name : null
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Remove matched mailbox from mailboxes line
|
|
83
|
-
_mailboxesLine = trimString(
|
|
84
|
-
_mailboxesLine.replace(_mailboxMatch[0], "")
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
if (_mailboxesLine) {
|
|
88
|
-
// Remove trailing mailboxes separator
|
|
89
|
-
for (var _i = 0; _i < MAILBOXES_SEPARATORS.length; _i++) {
|
|
90
|
-
let _separator = MAILBOXES_SEPARATORS[_i];
|
|
91
|
-
|
|
92
|
-
if (_mailboxesLine[0] === _separator) {
|
|
93
|
-
_mailboxesLine = trimString(_mailboxesLine.substring(1));
|
|
94
|
-
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
_mailboxes.push({
|
|
101
|
-
address : trimString(_mailboxesLine),
|
|
102
|
-
name : null
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// No more matches
|
|
106
|
-
_mailboxesLine = "";
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Return multiple mailboxes
|
|
111
|
-
if (_mailboxes.length > 1) {
|
|
112
|
-
return _mailboxes;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Return single mailbox
|
|
116
|
-
return (force_array === true) ? _mailboxes : _mailboxes[0];
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
console.log(
|
|
122
|
-
__parseMailbox("Walter Sheltan <walter.sheltan@acme.com>, Nicholas <nicholas@globex.corp>")
|
|
123
|
-
);
|
package/test.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const EmailForwardParser = require("./");
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
|
|
4
|
-
MY_EMAIL_STRING = fs.readFileSync("./result+1.txt", "utf-8");
|
|
5
|
-
|
|
6
|
-
const result = new EmailForwardParser().read(MY_EMAIL_STRING, "Fwd: [ACTION REQUIRED] Your Crisp subscription is about to be cancelled");
|
|
7
|
-
|
|
8
|
-
console.log(result.forwarded);
|
|
9
|
-
console.log(result);
|
|
10
|
-
console.log(result.email.to);
|
|
11
|
-
console.log(result.email.cc);
|
|
12
|
-
// console.log(result.email.subject);
|
|
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
|
-
// }
|