email-forward-parser 1.0.4 → 1.0.8
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/.github/workflows/test.yml +40 -0
- package/LICENSE +2 -2
- package/README.md +5 -4
- package/lib/index.js +2 -2
- package/lib/parser.js +106 -83
- package/package.json +4 -3
|
@@ -0,0 +1,40 @@
|
|
|
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
|
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 SARL
|
|
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
|
-
#
|
|
1
|
+
# Email Forward Parser
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/email-forward-parser) [](https://www.npmjs.com/package/email-forward-parser)
|
|
3
|
+
[](https://github.com/crisp-oss/email-forward-parser/actions?query=workflow%3A%22Test+and+Build%22) [](https://www.npmjs.com/package/email-forward-parser) [](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>
|
|
@@ -90,5 +92,4 @@ npm test
|
|
|
90
92
|
|
|
91
93
|
## License
|
|
92
94
|
|
|
93
|
-
email-forward-parser is released under the MIT License. See the bundled LICENSE
|
|
94
|
-
file for details.
|
|
95
|
+
email-forward-parser is released under the MIT License. See the bundled LICENSE file for details.
|
package/lib/index.js
CHANGED
package/lib/parser.js
CHANGED
|
@@ -60,23 +60,23 @@ var REGEXES = {
|
|
|
60
60
|
/^>?\s*Початок листа, що пересилається\s?:/m, // Apple Mail (uk)
|
|
61
61
|
/^\s*-{1,20}\s*Forwarded message\s*-{1,20}\s*/m, // Gmail (all locales)
|
|
62
62
|
/^\s*_{20,40}\s*$/m, // Outlook Live (all locales)
|
|
63
|
-
/^\s?Dne\s?(?<date>.+)\,\s?(?<from_name>.+)\s*[\[|<](?<
|
|
64
|
-
/^\s?D.\s?(?<date>.+)\s?skrev\s?\"(?<from_name>.+)\"\s*[\[|<](?<
|
|
65
|
-
/^\s?Am\s?(?<date>.+)\s?schrieb\s?\"(?<from_name>.+)\"\s*[\[|<](?<
|
|
66
|
-
/^\s?On\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<
|
|
67
|
-
/^\s?El\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<
|
|
68
|
-
/^\s?Le\s?(?<date>.+)\,\s?«(?<from_name>.+)»\s*[\[|<](?<
|
|
69
|
-
/^\s?(?<from_name>.+)\s*[\[|<](?<
|
|
70
|
-
/^\s?(?<date>.+)\s?időpontban\s?(?<from_name>.+)\s*[\[|<|(](?<
|
|
71
|
-
/^\s?Il giorno\s?(?<date>.+)\s?\"(?<from_name>.+)\"\s*[\[|<](?<
|
|
72
|
-
/^\s?Op\s?(?<date>.+)\s?heeft\s?(?<from_name>.+)\s*[\[|<](?<
|
|
73
|
-
/^\s?(?<from_name>.+)\s*[\[|<](?<
|
|
74
|
-
/^\s?Dnia\s?(?<date>.+)\s?„(?<from_name>.+)”\s*[\[|<](?<
|
|
75
|
-
/^\s?Em\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<
|
|
76
|
-
/^\s?(?<date>.+)\s?пользователь\s?\"(?<from_name>.+)\"\s*[\[|<](?<
|
|
77
|
-
/^\s?(?<date>.+)\s?používateľ\s?(?<from_name>.+)\s*\([\[|<](?<
|
|
78
|
-
/^\s?Den\s?(?<date>.+)\s?skrev\s?\"(?<from_name>.+)\"\s*[\[|<](?<
|
|
79
|
-
/^\s?\"(?<from_name>.+)\"\s*[\[|<](?<
|
|
63
|
+
/^\s?Dne\s?(?<date>.+)\,\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?napsal\(a\)\s?:/m, // Outlook 2019 (cz)
|
|
64
|
+
/^\s?D.\s?(?<date>.+)\s?skrev\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?:/m, // Outlook 2019 (da)
|
|
65
|
+
/^\s?Am\s?(?<date>.+)\s?schrieb\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?:/m, // Outlook 2019 (de)
|
|
66
|
+
/^\s?On\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?wrote\s?:/m, // Outlook 2019 (en)
|
|
67
|
+
/^\s?El\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?escribió\s?:/m, // Outlook 2019 (es)
|
|
68
|
+
/^\s?Le\s?(?<date>.+)\,\s?«(?<from_name>.+)»\s*[\[|<](?<from_address>.+)[\]|>]\s?a écrit\s?:/m, // Outlook 2019 (fr)
|
|
69
|
+
/^\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?kirjoitti\s?(?<date>.+)\s?:/m, // Outlook 2019 (fi)
|
|
70
|
+
/^\s?(?<date>.+)\s?időpontban\s?(?<from_name>.+)\s*[\[|<|(](?<from_address>.+)[\]|>|)]\s?ezt írta\s?:/m, // Outlook 2019 (hu)
|
|
71
|
+
/^\s?Il giorno\s?(?<date>.+)\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?ha scritto\s?:/m, // Outlook 2019 (it)
|
|
72
|
+
/^\s?Op\s?(?<date>.+)\s?heeft\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?geschreven\s?:/m, // Outlook 2019 (nl)
|
|
73
|
+
/^\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?skrev følgende den\s?(?<date>.+)\s?:/m, // Outlook 2019 (no)
|
|
74
|
+
/^\s?Dnia\s?(?<date>.+)\s?„(?<from_name>.+)”\s*[\[|<](?<from_address>.+)[\]|>]\s?napisał\s?:/m, // Outlook 2019 (pl)
|
|
75
|
+
/^\s?Em\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?escreveu\s?:/m, // Outlook 2019 (pt)
|
|
76
|
+
/^\s?(?<date>.+)\s?пользователь\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?написал\s?:/m, // Outlook 2019 (ru)
|
|
77
|
+
/^\s?(?<date>.+)\s?používateľ\s?(?<from_name>.+)\s*\([\[|<](?<from_address>.+)[\]|>]\)\s?napísal\s?:/m, // Outlook 2019 (sk)
|
|
78
|
+
/^\s?Den\s?(?<date>.+)\s?skrev\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?följande\s?:/m, // Outlook 2019 (sv)
|
|
79
|
+
/^\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\,\s?(?<date>.+)\s?tarihinde şunu yazdı\s?:/m, // Outlook 2019 (tr)
|
|
80
80
|
/\s*-{5,8} Přeposlaná zpráva -{5,8}\s*/m, // Yahoo Mail (cs), Thunderbird (cs)
|
|
81
81
|
/\s*-{5,8} Videresendt meddelelse -{5,8}\s*/m, // Yahoo Mail (da), Thunderbird (da)
|
|
82
82
|
/\s*-{5,8} Weitergeleitete Nachricht -{5,8}\s*/m, // Yahoo Mail (de), Thunderbird (de)
|
|
@@ -234,25 +234,25 @@ var REGEXES = {
|
|
|
234
234
|
],
|
|
235
235
|
|
|
236
236
|
original_reply_to : [
|
|
237
|
-
/^\s*Reply-To\s?:(.+)$/m // Apple Mail (en)
|
|
238
|
-
/^\s*Odgovori na\s?:(.+)$/m // Apple Mail (hr)
|
|
239
|
-
/^\s*Odpověď na\s?:(.+)$/m // Apple Mail (cs)
|
|
240
|
-
/^\s*Svar til\s?:(.+)$/m // Apple Mail (da)
|
|
241
|
-
/^\s*Antwoord aan\s?:(.+)$/m // Apple Mail (nl)
|
|
242
|
-
/^\s*Vastaus\s?:(.+)$/m // Apple Mail (fi)
|
|
243
|
-
/^\s*Répondre à\s?:(.+)$/m // Apple Mail (fr)
|
|
244
|
-
/^\s*Antwort an\s?:(.+)$/m // Apple Mail (de)
|
|
245
|
-
/^\s*Válaszcím\s?:(.+)$/m // Apple Mail (hu)
|
|
246
|
-
/^\s*Rispondi a\s?:(.+)$/m // Apple Mail (it)
|
|
247
|
-
/^\s*Svar til\s?:(.+)$/m // Apple Mail (no)
|
|
248
|
-
/^\s*Odpowiedź-do\s?:(.+)$/m // Apple Mail (pl)
|
|
249
|
-
/^\s*Responder A\s?:(.+)$/m // Apple Mail (pt)
|
|
250
|
-
/^\s*Responder a\s?:(.+)$/m // Apple Mail (pt-br, es)
|
|
251
|
-
/^\s*Răspuns către\s?:(.+)$/m // Apple Mail (ro)
|
|
252
|
-
/^\s*Ответ-Кому\s?:(.+)$/m // Apple Mail (ru)
|
|
253
|
-
/^\s*Odpovedať-Pre\s?:(.+)$/m // Apple Mail (sk)
|
|
254
|
-
/^\s*Svara till\s?:(.+)$/m // Apple Mail (sv)
|
|
255
|
-
/^\s*Yanıt Adresi\s?:(.+)$/m // Apple Mail (tr)
|
|
237
|
+
/^\s*Reply-To\s?:(.+)$/m, // Apple Mail (en)
|
|
238
|
+
/^\s*Odgovori na\s?:(.+)$/m, // Apple Mail (hr)
|
|
239
|
+
/^\s*Odpověď na\s?:(.+)$/m, // Apple Mail (cs)
|
|
240
|
+
/^\s*Svar til\s?:(.+)$/m, // Apple Mail (da)
|
|
241
|
+
/^\s*Antwoord aan\s?:(.+)$/m, // Apple Mail (nl)
|
|
242
|
+
/^\s*Vastaus\s?:(.+)$/m, // Apple Mail (fi)
|
|
243
|
+
/^\s*Répondre à\s?:(.+)$/m, // Apple Mail (fr)
|
|
244
|
+
/^\s*Antwort an\s?:(.+)$/m, // Apple Mail (de)
|
|
245
|
+
/^\s*Válaszcím\s?:(.+)$/m, // Apple Mail (hu)
|
|
246
|
+
/^\s*Rispondi a\s?:(.+)$/m, // Apple Mail (it)
|
|
247
|
+
/^\s*Svar til\s?:(.+)$/m, // Apple Mail (no)
|
|
248
|
+
/^\s*Odpowiedź-do\s?:(.+)$/m, // Apple Mail (pl)
|
|
249
|
+
/^\s*Responder A\s?:(.+)$/m, // Apple Mail (pt)
|
|
250
|
+
/^\s*Responder a\s?:(.+)$/m, // Apple Mail (pt-br, es)
|
|
251
|
+
/^\s*Răspuns către\s?:(.+)$/m, // Apple Mail (ro)
|
|
252
|
+
/^\s*Ответ-Кому\s?:(.+)$/m, // Apple Mail (ru)
|
|
253
|
+
/^\s*Odpovedať-Pre\s?:(.+)$/m, // Apple Mail (sk)
|
|
254
|
+
/^\s*Svara till\s?:(.+)$/m, // Apple Mail (sv)
|
|
255
|
+
/^\s*Yanıt Adresi\s?:(.+)$/m, // Apple Mail (tr)
|
|
256
256
|
/^\s*Кому відповісти\s?:(.+)$/m // Apple Mail (uk)
|
|
257
257
|
],
|
|
258
258
|
|
|
@@ -324,7 +324,7 @@ var REGEXES = {
|
|
|
324
324
|
/\s*Відправлено\s?:(.+)$/m // Yahoo Mail (uk)
|
|
325
325
|
],
|
|
326
326
|
|
|
327
|
-
|
|
327
|
+
name_address : [
|
|
328
328
|
/^\"(.+)\"\s?\n?\s*[\[|<](.+)[\]|>]$/, // ""Walter Sheltan" <walter.sheltan@acme.com>" or ""walter.sheltan@acme.com" <walter.sheltan@acme.com>"
|
|
329
329
|
/^(.+)\s?\n?\s*[\[|<](.+)[\]|>]$/, // "Walter Sheltan <walter.sheltan@acme.com>" or "walter.sheltan@acme.com <walter.sheltan@acme.com>"
|
|
330
330
|
/^(.?)\s?\n?\s*[\[|<](.+)[\]|>]$/, // "<walter.sheltan@acme.com>"
|
|
@@ -393,9 +393,9 @@ class Parser {
|
|
|
393
393
|
|
|
394
394
|
// Attempt second method?
|
|
395
395
|
// Notice: as this second method is more uncertain (we split via the From \
|
|
396
|
-
//
|
|
397
|
-
// attempt it. The `forwarded` boolean gives the confirmation that the
|
|
398
|
-
//
|
|
396
|
+
// 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)
|
|
399
399
|
if (forwarded === true) {
|
|
400
400
|
// Second method: split via the Form part (New Outlook 2019)
|
|
401
401
|
_match = loopRegexes(this.__regexes.original_from, _body, "split");
|
|
@@ -481,7 +481,7 @@ class Parser {
|
|
|
481
481
|
__parseOriginalBody(text) {
|
|
482
482
|
var _match = null;
|
|
483
483
|
|
|
484
|
-
// First method: extract the text after the Cc, To or Reply-To part
|
|
484
|
+
// First method: extract the text after the Cc, To or Reply-To part \
|
|
485
485
|
// (Apple Mail, Gmail) or after the Subject part (Outlook Live)
|
|
486
486
|
var _regexes = [
|
|
487
487
|
this.__regexes.original_subject,
|
|
@@ -500,7 +500,7 @@ class Parser {
|
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
502
|
|
|
503
|
-
// Second method: extract the text after the Subject part
|
|
503
|
+
// Second method: extract the text after the Subject part \
|
|
504
504
|
// (New Outlook 2019, Yahoo Mail)
|
|
505
505
|
_match = loopRegexes(
|
|
506
506
|
this.__regexes.original_subject.concat(
|
|
@@ -530,7 +530,7 @@ class Parser {
|
|
|
530
530
|
* @return {object} The parsed author
|
|
531
531
|
*/
|
|
532
532
|
__parseOriginalFrom(text, body) {
|
|
533
|
-
var
|
|
533
|
+
var _address = null;
|
|
534
534
|
var _name = null;
|
|
535
535
|
|
|
536
536
|
// First method: extract the author via the From part (Apple Mail, Gmail, \
|
|
@@ -538,7 +538,7 @@ class Parser {
|
|
|
538
538
|
var _author = this.__parseMailbox(this.__regexes.original_from, text);
|
|
539
539
|
|
|
540
540
|
// Author found?
|
|
541
|
-
if (_author.
|
|
541
|
+
if (_author.address) {
|
|
542
542
|
return _author;
|
|
543
543
|
}
|
|
544
544
|
|
|
@@ -548,15 +548,15 @@ class Parser {
|
|
|
548
548
|
if (_match && _match.length === 4 && _match.groups) {
|
|
549
549
|
// Notice: the order of parts may change depending on the localization, \
|
|
550
550
|
// hence the use of named groups
|
|
551
|
-
|
|
551
|
+
_address = trimString(_match.groups.from_address);
|
|
552
552
|
_name = trimString(_match.groups.from_name);
|
|
553
553
|
|
|
554
554
|
return {
|
|
555
|
-
|
|
555
|
+
address : _address,
|
|
556
556
|
|
|
557
|
-
// Some clients fill the name with the
|
|
557
|
+
// Some clients fill the name with the address \
|
|
558
558
|
// ("bessie.berry@acme.com <bessie.berry@acme.com>")
|
|
559
|
-
name
|
|
559
|
+
name : (_address !== _name) ? _name : null
|
|
560
560
|
};
|
|
561
561
|
}
|
|
562
562
|
|
|
@@ -565,21 +565,21 @@ class Parser {
|
|
|
565
565
|
_match = loopRegexes(this.__regexes.original_from_lax, text);
|
|
566
566
|
|
|
567
567
|
if (_match && _match.length > 1) {
|
|
568
|
-
|
|
568
|
+
_address = trimString(_match[3]);
|
|
569
569
|
_name = trimString(_match[2]);
|
|
570
570
|
|
|
571
571
|
return {
|
|
572
|
-
|
|
572
|
+
address : _address,
|
|
573
573
|
|
|
574
|
-
// Some clients fill the name with the
|
|
574
|
+
// Some clients fill the name with the address \
|
|
575
575
|
// ("bessie.berry@acme.com <bessie.berry@acme.com>")
|
|
576
|
-
name
|
|
576
|
+
name : (_address !== _name) ? _name : null
|
|
577
577
|
};
|
|
578
578
|
}
|
|
579
579
|
|
|
580
580
|
return {
|
|
581
|
-
|
|
582
|
-
name
|
|
581
|
+
address : _address,
|
|
582
|
+
name : _name
|
|
583
583
|
};
|
|
584
584
|
}
|
|
585
585
|
|
|
@@ -593,11 +593,16 @@ class Parser {
|
|
|
593
593
|
__parseOriginalTo(text) {
|
|
594
594
|
// First method: extract the primary recipient(s) via the To part \
|
|
595
595
|
// (Apple Mail, Gmail, Outlook Live, New Outlook 2019, Thunderbird)
|
|
596
|
-
var _recipients = this.__parseMailbox(
|
|
596
|
+
var _recipients = this.__parseMailbox(
|
|
597
|
+
this.__regexes.original_to,
|
|
598
|
+
|
|
599
|
+
text,
|
|
600
|
+
true //- [force_array]
|
|
601
|
+
);
|
|
597
602
|
|
|
598
603
|
// Recipient(s) found?
|
|
599
|
-
if (Array.isArray(_recipients)
|
|
600
|
-
!(_recipients.
|
|
604
|
+
if (Array.isArray(_recipients) &&
|
|
605
|
+
!(_recipients[0].address === null && _recipients[0].name === null)
|
|
601
606
|
) {
|
|
602
607
|
return _recipients;
|
|
603
608
|
}
|
|
@@ -626,8 +631,12 @@ class Parser {
|
|
|
626
631
|
"replace"
|
|
627
632
|
);
|
|
628
633
|
|
|
634
|
+
return this.__parseMailbox(
|
|
635
|
+
this.__regexes.original_to_lax,
|
|
629
636
|
|
|
630
|
-
|
|
637
|
+
_cleanText,
|
|
638
|
+
true //- [force_array]
|
|
639
|
+
);
|
|
631
640
|
}
|
|
632
641
|
|
|
633
642
|
|
|
@@ -638,13 +647,18 @@ class Parser {
|
|
|
638
647
|
* @return {object} The parsed carbon-copy recipient(s)
|
|
639
648
|
*/
|
|
640
649
|
__parseOriginalCc(text) {
|
|
641
|
-
// First method: extract the carbon-copy recipient(s) via the Cc part
|
|
650
|
+
// First method: extract the carbon-copy recipient(s) via the Cc part \
|
|
642
651
|
// (Apple Mail, Gmail, Outlook Live, New Outlook 2019, Thunderbird)
|
|
643
|
-
var _recipients = this.__parseMailbox(
|
|
652
|
+
var _recipients = this.__parseMailbox(
|
|
653
|
+
this.__regexes.original_cc,
|
|
654
|
+
|
|
655
|
+
text,
|
|
656
|
+
true //- [force_array]
|
|
657
|
+
);
|
|
644
658
|
|
|
645
659
|
// Recipient(s) found?
|
|
646
|
-
if (Array.isArray(_recipients)
|
|
647
|
-
!(_recipients.
|
|
660
|
+
if (Array.isArray(_recipients) &&
|
|
661
|
+
!(_recipients[0].address === null && _recipients[0].name === null)
|
|
648
662
|
) {
|
|
649
663
|
return _recipients;
|
|
650
664
|
}
|
|
@@ -666,17 +680,24 @@ class Parser {
|
|
|
666
680
|
"replace"
|
|
667
681
|
);
|
|
668
682
|
|
|
669
|
-
return this.__parseMailbox(
|
|
683
|
+
return this.__parseMailbox(
|
|
684
|
+
this.__regexes.original_cc_lax,
|
|
685
|
+
|
|
686
|
+
_cleanText,
|
|
687
|
+
true //- [force_array]
|
|
688
|
+
);
|
|
670
689
|
}
|
|
671
690
|
|
|
672
691
|
|
|
673
692
|
/**
|
|
674
693
|
* Parses mailboxes(s)
|
|
675
694
|
* @private
|
|
676
|
-
* @param {
|
|
677
|
-
* @
|
|
695
|
+
* @param {object} regexes
|
|
696
|
+
* @param {string} text
|
|
697
|
+
* @param {boolean} [force_array]
|
|
698
|
+
* @return {object} The parsed mailboxes(s)
|
|
678
699
|
*/
|
|
679
|
-
__parseMailbox(regexes, text) {
|
|
700
|
+
__parseMailbox(regexes, text, force_array=false) {
|
|
680
701
|
var _match = loopRegexes(regexes, text);
|
|
681
702
|
|
|
682
703
|
if (_match && _match.length > 0) {
|
|
@@ -690,29 +711,29 @@ class Parser {
|
|
|
690
711
|
"split"
|
|
691
712
|
);
|
|
692
713
|
|
|
693
|
-
// Extract name and
|
|
714
|
+
// Extract name and address (single / multiple mailboxes)
|
|
694
715
|
for (var _i = 0; _i < _mailboxes.length; _i++) {
|
|
695
|
-
var
|
|
696
|
-
this.__regexes.
|
|
716
|
+
var _nameAddressMatch = loopRegexes(
|
|
717
|
+
this.__regexes.name_address,
|
|
697
718
|
trimString(_mailboxes[_i])
|
|
698
719
|
);
|
|
699
720
|
|
|
700
|
-
// Name and
|
|
701
|
-
if (
|
|
702
|
-
var
|
|
703
|
-
var _name = trimString(
|
|
721
|
+
// Name and address available?
|
|
722
|
+
if (_nameAddressMatch && _nameAddressMatch.length > 0) {
|
|
723
|
+
var _address = trimString(_nameAddressMatch[2]);
|
|
724
|
+
var _name = trimString(_nameAddressMatch[1]);
|
|
704
725
|
|
|
705
726
|
_mailboxes[_i] = {
|
|
706
|
-
|
|
727
|
+
address : _address,
|
|
707
728
|
|
|
708
|
-
// Some clients fill the name with the
|
|
729
|
+
// Some clients fill the name with the address \
|
|
709
730
|
// ("bessie.berry@acme.com <bessie.berry@acme.com>")
|
|
710
|
-
name
|
|
731
|
+
name : (_address !== _name) ? _name : null
|
|
711
732
|
};
|
|
712
733
|
} else {
|
|
713
734
|
_mailboxes[_i] = {
|
|
714
|
-
|
|
715
|
-
name
|
|
735
|
+
address : trimString(_mailboxes[_i]),
|
|
736
|
+
name : null
|
|
716
737
|
};
|
|
717
738
|
}
|
|
718
739
|
}
|
|
@@ -723,14 +744,16 @@ class Parser {
|
|
|
723
744
|
}
|
|
724
745
|
|
|
725
746
|
// Return single mailbox
|
|
726
|
-
return _mailboxes[0];
|
|
747
|
+
return (force_array === true) ? _mailboxes : _mailboxes[0];
|
|
727
748
|
}
|
|
728
749
|
}
|
|
729
750
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
name
|
|
751
|
+
var _mailbox = {
|
|
752
|
+
address : null,
|
|
753
|
+
name : null
|
|
733
754
|
};
|
|
755
|
+
|
|
756
|
+
return (force_array === true) ? [_mailbox] : _mailbox;
|
|
734
757
|
}
|
|
735
758
|
|
|
736
759
|
|
|
@@ -741,7 +764,7 @@ class Parser {
|
|
|
741
764
|
* @return {string} The parsed subject
|
|
742
765
|
*/
|
|
743
766
|
__parseOriginalSubject(text) {
|
|
744
|
-
// First method: extract the subject via the Subject part (Apple Mail,
|
|
767
|
+
// First method: extract the subject via the Subject part (Apple Mail, \
|
|
745
768
|
// Gmail, Outlook Live, New Outlook 2019, Thunderbird)
|
|
746
769
|
var _match = loopRegexes(this.__regexes.original_subject, text);
|
|
747
770
|
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "email-forward-parser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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-
|
|
10
|
+
"url": "git://github.com/crisp-oss/email-forward-parser"
|
|
10
11
|
},
|
|
11
12
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/crisp-
|
|
13
|
+
"url": "https://github.com/crisp-oss/email-forward-parser/issues"
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|
|
15
16
|
"test": "nodeunit ./test/index.js"
|