|
NAMEConvert::UUlib - Perl interface to the uulib library (a.k.a. uudeview/uuenview).SYNOPSISuse Convert::UUlib ':all'; # read all the files named on the commandline and decode them # into the CURRENT directory. See below for a longer example. LoadFile $_ for @ARGV; for my $uu (GetFileList) { if ($uu->state & FILE_OK) { $uu->decode; print $uu->filename, "\n"; } } DESCRIPTIONRead the file doc/library.pdf from the distribution for in-depth information about the C-library used in this interface, and the rest of this document and especially the non-trivial decoder program at the end.EXPORTED CONSTANTSAction code constantsACT_IDLE we don't do anything ACT_SCANNING scanning an input file ACT_DECODING decoding into a temp file ACT_COPYING copying temp to target ACT_ENCODING encoding a file Message severity levelsMSG_MESSAGE just a message, nothing important MSG_NOTE something that should be noticed MSG_WARNING important msg, processing continues MSG_ERROR processing has been terminated MSG_FATAL decoder cannot process further requests MSG_PANIC recovery impossible, app must terminate OptionsOPT_VERSION version number MAJOR.MINORplPATCH (ro) OPT_FAST assumes only one part per file OPT_DUMBNESS switch off the program's intelligence OPT_BRACKPOL give numbers in [] higher precendence OPT_VERBOSE generate informative messages OPT_DESPERATE try to decode incomplete files OPT_IGNREPLY ignore RE:plies (off by default) OPT_OVERWRITE whether it's OK to overwrite ex. files OPT_SAVEPATH prefix to save-files on disk OPT_IGNMODE ignore the original file mode OPT_DEBUG print messages with FILE/LINE info OPT_ERRNO get last error code for RET_IOERR (ro) OPT_PROGRESS retrieve progress information OPT_USETEXT handle text messages OPT_PREAMB handle Mime preambles/epilogues OPT_TINYB64 detect short B64 outside of Mime OPT_ENCEXT extension for single-part encoded files OPT_REMOVE remove input files after decoding (dangerous) OPT_MOREMIME strict MIME adherence OPT_DOTDOT ".."-unescaping has not yet been done on input files OPT_RBUF set default read I/O buffer size in bytes OPT_WBUF set default write I/O buffer size in bytes OPT_AUTOCHECK automatically check file list after every loadfile Result/Error codesRET_OK everything went fine RET_IOERR I/O Error - examine errno RET_NOMEM not enough memory RET_ILLVAL illegal value for operation RET_NODATA decoder didn't find any data RET_NOEND encoded data wasn't ended properly RET_UNSUP unsupported function (encoding) RET_EXISTS file exists (decoding) RET_CONT continue -- special from ScanPart RET_CANCEL operation canceled File StatesThis code is zero, i.e. "false": UUFILE_READ Read in, but not further processed The following state codes are or'ed together: FILE_MISPART Missing Part(s) detected FILE_NOBEGIN No 'begin' found FILE_NOEND No 'end' found FILE_NODATA File does not contain valid uudata FILE_OK All Parts found, ready to decode FILE_ERROR Error while decoding FILE_DECODED Successfully decoded FILE_TMPFILE Temporary decoded file exists Encoding typesUU_ENCODED UUencoded data B64_ENCODED Mime-Base64 data XX_ENCODED XXencoded data BH_ENCODED Binhex encoded PT_ENCODED Plain-Text encoded (MIME) QP_ENCODED Quoted-Printable (MIME) YENC_ENCODED yEnc encoded (non-MIME) EXPORTED FUNCTIONSInitializing and cleanupInitialize is automatically called when the module is loaded and allocates quite a small amount of memory for todays machines ;) CleanUp releases that again.On my machine, a fairly complete decode with DBI backend needs about 10MB RSS to decode 20000 files.
Setting and querying options
See the "OPT_xxx" constants above to see which options exist. Setting various callbacks
Call the currently selected FNameFilter
Loading sourcefiles, optionally fuzzy merge and start decoding
Decoding files
Querying (and setting) item attributes
Information about source parts
Functions below are not documented and not very well tested - feedback welcomeQuickDecode EncodeMulti EncodePartial EncodeToStream EncodeToFile E_PrepSingle E_PrepPartial EXTENSION FUNCTIONSFunctions found in this module but not documented in the uulib documentation:
LARGE EXAMPLE DECODERThe general workflow for decoding is like this:
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}"; } print "\n"; } $uu->remove_temp; if (my $err = $uu->decode) { print " ERROR ", strerror $err, "\n"; } else { print " successfully saved as uudst/", $uu->filename, "\n"; } } print "cleanup...\n"; CleanUp; PERLMULTICORE SUPPORTThis module supports the perlmulticore standard (see <http://perlmulticore.schmorp.de/> for more info) for the following functions - generally these are functions accessing the disk and/or using considerable CPU time:LoadFile $item->decode $item->decode_temp $item->remove_temp $item->info The perl interpreter will be reacquired/released on every callback invocation, so for performance reasons, callbacks should be avoided if that is costly. Future versions might enable multicore support for more functions. BUGS AND LIMITATIONSThe original uulib library this module uses was written at a time where main memory of measured in megabytes and buffer overflows as a security thign didn't exist. While a lot of security fixes have been applied over the years (includign some defense in depth mechanism that can shield against a lot of as-of-yet undetected bugs), using this library for security purposes requires care.Likewise, file sizes when the uulib library was written were tiny compared to today, so do not expect this library to handle files larger than 2GB. Lastly, this module uses a very "C-like" interface, which means it doesn't protect you from invalid points as you might expect from "more perlish" modules - for example, accessing a file item object after callinbg "CleanUp" will likely result in crashes, memory corruption, or worse. AUTHORMarc Lehmann <schmorp@schmorp.de>, the original uulib library was written by Frank Pilhofer <fp@informatik.uni-frankfurt.de>, and later heavily bugfixed by Marc Lehmann.SEE ALSOperl(1), uudeview homepage at <http://www.fpx.de/fp/Software/UUDeview/>.
Visit the GSP FreeBSD Man Page Interface. |