lite-email-parser 2.0.3 → 2.1.7

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 (57) hide show
  1. package/dist/index.cjs +29 -4
  2. package/dist/index.d.cts.map +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +27 -29
  5. package/package.json +14 -29
  6. package/binding.gyp +0 -47
  7. package/core/include/html_extractor.h +0 -100
  8. package/core/include/html_parser.h +0 -13
  9. package/core/src/html_extractor.cpp +0 -662
  10. package/core/src/html_parser.cpp +0 -221
  11. package/deps/gumbo-parser/src/attribute.c +0 -44
  12. package/deps/gumbo-parser/src/attribute.h +0 -37
  13. package/deps/gumbo-parser/src/char_ref.c +0 -301
  14. package/deps/gumbo-parser/src/char_ref.h +0 -70
  15. package/deps/gumbo-parser/src/char_ref_gperf.c +0 -11126
  16. package/deps/gumbo-parser/src/error.c +0 -287
  17. package/deps/gumbo-parser/src/error.h +0 -225
  18. package/deps/gumbo-parser/src/gumbo.h +0 -683
  19. package/deps/gumbo-parser/src/insertion_mode.h +0 -55
  20. package/deps/gumbo-parser/src/parser.c +0 -4433
  21. package/deps/gumbo-parser/src/parser.h +0 -57
  22. package/deps/gumbo-parser/src/string_buffer.c +0 -110
  23. package/deps/gumbo-parser/src/string_buffer.h +0 -84
  24. package/deps/gumbo-parser/src/string_piece.c +0 -48
  25. package/deps/gumbo-parser/src/string_piece.h +0 -38
  26. package/deps/gumbo-parser/src/tag.c +0 -125
  27. package/deps/gumbo-parser/src/tag_enum.h +0 -155
  28. package/deps/gumbo-parser/src/tag_gperf.h +0 -350
  29. package/deps/gumbo-parser/src/tag_sizes.h +0 -2
  30. package/deps/gumbo-parser/src/tag_strings.h +0 -155
  31. package/deps/gumbo-parser/src/token_type.h +0 -42
  32. package/deps/gumbo-parser/src/tokenizer.c +0 -3003
  33. package/deps/gumbo-parser/src/tokenizer.h +0 -123
  34. package/deps/gumbo-parser/src/tokenizer_states.h +0 -104
  35. package/deps/gumbo-parser/src/utf8.c +0 -270
  36. package/deps/gumbo-parser/src/utf8.h +0 -132
  37. package/deps/gumbo-parser/src/util.c +0 -58
  38. package/deps/gumbo-parser/src/util.h +0 -60
  39. package/deps/gumbo-parser/src/vector.c +0 -128
  40. package/deps/gumbo-parser/src/vector.h +0 -70
  41. package/dist/cjs/index.cjs +0 -63
  42. package/dist/cjs/index.d.cts +0 -9
  43. package/dist/cjs/index.d.cts.map +0 -1
  44. package/dist/cjs/index.d.ts +0 -9
  45. package/dist/cjs/index.d.ts.map +0 -1
  46. package/dist/cjs/index.js +0 -92
  47. package/dist/cjs/package.json +0 -1
  48. package/dist/cjs/parser.d.ts +0 -4
  49. package/dist/cjs/parser.d.ts.map +0 -1
  50. package/dist/cjs/parser.js +0 -118
  51. package/dist/cjs/types.d.ts +0 -14
  52. package/dist/cjs/types.d.ts.map +0 -1
  53. package/dist/cjs/types.js +0 -2
  54. package/dist/parser.d.ts +0 -4
  55. package/dist/parser.d.ts.map +0 -1
  56. package/dist/parser.js +0 -81
  57. package/src/addon.cpp +0 -141
package/dist/index.cjs CHANGED
@@ -39,10 +39,35 @@ exports.removeSignature = removeSignature;
39
39
  exports.removeReplies = removeReplies;
40
40
  exports.removeDividers = removeDividers;
41
41
  exports.replaceSrc = replaceSrc;
