lite-email-parser 2.0.0 → 2.0.3

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.
Files changed (52) hide show
  1. package/binding.gyp +20 -6
  2. package/core/include/html_extractor.h +100 -0
  3. package/core/include/html_parser.h +13 -0
  4. package/core/src/html_extractor.cpp +662 -0
  5. package/core/src/html_parser.cpp +221 -0
  6. package/deps/gumbo-parser/src/attribute.c +44 -0
  7. package/deps/gumbo-parser/src/attribute.h +37 -0
  8. package/deps/gumbo-parser/src/char_ref.c +301 -0
  9. package/deps/gumbo-parser/src/char_ref.h +70 -0
  10. package/deps/gumbo-parser/src/char_ref_gperf.c +11126 -0
  11. package/deps/gumbo-parser/src/error.c +287 -0
  12. package/deps/gumbo-parser/src/error.h +225 -0
  13. package/deps/gumbo-parser/src/gumbo.h +683 -0
  14. package/deps/gumbo-parser/src/insertion_mode.h +55 -0
  15. package/deps/gumbo-parser/src/parser.c +4433 -0
  16. package/deps/gumbo-parser/src/parser.h +57 -0
  17. package/deps/gumbo-parser/src/string_buffer.c +110 -0
  18. package/deps/gumbo-parser/src/string_buffer.h +84 -0
  19. package/deps/gumbo-parser/src/string_piece.c +48 -0
  20. package/deps/gumbo-parser/src/string_piece.h +38 -0
  21. package/deps/gumbo-parser/src/tag.c +125 -0
  22. package/deps/gumbo-parser/src/tag_enum.h +155 -0
  23. package/deps/gumbo-parser/src/tag_gperf.h +350 -0
  24. package/deps/gumbo-parser/src/tag_sizes.h +2 -0
  25. package/deps/gumbo-parser/src/tag_strings.h +155 -0
  26. package/deps/gumbo-parser/src/token_type.h +42 -0
  27. package/deps/gumbo-parser/src/tokenizer.c +3003 -0
  28. package/deps/gumbo-parser/src/tokenizer.h +123 -0
  29. package/deps/gumbo-parser/src/tokenizer_states.h +104 -0
  30. package/deps/gumbo-parser/src/utf8.c +270 -0
  31. package/deps/gumbo-parser/src/utf8.h +132 -0
  32. package/deps/gumbo-parser/src/util.c +58 -0
  33. package/deps/gumbo-parser/src/util.h +60 -0
  34. package/deps/gumbo-parser/src/vector.c +128 -0
  35. package/deps/gumbo-parser/src/vector.h +70 -0
  36. package/dist/cjs/index.cjs +63 -0
  37. package/dist/cjs/index.d.cts +9 -0
  38. package/dist/cjs/index.d.cts.map +1 -0
  39. package/dist/cjs/index.d.ts.map +1 -1
  40. package/dist/cjs/index.js +32 -3
  41. package/dist/cjs/parser.d.ts +4 -0
  42. package/dist/cjs/parser.d.ts.map +1 -0
  43. package/dist/cjs/parser.js +118 -0
  44. package/dist/index.cjs +63 -0
  45. package/dist/index.d.cts +9 -0
  46. package/dist/index.d.cts.map +1 -0
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +32 -3
  49. package/dist/parser.d.ts +4 -0
  50. package/dist/parser.d.ts.map +1 -0
  51. package/dist/parser.js +81 -0
  52. package/package.json +11 -3
