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