42
- const path = __importStar(require("path"));
43
- // Load native addon - CJS uses __dirname
44
- const packageRoot = path.resolve(__dirname, '..');
45
- const addon = require(path.join(packageRoot, 'build', 'Release', 'parser.node'));
42
+ const os = __importStar(require("os"));
43
+ // Map of platform-arch to the corresponding scoped package name
44
+ const PLATFORM_PACKAGES = {
45
+ 'linux-x64': '@lite-email-parser-native/linux-x64',
46
+ 'linux-arm64': '@lite-email-parser-native/linux-arm64',
47
+ 'darwin-x64': '@lite-email-parser-native/darwin-x64',
48
+ 'darwin-arm64': '@lite-email-parser-native/darwin-arm64',
49
+ 'win32-x64': '@lite-email-parser-native/win32-x64',
50
+ };
51
+ function loadAddon() {
52
+ const platform = os.platform();
53
+ const arch = os.arch();
54
+ const key = `${platform}-${arch}`;
55
+ const packageName = PLATFORM_PACKAGES[key];
56
+ if (!packageName) {
57
+ throw new Error(`lite-email-parser: unsupported platform ${platform}-${arch}. ` +
58
+ `Supported: ${Object.keys(PLATFORM_PACKAGES).join(', ')}`);
59
+ }
60
+ try {
61
+ return require(packageName);
62
+ }
63
+ catch (e) {
64
+ throw new Error(`lite-email-parser: failed to load native binary for ${platform}-${arch}. ` +
65
+ `Make sure "${packageName}" is installed. ` +
66
+ `If you're using npm, ensure optionalDependencies are not disabled.\n` +
67
+ `Original error: ${e.message}`);
68
+ }
69
+ }
70
+ const addon = loadAddon();
46
71
  async function parseEmail(buffer) {
47
72
  return addon.parseEmail(buffer);
48
73
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.cts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAMrD,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAE1E;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAE/D;AAGD,YAAY,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.cts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAsCrD,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAE1E;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAE/D;AAGD,YAAY,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAyCrD,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAE1E;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAE/D;AAGD,YAAY,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAwCrD,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAE1E;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAE/D;AAGD,YAAY,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,36 +1,34 @@
1
1
  import { createRequire } from 'module';
2
- import * as path from 'path';
3
- const _require = typeof require !== 'undefined'
4
- ? require
5
- : createRequire(process.cwd());
6
- const getDirname = () => {
7
- if (typeof __dirname !== 'undefined') {
8
- return __dirname;
2
+ import * as os from 'os';
3
+ const _require = createRequire(import.meta.url);
4
+ // Map of platform-arch to the corresponding scoped package name
5
+ const PLATFORM_PACKAGES = {
6
+ 'linux-x64': '@lite-email-parser-native/linux-x64',
7
+ 'linux-arm64': '@lite-email-parser-native/linux-arm64',
8
+ 'darwin-x64': '@lite-email-parser-native/darwin-x64',
9
+ 'darwin-arm64': '@lite-email-parser-native/darwin-arm64',
10
+ 'win32-x64': '@lite-email-parser-native/win32-x64',
11
+ };
12
+ function loadAddon() {
13
+ const platform = os.platform();
14
+ const arch = os.arch();
15
+ const key = `${platform}-${arch}`;
16
+ const packageName = PLATFORM_PACKAGES[key];
17
+ if (!packageName) {
18
+ throw new Error(`lite-email-parser: unsupported platform ${platform}-${arch}. ` +
19
+ `Supported: ${Object.keys(PLATFORM_PACKAGES).join(', ')}`);
9
20
  }
10
- const err = new Error();
11
- const stackLines = err.stack?.split('\n') || [];
12
- for (const line of stackLines) {
13
- const match = line.match(/(?:at\s+|\()((?:file:\/\/)?\/[^:]+)/);
14
- if (match) {
15
- const p = match[1];
16
- if (p.includes('index.js') || p.includes('index.ts')) {
17
- let cleanPath = p;
18
- if (cleanPath.startsWith('file://')) {
19
- const fileURLToPath = _require('url').fileURLToPath;
20
- cleanPath = fileURLToPath(cleanPath);
21
- }
22
- return path.dirname(cleanPath);
23
- }
24
- }
21
+ try {
22
+ return _require(packageName);
23
+ }
24
+ catch (e) {
25
+ throw new Error(`lite-email-parser: failed to load native binary for ${platform}-${arch}. ` +
26
+ `Make sure "${packageName}" is installed. ` +
27
+ `If you're using npm, ensure optionalDependencies are not disabled.\n` +
28
+ `Original error: ${e.message}`);
25
29
  }
26
- return process.cwd();
27
- };
28
- const dirname = getDirname();
29
- let addonPath = path.resolve(dirname, '../build/Release/parser.node');
30
- if (!_require('fs').existsSync(addonPath)) {
31
- addonPath = path.resolve(dirname, '../../build/Release/parser.node');
32
30
  }
33
- const addon = _require(addonPath);
31
+ const addon = loadAddon();
34
32
  export async function parseEmail(buffer) {
35
33
  return addon.parseEmail(buffer);
36
34
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "lite-email-parser",
3
- "version": "2.0.3",
3
+ "version": "2.1.7",
4
4
  "description": "Parse email to get signature, replies, attachments and inline images",
5
- "main": "./dist/cjs/index.js",
5
+ "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
@@ -12,38 +12,18 @@
12
12
  "default": "./dist/index.js"
13
13
  },
14
14
  "require": {
15
- "types": "./dist/cjs/index.d.ts",
16
- "default": "./dist/cjs/index.js"
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
17
17
  }
18
18
  }
19
19
  },
20
20
  "files": [
21
- "dist/",
22
- "binding.gyp",
23
- "src/addon.cpp",
24
- "core/include/",
25
- "core/src/*.cpp",
26
- "deps/gumbo-parser/src/*.c",
27
- "deps/gumbo-parser/src/*.h"
21
+ "dist/"
28
22
  ],
29
- "binary": {
30
- "module_name": "parser",
31
- "module_path": "./build/Release/",
32
- "host": "https://github.com/philipedc/lite-email-parser/releases/download/",
33
- "remote_path": "{version}",
34
- "package_name": "{module_name}-v{version}-napi-v9-{platform}-{arch}.tar.gz",
35
- "napi_versions": [
36
- 9
37
- ]
38
- },
39
23
  "scripts": {
40
- "install": "prebuild-install || node-gyp rebuild",
41
24
  "build:native": "node-gyp rebuild",
42
- "build:ts": "npx tsc && npx tsc --module commonjs --outDir dist/cjs --declaration && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
25
+ "build:ts": "npx tsc",
43
26
  "build": "npm run build:native && npm run build:ts",
44
- "prebuild": "node-gyp rebuild && tar -czf parser-v2.0.0-napi-v9-linux-x64.tar.gz -C build/Release parser.node",
45
- "prepublishOnly": "cp -r ../core ./core && mkdir -p ./deps && cp -r ../deps/gumbo-parser ./deps/gumbo-parser",
46
- "postpublish": "rm -rf ./core ./deps",
47
27
  "test": "npx -y tsx samples/sample.ts"
48
28
  },
49
29
  "contributors": [
@@ -81,12 +61,17 @@
81
61
  "email-to-html",
82
62
  "signature-remover"
83
63
  ],
84
- "dependencies": {
85
- "node-addon-api": "^8.0.0",
86
- "prebuild-install": "^7.1.2"
64
+ "dependencies": {},
65
+ "optionalDependencies": {
66
+ "@lite-email-parser-native/linux-x64": "2.1.7",
67
+ "@lite-email-parser-native/linux-arm64": "2.1.7",
68
+ "@lite-email-parser-native/darwin-x64": "2.1.7",
69
+ "@lite-email-parser-native/darwin-arm64": "2.1.7",
70
+ "@lite-email-parser-native/win32-x64": "2.1.7"
87
71
  },
88
72
  "devDependencies": {
89
73
  "@types/node": "^20.11.0",
74
+ "node-addon-api": "^8.0.0",
90
75
  "node-gyp": "^13.0.0",
91
76
  "typescript": "^7.0.2"
92
77
  }
package/binding.gyp DELETED
@@ -1,47 +0,0 @@
1
- {
2
- "variables": {
3
- "src_root%": "<!(node -e \"var fs=require('fs');console.log(fs.existsSync('core')?'./':'../')\")"
4
- },
5
- "targets": [
6
- {
7
- "target_name": "parser",
8
- "sources": [
9
- "src/addon.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"
24
- ],
25
- "include_dirs": [
26
- "<!@(node -p \"require('node-addon-api').include\")",
27
- "<(src_root)core/include",
28
- "<(src_root)deps/gumbo-parser/src"
29
- ],
30
- "dependencies": [
31
- "<!(node -p \"require('node-addon-api').targets\"):node_addon_api"
32
- ],
33
- "libraries": [],
34
- "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
35
- "cflags!": [ "-fno-exceptions" ],
36
- "cflags_cc!": [ "-fno-exceptions" ],
37
- "xcode_settings": {
38
- "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
39
- "CLANG_CXX_LIBRARY": "libc++",
40
- "MACOSX_DEPLOYMENT_TARGET": "10.7"
41
- },
42
- "msvs_settings": {
43
- "VCCLCompilerTool": { "ExceptionHandling": 1 }
44
- }
45
- }
46
- ]
47
- }
@@ -1,100 +0,0 @@
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
@@ -1,13 +0,0 @@
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