-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgutil.js
126 lines (114 loc) · 2.48 KB
/
msgutil.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// $Id: msgutil.js,v 1.2 2020/04/25 00:49:32 rswindell Exp $
"use strict";
load('sbbsdefs.js');
load('822header.js');
function show_index(msgbase, first_msg, last_msg, include_votes)
{
var i;
var total_msgs = msgbase.total_msgs;
for(i = 0; i < total_msgs; i++) {
// print(i);
var idx = msgbase.get_msg_index(true, i, include_votes);
if(!idx)
continue;
print(i);
var p;
for(p in idx)
print(format("%10s = ", p) + idx[p]);
}
}
function show_headers_fast(msgbase, include_votes)
{
var hdrs = msgbase.get_all_msg_headers(include_votes);
var i;
for(i in hdrs) {
var h;
print(i);
for(h in hdrs[i])
print(format("%25s = ", h) + hdrs[i][h]);
}
}
function show_headers(msgbase, option)
{
var i;
var total_msgs = msgbase.total_msgs;
var errors = 0;
for(i = 0; i < total_msgs; i++) {
var hdr = msgbase.get_msg_header(true, i+1);
print("[" + i + "]");
if(!hdr) {
alert(msgbase.status);
errors++;
} else if(option.json)
print(lfexpand(JSON.stringify(hdr, null, 4)));
else {
for(var h in hdr)
print(format("%25s = ", h) + hdr[h]);
}
}
return errors;
}
function export_msgs(msgbase, option)
{
var errors = 0;
var hdrs = msgbase.get_all_msg_headers(option.votes);
var i;
for(i in hdrs) {
var msg = hdrs[i];
var fname = system.temp_dir + basecode + "_" + msg.number + ".txt";
var f = new File(fname);
if(!f.open("wb")) {
alert("Error " + f.error + " opening " + f.name);
errors++;
continue;
}
var text = msgbase.get_msg_body(msg
,/* strip ctrl-a */true
,/* dot-stuffing */false
,/* tails */true
,/* plain-text */true);
if(!text) {
errors++;
continue;
}
f.write(msg.get_rfc822_header(/* force_update: */false, /* unfold: */false));
f.write(text);
f.close();
print("Created " + f.name);
}
return errors;
}
var i;
var basecode;
var option = [];
for(i in argv) {
if(argv[i].charAt(0) != '-') {
if(!basecode)
basecode = argv[i];
} else
option[argv[i].slice(1)] = true;
}
if(basecode == undefined) {
alert("Message base not specified");
exit();
}
var msgbase = MsgBase(basecode);
if(!msgbase.open()) {
alert("Error " + msgbase.last_error + " opening " + basecode);
exit(1);
}
var errors = 0;
for(i in option) {
switch(i) {
case "hdrs":
errors += show_headers(msgbase, option);
break;
case "index":
errors += show_index(msgbase, msgbase.first_msg, msgbase.last_msg, option.votes);
break;
case "export":
errors += export_msgs(msgbase, option);
break;
}
}
print(errors + " errors");