| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Chess::Mbox; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
9273
|
use Chess::PGN::Parse; |
|
|
1
|
|
|
|
|
42790
|
|
|
|
1
|
|
|
|
|
110
|
|
|
4
|
1
|
|
|
1
|
|
145971
|
use Mail::MboxParser; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require 5.005_62; |
|
8
|
|
|
|
|
|
|
use strict; |
|
9
|
|
|
|
|
|
|
use warnings; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = sprintf '%s', 'q$Revision: 1.3 $' =~ /\S+\s+(\S+)\s+/ ; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub Parse { |
|
17
|
|
|
|
|
|
|
my $class = shift; |
|
18
|
|
|
|
|
|
|
my %C = @_; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $mailbox = $C{mbox}; |
|
21
|
|
|
|
|
|
|
my $game_dir = $C{output_dir}; |
|
22
|
|
|
|
|
|
|
my $postop = $C{post_op}; |
|
23
|
|
|
|
|
|
|
warn "POSTOP: $postop"; |
|
24
|
|
|
|
|
|
|
my $temp_file = "/tmp/chessfile$$"; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $mb = Mail::MboxParser->new($mailbox, decode => 'NEVER'); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
while (my $msg = $mb->next_message) { |
|
29
|
|
|
|
|
|
|
print $msg->header->{subject}, "\n"; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $pgnfile = $temp_file; |
|
32
|
|
|
|
|
|
|
open T, ">$pgnfile" or die "couldnt open $pgnfile: $!"; |
|
33
|
|
|
|
|
|
|
my $GAME = $msg->body($msg->find_body)->as_string; |
|
34
|
|
|
|
|
|
|
print T $GAME; |
|
35
|
|
|
|
|
|
|
close(T); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $pgn = Chess::PGN::Parse->new($pgnfile) or die "can't open $pgnfile\n"; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
while ($pgn->read_game) { |
|
40
|
|
|
|
|
|
|
mkdir sprintf "%s/%s", $game_dir, $pgn->white; |
|
41
|
|
|
|
|
|
|
my $dir = sprintf "%s/%s/%s", $game_dir, $pgn->white, $pgn->black; |
|
42
|
|
|
|
|
|
|
mkdir $dir; |
|
43
|
|
|
|
|
|
|
my $file = sprintf "%s-%s", $pgn->date, $pgn->time; |
|
44
|
|
|
|
|
|
|
$file =~ s/:/-/g; |
|
45
|
|
|
|
|
|
|
my $F = "$dir/$file.pgn"; |
|
46
|
|
|
|
|
|
|
print $F, $/; |
|
47
|
|
|
|
|
|
|
open F, ">$F" or die "couldnt open $F: $!"; |
|
48
|
|
|
|
|
|
|
print F $GAME; |
|
49
|
|
|
|
|
|
|
close(F); |
|
50
|
|
|
|
|
|
|
if ($postop) { |
|
51
|
|
|
|
|
|
|
chdir $dir; |
|
52
|
|
|
|
|
|
|
&$postop; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
|
64
|
|
|
|
|
|
|
__END__ |