-
Notifications
You must be signed in to change notification settings - Fork 53
/
app.js
104 lines (89 loc) · 2.36 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var os = require('os');
var fs = require('fs');
var path = require('path');
var emlformat = require('./lib/eml-format.js');
var config = {
verbose: process.env.NODE_VERBOSE == "true" || process.env.NODE_VERBOSE == "1",
json: false,
unpack: true
};
//Prints help message
function help() {
console.log("Usage:");
console.log(" eml-unpack [options] [message.eml] [directory]");
console.log("");
console.log("Options:");
console.log(" --help Print this message");
console.log(" --verbose Enable detailed logging");
console.log(" --version Print version number");
console.log(" --json Create parsed.json and manifest.json");
console.log(" --no-unpack Used with --json to skip unpacking");
console.log("");
console.log("Examples:");
console.log(" eml-unpack message.eml .");
console.log(" eml-unpack --verbose sample.eml folder");
console.log(" eml-unpack --json --no-unpack ./sample.eml ./folder");
}
//Command line arguments
var args = process.argv.slice(2);
for (var i = 0; i < args.length - 2; i++) {
switch (args[i]) {
case "--help":
help();
process.exit(0);
break;
case "--version":
console.log(require('./package.json').version);
process.exit(0);
break;
case "--version":
config.verbose = true;
break;
case "--json":
config.json = true;
break;
case "--no-unpack":
config.unpack = false;
break;
default:
console.error("Unknown command line argument: " + args[i]);
process.exit(1);
break;
}
}
if (args.length < 2) {
help();
process.exit(1);
}
try {
var src = args[args.length - 2];
var dst = args[args.length - 1];
if (!src) {
throw new Error("Missing .eml file path!");
}
if (!dst) {
throw new Error("Missing output directory path or folder name!");
}
var options = { };
if (config.json) {
options.parsedJsonFile = "parsed.json";
options.readJsonFile = "manifest.json";
}
if (!config.unpack) {
options.simulate = true;
}
var eml = fs.readFileSync(src, "utf-8");
emlformat.verbose = config.verbose;
emlformat.unpack(eml, dst, options, function(error, result) {
if (error) {
console.error(error);
process.exit(1);
return;
}
console.log("Done!");
});
}
catch (e) {
console.error(e);
process.exit(1);
}