-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsplit-msg.pl
executable file
·44 lines (33 loc) · 896 Bytes
/
split-msg.pl
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
#!/usr/bin/env perl
# Breaks a NAVADMIN record message (passed as a filename on the command line)
# into a header and then a main body.
use v5.28;
use feature 'signatures';
use lib 'modules';
use MsgReader qw(read_navadmin_from_file);
use Mojo::JSON qw(encode_json);
sub usage()
{
say <<~EOF;
$0 <path-to-navadmin.txt>
Reads the given NAVADMIN and spits out a JSON array containing two
strings in order, the header and then the message body.
EOF
exit 1;
}
if (!@ARGV) {
# List all NAVADMINs if no file specified
# @files = Mojo::File->new('NAVADMIN')->list_tree->grep(qr/\.txt$/)->each;
usage();
exit 1;
}
foreach my $path (@ARGV) {
my $navadmin_data = eval {
read_navadmin_from_file($path);
};
if ($@) {
say STDERR "Ran into error $@ on $path";
exit 1;
}
say encode_json($navadmin_data);
}