@mdgate/email 0.6.7 → 0.6.9

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 (2) hide show
  1. package/README.md +146 -8
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -1,11 +1,14 @@
1
1
  # @mdgate/email
2
2
 
3
- Convert email messages to Markdown. Outputs GitHub-Flavored Markdown. Works in Node, Edge, and
4
- browsers. No native addons.
3
+ **Convert email messages to Markdown in TypeScript.**
5
4
 
6
- Handles: `.eml`, `.msg`, `.mbox`, `.emlx`
5
+ [`@mdgate/email`](https://github.com/mdgate/converters/tree/main/packages/email) reads `.eml`, `.msg`, `.mbox`, and `.emlx` files directly in JavaScript and converts them into GitHub-Flavored Markdown, without Python, native addons, WASM, or an email client.
7
6
 
8
- ## Usage
7
+ Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
8
+
9
+ ```bash
10
+ npm install @mdgate/email
11
+ ```
9
12
 
10
13
  ```ts
11
14
  import { toMarkdown } from '@mdgate/email';
@@ -13,14 +16,149 @@ import { toMarkdown } from '@mdgate/email';
13
16
  const markdown = await toMarkdown(bytes);
14
17
  ```
15
18
 
16
- Compose with other converters:
19
+ `bytes` is a `Uint8Array`, so the message can come from a file upload, object storage, an IMAP export, a browser file picker, or anywhere else your application gets bytes.
20
+
21
+ ---
22
+
23
+ ## Why [`@mdgate/email`](https://github.com/mdgate/converters/tree/main/packages/email)
24
+
25
+ Email is a container: headers, a text or HTML body, and attachments. Agents need the message as text they can search and cite.
26
+
27
+ [`@mdgate/email`](https://github.com/mdgate/converters/tree/main/packages/email) is an email reader written for the same runtime as your application:
28
+
29
+ * **Pure TypeScript**
30
+ * **Email → Markdown locally**
31
+ * **No Python runtime**
32
+ * **No native addons**
33
+ * **No WASM runtime**
34
+ * **Zero third-party runtime dependencies**
35
+ * **Works with raw `Uint8Array` input**
36
+ * **Detects RFC 822 mail and Outlook MSG from their contents, not only the filename**
37
+
38
+ ---
39
+
40
+ ## What it extracts
41
+
42
+ [`@mdgate/email`](https://github.com/mdgate/converters/tree/main/packages/email) parses MIME messages, Apple EMLX, mbox, and Outlook MSG (OLE).
43
+
44
+ The converter handles email-specific concerns including:
45
+
46
+ * Subject as a heading
47
+ * From, To, Cc, and Date
48
+ * HTML bodies converted through the same HTML document model
49
+ * plain-text bodies
50
+ * attachment names listed under an Attachments heading
51
+ * Outlook `.msg` compound files
52
+
53
+ Standalone conversion lists attachment names. Nested conversion of those attachments happens when the message sits inside a composed reader that also has converters for those formats (for example a ZIP of `.eml` files handled by [`@mdgate/zip`](https://github.com/mdgate/converters/tree/main/packages/zip)).
54
+
55
+ ---
56
+
57
+ ## Node.js
58
+
59
+ ```ts
60
+ import { readFile } from 'node:fs/promises';
61
+ import { toMarkdown } from '@mdgate/email';
62
+
63
+ const bytes = new Uint8Array(await readFile('note.eml'));
64
+ const markdown = await toMarkdown(bytes);
65
+
66
+ console.log(markdown);
67
+ ```
68
+
69
+ ---
70
+
71
+ ## Browser
72
+
73
+ ```ts
74
+ import { toMarkdown } from '@mdgate/email';
75
+
76
+ const file = input.files![0];
77
+ const bytes = new Uint8Array(await file.arrayBuffer());
78
+
79
+ const markdown = await toMarkdown(bytes);
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Cloudflare Workers and Edge runtimes
85
+
86
+ ```ts
87
+ import { toMarkdown } from '@mdgate/email';
88
+
89
+ export default {
90
+ async fetch(request: Request) {
91
+ const bytes = new Uint8Array(await request.arrayBuffer());
92
+ const markdown = await toMarkdown(bytes);
93
+
94
+ return new Response(markdown, {
95
+ headers: {
96
+ 'content-type': 'text/markdown; charset=utf-8',
97
+ },
98
+ });
99
+ },
100
+ };
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Format detection
106
+
107
+ You do not need to trust the file extension.
108
+
109
+ RFC 822 messages are recognized from headers. Outlook MSG is recognized from OLE streams.
110
+
111
+ ```ts
112
+ const markdown = await toMarkdown(bytes);
113
+ ```
114
+
115
+ A path can still be supplied as a format hint when [`@mdgate/email`](https://github.com/mdgate/converters/tree/main/packages/email) is used through [`@mdgate/converters`](https://github.com/mdgate/converters/tree/main/packages/converters) or a reader composed with [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core), but the path is never used to read a file from disk.
116
+
117
+ ---
118
+
119
+ ## Compose it with other file readers
120
+
121
+ [`@mdgate/email`](https://github.com/mdgate/converters/tree/main/packages/email) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
17
122
 
18
123
  ```ts
19
124
  import { create } from '@mdgate/core';
20
125
  import { email } from '@mdgate/email';
126
+ import { html } from '@mdgate/html';
127
+ import { zip } from '@mdgate/zip';
128
+
129
+ const read = create([
130
+ email(),
131
+ html(),
132
+ zip(),
133
+ ]);
134
+ ```
135
+
136
+ The application still uses one reading interface while each format remains independently installable.
137
+
138
+ ---
139
+
140
+ ## Need more than email?
141
+
142
+ If your application needs to read many different file types, use the complete converter set:
21
143
 
22
- const convert = create([email()]);
144
+ ```bash
145
+ npm install @mdgate/converters
23
146
  ```
24
147
 
25
- Part of [mdgate converters](https://github.com/mdgate/converters); install
26
- `@mdgate/converters` for every format at once.
148
+ ```ts
149
+ import { toMarkdown } from '@mdgate/converters';
150
+
151
+ const markdown = await toMarkdown(bytes, {
152
+ path: filename,
153
+ });
154
+ ```
155
+
156
+ [`@mdgate/email`](https://github.com/mdgate/converters/tree/main/packages/email) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
157
+
158
+ For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
159
+
160
+ ---
161
+
162
+ ## License
163
+
164
+ MIT
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mdgate/email",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "description": "mdgate email converter (eml, msg, mbox)",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "homepage": "https://demo.mdgate.dev",
7
+ "homepage": "https://convert.mdgate.dev",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/mdgate/converters.git",
@@ -28,11 +28,11 @@
28
28
  "prepublishOnly": "bun run build"
29
29
  },
30
30
  "dependencies": {
31
- "@mdgate/containers": "0.6.7",
32
- "@mdgate/core": "0.6.7",
33
- "@mdgate/document": "0.6.7",
34
- "@mdgate/html": "0.6.7",
35
- "@mdgate/utils": "0.6.7"
31
+ "@mdgate/containers": "0.6.9",
32
+ "@mdgate/core": "0.6.9",
33
+ "@mdgate/document": "0.6.9",
34
+ "@mdgate/html": "0.6.9",
35
+ "@mdgate/utils": "0.6.9"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"