| 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 Coro::Multicore; |
| 7 |
|
| 8 |
use strict; |
| 9 |
|
| 10 |
use Convert::UUlib ':all'; |
| 11 |
|
| 12 |
sub namefilter { |
| 13 |
my ($path) = @_; |
| 14 |
|
| 15 |
$path=~s/^.*[\/\\]//; |
| 16 |
|
| 17 |
$path |
| 18 |
} |
| 19 |
|
| 20 |
sub busycb { |
| 21 |
my ($action, $curfile, $partno, $numparts, $percent, $fsize) = @_; |
| 22 |
$_[0]=straction($action); |
| 23 |
print "busy_callback(", (join ",",@_), ")\n"; |
| 24 |
0 |
| 25 |
} |
| 26 |
|
| 27 |
SetOption OPT_RBUF, 128*1024; |
| 28 |
SetOption OPT_WBUF, 1024*1024; |
| 29 |
SetOption OPT_IGNMODE, 1; |
| 30 |
SetOption OPT_VERBOSE, 1; |
| 31 |
SetOption OPT_DOTDOT, 1; |
| 32 |
SetOption OPT_AUTOCHECK, 0; |
| 33 |
|
| 34 |
# show the three ways you can set callback functions. I normally |
| 35 |
# prefer the one with the sub inplace. |
| 36 |
SetFNameFilter \&namefilter; |
| 37 |
|
| 38 |
SetBusyCallback "busycb", 333; |
| 39 |
|
| 40 |
SetMsgCallback sub { |
| 41 |
my ($msg, $level) = @_; |
| 42 |
print uc strmsglevel $_[1], ": $msg\n"; |
| 43 |
}; |
| 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/* |
| 84 |
for(<uusrc/*>) { |
| 85 |
my ($retval, $count) = LoadFile ($_, $_, 1); |
| 86 |
print "file($_), status(", strerror $retval, ") parts($count)\n"; |
| 87 |
} |
| 88 |
|
| 89 |
Smerge -1; |
| 90 |
|
| 91 |
SetOption OPT_SAVEPATH, "uudst/"; |
| 92 |
|
| 93 |
# now wade through all files and their source parts |
| 94 |
for my $uu (GetFileList) { |
| 95 |
print "file ", $uu->filename, "\n"; |
| 96 |
print " state ", $uu->state, "\n"; |
| 97 |
print " mode ", $uu->mode, "\n"; |
| 98 |
print " uudet ", strencoding $uu->uudet, "\n"; |
| 99 |
print " size ", $uu->size, "\n"; |
| 100 |
print " subfname ", $uu->subfname, "\n"; |
| 101 |
print " mimeid ", $uu->mimeid, "\n"; |
| 102 |
print " mimetype ", $uu->mimetype, "\n"; |
| 103 |
|
| 104 |
# print additional info about all parts |
| 105 |
print " parts"; |
| 106 |
for ($uu->parts) { |
| 107 |
for my $k (sort keys %$_) { |
| 108 |
print " $k=$_->{$k}"; |
| 109 |
} |
| 110 |
print "\n"; |
| 111 |
} |
| 112 |
|
| 113 |
$uu->remove_temp; |
| 114 |
|
| 115 |
if (my $err = $uu->decode) { |
| 116 |
print " ERROR ", strerror $err, "\n"; |
| 117 |
} else { |
| 118 |
print " successfully saved as uudst/", $uu->filename, "\n"; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
print "cleanup...\n"; |
| 123 |
|
| 124 |
CleanUp; |