package/binding.gyp CHANGED
@@ -1,22 +1,36 @@
1
1
  {
2
+ "variables": {
3
+ "src_root%": "<!(node -e \"var fs=require('fs');console.log(fs.existsSync('core')?'./':'../')\")"
4
+ },
2
5
  "targets": [
3
6
  {
4
7
  "target_name": "parser",
5
8
  "sources": [
6
9
  "src/addon.cpp",
7
- "../core/src/html_parser.cpp",
8
- "../core/src/html_extractor.cpp"
10
+ "<(src_root)core/src/html_parser.cpp",
11
+ "<(src_root)core/src/html_extractor.cpp",
12
+ "<(src_root)deps/gumbo-parser/src/attribute.c",
13
+ "<(src_root)deps/gumbo-parser/src/char_ref.c",
14
+ "<(src_root)deps/gumbo-parser/src/char_ref_gperf.c",
15
+ "<(src_root)deps/gumbo-parser/src/error.c",
16
+ "<(src_root)deps/gumbo-parser/src/parser.c",
17
+ "<(src_root)deps/gumbo-parser/src/string_buffer.c",
18
+ "<(src_root)deps/gumbo-parser/src/string_piece.c",
19
+ "<(src_root)deps/gumbo-parser/src/tag.c",
20
+ "<(src_root)deps/gumbo-parser/src/tokenizer.c",
21
+ "<(src_root)deps/gumbo-parser/src/utf8.c",
22
+ "<(src_root)deps/gumbo-parser/src/util.c",
23
+ "<(src_root)deps/gumbo-parser/src/vector.c"
9
24
  ],
10
25
  "include_dirs": [
11
26
  "<!@(node -p \"require('node-addon-api').include\")",
12
- "../core/include"
27
+ "<(src_root)core/include",
28
+ "<(src_root)deps/gumbo-parser/src"
13
29
  ],
14
30
  "dependencies": [
15
31
  "<!(node -p \"require('node-addon-api').targets\"):node_addon_api"
16
32
  ],
17
- "libraries": [
18
- "-lgumbo"
19
- ],
33
+ "libraries": [],
20
34
  "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
21
35
  "cflags!": [ "-fno-exceptions" ],
22
36
  "cflags_cc!": [ "-fno-exceptions" ],
@@ -0,0 +1,100 @@
1
+ #ifndef HTML_EXTRACTOR_H
2
+ #define HTML_EXTRACTOR_H
3
+
4
+ #include <string>
5
+ #include <vector>
6
+
7
+ namespace liteEmailParser {
8
+
9
+ // Represents a file attachment (mirrors IFile from types.ts)
10
+ struct Attachment {
11
+ std::string name; // filename (defaults to current date if absent)
12
+ std::string type; // MIME content type (e.g. "image/png")
13
+ std::size_t size = 0; // size in bytes
14
+ std::string buffer; // raw binary content
15
+ std::string src; // uploaded URL (populated by replaceSrc after upload)
16
+ std::string originalSrc; // base64 data URI for inline attachments (e.g. "data:image/png;base64,...")
17
+ };
18
+
19
+ // Full result of parsing an email
20
+ struct ParseEmailResult {
21
+ std::string subject;
22
+ std::string from;
23
+ std::string to;
24
+ std::string text; // cleaned HTML (or plain text fallback)
25
+ std::vector<Attachment> attachments; // regular attachments
26
+ std::vector<Attachment> inlineAttachments; // inline (cid-referenced) attachments
27
+ };
28
+
29
+ // Result of HTML extraction from a raw email buffer
30
+ struct ExtractionResult {
31
+ std::string body; // HTML content (or plain text fallback)
32
+ bool isHtml; // true if body came from a text/html part
33
+ };
34
+
35
+ // Main entry point: parses a raw .eml buffer into a full result.
36
+ ParseEmailResult parseEmail(const std::string& rawEmail);
37
+
38
+ // Main entry point: extracts the HTML (or text) body from a raw .eml buffer.
39
+ // Parses MIME boundaries, finds the text/html part (falls back to text/plain),
40
+ // and decodes Content-Transfer-Encoding (quoted-printable or base64).
41
+ ExtractionResult extractHtmlBody(const std::string& rawEmail);
42
+
43
+ // Reads an .eml file from disk into a string buffer
44
+ std::string readEmailFile(const std::string& filePath);
45
+
46
+ // Replaces img src attributes in HTML: for each file with originalSrc and src set,
47
+ // finds matching img elements and swaps the src to the new URL.
48
+ std::string replaceSrc(const std::string& html, const std::vector<Attachment>& files);
49
+
50
+ namespace detail {
51
+
52
+ // Represents a single MIME part extracted from the email
53
+ struct MimePart {
54
+ std::string contentType; // e.g. "text/html; charset=\"UTF-8\""
55
+ std::string transferEncoding; // e.g. "quoted-printable", "base64"
56
+ std::string contentId; // e.g. "ii_mrnoxu771" (without angle brackets)
57
+ std::string contentDisposition; // e.g. "attachment", "inline"
58
+ std::string filename; // from Content-Disposition or Content-Type name=
59
+ std::string body; // raw body content of this part
60
+ };
61
+
62
+ // Parse the top-level Content-Type header to extract the boundary string
63
+ std::string extractBoundary(const std::string& contentTypeHeader);
64
+
65
+ // Split a raw email (or a multipart section) into its MIME parts by boundary.
66
+ // Recurses into nested multipart parts.
67
+ std::vector<MimePart> parseMimeParts(const std::string& rawContent,
68
+ const std::string& boundary);
69
+
70
+ // Extract a header value from raw headers block (case-insensitive key match)
71
+ std::string getHeaderValue(const std::string& headers, const std::string& key);
72
+
73
+ // Decode quoted-printable encoded content
74
+ std::string decodeQuotedPrintable(const std::string& input);
75
+
76
+ // Decode base64 encoded content
77
+ std::string decodeBase64(const std::string& input);
78
+
79
+ // Encode binary data to base64
80
+ std::string encodeBase64(const std::string& input);
81
+
82
+ // Extract the MIME type (e.g. "image/png") from a Content-Type header value
83
+ std::string extractMimeType(const std::string& contentTypeHeader);
84
+
85
+ // Extract Content-ID value, stripping angle brackets
86
+ std::string extractContentId(const std::string& contentIdHeader);
87
+
88
+ // Extract filename from Content-Disposition or Content-Type name= parameter
89
+ std::string extractFilename(const std::string& contentDisposition,
90
+ const std::string& contentType);
91
+
92
+ // Replace cid: references in HTML with base64 data URIs using the provided parts
93
+ std::string replaceCidWithBase64(const std::string& html,
94
+ const std::vector<MimePart>& parts);
95
+
96
+ } // namespace detail
97
+
98
+ } // namespace liteEmailParser
99
+
100
+ #endif // HTML_EXTRACTOR_H
@@ -0,0 +1,13 @@
1
+ #ifndef HTML_PARSER_H
2
+ #define HTML_PARSER_H
3
+
4
+ #include <string>
5
+
6
+ namespace liteEmailParser {
7
+ std::string removeSignature(std::string html);
8
+ std::string removeReplies(std::string html);
9
+ std::string removeDividers(std::string html);
10
+ std::string cleanHtml(std::string html);
11
+ }
12
+
13
+ #endif // HTML_PARSER_H