email-forward-parser 1.7.2 → 1.8.1

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/lib/parser.js DELETED
@@ -1,1107 +0,0 @@
1
- "use strict";
2
-
3
-
4
- var RE2 = require("re2");
5
- var { loopRegexes, reconciliateSplitMatch, trimString } = require("./utils");
6
-
7
-
8
- var MAILBOXES_SEPARATORS = [
9
- ",", // Apple Mail, Gmail, New Outlook 2019, Thunderbird
10
- ";" // Outlook Live / 365, Yahoo Mail
11
- ];
12
-
13
- var LINE_REGEXES = [
14
- "separator",
15
- "original_subject",
16
- "original_subject_lax",
17
- "original_to",
18
- "original_reply_to",
19
- "original_cc",
20
- "original_date"
21
- ];
22
-
23
- var REGEXES = {
24
- quote_line_break : /^(>+)\s?$/gm, // Apple Mail, Missive
25
- quote : /^(>+)\s?/gm, // Apple Mail
26
- four_spaces : /^(\ {4})\s?/gm, // Outlook 2019
27
- carriage_return : /\r\n/gm, // Outlook 2019
28
- byte_order_mark : /\uFEFF/gm, // Outlook 2019
29
- trailing_non_breaking_space : /\u00A0$/gm, // IONOS by 1 & 1
30
- non_breaking_space : /\u00A0/gm, // HubSpot
31
-
32
- subject : [
33
- /^Fw:(.*)/m, // Outlook Live / 365 (cs, en, hr, hu, sk), Yahoo Mail (all locales)
34
- /^VS:(.*)/m, // Outlook Live / 365 (da), New Outlook 2019 (da)
35
- /^WG:(.*)/m, // Outlook Live / 365 (de), New Outlook 2019 (de)
36
- /^RV:(.*)/m, // Outlook Live / 365 (es), New Outlook 2019 (es)
37
- /^TR:(.*)/m, // Outlook Live / 365 (fr), New Outlook 2019 (fr)
38
- /^I:(.*)/m, // Outlook Live / 365 (it), New Outlook 2019 (it)
39
- /^FW:(.*)/m, // Outlook Live / 365 (nl, pt), New Outlook 2019 (cs, en, hu, nl, pt, ru, sk), Outlook 2019 (all locales)
40
- /^Vs:(.*)/m, // Outlook Live / 365 (no)
41
- /^PD:(.*)/m, // Outlook Live / 365 (pl), New Outlook 2019 (pl)
42
- /^ENC:(.*)/m, // Outlook Live / 365 (pt-br), New Outlook 2019 (pt-br)
43
- /^Redir.:(.*)/m, // Outlook Live / 365 (ro)
44
- /^VB:(.*)/m, // Outlook Live / 365 (sv), New Outlook 2019 (sv)
45
- /^VL:(.*)/m, // New Outlook 2019 (fi)
46
- /^Videresend:(.*)/m, // New Outlook 2019 (no)
47
- /^İLT:(.*)/m, // New Outlook 2019 (tr)
48
- /^Fwd:(.*)/m // Gmail (all locales), Thunderbird (all locales), Missive (en), MailMate (en)
49
- ],
50
-
51
- separator : [
52
- /^>?\s*Begin forwarded message\s?:/m, // Apple Mail (en)
53
- /^>?\s*Začátek přeposílané zprávy\s?:/m, // Apple Mail (cs)
54
- /^>?\s*Start på videresendt besked\s?:/m, // Apple Mail (da)
55
- /^>?\s*Anfang der weitergeleiteten Nachricht\s?:/m, // Apple Mail (de)
56
- /^>?\s*Inicio del mensaje reenviado\s?:/m, // Apple Mail (es)
57
- /^>?\s*Välitetty viesti alkaa\s?:/m, // Apple Mail (fi)
58
- /^>?\s*Début du message réexpédié\s?:/m, // Apple Mail (fr)
59
- /^>?\s*Début du message transféré\s?:/m, // Apple Mail iOS (fr)
60
- /^>?\s*Započni proslijeđenu poruku\s?:/m, // Apple Mail (hr)
61
- /^>?\s*Továbbított levél kezdete\s?:/m, // Apple Mail (hu)
62
- /^>?\s*Inizio messaggio inoltrato\s?:/m, // Apple Mail (it)
63
- /^>?\s*Begin doorgestuurd bericht\s?:/m, // Apple Mail (nl)
64
- /^>?\s*Videresendt melding\s?:/m, // Apple Mail (no)
65
- /^>?\s*Początek przekazywanej wiadomości\s?:/m, // Apple Mail (pl)
66
- /^>?\s*Início da mensagem reencaminhada\s?:/m, // Apple Mail (pt)
67
- /^>?\s*Início da mensagem encaminhada\s?:/m, // Apple Mail (pt-br)
68
- /^>?\s*Începe mesajul redirecționat\s?:/m, // Apple Mail (ro)
69
- /^>?\s*Начало переадресованного сообщения\s?:/m, // Apple Mail (ro)
70
- /^>?\s*Začiatok preposlanej správy\s?:/m, // Apple Mail (sk)
71
- /^>?\s*Vidarebefordrat mejl\s?:/m, // Apple Mail (sv)
72
- /^>?\s*İleti başlangıcı\s?:/m, // Apple Mail (tr)
73
- /^>?\s*Початок листа, що пересилається\s?:/m, // Apple Mail (uk)
74
- /^\s*-{8,10}\s*Forwarded message\s*-{8,10}\s*/m, // Gmail (all locales), Missive (en), HubSpot (en)
75
- /^\s*_{32}\s*$/m, // Outlook Live / 365 (all locales)
76
- /^\s?Forwarded message:/m, // Mailmate
77
- /^\s?Dne\s?.+\,\s?.+\s*[\[|<].+[\]|>]\s?napsal\(a\)\s?:/m, // Outlook 2019 (cz)
78
- /^\s?D.\s?.+\s?skrev\s?\".+\"\s*[\[|<].+[\]|>]\s?:/m, // Outlook 2019 (da)
79
- /^\s?Am\s?.+\s?schrieb\s?\".+\"\s*[\[|<].+[\]|>]\s?:/m, // Outlook 2019 (de)
80
- /^\s?On\s?.+\,\s?\".+\"\s*[\[|<].+[\]|>]\s?wrote\s?:/m, // Outlook 2019 (en)
81
- /^\s?El\s?.+\,\s?\".+\"\s*[\[|<].+[\]|>]\s?escribió\s?:/m, // Outlook 2019 (es)
82
- /^\s?Le\s?.+\,\s?«.+»\s*[\[|<].+[\]|>]\s?a écrit\s?:/m, // Outlook 2019 (fr)
83
- /^\s?.+\s*[\[|<].+[\]|>]\s?kirjoitti\s?.+\s?:/m, // Outlook 2019 (fi)
84
- /^\s?.+\s?időpontban\s?.+\s*[\[|<|(].+[\]|>|)]\s?ezt írta\s?:/m, // Outlook 2019 (hu)
85
- /^\s?Il giorno\s?.+\s?\".+\"\s*[\[|<].+[\]|>]\s?ha scritto\s?:/m, // Outlook 2019 (it)
86
- /^\s?Op\s?.+\s?heeft\s?.+\s*[\[|<].+[\]|>]\s?geschreven\s?:/m, // Outlook 2019 (nl)
87
- /^\s?.+\s*[\[|<].+[\]|>]\s?skrev følgende den\s?.+\s?:/m, // Outlook 2019 (no)
88
- /^\s?Dnia\s?.+\s?„.+”\s*[\[|<].+[\]|>]\s?napisał\s?:/m, // Outlook 2019 (pl)
89
- /^\s?Em\s?.+\,\s?\".+\"\s*[\[|<].+[\]|>]\s?escreveu\s?:/m, // Outlook 2019 (pt)
90
- /^\s?.+\s?пользователь\s?\".+\"\s*[\[|<].+[\]|>]\s?написал\s?:/m, // Outlook 2019 (ru)
91
- /^\s?.+\s?používateľ\s?.+\s*\([\[|<].+[\]|>]\)\s?napísal\s?:/m, // Outlook 2019 (sk)
92
- /^\s?Den\s?.+\s?skrev\s?\".+\"\s*[\[|<].+[\]|>]\s?följande\s?:/m, // Outlook 2019 (sv)
93
- /^\s?\".+\"\s*[\[|<].+[\]|>]\,\s?.+\s?tarihinde şunu yazdı\s?:/m, // Outlook 2019 (tr)
94
- /^\s*-{5,8} Přeposlaná zpráva -{5,8}\s*/m, // Yahoo Mail (cs), Thunderbird (cs)
95
- /^\s*-{5,8} Videresendt meddelelse -{5,8}\s*/m, // Yahoo Mail (da), Thunderbird (da)
96
- /^\s*-{5,10} Weitergeleitete Nachricht -{5,10}\s*/m, // Yahoo Mail (de), Thunderbird (de), HubSpot (de)
97
- /^\s*-{5,8} Forwarded Message -{5,8}\s*/m, // Yahoo Mail (en), Thunderbird (en)
98
- /^\s*-{5,10} Mensaje reenviado -{5,10}\s*/m, // Yahoo Mail (es), Thunderbird (es), HubSpot (es)
99
- /^\s*-{5,10} Edelleenlähetetty viesti -{5,10}\s*/m, // Yahoo Mail (fi), HubSpot (fi)
100
- /^\s*-{5} Message transmis -{5}\s*/m, // Yahoo Mail (fr)
101
- /^\s*-{5,8} Továbbított üzenet -{5,8}\s*/m, // Yahoo Mail (hu), Thunderbird (hu)
102
- /^\s*-{5,10} Messaggio inoltrato -{5,10}\s*/m, // Yahoo Mail (it), HubSpot (it)
103
- /^\s*-{5,10} Doorgestuurd bericht -{5,10}\s*/m, // Yahoo Mail (nl), Thunderbird (nl), HubSpot (nl)
104
- /^\s*-{5,8} Videresendt melding -{5,8}\s*/m, // Yahoo Mail (no), Thunderbird (no)
105
- /^\s*-{5} Przekazana wiadomość -{5}\s*/m, // Yahoo Mail (pl)
106
- /^\s*-{5,8} Mensagem reencaminhada -{5,8}\s*/m, // Yahoo Mail (pt), Thunderbird (pt)
107
- /^\s*-{5,10} Mensagem encaminhada -{5,10}\s*/m, // Yahoo Mail (pt-br), Thunderbird (pt-br), HubSpot (pt-br)
108
- /^\s*-{5,8} Mesaj redirecționat -{5,8}\s*/m, // Yahoo Mail (ro)
109
- /^\s*-{5} Пересылаемое сообщение -{5}\s*/m, // Yahoo Mail (ru)
110
- /^\s*-{5} Preposlaná správa -{5}\s*/m, // Yahoo Mail (sk)
111
- /^\s*-{5,10} Vidarebefordrat meddelande -{5,10}\s*/m, // Yahoo Mail (sv), Thunderbird (sv), HubSpot (sv)
112
- /^\s*-{5} İletilmiş Mesaj -{5}\s*/m, // Yahoo Mail (tr)
113
- /^\s*-{5} Перенаправлене повідомлення -{5}\s*/m, // Yahoo Mail (uk)
114
- /^\s*-{8} Välitetty viesti \/ Fwd.Msg -{8}\s*/m, // Thunderbird (fi)
115
- /^\s*-{8,10} Message transféré -{8,10}\s*/m, // Thunderbird (fr), HubSpot (fr)
116
- /^\s*-{8} Proslijeđena poruka -{8}\s*/m, // Thunderbird (hr)
117
- /^\s*-{8} Messaggio Inoltrato -{8}\s*/m, // Thunderbird (it)
118
- /^\s*-{3} Treść przekazanej wiadomości -{3}\s*/m, // Thunderbird (pl)
119
- /^\s*-{8} Перенаправленное сообщение -{8}\s*/m, // Thunderbird (ru)
120
- /^\s*-{8} Preposlaná správa --- Forwarded Message -{8}\s*/m, // Thunderbird (sk)
121
- /^\s*-{8} İletilen İleti -{8}\s*/m, // Thunderbird (tr)
122
- /^\s*-{8} Переслане повідомлення -{8}\s*/m, // Thunderbird (uk)
123
- /^\s*-{9,10} メッセージを転送 -{9,10}\s*/m, // HubSpot (ja)
124
- /^\s*-{9,10} Wiadomość przesłana dalej -{9,10}\s*/m, // HubSpot (pl)
125
- /^>?\s*-{10} Original Message -{10}\s*/m // IONOS by 1 & 1 (en)
126
- ],
127
-
128
- separator_with_information : [
129
- /^\s?Dne\s?(?<date>.+)\,\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?napsal\(a\)\s?:/m, // Outlook 2019 (cz)
130
- /^\s?D.\s?(?<date>.+)\s?skrev\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?:/m, // Outlook 2019 (da)
131
- /^\s?Am\s?(?<date>.+)\s?schrieb\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?:/m, // Outlook 2019 (de)
132
- /^\s?On\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?wrote\s?:/m, // Outlook 2019 (en)
133
- /^\s?El\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?escribió\s?:/m, // Outlook 2019 (es)
134
- /^\s?Le\s?(?<date>.+)\,\s?«(?<from_name>.+)»\s*[\[|<](?<from_address>.+)[\]|>]\s?a écrit\s?:/m, // Outlook 2019 (fr)
135
- /^\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?kirjoitti\s?(?<date>.+)\s?:/m, // Outlook 2019 (fi)
136
- /^\s?(?<date>.+)\s?időpontban\s?(?<from_name>.+)\s*[\[|<|(](?<from_address>.+)[\]|>|)]\s?ezt írta\s?:/m, // Outlook 2019 (hu)
137
- /^\s?Il giorno\s?(?<date>.+)\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?ha scritto\s?:/m, // Outlook 2019 (it)
138
- /^\s?Op\s?(?<date>.+)\s?heeft\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?geschreven\s?:/m, // Outlook 2019 (nl)
139
- /^\s?(?<from_name>.+)\s*[\[|<](?<from_address>.+)[\]|>]\s?skrev følgende den\s?(?<date>.+)\s?:/m, // Outlook 2019 (no)
140
- /^\s?Dnia\s?(?<date>.+)\s?„(?<from_name>.+)”\s*[\[|<](?<from_address>.+)[\]|>]\s?napisał\s?:/m, // Outlook 2019 (pl)
141
- /^\s?Em\s?(?<date>.+)\,\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?escreveu\s?:/m, // Outlook 2019 (pt)
142
- /^\s?(?<date>.+)\s?пользователь\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?написал\s?:/m, // Outlook 2019 (ru)
143
- /^\s?(?<date>.+)\s?používateľ\s?(?<from_name>.+)\s*\([\[|<](?<from_address>.+)[\]|>]\)\s?napísal\s?:/m, // Outlook 2019 (sk)
144
- /^\s?Den\s?(?<date>.+)\s?skrev\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\s?följande\s?:/m, // Outlook 2019 (sv)
145
- /^\s?\"(?<from_name>.+)\"\s*[\[|<](?<from_address>.+)[\]|>]\,\s?(?<date>.+)\s?tarihinde şunu yazdı\s?:/m // Outlook 2019 (tr)
146
- ],
147
-
148
- original_subject : [
149
- /^\*?Subject\s?:\*?(.+)/im, // Apple Mail (en), Gmail (all locales), Outlook Live / 365 (all locales), New Outlook 2019 (en), Thunderbird (da, en), Missive (en), HubSpot (en)
150
- /^Předmět\s?:(.+)/im, // Apple Mail (cs), New Outlook 2019 (cs), Thunderbird (cs)
151
- /^Emne\s?:(.+)/im, // Apple Mail (da, no), New Outlook 2019 (da), Thunderbird (no)
152
- /^Betreff\s?:(.+)/im, // Apple Mail (de), New Outlook 2019 (de), Thunderbird (de), HubSpot (de)
153
- /^Asunto\s?:(.+)/im, // Apple Mail (es), New Outlook 2019 (es), Thunderbird (es), HubSpot (es)
154
- /^Aihe\s?:(.+)/im, // Apple Mail (fi), New Outlook 2019 (fi), Thunderbird (fi), HubSpot (fi)
155
- /^Objet\s?:(.+)/im, // Apple Mail (fr), New Outlook 2019 (fr), HubSpot (fr)
156
- /^Predmet\s?:(.+)/im, // Apple Mail (hr, sk), New Outlook 2019 (sk), Thunderbird (sk)
157
- /^Tárgy\s?:(.+)/im, // Apple Mail (hu), New Outlook 2019 (hu), Thunderbird (hu)
158
- /^Oggetto\s?:(.+)/im, // Apple Mail (it), New Outlook 2019 (it), Thunderbird (it), HubSpot (it)
159
- /^Onderwerp\s?:(.+)/im, // Apple Mail (nl), New Outlook 2019 (nl), Thunderbird (nl), HubSpot (nl)
160
- /^Temat\s?:(.+)/im, // Apple Mail (pl), New Outlook 2019 (pl), Thunderbird (pl), HubSpot (pl)
161
- /^Assunto\s?:(.+)/im, // Apple Mail (pt, pt-br), New Outlook 2019 (pt, pt-br), Thunderbird (pt, pt-br), HubSpot (pt-br)
162
- /^Subiectul\s?:(.+)/im, // Apple Mail (ro), Thunderbird (ro)
163
- /^Тема\s?:(.+)/im, // Apple Mail (ru, uk), New Outlook 2019 (ru), Thunderbird (ru, uk)
164
- /^Ämne\s?:(.+)/im, // Apple Mail (sv), New Outlook 2019 (sv), Thunderbird (sv), HubSpot (sv)
165
- /^Konu\s?:(.+)/im, // Apple Mail (tr), Thunderbird (tr)
166
- /^Sujet\s?:(.+)/im, // Thunderbird (fr)
167
- /^Naslov\s?:(.+)/im, // Thunderbird (hr)
168
- /^件名:(.+)/im // HubSpot (ja)
169
- ],
170
-
171
- original_subject_lax : [
172
- /Subject\s?:(.+)/i, // Yahoo Mail (en)
173
- /Emne\s?:(.+)/i, // Yahoo Mail (da, no)
174
- /Předmět\s?:(.+)/i, // Yahoo Mail (cs)
175
- /Betreff\s?:(.+)/i, // Yahoo Mail (de)
176
- /Asunto\s?:(.+)/i, // Yahoo Mail (es)
177
- /Aihe\s?:(.+)/i, // Yahoo Mail (fi)
178
- /Objet\s?:(.+)/i, // Yahoo Mail (fr)
179
- /Tárgy\s?:(.+)/i, // Yahoo Mail (hu)
180
- /Oggetto\s?:(.+)/i, // Yahoo Mail (it)
181
- /Onderwerp\s?:(.+)/i, // Yahoo Mail (nl)
182
- /Assunto\s?:?(.+)/i, // Yahoo Mail (pt, pt-br)
183
- /Temat\s?:(.+)/i, // Yahoo Mail (pl)
184
- /Subiect\s?:(.+)/i, // Yahoo Mail (ro)
185
- /Тема\s?:(.+)/i, // Yahoo Mail (ru, uk)
186
- /Predmet\s?:(.+)/i, // Yahoo Mail (sk)
187
- /Ämne\s?:(.+)/i, // Yahoo Mail (sv)
188
- /Konu\s?:(.+)/i // Yahoo Mail (tr)
189
- ],
190
-
191
- original_from : [
192
- /^(\*?\s*From\s?:\*?(.+))$/m, // Apple Mail (en), Outlook Live / 365 (all locales), New Outlook 2019 (en), Thunderbird (da, en), Missive (en), HubSpot (en)
193
- /^(\s*Od\s?:(.+))$/m, // Apple Mail (cs, pl, sk), Gmail (cs, pl, sk), New Outlook 2019 (cs, pl, sk), Thunderbird (cs, sk), HubSpot (pl)
194
- /^(\s*Fra\s?:(.+))$/m, // Apple Mail (da, no), Gmail (da, no), New Outlook 2019 (da), Thunderbird (no)
195
- /^(\s*Von\s?:(.+))$/m, // Apple Mail (de), Gmail (de), New Outlook 2019 (de), Thunderbird (de), HubSpot (de)
196
- /^(\s*De\s?:(.+))$/m, // Apple Mail (es, fr, pt, pt-br), Gmail (es, fr, pt, pt-br), New Outlook 2019 (es, fr, pt, pt-br), Thunderbird (fr, pt, pt-br), HubSpot (es, fr, pt-br)
197
- /^(\s*Lähettäjä\s?:(.+))$/m, // Apple Mail (fi), Gmail (fi), New Outlook 2019 (fi), Thunderbird (fi), HubSpot (fi)
198
- /^(\s*Šalje\s?:(.+))$/m, // Apple Mail (hr), Gmail (hr), Thunderbird (hr)
199
- /^(\s*Feladó\s?:(.+))$/m, // Apple Mail (hu), Gmail (hu), New Outlook 2019 (fr), Thunderbird (hu)
200
- /^(\s*Da\s?:(.+))$/m, // Apple Mail (it), Gmail (it), New Outlook 2019 (it), HubSpot (it)
201
- /^(\s*Van\s?:(.+))$/m, // Apple Mail (nl), Gmail (nl), New Outlook 2019 (nl), Thunderbird (nl), HubSpot (nl)
202
- /^(\s*Expeditorul\s?:(.+))$/m, // Apple Mail (ro)
203
- /^(\s*Отправитель\s?:(.+))$/m, // Apple Mail (ru)
204
- /^(\s*Från\s?:(.+))$/m, // Apple Mail (sv), Gmail (sv), New Outlook 2019 (sv), Thunderbird (sv), HubSpot (sv)
205
- /^(\s*Kimden\s?:(.+))$/m, // Apple Mail (tr), Thunderbird (tr)
206
- /^(\s*Від кого\s?:(.+))$/m, // Apple Mail (uk)
207
- /^(\s*Saatja\s?:(.+))$/m, // Gmail (et)
208
- /^(\s*De la\s?:(.+))$/m, // Gmail (ro)
209
- /^(\s*Gönderen\s?:(.+))$/m, // Gmail (tr)
210
- /^(\s*От\s?:(.+))$/m, // Gmail (ru), New Outlook 2019 (ru), Thunderbird (ru)
211
- /^(\s*Від\s?:(.+))$/m, // Gmail (uk), Thunderbird (uk)
212
- /^(\s*Mittente\s?:(.+))$/m, // Thunderbird (it)
213
- /^(\s*Nadawca\s?:(.+))$/m, // Thunderbird (pl)
214
- /^(\s*de la\s?:(.+))$/m, // Thunderbird (ro)
215
- /^(\s*送信元:(.+))$/m // HubSpot (ja)
216
- ],
217
-
218
- original_from_lax : [
219
- /(\s*From\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (en)
220
- /(\s*Od\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (cs, pl, sk)
221
- /(\s*Fra\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (da, no)
222
- /(\s*Von\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (de)
223
- /(\s*De\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (es, fr, pt, pt-br)
224
- /(\s*Lähettäjä\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (fi)
225
- /(\s*Feladó\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (hu)
226
- /(\s*Da\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (it)
227
- /(\s*Van\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (nl)
228
- /(\s*De la\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (ro)
229
- /(\s*От\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (ru)
230
- /(\s*Från\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (sv)
231
- /(\s*Kimden\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/, // Yahoo Mail (tr)
232
- /(\s*Від\s?:(.+?)\s?\n?\s*[\[|<](.+?)[\]|>])/ // Yahoo Mail (uk)
233
- ],
234
-
235
- original_to : [
236
- /^\*?\s*To\s?:\*?(.+)$/m, // Apple Mail (en), Gmail (all locales), Outlook Live / 365 (all locales), Thunderbird (da, en), Missive (en), HubSpot (en)
237
- /^\s*Komu\s?:(.+)$/m, // Apple Mail (cs), New Outlook 2019 (cs, sk), Thunderbird (cs)
238
- /^\s*Til\s?:(.+)$/m, // Apple Mail (da, no), New Outlook 2019 (da), Thunderbird (no)
239
- /^\s*An\s?:(.+)$/m, // Apple Mail (de), New Outlook 2019 (de), Thunderbird (de), HubSpot (de)
240
- /^\s*Para\s?:(.+)$/m, // Apple Mail (es, pt, pt-br), New Outlook 2019 (es, pt, pt-br), Thunderbird (es, pt, pt-br), HubSpot (pt-br)
241
- /^\s*Vastaanottaja\s?:(.+)$/m, // Apple Mail (fi), New Outlook 2019 (fi), Thunderbird (fi), HubSpot (fi)
242
- /^\s*À\s?:(.+)$/m, // Apple Mail (fr), New Outlook 2019 (fr), HubSpot (fr)
243
- /^\s*Prima\s?:(.+)$/m, // Apple Mail (hr), Thunderbird (hr)
244
- /^\s*Címzett\s?:(.+)$/m, // Apple Mail (hu), New Outlook 2019 (hu), Thunderbird (hu)
245
- /^\s*A\s?:(.+)$/m, // Apple Mail (it), New Outlook 2019 (it), Thunderbird (it), HubSpot (es, it)
246
- /^\s*Aan\s?:(.+)$/m, // Apple Mail (nl), New Outlook 2019 (nl), Thunderbird (nl), HubSpot (nl)
247
- /^\s*Do\s?:(.+)$/m, // Apple Mail (pl), New Outlook 2019 (pl), HubSpot (pl)
248
- /^\s*Destinatarul\s?:(.+)$/m, // Apple Mail (ro)
249
- /^\s*Кому\s?:(.+)$/m, // Apple Mail (ru, uk), New Outlook 2019 (ru), Thunderbird (ru, uk)
250
- /^\s*Pre\s?:(.+)$/m, // Apple Mail (sk), Thunderbird (sk)
251
- /^\s*Till\s?:(.+)$/m, // Apple Mail (sv), New Outlook 2019 (sv), Thunderbird (sv)
252
- /^\s*Kime\s?:(.+)$/m, // Apple Mail (tr), Thunderbird (tr)
253
- /^\s*Pour\s?:(.+)$/m, // Thunderbird (fr)
254
- /^\s*Adresat\s?:(.+)$/m, // Thunderbird (pl)
255
- /^\s*送信先:(.+)$/m // HubSpot (ja)
256
- ],
257
-
258
- original_to_lax : [
259
- /\s*To\s?:(.+)$/m, // Yahook Mail (en)
260
- /\s*Komu\s?:(.+)$/m, // Yahook Mail (cs, sk)
261
- /\s*Til\s?:(.+)$/m, // Yahook Mail (da, no, sv)
262
- /\s*An\s?:(.+)$/m, // Yahook Mail (de)
263
- /\s*Para\s?:(.+)$/m, // Yahook Mail (es, pt, pt-br)
264
- /\s*Vastaanottaja\s?:(.+)$/m, // Yahook Mail (fi)
265
- /\s*À\s?:(.+)$/m, // Yahook Mail (fr)
266
- /\s*Címzett\s?:(.+)$/m, // Yahook Mail (hu)
267
- /\s*A\s?:(.+)$/m, // Yahook Mail (it)
268
- /\s*Aan\s?:(.+)$/m, // Yahook Mail (nl)
269
- /\s*Do\s?:(.+)$/m, // Yahook Mail (pl)
270
- /\s*Către\s?:(.+)$/m, // Yahook Mail (ro), Thunderbird (ro)
271
- /\s*Кому\s?:(.+)$/m, // Yahook Mail (ru, uk)
272
- /\s*Till\s?:(.+)$/m, // Yahook Mail (sv)
273
- /\s*Kime\s?:(.+)$/m // Yahook Mail (tr)
274
- ],
275
-
276
- original_reply_to : [
277
- /^\s*Reply-To\s?:(.+)$/m, // Apple Mail (en)
278
- /^\s*Odgovori na\s?:(.+)$/m, // Apple Mail (hr)
279
- /^\s*Odpověď na\s?:(.+)$/m, // Apple Mail (cs)
280
- /^\s*Svar til\s?:(.+)$/m, // Apple Mail (da)
281
- /^\s*Antwoord aan\s?:(.+)$/m, // Apple Mail (nl)
282
- /^\s*Vastaus\s?:(.+)$/m, // Apple Mail (fi)
283
- /^\s*Répondre à\s?:(.+)$/m, // Apple Mail (fr)
284
- /^\s*Antwort an\s?:(.+)$/m, // Apple Mail (de)
285
- /^\s*Válaszcím\s?:(.+)$/m, // Apple Mail (hu)
286
- /^\s*Rispondi a\s?:(.+)$/m, // Apple Mail (it)
287
- /^\s*Svar til\s?:(.+)$/m, // Apple Mail (no)
288
- /^\s*Odpowiedź-do\s?:(.+)$/m, // Apple Mail (pl)
289
- /^\s*Responder A\s?:(.+)$/m, // Apple Mail (pt)
290
- /^\s*Responder a\s?:(.+)$/m, // Apple Mail (pt-br, es)
291
- /^\s*Răspuns către\s?:(.+)$/m, // Apple Mail (ro)
292
- /^\s*Ответ-Кому\s?:(.+)$/m, // Apple Mail (ru)
293
- /^\s*Odpovedať-Pre\s?:(.+)$/m, // Apple Mail (sk)
294
- /^\s*Svara till\s?:(.+)$/m, // Apple Mail (sv)
295
- /^\s*Yanıt Adresi\s?:(.+)$/m, // Apple Mail (tr)
296
- /^\s*Кому відповісти\s?:(.+)$/m // Apple Mail (uk)
297
- ],
298
-
299
- original_cc : [
300
- /^\*?\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), HubSpot (de, en, es, it, nl, pt-br)
301
- /^\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)
302
- /^\s*Kopie\s?:(.+)$/m, // Apple Mail (cs, de, nl), New Outlook 2019 (cs), Thunderbird (cs)
303
- /^\s*Kopio\s?:(.+)$/m, // Apple Mail (fi), New Outlook 2019 (fi), HubSpot (fi)
304
- /^\s*Másolat\s?:(.+)$/m, // Apple Mail (hu)
305
- /^\s*Kopi\s?:(.+)$/m, // Apple Mail (no)
306
- /^\s*Dw\s?:(.+)$/m, // Apple Mail (pl)
307
- /^\s*Копия\s?:(.+)$/m, // Apple Mail (ru), New Outlook 2019 (ru), Thunderbird (ru)
308
- /^\s*Kopia\s?:(.+)$/m, // Apple Mail (sv), New Outlook 2019 (sv), Thunderbird (pl, sv), HubSpot (sv)
309
- /^\s*Bilgi\s?:(.+)$/m, // Apple Mail (tr)
310
- /^\s*Копія\s?:(.+)$/m, // Apple Mail (uk),
311
- /^\s*Másolatot kap\s?:(.+)$/m, // New Outlook 2019 (hu)
312
- /^\s*Kópia\s?:(.+)$/m, // New Outlook 2019 (sk), Thunderbird (sk)
313
- /^\s*DW\s?:(.+)$/m, // New Outlook 2019 (pl), HubSpot (pl)
314
- /^\s*Kopie \(CC\)\s?:(.+)$/m, // Thunderbird (de)
315
- /^\s*Copie à\s?:(.+)$/m, // Thunderbird (fr)
316
- /^\s*CC:(.+)$/m // HubSpot (ja)
317
- ],
318
-
319
- original_cc_lax : [
320
- /\s*Cc\s?:(.+)$/m, // Yahoo Mail (da, en, it, nl, pt, pt-br, ro, tr)
321
- /\s*CC\s?:(.+)$/m, // Yahoo Mail (de, es)
322
- /\s*Kopie\s?:(.+)$/m, // Yahoo Mail (cs)
323
- /\s*Kopio\s?:(.+)$/m, // Yahoo Mail (fi)
324
- /\s*Másolat\s?:(.+)$/m, // Yahoo Mail (hu)
325
- /\s*Kopi\s?:(.+)$/m, // Yahoo Mail (no)
326
- /\s*Dw\s?(.+)$/m, // Yahoo Mail (pl)
327
- /\s*Копия\s?:(.+)$/m, // Yahoo Mail (ru)
328
- /\s*Kópia\s?:(.+)$/m, // Yahoo Mail (sk)
329
- /\s*Kopia\s?:(.+)$/m, // Yahoo Mail (sv)
330
- /\s*Копія\s?:(.+)$/m // Yahoo Mail (uk)
331
- ],
332
-
333
- original_date : [
334
- /^\s*Date\s?:(.+)$/m, // Apple Mail (en, fr), Gmail (all locales), New Outlook 2019 (en, fr), Thunderbird (da, en, fr), Missive (en), HubSpot (en, fr)
335
- /^\s*Datum\s?:(.+)$/m, // Apple Mail (cs, de, hr, nl, sv), New Outlook 2019 (cs, de, nl, sv), Thunderbird (cs, de, hr, nl, sv), HubSpot (de, nl, sv)
336
- /^\s*Dato\s?:(.+)$/m, // Apple Mail (da, no), New Outlook 2019 (da), Thunderbird (no)
337
- /^\s*Envoyé\s?:(.+)$/m, // New Outlook 2019 (fr)
338
- /^\s*Fecha\s?:(.+)$/m, // Apple Mail (es), New Outlook 2019 (es), Thunderbird (es), HubSpot (es)
339
- /^\s*Päivämäärä\s?:(.+)$/m, // Apple Mail (fi), New Outlook 2019 (fi), HubSpot (fi)
340
- /^\s*Dátum\s?:(.+)$/m, // Apple Mail (hu, sk), New Outlook 2019 (sk), Thunderbird (hu, sk)
341
- /^\s*Data\s?:(.+)$/m, // Apple Mail (it, pl, pt, pt-br), New Outlook 2019 (it, pl, pt, pt-br), Thunderbird (it, pl, pt, pt-br), HubSpot (it, pl, pt-br)
342
- /^\s*Dată\s?:(.+)$/m, // Apple Mail (ro), Thunderbird (ro)
343
- /^\s*Дата\s?:(.+)$/m, // Apple Mail (ru, uk), New Outlook 2019 (ru), Thunderbird (ru, uk)
344
- /^\s*Tarih\s?:(.+)$/m, // Apple Mail (tr), Thunderbird (tr)
345
- /^\*?\s*Sent\s?:\*?(.+)$/m, // Outlook Live / 365 (all locales)
346
- /^\s*Päiväys\s?:(.+)$/m, // Thunderbird (fi)
347
- /^\s*日付:(.+)$/m // HubSpot (ja)
348
- ],
349
-
350
- original_date_lax : [
351
- /\s*Datum\s?:(.+)$/m, // Yahoo Mail (cs)
352
- /\s*Sendt\s?:(.+)$/m, // Yahoo Mail (da, no)
353
- /\s*Gesendet\s?:(.+)$/m, // Yahoo Mail (de)
354
- /\s*Sent\s?:(.+)$/m, // Yahoo Mail (en)
355
- /\s*Enviado\s?:(.+)$/m, // Yahoo Mail (es, pt, pt-br)
356
- /\s*Envoyé\s?:(.+)$/m, // Yahoo Mail (fr)
357
- /\s*Lähetetty\s?:(.+)$/m, // Yahoo Mail (fi)
358
- /\s*Elküldve\s?:(.+)$/m, // Yahoo Mail (hu)
359
- /\s*Inviato\s?:(.+)$/m, // Yahoo Mail (it)
360
- /\s*Verzonden\s?:(.+)$/m, // Yahoo Mail (it)
361
- /\s*Wysłano\s?:(.+)$/m, // Yahoo Mail (pl)
362
- /\s*Trimis\s?:(.+)$/m, // Yahoo Mail (ro)
363
- /\s*Отправлено\s?:(.+)$/m, // Yahoo Mail (ru)
364
- /\s*Odoslané\s?:(.+)$/m, // Yahoo Mail (sk)
365
- /\s*Skickat\s?:(.+)$/m, // Yahoo Mail (sv)
366
- /\s*Gönderilen\s?:(.+)$/m, // Yahoo Mail (tr)
367
- /\s*Відправлено\s?:(.+)$/m // Yahoo Mail (uk)
368
- ],
369
-
370
- mailbox : [
371
- /^\s?\n?\s*<.+?<mailto\:(.+?)>>/, // "<walter.sheltan@acme.com<mailto:walter.sheltan@acme.com>>"
372
- /^(.+?)\s?\n?\s*<.+?<mailto\:(.+?)>>/, // "Walter Sheltan <walter.sheltan@acme.com<mailto:walter.sheltan@acme.com>>"
373
- /^(.+?)\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>"
374
- /^\'(.+?)\'\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>"
375
- /^\"\'(.+?)\'\"\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>"
376
- /^\"(.+?)\"\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>"
377
- /^([^,;]+?)\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>"
378
- /^(.?)\s?\n?\s*[\[|<](.+?)[\]|>]/, // "<walter.sheltan@acme.com>"
379
- /^([^\s@]+@[^\s@]+\.[^\s@,]+)/, // "walter.sheltan@acme.com"
380
- /^([^;].+?)\s?\n?\s*[\[|<](.+?)[\]|>]/, // "Walter, Sheltan <walter.sheltan@acme.com>" or "Walter, Sheltan [walter.sheltan@acme.com]"
381
- ],
382
-
383
- mailbox_address : [
384
- /^(([^\s@]+)@([^\s@]+)\.([^\s@]+))$/
385
- ]
386
- };
387
-
388
-
389
- /**
390
- * Parser
391
- * @class
392
- */
393
- class Parser {
394
- /**
395
- * Constructor
396
- */
397
- constructor() {
398
- this.__regexes = {};
399
-
400
- this.__initRegexes();
401
- }
402
-
403
- /**
404
- * Parses the subject part of the email
405
- * @public
406
- * @param {string} subject
407
- * @return {object} The result
408
- */
409
- parseSubject(subject) {
410
- var _match = loopRegexes(this.__regexes.subject, subject);
411
-
412
- if (_match && _match.length > 1) {
413
- // Notice: return an empty string if the detected subject is empty \
414
- // (e.g. 'Fwd: ')
415
- return trimString(_match[1]) || "";
416
- }
417
-
418
- return null;
419
- }
420
-
421
-
422
- /**
423
- * Parses the body part of the email
424
- * @public
425
- * @param {string} body
426
- * @param {boolean} [forwarded]
427
- * @return {object} The result
428
- */
429
- parseBody(body, forwarded = false) {
430
- // Replace carriage return by regular line break
431
- var _body = body.replace(this.__regexes.carriage_return, "\n");
432
-
433
- // Remove Byte Order Mark
434
- _body = _body.replace(this.__regexes.byte_order_mark, "");
435
-
436
- // Remove trailing Non-breaking space
437
- _body = _body.replace(this.__regexes.trailing_non_breaking_space, "");
438
-
439
- // Replace Non-breaking space with regular space
440
- _body = _body.replace(this.__regexes.non_breaking_space, " ");
441
-
442
- // First method: split via the separator (Apple Mail, Gmail, \
443
- // Outlook Live / 365, Outlook 2019, Yahoo Mail, Thunderbird)
444
- // Notice: use 'line' regex that will capture the line itself, as we may \
445
- // need it to build the original email back (in case of nested emails)
446
- var _match = loopRegexes(this.__regexes.separator_line, _body, "split");
447
-
448
- if (_match && _match.length > 2) {
449
- // The `split` operation creates a match with 3 substrings:
450
- // * 0: anything before the line with the separator (i.e. the message)
451
- // * 1: the line with the separator
452
- // * 2: anything after the line with the separator (i.e. the body of \
453
- // the original email)
454
- // Notice: in case of nested emails, there may be several matches \
455
- // against 'separator_line'. In that case, the `split` operation \
456
- // creates a match with (n x 3) substrings. We need to reconciliate \
457
- // those substrings.
458
- var _email = reconciliateSplitMatch(
459
- _match,
460
-
461
- //-[min_substrings]
462
- 3,
463
-
464
- //-[default_substrings]
465
- // By default, attach anything after the line with the separator
466
- [2]
467
- );
468
-
469
- return {
470
- body : _body,
471
-
472
- message : trimString(_match[0]),
473
- email : trimString(_email)
474
- };
475
- }
476
-
477
- // Attempt second method?
478
- // Notice: as this second method is more uncertain (we split via the From \
479
- // part, without further verification), we have to be sure we can \
480
- // attempt it. The `forwarded` boolean gives the confirmation that the \
481
- // email was indeed forwarded (detected from the Subject part)
482
- if (forwarded === true) {
483
- // Second method: split via the From part (New Outlook 2019, \
484
- // Outlook Live / 365)
485
- _match = loopRegexes(this.__regexes.original_from, _body, "split");
486
-
487
- if (_match && _match.length > 3) {
488
- // The `split` operation creates a match with 4 substrings:
489
- // * 0: anything before the line with the From part (i.e. the \
490
- // message before the original email)
491
- // * 1: the line with the From part (in the original email)
492
- // * 2: the From part itself
493
- // * 3: anything after the line with the From part (i.e. \
494
- // the rest of the original email)
495
- // Notice: in case of nested emails, there may be several matches \
496
- // against 'original_from'. In that case, the `split` operation \
497
- // creates a match with (n x 4) substrings. We need to reconciliate \
498
- // those substrings.
499
- var _email = reconciliateSplitMatch(
500
- _match,
501
-
502
- //-[min_substrings]
503
- 4,
504
-
505
- //-[default_substrings]
506
- // By default, attach the line that contains the From part back to \
507
- // the rest of the original email (exclude the From part itself)
508
- [1, 3],
509
-
510
- //-[fn_exlude]
511
- // When reconciliating other substrings, we want to exclude the From \
512
- // part itself
513
- function(i) {
514
- return (i % 3 === 2);
515
- }
516
- );
517
-
518
- return {
519
- body : _body,
520
-
521
- message : trimString(_match[0]),
522
- email : trimString(_email)
523
- };
524
- }
525
- }
526
-
527
- return {};
528
- }
529
-
530
-
531
- /**
532
- * Parses the original forwarded email
533
- * @public
534
- * @param {string} text
535
- * @param {string} body
536
- * @return {object} The parsed email
537
- */
538
- parseOriginalEmail(text, body) {
539
- // Remove Byte Order Mark
540
- var _text = text.replace(this.__regexes.byte_order_mark, "");
541
-
542
- // Remove ">" at the beginning of each line, while keeping line breaks
543
- _text = _text.replace(this.__regexes.quote_line_break, "");
544
-
545
- // Remove ">" at the beginning of other lines
546
- _text = _text.replace(this.__regexes.quote, "");
547
-
548
- // Remove " " at the beginning of lines
549
- _text = _text.replace(this.__regexes.four_spaces, "");
550
-
551
- return {
552
- body : this.__parseOriginalBody(_text),
553
-
554
- from : this.__parseOriginalFrom(_text, body),
555
- to : this.__parseOriginalTo(_text),
556
- cc : this.__parseOriginalCc(_text),
557
-
558
- subject : this.__parseOriginalSubject(_text),
559
- date : this.__parseOriginalDate(_text, body)
560
- };
561
- }
562
-
563
-
564
- /**
565
- * Initializes regexes
566
- * @private
567
- * @return {undefined}
568
- */
569
- __initRegexes() {
570
- for (var _key in REGEXES) {
571
- var _key_line = `${_key}_line`;
572
- var _entry = REGEXES[_key];
573
-
574
- if (Array.isArray(_entry)) {
575
- this.__regexes[_key] = [];
576
- this.__regexes[_key_line] = [];
577
-
578
- for (var _i = 0; _i < _entry.length; _i++) {
579
- var _regex = _entry[_i];
580
-
581
- // Build 'line' alternative?
582
- if (LINE_REGEXES.includes(_key)) {
583
- var _regex_line = this.__buildLineRegex(_regex);
584
-
585
- this.__regexes[_key_line].push(_regex_line);
586
- }
587
-
588
- this.__regexes[_key].push(
589
- new RE2(_regex)
590
- );
591
- }
592
- } else {
593
- var _regex = _entry;
594
-
595
- // Build 'line' alternative?
596
- if (LINE_REGEXES.includes(_key)) {
597
- var _regex_line = this.__buildLineRegex(_regex);
598
-
599
- this.__regexes[_key_line] = _regex_line;
600
- }
601
-
602
- this.__regexes[_key] = new RE2(_regex);
603
- }
604
- }
605
- }
606
-
607
-
608
- /**
609
- * Builds 'line' alternative regex
610
- * @private
611
- * @param {object} regex
612
- * @return {object} 'Line' regex
613
- */
614
- __buildLineRegex(regex) {
615
- // A 'line' regex will capture not only inner groups, but also the line \
616
- // itself
617
- // Important: `regex` must be a raw regular expression literal, not an RE2 \
618
- // instance. It seems that under some inexplicable circumstances, \
619
- // the RE2 instance sometimes doesn't have its `source` and `flags` \
620
- // properties correctly populated.
621
- var _source = `(${regex.source})`;
622
- var _flags = regex.flags;
623
-
624
- return new RE2(_source, _flags);
625
- }
626
-
627
-
628
- /**
629
- * Parses the body part
630
- * @private
631
- * @param {string} text
632
- * @return {string} The parsed body
633
- */
634
- __parseOriginalBody(text) {
635
- var _match = null;
636
-
637
- // First method: extract the text after the Subject part \
638
- // (Outlook Live / 365) or after the Cc, To or Reply-To part \
639
- // (Apple Mail, Gmail) or Date part (MailMate). A new line must be \
640
- // present.
641
- // Notice: use 'line' regexes that will capture not only the Subject, Cc, \
642
- // To or Reply-To part, but also the line itself, as we may need it \
643
- // to build the original body back (in case of nested emails)
644
- var _regexes = [
645
- this.__regexes.original_subject_line,
646
- this.__regexes.original_cc_line,
647
- this.__regexes.original_to_line,
648
- this.__regexes.original_reply_to_line,
649
- this.__regexes.original_date_line
650
- ];
651
-
652
- for (var _i = 0; _i < _regexes.length; _i++) {
653
- _match = loopRegexes(_regexes[_i], text, "split");
654
-
655
- // A new line must be present between the Cc, To, Reply-To or Subject \
656
- // part and the actual body
657
- if (_match && _match.length > 2 && _match[3].startsWith("\n\n")) {
658
- // The `split` operation creates a match with 4 substrings:
659
- // * 0: anything before the line with the Subject, Cc, To or Reply-To \
660
- // part
661
- // * 1: the line with the Subject, Cc, To or Reply-To part
662
- // * 2: the Subject, Cc, To or Reply-To part itself
663
- // * 3: anything after the line with the Subject, Cc, To or Reply-To \
664
- // part (i.e. the body of the original email)
665
- // Notice: in case of nested emails, there may be several matches \
666
- // against 'original_subject_line', 'original_cc_line', \
667
- // 'original_to_line' or 'original_reply_to_line'. In that case, the \
668
- // `split` operation creates a match with (n x 4) substrings. We \
669
- // need to reconciliate those substrings.
670
- var _body = reconciliateSplitMatch(
671
- _match,
672
-
673
- //-[min_substrings]
674
- 4,
675
-
676
- //-[default_substrings]
677
- // By default, attach anything after the line with the Subject, Cc, \
678
- // To or Reply-To part
679
- [3],
680
-
681
- //-[fn_exlude]
682
- // When reconciliating other substrings, we want to exclude the \
683
- // Subject, Cc, To or Reply-To part itself
684
- function(i) {
685
- return (i % 3 === 2);
686
- }
687
- );
688
-
689
- return trimString(_body);
690
- }
691
- }
692
-
693
- // Second method: extract the text after the Subject part \
694
- // (New Outlook 2019, Yahoo Mail). No new line must be present.
695
- // Notice: use 'line' regexes that will capture not only the Subject part, \
696
- // but also the line itself, as we may need it to build the original \
697
- // body back (in case of nested emails)
698
- _match = loopRegexes(
699
- [].concat(
700
- this.__regexes.original_subject_line,
701
- this.__regexes.original_subject_lax_line
702
- ),
703
-
704
- text,
705
- "split"
706
- );
707
-
708
- // Do not bother checking for new line between the Subject part and the \
709
- // actual body (specificity of New Outlook 2019 and Yahoo Mail)
710
- if (_match && _match.length > 3) {
711
- // The `split` operation creates a match with 4 substrings:
712
- // * 0: anything before the line with the Subject part
713
- // * 1: the line with the Subject part (in the original email)
714
- // * 2: the Subject part itself
715
- // * 3: anything after the line with the Subject part (i.e. the body of \
716
- // the original email)
717
- // Notice: in case of nested emails, there may be several matches \
718
- // against 'original_subject_line' and 'original_subject_lax_line'. In \
719
- // that case, the `split` operation creates a match with (n x 4) \
720
- // substrings. We need to reconciliate those substrings.
721
- var _body = reconciliateSplitMatch(
722
- _match,
723
-
724
- //-[min_substrings]
725
- 4,
726
-
727
- //-[default_substrings]
728
- // By default, attach anything after the line with the Subject part
729
- [3],
730
-
731
- //-[fn_exlude]
732
- // When reconciliating other substrings, we want to exclude the \
733
- // Subject part itself
734
- function(i) {
735
- return (i % 3 === 2);
736
- }
737
- );
738
-
739
- return trimString(_body);
740
- }
741
-
742
- // Third method: return the raw text, as there is no original information \
743
- // embbeded (no Cc, To, Subject, etc.) (Outlook 2019)
744
- return text;
745
- }
746
-
747
-
748
- /**
749
- * Parses the author (From)
750
- * @private
751
- * @param {string} text
752
- * @param {string} body
753
- * @return {object} The parsed author
754
- */
755
- __parseOriginalFrom(text, body) {
756
- var _address = null;
757
- var _name = null;
758
-
759
- // First method: extract the author via the From part (Apple Mail, Gmail, \
760
- // Outlook Live / 365, New Outlook 2019, Thunderbird)
761
- var _author = this.__parseMailbox(this.__regexes.original_from, text);
762
-
763
- // Author found?
764
- if ((_author || {}).address || (_author || {}).name) {
765
- return _author;
766
- }
767
-
768
- // Multiple authors found?
769
- if (Array.isArray(_author) && (_author[0].address || _author[0].name)) {
770
- return _author[0];
771
- }
772
-
773
- // Second method: extract the author via the separator (Outlook 2019)
774
- var _match = loopRegexes(this.__regexes.separator_with_information, body);
775
-
776
- if (_match && _match.length === 4 && _match.groups) {
777
- // Notice: the order of parts may change depending on the localization, \
778
- // hence the use of named groups
779
- _address = _match.groups.from_address;
780
- _name = _match.groups.from_name;
781
-
782
- return this.__prepareMailbox(
783
- _address,
784
- _name
785
- );
786
- }
787
-
788
- // Third method: extract the author via the From part, using lax regexes \
789
- // (Yahoo Mail)
790
- _match = loopRegexes(this.__regexes.original_from_lax, text);
791
-
792
- if (_match && _match.length > 1) {
793
- _address = _match[3];
794
- _name = _match[2];
795
-
796
- return this.__prepareMailbox(
797
- _address,
798
- _name
799
- );
800
- }
801
-
802
- return this.__prepareMailbox(
803
- _address,
804
- _name
805
- );
806
- }
807
-
808
-
809
- /**
810
- * Parses the primary recipient(s) (To)
811
- * @private
812
- * @param {string} text
813
- * @return {object} The parsed primary recipient(s)
814
- */
815
- __parseOriginalTo(text) {
816
- // First method: extract the primary recipient(s) via the To part \
817
- // (Apple Mail, Gmail, Outlook Live / 365, New Outlook 2019, Thunderbird)
818
- var _recipients = this.__parseMailbox(
819
- this.__regexes.original_to,
820
-
821
- text,
822
- true //-[force_array]
823
- );
824
-
825
- // Recipient(s) found?
826
- if (Array.isArray(_recipients) && _recipients.length > 0) {
827
- return _recipients;
828
- }
829
-
830
- // Second method: the Subject, Date and Cc parts are stuck to the To part, \
831
- // remove them before attempting a new extract, using lax regexes \
832
- // (Yahoo Mail)
833
- var _cleanText = loopRegexes(
834
- this.__regexes.original_subject_lax,
835
- text,
836
-
837
- "replace"
838
- );
839
-
840
- _cleanText = loopRegexes(
841
- this.__regexes.original_date_lax,
842
- _cleanText,
843
-
844
- "replace"
845
- );
846
-
847
- _cleanText = loopRegexes(
848
- this.__regexes.original_cc_lax,
849
- _cleanText,
850
-
851
- "replace"
852
- );
853
-
854
- return this.__parseMailbox(
855
- this.__regexes.original_to_lax,
856
-
857
- _cleanText,
858
- true //-[force_array]
859
- );
860
- }
861
-
862
-
863
- /**
864
- * Parses the carbon-copy recipient(s) (Cc)
865
- * @private
866
- * @param {string} text
867
- * @return {object} The parsed carbon-copy recipient(s)
868
- */
869
- __parseOriginalCc(text) {
870
- // First method: extract the carbon-copy recipient(s) via the Cc part \
871
- // (Apple Mail, Gmail, Outlook Live / 365, New Outlook 2019, Thunderbird)
872
- var _recipients = this.__parseMailbox(
873
- this.__regexes.original_cc,
874
-
875
- text,
876
- true //-[force_array]
877
- );
878
-
879
- // Recipient(s) found?
880
- if (Array.isArray(_recipients) && _recipients.length > 0) {
881
- return _recipients;
882
- }
883
-
884
- // Second method: the Subject and Date parts are stuck to the To part, \
885
- // remove them before attempting a new extract, using lax regexes \
886
- // (Yahoo Mail)
887
- var _cleanText = loopRegexes(
888
- this.__regexes.original_subject_lax,
889
- text,
890
-
891
- "replace"
892
- );
893
-
894
- _cleanText = loopRegexes(
895
- this.__regexes.original_date_lax,
896
- _cleanText,
897
-
898
- "replace"
899
- );
900
-
901
- return this.__parseMailbox(
902
- this.__regexes.original_cc_lax,
903
-
904
- _cleanText,
905
- true //-[force_array]
906
- );
907
- }
908
-
909
-
910
- /**
911
- * Parses mailboxes(s)
912
- * @private
913
- * @param {object} regexes
914
- * @param {string} text
915
- * @param {boolean} [force_array]
916
- * @return {object} The parsed mailboxes(s)
917
- */
918
- __parseMailbox(regexes, text, force_array=false) {
919
- var _match = loopRegexes(regexes, text);
920
-
921
- if (_match && _match.length > 0) {
922
- var _mailboxesLine = trimString(_match[_match.length - 1]);
923
-
924
- if (_mailboxesLine) {
925
- var _mailboxes = [];
926
-
927
- while (_mailboxesLine) {
928
- var _mailboxMatch = loopRegexes(
929
- this.__regexes.mailbox,
930
- _mailboxesLine
931
- );
932
-
933
- // Address and / or name available?
934
- if (_mailboxMatch && _mailboxMatch.length > 0) {
935
- var _address = null;
936
- var _name = null;
937
-
938
- // Address and name available?
939
- if (_mailboxMatch.length === 3) {
940
- _address = _mailboxMatch[2];
941
- _name = _mailboxMatch[1];
942
- } else {
943
- _address = _mailboxMatch[1];
944
- }
945
-
946
- _mailboxes.push(
947
- this.__prepareMailbox(
948
- _address,
949
- _name
950
- )
951
- );
952
-
953
- // Remove matched mailbox from mailboxes line
954
- _mailboxesLine = trimString(
955
- _mailboxesLine.replace(_mailboxMatch[0], "")
956
- );
957
-
958
- if (_mailboxesLine) {
959
- // Remove leading mailboxes separator \
960
- // (", Nicholas <nicholas@globex.corp>")
961
- for (var _i = 0; _i < MAILBOXES_SEPARATORS.length; _i++) {
962
- var _separator = MAILBOXES_SEPARATORS[_i];
963
-
964
- if (_mailboxesLine[0] === _separator) {
965
- _mailboxesLine = trimString(_mailboxesLine.substring(1));
966
-
967
- break;
968
- }
969
- }
970
- }
971
- } else {
972
- _mailboxes.push(
973
- this.__prepareMailbox(
974
- _mailboxesLine,
975
- null
976
- )
977
- );
978
-
979
- // No more matches
980
- _mailboxesLine = "";
981
- }
982
- }
983
-
984
- // Return multiple mailboxes
985
- if (_mailboxes.length > 1) {
986
- return _mailboxes;
987
- }
988
-
989
- // Return single mailbox
990
- return (force_array === true) ? _mailboxes : _mailboxes[0];
991
- }
992
- }
993
-
994
- // No mailbox found
995
- return (force_array === true) ? [] : null;
996
- }
997
-
998
-
999
- /**
1000
- * Parses the subject part
1001
- * @private
1002
- * @param {string} text
1003
- * @return {string} The parsed subject
1004
- */
1005
- __parseOriginalSubject(text) {
1006
- // First method: extract the subject via the Subject part (Apple Mail, \
1007
- // Gmail, Outlook Live / 365, New Outlook 2019, Thunderbird)
1008
- var _match = loopRegexes(this.__regexes.original_subject, text);
1009
-
1010
- if (_match && _match.length > 0) {
1011
- return trimString(_match[1]);
1012
- }
1013
-
1014
- // Second method: extract the subject via the Subject part, using lax \
1015
- // regexes (Yahoo Mail)
1016
- _match = loopRegexes(this.__regexes.original_subject_lax, text);
1017
-
1018
- if (_match && _match.length > 0) {
1019
- return trimString(_match[1]);
1020
- }
1021
-
1022
- return null;
1023
- }
1024
-
1025
-
1026
- /**
1027
- * Parses the date part
1028
- * @private
1029
- * @param {string} text
1030
- * @param {string} body
1031
- * @return {string} The parsed date
1032
- */
1033
- __parseOriginalDate(text, body) {
1034
- // First method: extract the date via the Date part (Apple Mail, Gmail, \
1035
- // Outlook Live / 365, New Outlook 2019, Thunderbird)
1036
- var _match = loopRegexes(this.__regexes.original_date, text);
1037
-
1038
- if (_match && _match.length > 0) {
1039
- return trimString(_match[1]);
1040
- }
1041
-
1042
- // Second method: extract the date via the separator (Outlook 2019)
1043
- _match = loopRegexes(this.__regexes.separator_with_information, body);
1044
-
1045
- if (_match && _match.length === 4 && _match.groups) {
1046
- // Notice: the order of parts may change depending on the localization, \
1047
- // hence the use of named groups
1048
- return trimString(_match.groups.date);
1049
- }
1050
-
1051
- // Third method: the Subject part is stuck to the Date part, remove it \
1052
- // before attempting a new extract, using lax regexes (Yahoo Mail)
1053
- var _cleanText = loopRegexes(
1054
- this.__regexes.original_subject_lax,
1055
- text,
1056
-
1057
- "replace"
1058
- );
1059
-
1060
- _match = loopRegexes(this.__regexes.original_date_lax, _cleanText);
1061
-
1062
- if (_match && _match.length > 0) {
1063
- return trimString(_match[1]);
1064
- }
1065
-
1066
- return null;
1067
- }
1068
-
1069
-
1070
- /**
1071
- * Prepares mailbox
1072
- * @private
1073
- * @param {string} address
1074
- * @param {string} name
1075
- * @return {string} The prepared mailbox
1076
- */
1077
- __prepareMailbox(address, name) {
1078
- var _address = trimString(address);
1079
- var _name = trimString(name);
1080
-
1081
- // Make sure mailbox address is valid
1082
- var _mailboxAddressMatch = loopRegexes(
1083
- this.__regexes.mailbox_address,
1084
- _address
1085
- );
1086
-
1087
- // Invalid mailbox address? Some clients only include the name
1088
- if ((_mailboxAddressMatch || []).length === 0) {
1089
- _name = _address;
1090
- _address = null;
1091
- }
1092
-
1093
- _address = _address || null;
1094
- _name = _name || null;
1095
-
1096
- return {
1097
- address : _address,
1098
-
1099
- // Some clients fill the name with the address \
1100
- // ("bessie.berry@acme.com <bessie.berry@acme.com>")
1101
- name : (_address !== _name) ? _name : null
1102
- };
1103
- }
1104
- }
1105
-
1106
-
1107
- module.exports = Parser;