ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/example-decoder
Revision: 1.8
Committed: Tue Oct 15 23:20:30 2002 UTC (21 years, 7 months ago) by root
Branch: MAIN
Changes since 1.7: +99 -97 lines
Log Message:
*** empty log message ***

File Contents

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