ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/example-decoder
Revision: 1.7
Committed: Sun Oct 13 13:47:09 2002 UTC (21 years, 7 months ago) by root
Branch: MAIN
Changes since 1.6: +97 -95 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.7 # decode all the files in the directory uusrc/ and copy
2     # the resulting files to uudst/
3 root 1.1
4 root 1.7 use Convert::UUlib ':all';
5 root 1.1
6 root 1.7 sub namefilter {
7     my($path)=@_;
8     $path=~s/^.*[\/\\]//;
9     $path;
10     }
11    
12     sub busycb {
13     my ($action, $curfile, $partno, $numparts, $percent, $fsize) = @_;
14     $_[0]=straction($action);
15     print "busy_callback(", (join ",",@_), ")\n";
16     0;
17     }
18    
19     SetOption OPT_IGNMODE, 1;
20     SetOption OPT_VERBOSE, 1;
21    
22     # show the three ways you can set callback functions. I normally
23     # prefer the one with the sub inplace.
24     SetFNameFilter \&namefilter;
25    
26     SetBusyCallback "busycb", 333;
27    
28     SetMsgCallback sub {
29     my ($msg, $level) = @_;
30     print uc strmsglevel $_[1], ": $msg\n";
31     };
32    
33     # the following non-trivial FileNameCallback takes care
34     # of some subject lines not detected properly by uulib:
35     SetFileNameCallback sub {
36     return unless $_[1]; # skip "Re:"-plies et al.
37     local $_ = $_[0];
38    
39     # the following rules are rather effective on some newsgroups,
40     # like alt.binaries.games.anime, where non-mime, uuencoded data
41     # is very common
42    
43     # if we find some *.rar, take it as the filename
44     return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d|rar))\s/i;
45    
46     # one common subject format
47     return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i;
48    
49     # - filename.par (04/55)
50     return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i;
51    
52     # - (xxx) No. 1 sayuri81.jpg 756565 bytes
53     # - (20 files) No.17 Roseanne.jpg [2/2]
54     return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/;
55    
56     # otherwise just pass what we have
57     return ();
58     };
59    
60     # now read all files in the directory uusrc/*
61     for(<uusrc/*>) {
62     my($retval,$count)=LoadFile ($_, $_, 1);
63     print "file($_), status(", strerror $retval, ") parts($count)\n";
64     }
65    
66     SetOption OPT_SAVEPATH, "uudst/";
67    
68     # now wade through all files and their source parts
69     $i = 0;
70     while ($uu = GetFileListItem($i)) {
71     $i++;
72     print "file nr. $i";
73     print " state ", $uu->state;
74     print " mode ", $uu->mode;
75     print " uudet ", strencoding $uu->uudet;
76     print " size ", $uu->size;
77     print " filename ", $uu->filename;
78     print " subfname ", $uu->subfname;
79     print " mimeid ", $uu->mimeid;
80     print " mimetype ", $uu->mimetype;
81     print "\n";
82    
83     # print additional info about all parts
84     for ($uu->parts) {
85     while (my ($k, $v) = each %$_) {
86     print "$k > $v, ";
87     }
88     print "\n";
89     }
90    
91     $uu->decode_temp;
92     print " temporarily decoded to ", $uu->binfile, "\n";
93     $uu->remove_temp;
94    
95     print strerror $uu->decode;
96     print " saved as uudst/", $uu->filename, "\n";
97     }
98 root 1.1
99 root 1.7 print "cleanup...\n";
100 root 1.1
101 root 1.7 CleanUp();