Convert-UUlib
view release on metacpan or search on metacpan
$str = strmsglevel MSG_xxx
Returns the message level as a string.
SetFileNameCallback $cb
Sets (or queries) the FileNameCallback, which is called whenever the
decoding library can't find a filename and wants to extract a
filename from the subject line of a posting. The callback will be
called with two arguments, the subject line and the current
candidate for the filename. The latter argument can be "undef",
which means that no filename could be found (and likely no one
exists, so it is safe to also return "undef" in this case). If it
doesn't return anything (not even "undef"!), then nothing happens,
so this is a no-op callback:
sub cb {
return ();
}
If it returns "undef", then this indicates that no filename could be
found. In all other cases, the return value is taken to be the
filename.
This is a slightly more useful callback:
sub cb {
return unless $_[1]; # skip "Re:"-plies et al.
my ($subject, $filename) = @_;
# if we find some *.rar, take it
return $1 if $subject =~ /(\w+\.rar)/;
# otherwise just pass what we have
return ();
}
LARGE EXAMPLE DECODER
The general workflow for decoding is like this:
1. Configure options with "SetOption" or "SetXXXCallback".
2. Load all source files with "LoadFile".
3. Optionally "Smerge".
4. Iterate over all "GetFileList" items (i.e. result files).
5. "CleanUp" to delete files and free items.
What follows is the file "example-decoder" from the distribution that
illustrates the above worklfow in a non-trivial example.
#!/usr/bin/perl
# decode all the files in the directory uusrc/ and copy
# the resulting files to uudst/
use Convert::UUlib ':all';
sub namefilter {
my ($path) = @_;
$path=~s/^.*[\/\\]//;
$path
}
sub busycb {
my ($action, $curfile, $partno, $numparts, $percent, $fsize) = @_;
$_[0]=straction($action);
print "busy_callback(", (join ",",@_), ")\n";
0
}
SetOption OPT_RBUF, 128*1024;
SetOption OPT_WBUF, 1024*1024;
SetOption OPT_IGNMODE, 1;
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];
# the following rules are rather effective on some newsgroups,
# like alt.binaries.games.anime, where non-mime, uuencoded data
# is very common
# 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{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 )?\[/;
# try to detect some common forms of filenames
return $1 if /([a-z0-9_\-+.]{3,}\.[a-z]{3,4}(?:.\d+))/i;
# otherwise just pass what we have
()
};
# now read all files in the directory uusrc/*
for (<uusrc/*>) {
my ($retval, $count) = LoadFile ($_, $_, 1);
print "file($_), status(", strerror $retval, ") parts($count)\n";
}
SetOption OPT_SAVEPATH, "uudst/";
# now wade through all files and their source parts
for my $uu (GetFileList) {
print "file ", $uu->filename, "\n";
print " state ", $uu->state, "\n";
print " mode ", $uu->mode, "\n";
print " uudet ", strencoding $uu->uudet, "\n";
print " size ", $uu->size, "\n";
print " subfname ", $uu->subfname, "\n";
print " mimeid ", $uu->mimeid, "\n";
print " mimetype ", $uu->mimetype, "\n";
# print additional info about all parts
print " parts";
for ($uu->parts) {
for my $k (sort keys %$_) {
print " $k=$_->{$k}";
( run in 0.962 second using v1.01-cache-2.11-cpan-39bf76dae61 )