@orkestrel/msg 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Orkestrel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # @orkestrel/msg
2
+
3
+ A zero-dependency Outlook `.msg` (CFB/OLE2) and `.eml` (RFC 2822/MIME) email
4
+ parser — extracts headers, bodies, recipients, and attachments into typed
5
+ structures. Feed it raw file bytes plus an optional file name or MIME hint; the
6
+ format is detected automatically and the file is parsed into a structured
7
+ `EmailChain` — sender, recipients, subject, date, text/HTML bodies, and
8
+ decoded attachments. `.msg` files are read via a from-scratch CFB (Compound
9
+ File Binary / OLE2) parser that walks the directory tree and extracts MAPI
10
+ properties directly; `.eml` files are read via a from-scratch RFC 2822/MIME
11
+ parser that walks the header block and the (possibly nested) MIME part tree.
12
+ A lower-level `MSGReader` / `MSGBurner` pair is also exposed for readers that
13
+ need direct CFB access — `MSGReader` parses a `.msg` binary into its raw
14
+ directory/property structure, and `MSGBurner` reconstitutes that structure
15
+ back into a valid CFB byte stream (a round-trip "burn"), useful for rebuilding
16
+ or re-serializing a `.msg` file after editing its parsed fields. It never
17
+ throws on malformed input, only a typed `MSGError` returned inside a
18
+ `Result`. Part of the `@orkestrel` line.
19
+
20
+ ## Install
21
+
22
+ ```sh
23
+ npm install @orkestrel/msg
24
+ ```
25
+
26
+ ## Requirements
27
+
28
+ - Node.js >= 24
29
+ - ESM + CJS (dual-format build)
30
+ - No runtime dependencies
31
+
32
+ ## Usage
33
+
34
+ ```ts
35
+ import { createEmailParser, isSuccess } from '@orkestrel/msg'
36
+
37
+ const parser = createEmailParser()
38
+ const result = parser.parse({ bytes, name: 'message.msg' }) // bytes: Uint8Array
39
+
40
+ if (isSuccess(result)) {
41
+ const chain = result.value
42
+ console.log(chain.format) // 'msg' or 'eml'
43
+
44
+ const message = chain.messages[0]
45
+ console.log(message.from, message.to, message.subject)
46
+ console.log(message.text) // plain-text body (includes quoted reply chain)
47
+ console.log(message.html) // HTML body (includes quoted reply chain)
48
+
49
+ for (const attachment of message.attachments) {
50
+ console.log(attachment.name, attachment.mimeType, attachment.size)
51
+ }
52
+ } else {
53
+ console.error(result.error.code, result.error.message) // 'UNSUPPORTED' | 'MALFORMED' | ...
54
+ }
55
+ ```
56
+
57
+ `parse` is synchronous and returns a `Result<EmailChain, MSGError>` — never
58
+ throws. Format is inferred from the `name` / `mime` hints when supplied, or
59
+ detected from the byte content itself (CFB header for `.msg`, RFC 2822 header
60
+ block for `.eml`) when they are absent.
61
+
62
+ For direct access to the underlying `.msg` CFB structure — and to rebuild a
63
+ `.msg` binary after editing its parsed fields — use `createMSGReader` and
64
+ `createMSGBurner`:
65
+
66
+ ```ts
67
+ import { createMSGReader, createMSGBurner } from '@orkestrel/msg'
68
+
69
+ const reader = createMSGReader(buffer) // ArrayBuffer or Uint8Array
70
+ const data = reader.parse() // raw directory/property structure
71
+ const rebuilt = reader.burn() // round-trip back into a CFB byte stream
72
+
73
+ const burner = createMSGBurner()
74
+ const binary = burner.burn(entries) // build a CFB byte stream from entry descriptors
75
+ ```
76
+
77
+ ## Guide
78
+
79
+ For the full surface — the `EmailParser`, `MSGReader`, and `MSGBurner`
80
+ classes, their supporting types (`EmailChain`, `EmailMessage`,
81
+ `EmailAttachment`, `MSGDirectoryEntry`, and friends), and the CFB/MIME formats
82
+ they implement — see [`guides/src/msg.md`](guides/src/msg.md).
83
+
84
+ ## Package
85
+
86
+ Published as a single typed entry point per the `exports` field in
87
+ `package.json`.
88
+
89
+ ## License
90
+
91
+ MIT © [Orkestrel](https://github.com/orkestrel) — see [LICENSE](./LICENSE).