ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/example-decoder
Revision: 1.9
Committed: Tue Dec 28 14:09:19 2004 UTC (19 years, 4 months ago) by root
Branch: MAIN
CVS Tags: rel-1_04
Changes since 1.8: +2 -0 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 root 1.9 return $1 if /([a-z0-9_]{3,}\.[a-z]{3,4}(?:.\d+))/i;
46    
47 root 1.8 # if we find some *.rar, take it as the filename
48     return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d|rar))\s/i;
49    
50     # one common subject format
51     return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i;
52    
53     # - filename.par (04/55)
54     return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i;
55    
56     # - (xxx) No. 1 sayuri81.jpg 756565 bytes
57     # - (20 files) No.17 Roseanne.jpg [2/2]
58     return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/;
59    
60     # otherwise just pass what we have
61     return ();
62     };
63    
64     # now read all files in the directory uusrc/*
65     for(<uusrc/*>) {
66     my($retval,$count)=LoadFile ($_, $_, 1);
67     print "file($_), status(", strerror $retval, ") parts($count)\n";
68     }
69    
70     SetOption OPT_SAVEPATH, "uudst/";
71    
72     # now wade through all files and their source parts
73     $i = 0;
74     while ($uu = GetFileListItem $i) {
75     $i++;
76     print "file nr. $i";
77     print " state ", $uu->state;
78     print " mode ", $uu->mode;
79     print " uudet ", strencoding $uu->uudet;
80     print " size ", $uu->size;
81     print " filename ", $uu->filename;
82     print " subfname ", $uu->subfname;
83     print " mimeid ", $uu->mimeid;
84     print " mimetype ", $uu->mimetype;
85     print "\n";
86    
87     # print additional info about all parts
88     for ($uu->parts) {
89     while (my ($k, $v) = each %$_) {
90     print "$k > $v, ";
91     }
92     print "\n";
93     }
94    
95     $uu->decode_temp;
96     print " temporarily decoded to ", $uu->binfile, "\n";
97     $uu->remove_temp;
98    
99     print strerror $uu->decode;
100     print " saved as uudst/", $uu->filename, "\n";
101     }
102 root 1.1
103 root 1.8 print "cleanup...\n";
104    
105     CleanUp();