ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/example-decoder
(Generate patch)

Comparing Convert-UUlib/example-decoder (file contents):
Revision 1.3 by root, Sun Mar 31 21:42:36 2002 UTC vs.
Revision 1.9 by root, Tue Dec 28 14:09:19 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines