/[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.6 - (hide annotations)
Wed Apr 17 10:28:41 2002 UTC (21 years, 11 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -0 lines
default perm fix

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

  ViewVC Help
Powered by ViewVC 1.1.26