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