readpst 0.0.0-stage → 0.2.0
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 +21 -0
- package/README.md +59 -2
- package/index.d.ts +26 -0
- package/index.js +45 -0
- package/package.json +18 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Philip van Burleigh
|
|
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
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# readpst
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Convert Outlook `.pst` (and `.ost`) files to `.eml` files from Node.js, using [libpst](https://www.five-ten-sg.com/libpst/)'s `readpst`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
The `readpst` binary must be on your `PATH`:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
brew install libpst # macOS
|
|
11
|
+
apt install pst-utils # Debian/Ubuntu
|
|
12
|
+
apk add libpst # Alpine
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install readpst
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { extract } from "readpst";
|
|
23
|
+
|
|
24
|
+
const files = await extract("mailbox.pst", { outDir: "out" });
|
|
25
|
+
// ["/abs/out/Inbox/1.eml", "/abs/out/Sent Items/1.eml", ...]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Without managing files
|
|
29
|
+
|
|
30
|
+
`read` extracts into a temp dir, yields each item and removes the dir when the loop ends (also on `break` or a thrown error):
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { read } from "readpst";
|
|
34
|
+
|
|
35
|
+
for await (const item of read("mailbox.pst")) {
|
|
36
|
+
item.path; // "Inbox/1.eml"
|
|
37
|
+
await item.buffer(); // Buffer
|
|
38
|
+
item.stream(); // fs.ReadStream, e.g. to upload to S3
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Consume each item's buffer or stream before moving to the next one; the files are gone once the loop finishes.
|
|
43
|
+
|
|
44
|
+
### Writing to a directory
|
|
45
|
+
|
|
46
|
+
`extract` writes to a directory you own and returns the file paths. `outDir` mirrors the PST's folder tree, with one RFC 822 `.eml` per message and attachments kept inline as MIME parts. Text is written as UTF-8.
|
|
47
|
+
|
|
48
|
+
### Options
|
|
49
|
+
|
|
50
|
+
| Option | Default | Description |
|
|
51
|
+
| ------------- | ------------- | ----------------------------------------------------------------- |
|
|
52
|
+
| `outDir` | (required) | `extract` only: output directory, created if missing |
|
|
53
|
+
| `types` | `["email"]` | Any of `"email"`, `"appointment"`, `"journal"`, `"contact"` |
|
|
54
|
+
| `readpstPath` | `"readpst"` | Path to the binary |
|
|
55
|
+
|
|
56
|
+
`readpst` needs a seekable file on local disk, so download a remote PST to a temp file first. With `extract`, cleaning up `outDir` is up to you.
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT. libpst itself is GPL-2.0; this package only runs it as a separate program and does not bundle it.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type ItemType = "email" | "appointment" | "journal" | "contact";
|
|
2
|
+
|
|
3
|
+
export interface ExtractOptions {
|
|
4
|
+
/** Directory to write into. Created if missing; mirrors the PST's folder tree. */
|
|
5
|
+
outDir: string;
|
|
6
|
+
/** Item types to export. Defaults to ["email"]. */
|
|
7
|
+
types?: ItemType[];
|
|
8
|
+
/** Path to the readpst binary. Defaults to "readpst" on PATH. */
|
|
9
|
+
readpstPath?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Converts a .pst/.ost into one .eml per item and resolves to the absolute paths of the written files. */
|
|
13
|
+
export function extract(pstPath: string, options: ExtractOptions): Promise<string[]>;
|
|
14
|
+
|
|
15
|
+
export interface PstItem {
|
|
16
|
+
/** Path relative to the PST root, e.g. "Inbox/1.eml". */
|
|
17
|
+
path: string;
|
|
18
|
+
buffer(): Promise<Buffer>;
|
|
19
|
+
stream(): import("node:fs").ReadStream;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Extracts into a temp dir and yields each item; the dir is removed when the loop ends, breaks or throws.
|
|
24
|
+
* Read an item's buffer or stream before moving to the next one.
|
|
25
|
+
*/
|
|
26
|
+
export function read(pstPath: string, options?: Omit<ExtractOptions, "outDir">): AsyncGenerator<PstItem, void, undefined>;
|
package/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
3
|
+
import { mkdir, mkdtemp, readFile, readdir, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join, relative, resolve } from "node:path";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
|
|
8
|
+
const run = promisify(execFile);
|
|
9
|
+
|
|
10
|
+
const TYPE_CODES = { email: "e", appointment: "a", journal: "j", contact: "c" };
|
|
11
|
+
|
|
12
|
+
export async function extract(pstPath, { outDir, types = ["email"], readpstPath = "readpst" }) {
|
|
13
|
+
const dir = resolve(outDir);
|
|
14
|
+
await mkdir(dir, { recursive: true });
|
|
15
|
+
|
|
16
|
+
const typeCodes = types.map((type) => {
|
|
17
|
+
if (!TYPE_CODES[type]) throw new Error(`Unknown item type "${type}"`);
|
|
18
|
+
return TYPE_CODES[type];
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
await run(readpstPath, ["-e", "-8", "-q", "-t", typeCodes.join(","), "-o", dir, resolve(pstPath)]);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error.code === "ENOENT") {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`"${readpstPath}" not found. Install libpst: brew install libpst, apt install pst-utils or apk add libpst`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`readpst failed: ${(error.stderr || error.stdout)?.trim() || error.message}`, { cause: error });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const entries = await readdir(dir, { recursive: true, withFileTypes: true });
|
|
33
|
+
return entries.filter((entry) => entry.isFile()).map((entry) => join(entry.parentPath, entry.name));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function* read(pstPath, options = {}) {
|
|
37
|
+
const dir = await mkdtemp(join(tmpdir(), "readpst-"));
|
|
38
|
+
try {
|
|
39
|
+
for (const file of await extract(pstPath, { ...options, outDir: dir })) {
|
|
40
|
+
yield { path: relative(dir, file), buffer: () => readFile(file), stream: () => createReadStream(file) };
|
|
41
|
+
}
|
|
42
|
+
} finally {
|
|
43
|
+
await rm(dir, { recursive: true, force: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "readpst",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Convert Outlook .pst files to .eml files with libpst's readpst",
|
|
5
|
+
"keywords": ["pst", "ost", "outlook", "eml", "email", "readpst", "libpst"],
|
|
6
|
+
"author": "Philip van Burleigh",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
},
|
|
13
|
+
"files": ["index.js", "index.d.ts"],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20.12"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "node --test"
|
|
19
|
+
}
|
|
20
|
+
}
|