1 | # decode all the files in the directory uusrc/ and copy |
1 | #!/usr/bin/perl |
2 | # the resulting files to uudst/ |
|
|
3 | |
2 | |
4 | use Convert::UUlib ':all'; |
3 | # decode all the files in the directory uusrc/ and copy |
|
|
4 | # the resulting files to uudst/ |
5 | |
5 | |
6 | sub namefilter { |
6 | #use Coro::Multicore; |
7 | my($path)=@_; |
|
|
8 | $path=~s/^.*[\/\\]//; |
|
|
9 | $path; |
|
|
10 | } |
|
|
11 | |
7 | |
12 | sub busycb { |
8 | use Convert::UUlib ':all'; |
13 | my ($action, $curfile, $partno, $numparts, $percent, $fsize) = @_; |
|
|
14 | $_[0]=straction($action); |
|
|
15 | print "busy_callback(", (join ",",@_), ")\n"; |
|
|
16 | 0; |
|
|
17 | } |
|
|
18 | |
9 | |
19 | SetOption OPT_IGNMODE, 1; |
10 | sub namefilter { |
20 | SetOption OPT_VERBOSE, 1; |
11 | my ($path) = @_; |
21 | |
12 | |
22 | # show the three ways you can set callback functions. I normally |
13 | $path=~s/^.*[\/\\]//; |
23 | # prefer the one with the sub inplace. |
|
|
24 | SetFNameFilter \&namefilter; |
|
|
25 | |
14 | |
26 | SetBusyCallback "busycb", 333; |
15 | $path |
|
|
16 | } |
27 | |
17 | |
28 | SetMsgCallback sub { |
18 | sub busycb { |
29 | my ($msg, $level) = @_; |
19 | my ($action, $curfile, $partno, $numparts, $percent, $fsize) = @_; |
30 | print uc strmsglevel $_[1], ": $msg\n"; |
20 | $_[0]=straction($action); |
31 | }; |
21 | print "busy_callback(", (join ",",@_), ")\n"; |
|
|
22 | 0 |
|
|
23 | } |
32 | |
24 | |
33 | # the following non-trivial FileNameCallback takes care |
25 | SetOption OPT_RBUF, 128*1024; |
34 | # of some subject lines not detected properly by uulib: |
26 | SetOption OPT_WBUF, 1024*1024; |
35 | SetFileNameCallback sub { |
27 | SetOption OPT_IGNMODE, 1; |
36 | return unless $_[1]; # skip "Re:"-plies et al. |
28 | SetOption OPT_VERBOSE, 1; |
37 | local $_ = $_[0]; |
29 | SetOption OPT_DOTDOT, 1; |
|
|
30 | SetOption OPT_AUTOCHECK, 0; |
38 | |
31 | |
39 | # the following rules are rather effective on some newsgroups, |
32 | # show the three ways you can set callback functions. I normally |
40 | # like alt.binaries.games.anime, where non-mime, uuencoded data |
33 | # prefer the one with the sub inplace. |
41 | # is very common |
34 | SetFNameFilter \&namefilter; |
42 | |
35 | |
43 | # if we find some *.rar, take it as the filename |
36 | SetBusyCallback "busycb", 333; |
44 | return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d|rar))\s/i; |
|
|
45 | |
37 | |
46 | # one common subject format |
38 | SetMsgCallback sub { |
47 | return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i; |
39 | my ($msg, $level) = @_; |
|
|
40 | print uc strmsglevel $_[1], ": $msg\n"; |
|
|
41 | }; |
48 | |
42 | |
49 | # - filename.par (04/55) |
43 | # the following non-trivial FileNameCallback takes care |
50 | return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i; |
44 | # of some subject lines not detected properly by uulib: |
|
|
45 | SetFileNameCallback sub { |
|
|
46 | return unless $_[1]; # skip "Re:"-plies et al. |
|
|
47 | local $_ = $_[0]; |
51 | |
48 | |
52 | # - (xxx) No. 1 sayuri81.jpg 756565 bytes |
49 | if ($_[1] =~ /^(img_?\d+|\d+\w?)\./) { |
53 | # - (20 files) No.17 Roseanne.jpg [2/2] |
50 | return "$1 $_[1]" |
54 | return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/; |
51 | if /^\s*\(([^)]+)\) \[\d+/; |
|
|
52 | } |
55 | |
53 | |
56 | # otherwise just pass what we have |
54 | # the following rules are rather effective on some newsgroups, |
57 | return (); |
55 | # like alt.binaries.games.anime, where non-mime, uuencoded data |
58 | }; |
56 | # is very common |
59 | |
57 | |
60 | # now read all files in the directory uusrc/* |
58 | # File 06 of 33 - Kendo - Final - 0001.jpg (2/3) |
61 | for(<uusrc/*>) { |
59 | return $1 if /File \d+ of \d+ - (.*) \(\d+\/\d+\)/i; |
62 | my($retval,$count)=LoadFile ($_, $_, 1); |
|
|
63 | print "file($_), status(", strerror $retval, ") parts($count)\n"; |
|
|
64 | } |
|
|
65 | |
60 | |
66 | SetOption OPT_SAVEPATH, "uudst/"; |
61 | # if we find some *.rar, take it as the filename |
|
|
62 | return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d|rar))\s/i; |
67 | |
63 | |
68 | # now wade through all files and their source parts |
64 | # one common subject format |
69 | $i = 0; |
65 | return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i; |
70 | while ($uu = GetFileListItem($i)) { |
|
|
71 | $i++; |
|
|
72 | print "file nr. $i"; |
|
|
73 | print " state ", $uu->state; |
|
|
74 | print " mode ", $uu->mode; |
|
|
75 | print " uudet ", strencoding $uu->uudet; |
|
|
76 | print " size ", $uu->size; |
|
|
77 | print " filename ", $uu->filename; |
|
|
78 | print " subfname ", $uu->subfname; |
|
|
79 | print " mimeid ", $uu->mimeid; |
|
|
80 | print " mimetype ", $uu->mimetype; |
|
|
81 | print "\n"; |
|
|
82 | |
66 | |
83 | # print additional info about all parts |
67 | # - filename.par (04/55) |
84 | for ($uu->parts) { |
68 | return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i; |
85 | while (my ($k, $v) = each %$_) { |
|
|
86 | print "$k > $v, "; |
|
|
87 | } |
|
|
88 | print "\n"; |
|
|
89 | } |
|
|
90 | |
69 | |
91 | $uu->decode_temp; |
70 | # - (xxx) No. 1 sayuri81.jpg 756565 bytes |
92 | print " temporarily decoded to ", $uu->binfile, "\n"; |
71 | # - (20 files) No.17 Roseanne.jpg [2/2] |
93 | $uu->remove_temp; |
72 | return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/; |
94 | |
73 | |
95 | print strerror $uu->decode; |
74 | # try to detect some common forms of filenames |
96 | print " saved as uudst/", $uu->filename, "\n"; |
75 | return $1 if /([a-z0-9_\-+.]{3,}\.[a-z]{3,4}(?:.\d+))/i; |
97 | } |
|
|
98 | |
76 | |
99 | print "cleanup...\n"; |
77 | # otherwise just pass what we have |
|
|
78 | () |
|
|
79 | }; |
100 | |
80 | |
|
|
81 | # now read all files in the directory uusrc/* |
|
|
82 | for(<uusrc/*>) { |
|
|
83 | my ($retval, $count) = LoadFile ($_, $_, 1); |
|
|
84 | print "file($_), status(", strerror $retval, ") parts($count)\n"; |
|
|
85 | } |
|
|
86 | |
|
|
87 | Smerge -1; |
|
|
88 | |
|
|
89 | SetOption OPT_SAVEPATH, "uudst/"; |
|
|
90 | |
|
|
91 | # now wade through all files and their source parts |
|
|
92 | $i = 0; |
|
|
93 | while ($uu = GetFileListItem $i) { |
|
|
94 | $i++; |
|
|
95 | print "file nr. $i"; |
|
|
96 | print " state ", $uu->state; |
|
|
97 | print " mode ", $uu->mode; |
|
|
98 | print " uudet ", strencoding $uu->uudet; |
|
|
99 | print " size ", $uu->size; |
|
|
100 | print " filename ", $uu->filename; |
|
|
101 | print " subfname ", $uu->subfname; |
|
|
102 | print " mimeid ", $uu->mimeid; |
|
|
103 | print " mimetype ", $uu->mimetype; |
|
|
104 | print "\n"; |
|
|
105 | |
|
|
106 | # print additional info about all parts |
|
|
107 | for ($uu->parts) { |
|
|
108 | while (my ($k, $v) = each %$_) { |
|
|
109 | print "$k > $v, "; |
|
|
110 | } |
|
|
111 | print "\n"; |
|
|
112 | } |
|
|
113 | |
|
|
114 | print $uu->filename; |
|
|
115 | |
|
|
116 | $uu->remove_temp; |
|
|
117 | |
|
|
118 | print "<s", $uu->state, ">";#d# |
|
|
119 | if (my $err = $uu->decode) { |
|
|
120 | print ", ", strerror $err, "\n"; |
|
|
121 | } else { |
|
|
122 | print ", saved as uudst/", $uu->filename, "\n"; |
|
|
123 | } |
|
|
124 | } |
|
|
125 | |
|
|
126 | print "cleanup...\n"; |
|
|
127 | |
101 | CleanUp(); |
128 | CleanUp; |