email-forward-parser 1.0.14 → 1.0.17
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 +2 -1
- package/lib/parser.js +63 -35
- package/package.json +1 -1
- package/test.js +0 -25
- package/test.txt +0 -14
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, 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
|
|
@@ -95,6 +95,7 @@ Outlook 2019 | Yes | Yes | No | Yes | No | Yes | The From and Date parts (only o
|
|
|
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
|
@@ -5,7 +5,7 @@ var RE2 = require("re2");
|
|
|
5
5
|
var { loopRegexes, trimString } = require("./utils");
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var MAILBOXES_SEPARATORS = [
|
|
9
9
|
",", // Apple Mail, Gmail, New Outlook 2019, Thunderbird
|
|
10
10
|
";" // Outlook Live, Yahoo Mail
|
|
11
11
|
];
|
|
@@ -33,7 +33,7 @@ var REGEXES = {
|
|
|
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,7 +59,7 @@ 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)
|
|
62
|
+
/^\s*-{8,10}\s*Forwarded message\s*-{8,10}\s*/m, // Gmail (all locales), Missive (en)
|
|
63
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)
|
|
@@ -110,7 +110,7 @@ var REGEXES = {
|
|
|
110
110
|
],
|
|
111
111
|
|
|
112
112
|
original_subject : [
|
|
113
|
-
/^Subject\s?:(.+)/im, // Apple Mail (en), Gmail (all locales), Outlook Live (all locales), New Outlook 2019 (en), Thunderbird (da, en)
|
|
113
|
+
/^Subject\s?:(.+)/im, // Apple Mail (en), Gmail (all locales), Outlook Live (all locales), New Outlook 2019 (en), Thunderbird (da, en), Missive (en)
|
|
114
114
|
/^Předmět\s?:(.+)/im, // Apple Mail (cs), New Outlook 2019 (cs), Thunderbird (cs)
|
|
115
115
|
/^Emne\s?:(.+)/im, // Apple Mail (da, no), New Outlook 2019 (da), Thunderbird (no)
|
|
116
116
|
/^Betreff\s?:(.+)/im, // Apple Mail (de), New Outlook 2019 (de), Thunderbird (de)
|
|
@@ -152,7 +152,7 @@ var REGEXES = {
|
|
|
152
152
|
],
|
|
153
153
|
|
|
154
154
|
original_from : [
|
|
155
|
-
/^(\s*From\s?:(.+))$/m, // Apple Mail (en), Outlook Live (all locales), New Outlook 2019 (en), Thunderbird (da, en)
|
|
155
|
+
/^(\s*From\s?:(.+))$/m, // Apple Mail (en), Outlook Live (all locales), New Outlook 2019 (en), Thunderbird (da, en), Missive (en)
|
|
156
156
|
/^(\s*Od\s?:(.+))$/m, // Apple Mail (cs, pl, sk), Gmail (cs, pl, sk), New Outlook 2019 (cs, pl, sk), Thunderbird (cs, sk)
|
|
157
157
|
/^(\s*Fra\s?:(.+))$/m, // Apple Mail (da, no), Gmail (da, no), New Outlook 2019 (da), Thunderbird (no)
|
|
158
158
|
/^(\s*Von\s?:(.+))$/m, // Apple Mail (de), Gmail (de), New Outlook 2019 (de), Thunderbird (de)
|
|
@@ -195,7 +195,7 @@ var REGEXES = {
|
|
|
195
195
|
],
|
|
196
196
|
|
|
197
197
|
original_to : [
|
|
198
|
-
/^\s*To\s?:(.+)$/m, // Apple Mail (en), Gmail (all locales), Outlook Live (all locales), Thunderbird (da, en)
|
|
198
|
+
/^\s*To\s?:(.+)$/m, // Apple Mail (en), Gmail (all locales), Outlook Live (all locales), Thunderbird (da, en), Missive (en)
|
|
199
199
|
/^\s*Komu\s?:(.+)$/m, // Apple Mail (cs), New Outlook 2019 (cs, sk), Thunderbird (cs)
|
|
200
200
|
/^\s*Til\s?:(.+)$/m, // Apple Mail (da, no), New Outlook 2019 (da), Thunderbird (no)
|
|
201
201
|
/^\s*An\s?:(.+)$/m, // Apple Mail (de), New Outlook 2019 (de), Thunderbird (de)
|
|
@@ -258,7 +258,7 @@ var REGEXES = {
|
|
|
258
258
|
],
|
|
259
259
|
|
|
260
260
|
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)
|
|
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), Missive (en)
|
|
262
262
|
/^\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
263
|
/^\s*Kopie\s?:(.+)$/m, // Apple Mail (cs, de, nl), New Outlook 2019 (cs), Thunderbird (cs)
|
|
264
264
|
/^\s*Kopio\s?:(.+)$/m, // Apple Mail (fi), New Outlook 2019 (es)
|
|
@@ -291,7 +291,7 @@ var REGEXES = {
|
|
|
291
291
|
],
|
|
292
292
|
|
|
293
293
|
original_date : [
|
|
294
|
-
/^\s*Date\s?:(.+)$/m, // Apple Mail (en, fr), Gmail (all locales), New Outlook 2019 (en, fr), Thunderbird (da, en, fr)
|
|
294
|
+
/^\s*Date\s?:(.+)$/m, // Apple Mail (en, fr), Gmail (all locales), New Outlook 2019 (en, fr), Thunderbird (da, en, fr), Missive (en)
|
|
295
295
|
/^\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
296
|
/^\s*Dato\s?:(.+)$/m, // Apple Mail (da, no), New Outlook 2019 (da), Thunderbird (no)
|
|
297
297
|
/^\s*Fecha\s?:(.+)$/m, // Apple Mail (es), New Outlook 2019 (es), Thunderbird (es)
|
|
@@ -325,12 +325,16 @@ var REGEXES = {
|
|
|
325
325
|
/\s*Відправлено\s?:(.+)$/m // Yahoo Mail (uk)
|
|
326
326
|
],
|
|
327
327
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
/^(
|
|
332
|
-
|
|
333
|
-
|
|
328
|
+
mailbox : [
|
|
329
|
+
/^\s?\n?\s*<.+?<mailto\:(.+?)>>/, // "<walter.sheltan@acme.com<mailto:walter.sheltan@acme.com>>"
|
|
330
|
+
/^(.+?)\s?\n?\s*<.+?<mailto\:(.+?)>>/, // "Walter Sheltan <walter.sheltan@acme.com<mailto:walter.sheltan@acme.com>>"
|
|
331
|
+
/^(.+?)\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>"
|
|
332
|
+
/^\'(.+?)\'\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>"
|
|
333
|
+
/^\"\'(.+?)\'\"\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>"
|
|
334
|
+
/^\"(.+?)\"\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>"
|
|
335
|
+
/^([^,;]+?)\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>"
|
|
336
|
+
/^(.?)\s?\n?\s*[\[|<](.+?)[\]|>]/, // "<walter.sheltan@acme.com>"
|
|
337
|
+
/^([^\s@]+@[^\s@]+\.[^\s@,]+)/ // "walter.sheltan@acme.com"
|
|
334
338
|
]
|
|
335
339
|
};
|
|
336
340
|
|
|
@@ -708,37 +712,61 @@ class Parser {
|
|
|
708
712
|
var _mailboxesLine = trimString(_match[_match.length - 1]);
|
|
709
713
|
|
|
710
714
|
if (_mailboxesLine) {
|
|
711
|
-
var _mailboxes =
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
// Extract name and address (single / multiple mailboxes)
|
|
719
|
-
for (var _i = 0; _i < _mailboxes.length; _i++) {
|
|
720
|
-
var _nameAddressMatch = loopRegexes(
|
|
721
|
-
this.__regexes.name_address,
|
|
722
|
-
trimString(_mailboxes[_i])
|
|
715
|
+
var _mailboxes = [];
|
|
716
|
+
|
|
717
|
+
while (_mailboxesLine) {
|
|
718
|
+
var _mailboxMatch = loopRegexes(
|
|
719
|
+
this.__regexes.mailbox,
|
|
720
|
+
_mailboxesLine
|
|
723
721
|
);
|
|
724
722
|
|
|
725
|
-
//
|
|
726
|
-
if (
|
|
727
|
-
var _address =
|
|
728
|
-
var _name =
|
|
723
|
+
// Address and / or name available?
|
|
724
|
+
if (_mailboxMatch && _mailboxMatch.length > 0) {
|
|
725
|
+
var _address = null;
|
|
726
|
+
var _name = null;
|
|
727
|
+
|
|
728
|
+
// Address and name available?
|
|
729
|
+
if (_mailboxMatch.length === 3) {
|
|
730
|
+
_address = trimString(_mailboxMatch[2]);
|
|
731
|
+
_name = trimString(_mailboxMatch[1]);
|
|
732
|
+
} else {
|
|
733
|
+
_address = trimString(_mailboxMatch[1]);
|
|
734
|
+
}
|
|
729
735
|
|
|
730
|
-
_mailboxes
|
|
736
|
+
_mailboxes.push({
|
|
731
737
|
address : _address,
|
|
732
738
|
|
|
733
739
|
// Some clients fill the name with the address \
|
|
734
740
|
// ("bessie.berry@acme.com <bessie.berry@acme.com>")
|
|
735
741
|
name : (_address !== _name) ? _name : null
|
|
736
|
-
};
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
// Remove matched mailbox from mailboxes line
|
|
745
|
+
_mailboxesLine = trimString(
|
|
746
|
+
_mailboxesLine.replace(_mailboxMatch[0], "")
|
|
747
|
+
);
|
|
748
|
+
|
|
749
|
+
if (_mailboxesLine) {
|
|
750
|
+
// Remove leading mailboxes separator \
|
|
751
|
+
// (", Nicholas <nicholas@globex.corp>")
|
|
752
|
+
for (var _i = 0; _i < MAILBOXES_SEPARATORS.length; _i++) {
|
|
753
|
+
let _separator = MAILBOXES_SEPARATORS[_i];
|
|
754
|
+
|
|
755
|
+
if (_mailboxesLine[0] === _separator) {
|
|
756
|
+
_mailboxesLine = trimString(_mailboxesLine.substring(1));
|
|
757
|
+
|
|
758
|
+
break;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
737
762
|
} else {
|
|
738
|
-
_mailboxes
|
|
739
|
-
address : trimString(
|
|
763
|
+
_mailboxes.push({
|
|
764
|
+
address : trimString(_mailboxesLine),
|
|
740
765
|
name : null
|
|
741
|
-
};
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
// No more matches
|
|
769
|
+
_mailboxesLine = "";
|
|
742
770
|
}
|
|
743
771
|
}
|
|
744
772
|
|
package/package.json
CHANGED
package/test.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const EmailForwardParser = require("./");
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
|
|
4
|
-
MY_EMAIL_STRING = fs.readFileSync("./test.txt", "utf-8");
|
|
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:");
|
|
8
|
-
|
|
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
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
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
|