1UUlib(3) User Contributed Perl Documentation UUlib(3)
2
3
4
6 Convert::UUlib - Perl interface to the uulib library (a.k.a. uude‐
7 view/uuenview).
8
10 use Convert::UUlib ':all';
11
12 # read all the files named on the commandline and decode them
13 # into the CURRENT directory. See below for a longer example.
14 LoadFile $_ for @ARGV;
15 for (my $i = 0; my $uu = GetFileListItem $i; $i++) {
16 if ($uu->state & FILE_OK) {
17 $uu->decode;
18 print $uu->filename, "\n";
19 }
20 }
21
23 Read the file doc/library.pdf from the distribution for in-depth infor‐
24 mation about the C-library used in this interface, and the rest of this
25 document and especially the non-trivial decoder program at the end.
26
28 Action code constants
29
30 ACT_IDLE we don't do anything
31 ACT_SCANNING scanning an input file
32 ACT_DECODING decoding into a temp file
33 ACT_COPYING copying temp to target
34 ACT_ENCODING encoding a file
35
36 Message severity levels
37
38 MSG_MESSAGE just a message, nothing important
39 MSG_NOTE something that should be noticed
40 MSG_WARNING important msg, processing continues
41 MSG_ERROR processing has been terminated
42 MSG_FATAL decoder cannot process further requests
43 MSG_PANIC recovery impossible, app must terminate
44
45 Options
46
47 OPT_VERSION version number MAJOR.MINORplPATCH (ro)
48 OPT_FAST assumes only one part per file
49 OPT_DUMBNESS switch off the program's intelligence
50 OPT_BRACKPOL give numbers in [] higher precendence
51 OPT_VERBOSE generate informative messages
52 OPT_DESPERATE try to decode incomplete files
53 OPT_IGNREPLY ignore RE:plies (off by default)
54 OPT_OVERWRITE whether it's OK to overwrite ex. files
55 OPT_SAVEPATH prefix to save-files on disk
56 OPT_IGNMODE ignore the original file mode
57 OPT_DEBUG print messages with FILE/LINE info
58 OPT_ERRNO get last error code for RET_IOERR (ro)
59 OPT_PROGRESS retrieve progress information
60 OPT_USETEXT handle text messages
61 OPT_PREAMB handle Mime preambles/epilogues
62 OPT_TINYB64 detect short B64 outside of Mime
63 OPT_ENCEXT extension for single-part encoded files
64 OPT_REMOVE remove input files after decoding (dangerous)
65 OPT_MOREMIME strict MIME adherence
66 OPT_DOTDOT ".."-unescaping has not yet been done on input files
67 OPT_RBUF set default read I/O buffer size in bytes *EXPERIMENTAL*
68 OPT_WBUF set default write I/O buffer size in bytes *EXPERIMENTAL*
69
70 Result/Error codes
71
72 RET_OK everything went fine
73 RET_IOERR I/O Error - examine errno
74 RET_NOMEM not enough memory
75 RET_ILLVAL illegal value for operation
76 RET_NODATA decoder didn't find any data
77 RET_NOEND encoded data wasn't ended properly
78 RET_UNSUP unsupported function (encoding)
79 RET_EXISTS file exists (decoding)
80 RET_CONT continue -- special from ScanPart
81 RET_CANCEL operation canceled
82
83 File States
84
85 This code is zero, i.e. "false":
86
87 UUFILE_READ Read in, but not further processed
88
89 The following state codes are or'ed together:
90
91 FILE_MISPART Missing Part(s) detected
92 FILE_NOBEGIN No 'begin' found
93 FILE_NOEND No 'end' found
94 FILE_NODATA File does not contain valid uudata
95 FILE_OK All Parts found, ready to decode
96 FILE_ERROR Error while decoding
97 FILE_DECODED Successfully decoded
98 FILE_TMPFILE Temporary decoded file exists
99
100 Encoding types
101
102 UU_ENCODED UUencoded data
103 B64_ENCODED Mime-Base64 data
104 XX_ENCODED XXencoded data
105 BH_ENCODED Binhex encoded
106 PT_ENCODED Plain-Text encoded (MIME)
107 QP_ENCODED Quoted-Printable (MIME)
108 YENC_ENCODED yEnc encoded (non-MIME)
109
111 Initializing and cleanup
112
113 Initialize is automatically called when the module is loaded and allo‐
114 cates quite a small amount of memory for todays machines ;) CleanUp
115 releases that again.
116
117 On my machine, a fairly complete decode with DBI backend needs about
118 10MB RSS to decode 20000 files.
119
120 Initialize
121 Not normally necessary, (re-)initializes the library.
122
123 CleanUp
124 Not normally necessary, could be called at the end to release mem‐
125 ory before starting a new decoding round.
126
127 Setting and querying options
128
129 $option = GetOption OPT_xxx
130 SetOption OPT_xxx, opt-value
131
132 See the "OPT_xxx" constants above to see which options exist.
133
134 Setting various callbacks
135
136 SetMsgCallback [callback-function]
137 SetBusyCallback [callback-function]
138 SetFileCallback [callback-function]
139 SetFNameFilter [callback-function]
140
141 Call the currently selected FNameFilter
142
143 $file = FNameFilter $file
144
145 Loading sourcefiles, optionally fuzzy merge and start decoding
146
147 ($retval, $count) = LoadFile $fname, [$id, [$delflag, [$partno]]]
148 Load the given file and scan it for encoded contents. Optionally
149 tag it with the given id, and if $delflag is true, delete the file
150 after it is no longer necessary. If you are certain of the part
151 number, you can specify it as the last argument.
152
153 A better (usually faster) way of doing this is using the "SetFName‐
154 Filter" functionality.
155
156 $retval = Smerge $pass
157 If you are desperate, try to call "Smerge" with increasing $pass
158 values, beginning at 0, to try to merge parts that usually would
159 not have been merged.
160
161 Most probably this will result in garbled files, so never do this
162 by default.
163
164 $item = GetFileListItem $item_number
165 Return the $item structure for the $item_number'th found file, or
166 "undef" of no file with that number exists.
167
168 The first file has number 0, and the series has no holes, so you
169 can iterate over all files by starting with zero and incrementing
170 until you hit "undef".
171
172 Decoding files
173
174 $retval = $item->rename($newname)
175 Change the ondisk filename where the decoded file will be saved.
176
177 $retval = $item->decode_temp
178 Decode the file into a temporary location, use "$item->infile" to
179 retrieve the temporary filename.
180
181 $retval = $item->remove_temp
182 Remove the temporarily decoded file again.
183
184 $retval = $item->decode([$target_path])
185 Decode the file to it's destination, or the given target path.
186
187 $retval = $item->info(callback-function)
188
189 Querying (and setting) item attributes
190
191 $state = $item->state
192 $mode = $item->mode([newmode])
193 $uudet = $item->uudet
194 $size = $item->size
195 $filename = $item->filename([newfilename})
196 $subfname = $item->subfname
197 $mimeid = $item->mimeid
198 $mimetype = $item->mimetype
199 $binfile = $item->binfile
200
201 Information about source parts
202
203 $parts = $item->parts
204 Return information about all parts (source files) used to decode
205 the file as a list of hashrefs with the following structure:
206
207 {
208 partno => <integer describing the part number, starting with 1>,
209 # the following member sonly exist when they contain useful information
210 sfname => <local pathname of the file where this part is from>,
211 filename => <the ondisk filename of the decoded file>,
212 subfname => <used to cluster postings, possibly the posting filename>,
213 subject => <the subject of the posting/mail>,
214 origin => <the possible source (From) address>,
215 mimetype => <the possible mimetype of the decoded file>,
216 mimeid => <the id part of the Content-Type>,
217 }
218
219 Usually you are interested mostly the "sfname" and possibly the
220 "partno" and "filename" members.
221
222 Functions below not documented and not very well tested
223
224 QuickDecode
225 EncodeMulti
226 EncodePartial
227 EncodeToStream
228 EncodeToFile
229 E_PrepSingle
230 E_PrepPartial
231
232 EXTENSION FUNCTIONS
233
234 Functions found in this module but not documented in the uulib documen‐
235 tation:
236
237 $msg = straction ACT_xxx
238 Return a human readable string representing the given action code.
239
240 $msg = strerror RET_xxx
241 Return a human readable string representing the given error code.
242
243 $str = strencoding xxx_ENCODED
244 Return the name of the encoding type as a string.
245
246 $str = strmsglevel MSG_xxx
247 Returns the message level as a string.
248
249 SetFileNameCallback $cb
250 Sets (or queries) the FileNameCallback, which is called whenever
251 the decoding library can't find a filename and wants to extract a
252 filename from the subject line of a posting. The callback will be
253 called with two arguments, the subject line and the current candi‐
254 date for the filename. The latter argument can be "undef", which
255 means that no filename could be found (and likely no one exists, so
256 it is safe to also return "undef" in this case). If it doesn't
257 return anything (not even "undef"!), then nothing happens, so this
258 is a no-op callback:
259
260 sub cb {
261 return ();
262 }
263
264 If it returns "undef", then this indicates that no filename could
265 be found. In all other cases, the return value is taken to be the
266 filename.
267
268 This is a slightly more useful callback:
269
270 sub cb {
271 return unless $_[1]; # skip "Re:"-plies et al.
272 my ($subject, $filename) = @_;
273 # if we find some *.rar, take it
274 return $1 if $subject =~ /(\w+\.rar)/;
275 # otherwise just pass what we have
276 return ();
277 }
278
280 This is the file "example-decoder" from the distribution, put here
281 instead of more thorough documentation.
282
283 # decode all the files in the directory uusrc/ and copy
284 # the resulting files to uudst/
285
286 use Convert::UUlib ':all';
287
288 sub namefilter {
289 my($path)=@_;
290 $path=~s/^.*[\/\\]//;
291 $path;
292 }
293
294 sub busycb {
295 my ($action, $curfile, $partno, $numparts, $percent, $fsize) = @_;
296 $_[0]=straction($action);
297 print "busy_callback(", (join ",",@_), ")\n";
298 0;
299 }
300
301 SetOption OPT_IGNMODE, 1;
302 SetOption OPT_VERBOSE, 1;
303
304 # show the three ways you can set callback functions. I normally
305 # prefer the one with the sub inplace.
306 SetFNameFilter \&namefilter;
307
308 SetBusyCallback "busycb", 333;
309
310 SetMsgCallback sub {
311 my ($msg, $level) = @_;
312 print uc strmsglevel $_[1], ": $msg\n";
313 };
314
315 # the following non-trivial FileNameCallback takes care
316 # of some subject lines not detected properly by uulib:
317 SetFileNameCallback sub {
318 return unless $_[1]; # skip "Re:"-plies et al.
319 local $_ = $_[0];
320
321 # the following rules are rather effective on some newsgroups,
322 # like alt.binaries.games.anime, where non-mime, uuencoded data
323 # is very common
324
325 # if we find some *.rar, take it as the filename
326 return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d⎪rar))\s/i;
327
328 # one common subject format
329 return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i;
330
331 # - filename.par (04/55)
332 return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i;
333
334 # - (xxx) No. 1 sayuri81.jpg 756565 bytes
335 # - (20 files) No.17 Roseanne.jpg [2/2]
336 return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/;
337
338 # otherwise just pass what we have
339 return ();
340 };
341
342 # now read all files in the directory uusrc/*
343 for(<uusrc/*>) {
344 my($retval,$count)=LoadFile ($_, $_, 1);
345 print "file($_), status(", strerror $retval, ") parts($count)\n";
346 }
347
348 SetOption OPT_SAVEPATH, "uudst/";
349
350 # now wade through all files and their source parts
351 $i = 0;
352 while ($uu = GetFileListItem($i)) {
353 $i++;
354 print "file nr. $i";
355 print " state ", $uu->state;
356 print " mode ", $uu->mode;
357 print " uudet ", strencoding $uu->uudet;
358 print " size ", $uu->size;
359 print " filename ", $uu->filename;
360 print " subfname ", $uu->subfname;
361 print " mimeid ", $uu->mimeid;
362 print " mimetype ", $uu->mimetype;
363 print "\n";
364
365 # print additional info about all parts
366 for ($uu->parts) {
367 while (my ($k, $v) = each %$_) {
368 print "$k > $v, ";
369 }
370 print "\n";
371 }
372
373 $uu->decode_temp;
374 print " temporarily decoded to ", $uu->binfile, "\n";
375 $uu->remove_temp;
376
377 print strerror $uu->decode;
378 print " saved as uudst/", $uu->filename, "\n";
379 }
380
381 print "cleanup...\n";
382
383 CleanUp();
384
386 Marc Lehmann <schmorp@schmorp.de>, the original uulib library was writ‐
387 ten by Frank Pilhofer <fp@informatik.uni-frankfurt.de>, and later heav‐
388 ily bugfixed by Marc Lehmann.
389
391 perl(1), uudeview homepage at http://www.uni-frankfurt.de/~fp/uude‐
392 view/.
393
394
395
396perl v5.8.8 2006-12-16 UUlib(3)