ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/example-decoder
Revision: 1.10
Committed: Tue Dec 28 21:32:27 2004 UTC (19 years, 4 months ago) by root
Branch: MAIN
CVS Tags: rel-1_05
Changes since 1.9: +3 -2 lines
Log Message:
*** empty log message ***

File Contents

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