Skip to content

Commit 70b1521

Browse files
committed
first commit
0 parents  commit 70b1521

File tree

5 files changed

+183
-0
lines changed

5 files changed

+183
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
output.json

index.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
const extractor = require("pst-extractor");
2+
const fs = require("fs-extra")
3+
const resolve = require("path").resolve;
4+
const program = require("commander");
5+
6+
7+
let depth = -1;
8+
let col = 0;
9+
let output = [];
10+
let options = null
11+
let debug = false
12+
13+
program
14+
.requiredOption('-s, --source <path>', 'Source File (.pst)')
15+
.requiredOption('-d, --destination <path>', 'Destination File (.json)')
16+
.option('-v, --verbose', 'Detailed output')
17+
.option('-p, --pretty', 'Pretty printed JSON output');
18+
19+
program.parse(process.argv);
20+
21+
console.log(program.opts());
22+
23+
if (program.verbose != null) {
24+
debug = true
25+
}
26+
27+
28+
if (program.pretty != null) {
29+
options = { spaces: 2 };
30+
}
31+
32+
if (fs.pathExistsSync(program.source)) {
33+
34+
35+
const pstFile = new extractor.PSTFile(resolve(program.source));
36+
37+
console.log(pstFile.getMessageStore().displayName);
38+
39+
processFolder(pstFile.getRootFolder());
40+
fs.writeJsonSync(program.destination,output, options)
41+
42+
} else {
43+
console.log("Source: " + program.source + " does not exist.");
44+
}
45+
46+
47+
48+
49+
/**
50+
* Walk the folder tree recursively and process emails.
51+
* @param {PSTFolder} folder
52+
*/
53+
54+
function processFolder(folder) {
55+
depth++;
56+
// the root folder doesn"t have a display name
57+
if (depth > 0) {
58+
console.log(getDepth(depth) + folder.displayName);
59+
}
60+
// go through the folders...
61+
if (folder.hasSubfolders) {
62+
let childFolders = folder.getSubFolders();
63+
for (let childFolder of childFolders) {
64+
processFolder(childFolder);
65+
}
66+
}
67+
// and now the emails for this folder
68+
if (folder.contentCount > 0) {
69+
depth++;
70+
let email = folder.getNextChild();
71+
while (email != null) {
72+
output.push(email);
73+
if (debug) {
74+
console.log(getDepth(depth) +
75+
"Time: " + email.messageDeliveryTime +
76+
", Sender: " + email.senderName +
77+
", Subject: " + email.subject );
78+
}
79+
email = folder.getNextChild();
80+
81+
}
82+
depth--;
83+
}
84+
depth--;
85+
}
86+
/**
87+
* Returns a string with visual indication of depth in tree.
88+
* @param {number} depth
89+
* @returns {string}
90+
*/
91+
function getDepth(depth) {
92+
let sdepth = "";
93+
if (col > 0) {
94+
col = 0;
95+
sdepth += "\n";
96+
}
97+
for (let x = 0; x < depth - 1; x++) {
98+
sdepth += " | ";
99+
}
100+
sdepth += " |- ";
101+
return sdepth;
102+
}

package-lock.json

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "pst_migration",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"commander": "^4.0.1",
13+
"fs-extra": "^8.1.0",
14+
"pst-extractor": "^1.5.0"
15+
}
16+
}

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Outlook PST to JSON
2+
3+
Converts an Outlook PST file to JSON

0 commit comments

Comments
 (0)