--- Convert-UUlib/example-decoder 2002/08/19 23:25:34 1.6 +++ Convert-UUlib/example-decoder 2004/12/28 14:09:19 1.9 @@ -12,26 +12,28 @@ } sub busycb { - my($action,$curfile,$partno,$numparts,$percent,$fsize)=@_; + my ($action, $curfile, $partno, $numparts, $percent, $fsize) = @_; $_[0]=straction($action); - print "busy_callback(",join(",",@_),")\n"; + print "busy_callback(", (join ",",@_), ")\n"; 0; } -SetOption (OPT_IGNMODE, 1); -SetOption (OPT_VERBOSE, 1); -#SetOption (OPT_DOTDOT, 1); - -# show the three ways you can set callback functions -SetFNameFilter (\&namefilter); - -SetBusyCallback ("busycb",333); - -SetMsgCallback (sub { - my($msg,$level)=@_; - print uc(strmsglevel($_[1])),": $msg\n"; -}); +SetOption OPT_IGNMODE, 1; +SetOption OPT_VERBOSE, 1; +# show the three ways you can set callback functions. I normally +# prefer the one with the sub inplace. +SetFNameFilter \&namefilter; + +SetBusyCallback "busycb", 333; + +SetMsgCallback sub { + my ($msg, $level) = @_; + print uc strmsglevel $_[1], ": $msg\n"; +}; + +# the following non-trivial FileNameCallback takes care +# of some subject lines not detected properly by uulib: SetFileNameCallback sub { return unless $_[1]; # skip "Re:"-plies et al. local $_ = $_[0]; @@ -40,58 +42,62 @@ # like alt.binaries.games.anime, where non-mime, uuencoded data # is very common - # if we find some *.rar, take it - return $1 if /(\S+\.(?:[rstuvwxyz]\d\d|rar))\s/i; + return $1 if /([a-z0-9_]{3,}\.[a-z]{3,4}(?:.\d+))/i; + + # if we find some *.rar, take it as the filename + return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d|rar))\s/i; + + # one common subject format + return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i; # - filename.par (04/55) - return $1 if /- "?(\S+\.\S+?)"? (:yenc )?\(\d+\/\d+\)/i; + return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i; + # - (xxx) No. 1 sayuri81.jpg 756565 bytes + # - (20 files) No.17 Roseanne.jpg [2/2] return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/; # otherwise just pass what we have return (); }; - +# now read all files in the directory uusrc/* for() { - my($retval,$count)=LoadFile ($_,$_,1); - print "file($_), status(",strerror($retval),") parts($count)\n"; + my($retval,$count)=LoadFile ($_, $_, 1); + print "file($_), status(", strerror $retval, ") parts($count)\n"; } -SetOption (OPT_SAVEPATH, "uudst/"); +SetOption OPT_SAVEPATH, "uudst/"; -$i=0; -while($uu=GetFileListItem($i)) { +# now wade through all files and their source parts +$i = 0; +while ($uu = GetFileListItem $i) { $i++; print "file nr. $i"; - print " state ",$uu->state; - print " mode ",$uu->mode; - print " uudet ",strencoding($uu->uudet); - print " size ",$uu->size; - print " filename ",$uu->filename; - print " subfname ",$uu->subfname; - print " mimeid ",$uu->mimeid; - print " mimetype ",$uu->mimetype; + print " state ", $uu->state; + print " mode ", $uu->mode; + print " uudet ", strencoding $uu->uudet; + print " size ", $uu->size; + print " filename ", $uu->filename; + print " subfname ", $uu->subfname; + print " mimeid ", $uu->mimeid; + print " mimetype ", $uu->mimetype; print "\n"; # print additional info about all parts - for($uu->parts) { - while(my($k,$v)=each(%$_)) { + for ($uu->parts) { + while (my ($k, $v) = each %$_) { print "$k > $v, "; } print "\n"; } - if ($uu->state & FILE_OK) { - print strerror($uu->decode_temp)."\n"; - print " temporarily decoded to ",$uu->binfile,"\n"; - $uu->remove_temp; - - print strerror($uu->decode)."\n"; - print " saved as uudst/",$uu->filename,"\n"; - } else { - print "file NOT ok, not decoding\n"; - } + $uu->decode_temp; + print " temporarily decoded to ", $uu->binfile, "\n"; + $uu->remove_temp; + + print strerror $uu->decode; + print " saved as uudst/", $uu->filename, "\n"; } print "cleanup...\n";