/[clipping]/mimex
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /mimex

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Sat Nov 3 11:02:30 2001 UTC (22 years, 5 months ago) by dpavlin
Branch: MAIN
Changes since 1.4: +4 -3 lines
generate just one md5 dir per message, just store usefull info in log

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     require 5.001;
4    
5     use strict;
6     use vars qw($Msgno);
7     use Digest::MD5 qw(md5_hex);
8    
9     use MIME::Parser;
10    
11 dpavlin 1.2 my $outdir = "/data/store";
12     my $msgdir = "/data/store/tmp/mime$$"; # temp
13     my $from = 'clipping-info@pliva.hr';
14     my $to = 'clipdir@pliva.hr';
15 dpavlin 1.3 my $log = "/data/store/mimex.log";
16    
17 dpavlin 1.4 open(LOG,">> $log") || warn "log $log: $!";
18 dpavlin 1.1
19 dpavlin 1.2 open(MAIL,"| /usr/sbin/sendmail $to") || die "sendmail: $!";
20    
21     print MAIL "From: Press Clipping <$from>\nSubject: Press Clipping update\n\n";
22 dpavlin 1.1
23     #------------------------------------------------------------
24     # dump_entity - dump an entity's file info
25     #------------------------------------------------------------
26     sub dump_entity {
27     my $ent = shift;
28     my @parts = $ent->parts;
29    
30 dpavlin 1.5 my $md5=md5_hex(time());
31     mkdir "$outdir/$md5",0755 || die "mkdir $outdir/$md5: $!";
32    
33 dpavlin 1.1 if (@parts) { # multipart...
34     map { dump_entity($_) } @parts;
35     } else { # single part...
36     # print " Part: ", $ent->bodyhandle->path,
37     # " (", scalar($ent->head->mime_type), ")\n";
38     if ($ent->head->mime_type =~ m,text/plain,i) {
39     open(I,$ent->bodyhandle->path) || die "$ent->bodyhandle->path: $!";
40 dpavlin 1.2 while(<I>) { print MAIL $_; }
41 dpavlin 1.1 close(I);
42     unlink $ent->bodyhandle->path;
43     } else {
44     my $file=$ent->bodyhandle->path;
45     my $new=$file;
46     $new=~s/ +/_/g;
47     $new=~s/^.*\/([^\/]+)$/$1/g;
48     $new=~s/[^a-zA-Z._0-9]//g;
49     rename $file,"$outdir/$md5/$new" || die "$file -> $md5 $new: $!";
50 dpavlin 1.2 print MAIL "\n","-" x 76,"\nhttp://store.pliva.hr/$md5/$new\n";
51 dpavlin 1.5 print LOG "$md5/$new\n";
52 dpavlin 1.1 }
53     }
54     }
55    
56     #------------------------------------------------------------
57     # main
58     #------------------------------------------------------------
59     sub main {
60     my $file;
61     my $entity;
62    
63     mkdir $msgdir,0755 || die "can't create $msgdir: $!";
64    
65     my $parser = new MIME::Parser;
66     ### $parser->parse_nested_messages('REPLACE');
67    
68     $parser->output_dir($msgdir);
69    
70     open FILE, "-" or die "couldn't open $file";
71     $entity = $parser->read(\*FILE) or
72     print STDERR "Couldn't parse MIME in $file; continuing...\n";
73     close FILE;
74    
75     dump_entity($entity) if $entity;
76     ### $entity->dump_skeleton if $entity;
77    
78     rmdir $msgdir || die "can't remove $msgdir: $!";
79    
80     1;
81     }
82    
83     exit (&main ? 0 : -1);
84     #------------------------------------------------------------
85     1;
86    

  ViewVC Help
Powered by ViewVC 1.1.26