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.
@@ -0,0 +1,43 @@
1
+ /**************************************************************************
2
+ * TYPES
3
+ ***************************************************************************/
4
+ interface EmailForwardMailbox {
5
+ address: string | null;
6
+ name: string | null;
7
+ }
8
+ interface EmailForwardEmail {
9
+ body?: string;
10
+ from: EmailForwardMailbox;
11
+ to?: EmailForwardMailbox | EmailForwardMailbox[] | null;
12
+ cc?: EmailForwardMailbox | EmailForwardMailbox[] | null;
13
+ subject: string | null;
14
+ date?: string | null;
15
+ }
16
+ interface EmailForwardResult {
17
+ forwarded: boolean;
18
+ message: string | null;
19
+ email: EmailForwardEmail;
20
+ }
21
+ /**************************************************************************
22
+ * EMAIL FORWARD PARSER
23
+ ***************************************************************************/
24
+ /**
25
+ * EmailForwardParser
26
+ * @class
27
+ */
28
+ declare class EmailForwardParser {
29
+ private parser;
30
+ /**
31
+ * Constructor
32
+ */
33
+ constructor();
34
+ /**
35
+ * Attempts to parse a forwarded email
36
+ */
37
+ read(body: string, subject?: string | null): EmailForwardResult;
38
+ }
39
+ /**************************************************************************
40
+ * EXPORTS
41
+ ***************************************************************************/
42
+ export default EmailForwardParser;
43
+ export type { EmailForwardMailbox, EmailForwardEmail, EmailForwardResult };
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
1
+ /*
2
+ * This file is part of email-forward-parser
3
+ *
4
+ * Copyright (c) 2026 Crisp IM SAS
5
+ * All rights belong to Crisp IM SAS
6
+ */
7
+ /**************************************************************************
8
+ * IMPORTS
9
+ ***************************************************************************/
10
+ // PROJECT: LIB
11
+ import Parser from "./parser.js";
12
+ /**************************************************************************
13
+ * EMAIL FORWARD PARSER
14
+ ***************************************************************************/
15
+ /**
16
+ * EmailForwardParser
17
+ * @class
18
+ */
19
+ class EmailForwardParser {
20
+ /**
21
+ * Constructor
22
+ */
23
+ constructor() {
24
+ this.parser = new Parser();
25
+ }
26
+ /**
27
+ * Attempts to parse a forwarded email
28
+ */
29
+ read(body, subject = null) {
30
+ var _a, _b;
31
+ let parsedSubject = null;
32
+ let parsedEmail = {};
33
+ let parsedResult = {};
34
+ // Check if email was forwarded or not (via the subject)
35
+ if (subject) {
36
+ parsedSubject = this.parser.parseSubject(subject);
37
+ }
38
+ let forwarded = ((subject && parsedSubject !== null) && true) || false;
39
+ // Check if email was forwarded or not (via the body)
40
+ if (!subject || forwarded) {
41
+ parsedResult = this.parser.parseBody(body, forwarded);
42
+ if (parsedResult.email) {
43
+ forwarded = true;
44
+ parsedEmail = this.parser.parseOriginalEmail(parsedResult.email, parsedResult.body);
45
+ }
46
+ }
47
+ return {
48
+ forwarded: forwarded,
49
+ message: parsedResult.message || null,
50
+ email: {
51
+ body: parsedEmail.body,
52
+ from: {
53
+ address: (_a = parsedEmail.from) === null || _a === void 0 ? void 0 : _a.address,
54
+ name: (_b = parsedEmail.from) === null || _b === void 0 ? void 0 : _b.name
55
+ },
56
+ to: parsedEmail.to,
57
+ cc: parsedEmail.cc,
58
+ subject: parsedSubject || parsedEmail.subject,
59
+ date: parsedEmail.date
60
+ }
61
+ };
62
+ }
63
+ }
64
+ /**************************************************************************
65
+ * EXPORTS
66
+ ***************************************************************************/
67
+ export default EmailForwardParser;
@@ -0,0 +1,85 @@
1
+ interface Mailbox {
2
+ address: string | null;
3
+ name: string | null;
4
+ }
5
+ /**************************************************************************
6
+ * PARSER
7
+ ***************************************************************************/
8
+ /**
9
+ * Parser
10
+ */
11
+ declare class Parser {
12
+ private regexes;
13
+ /**
14
+ * Constructor
15
+ */
16
+ constructor();
17
+ /**
18
+ * Parses the subject part of the email
19
+ */
20
+ parseSubject(subject: string): string;
21
+ /**
22
+ * Parses the body part of the email
23
+ */
24
+ parseBody(body: string, forwarded?: boolean): {
25
+ body: string;
26
+ message: string;
27
+ email: string;
28
+ } | {
29
+ body?: undefined;
30
+ message?: undefined;
31
+ email?: undefined;
32
+ };
33
+ /**
34
+ * Parses the original forwarded email
35
+ */
36
+ parseOriginalEmail(text: string, body: string): {
37
+ body: string;
38
+ from: Mailbox;
39
+ to: Mailbox | Mailbox[];
40
+ cc: Mailbox | Mailbox[];
41
+ subject: string;
42
+ date: string;
43
+ };
44
+ /**
45
+ * Initializes regexes
46
+ */
47
+ private initRegexes;
48
+ /**
49
+ * Builds 'line' alternative regex
50
+ */
51
+ private buildLineRegex;
52
+ /**
53
+ * Parses the body part
54
+ */
55
+ private parseOriginalBody;
56
+ /**
57
+ * Parses the author (From)
58
+ */
59
+ private parseOriginalFrom;
60
+ /**
61
+ * Parses the primary recipient(s) (To)
62
+ */
63
+ private parseOriginalTo;
64
+ /**
65
+ * Parses the carbon-copy recipient(s) (Cc)
66
+ */
67
+ private parseOriginalCc;
68
+ /**
69
+ * Parses mailboxes(s)
70
+ */
71
+ private parseMailbox;
72
+ /**
73
+ * Parses the subject part
74
+ */
75
+ private parseOriginalSubject;
76
+ /**
77
+ * Parses the date part
78
+ */
79
+ private parseOriginalDate;
80
+ /**
81
+ * Prepares mailbox
82
+ */
83
+ private prepareMailbox;
84
+ }
85
+ export default Parser;