readpst 0.1.0 → 0.2.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/README.md +23 -4
- package/index.d.ts +13 -0
- package/index.js +16 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,9 +9,10 @@ The `readpst` binary must be on your `PATH`:
|
|
|
9
9
|
```sh
|
|
10
10
|
brew install libpst # macOS
|
|
11
11
|
apt install pst-utils # Debian/Ubuntu
|
|
12
|
-
apk add libpst # Alpine
|
|
13
12
|
```
|
|
14
13
|
|
|
14
|
+
Alpine has no libpst package; build it from [source](https://www.five-ten-sg.com/libpst/) with `libgsf-dev` installed and `CFLAGS="-std=gnu17"` (GCC 15 rejects its pre-C23 declarations).
|
|
15
|
+
|
|
15
16
|
```sh
|
|
16
17
|
npm install readpst
|
|
17
18
|
```
|
|
@@ -25,17 +26,35 @@ const files = await extract("mailbox.pst", { outDir: "out" });
|
|
|
25
26
|
// ["/abs/out/Inbox/1.eml", "/abs/out/Sent Items/1.eml", ...]
|
|
26
27
|
```
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
### Without managing files
|
|
30
|
+
|
|
31
|
+
`read` extracts into a temp dir, yields each item and removes the dir when the loop ends (also on `break` or a thrown error):
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { read } from "readpst";
|
|
35
|
+
|
|
36
|
+
for await (const item of read("mailbox.pst")) {
|
|
37
|
+
item.path; // "Inbox/1.eml"
|
|
38
|
+
await item.buffer(); // Buffer
|
|
39
|
+
item.stream(); // fs.ReadStream, e.g. to upload to S3
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Consume each item's buffer or stream before moving to the next one; the files are gone once the loop finishes.
|
|
44
|
+
|
|
45
|
+
### Writing to a directory
|
|
46
|
+
|
|
47
|
+
`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.
|
|
29
48
|
|
|
30
49
|
### Options
|
|
31
50
|
|
|
32
51
|
| Option | Default | Description |
|
|
33
52
|
| ------------- | ------------- | ----------------------------------------------------------------- |
|
|
34
|
-
| `outDir` | (required) |
|
|
53
|
+
| `outDir` | (required) | `extract` only: output directory, created if missing |
|
|
35
54
|
| `types` | `["email"]` | Any of `"email"`, `"appointment"`, `"journal"`, `"contact"` |
|
|
36
55
|
| `readpstPath` | `"readpst"` | Path to the binary |
|
|
37
56
|
|
|
38
|
-
`readpst` needs a seekable file on local disk, so download a remote PST to a temp file first.
|
|
57
|
+
`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.
|
|
39
58
|
|
|
40
59
|
## License
|
|
41
60
|
|
package/index.d.ts
CHANGED
|
@@ -11,3 +11,16 @@ export interface ExtractOptions {
|
|
|
11
11
|
|
|
12
12
|
/** Converts a .pst/.ost into one .eml per item and resolves to the absolute paths of the written files. */
|
|
13
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
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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";
|
|
4
6
|
import { promisify } from "node:util";
|
|
5
7
|
|
|
6
8
|
const run = promisify(execFile);
|
|
@@ -21,7 +23,7 @@ export async function extract(pstPath, { outDir, types = ["email"], readpstPath
|
|
|
21
23
|
} catch (error) {
|
|
22
24
|
if (error.code === "ENOENT") {
|
|
23
25
|
throw new Error(
|
|
24
|
-
`"${readpstPath}" not found. Install libpst: brew install libpst
|
|
26
|
+
`"${readpstPath}" not found. Install libpst: brew install libpst or apt install pst-utils`
|
|
25
27
|
);
|
|
26
28
|
}
|
|
27
29
|
throw new Error(`readpst failed: ${(error.stderr || error.stdout)?.trim() || error.message}`, { cause: error });
|
|
@@ -30,3 +32,14 @@ export async function extract(pstPath, { outDir, types = ["email"], readpstPath
|
|
|
30
32
|
const entries = await readdir(dir, { recursive: true, withFileTypes: true });
|
|
31
33
|
return entries.filter((entry) => entry.isFile()).map((entry) => join(entry.parentPath, entry.name));
|
|
32
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