email-forward-parser 1.0.15 → 1.0.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "email-forward-parser",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Parses forwarded emails and extract content",
5
5
  "author": "Eliott Vincent <eliott@crisp.chat>",
6
6
  "main": "lib/index.js",
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
- // }