8 |
|
|
9 |
use MIME::Parser; |
use MIME::Parser; |
10 |
|
|
11 |
my $outdir = "/tmp/store"; |
my $outdir = "/data/store"; |
12 |
my $msgdir = "/tmp/mime$$"; # temp |
my $msgdir = "/data/store/tmp/mime$$"; # temp |
13 |
my $to = "dpavlin@pliva.hr"; |
my $from = 'clipping-info@pliva.hr'; |
14 |
|
my $to = 'clipdir@pliva.hr'; |
15 |
|
my $log = "/data/store/mimex.log"; |
16 |
|
|
17 |
print "From: Press Clipping <pcst\@pliva.hr>\nSubject: Press Clipping update\n\n"; |
umask 022; # world readable |
18 |
|
|
19 |
|
open(LOG,">> $log") || warn "log $log: $!"; |
20 |
|
|
21 |
|
open(MAIL,"| /usr/sbin/sendmail $to") || die "sendmail: $!"; |
22 |
|
|
23 |
|
print MAIL "From: Press Clipping <$from>\nSubject: Press Clipping update\n\n"; |
24 |
|
|
25 |
#------------------------------------------------------------ |
#------------------------------------------------------------ |
26 |
# dump_entity - dump an entity's file info |
# dump_entity - dump an entity's file info |
29 |
my $ent = shift; |
my $ent = shift; |
30 |
my @parts = $ent->parts; |
my @parts = $ent->parts; |
31 |
|
|
32 |
|
my $md5=md5_hex(time()); |
33 |
|
mkdir "$outdir/$md5",0755 || die "mkdir $outdir/$md5: $!"; |
34 |
|
|
35 |
if (@parts) { # multipart... |
if (@parts) { # multipart... |
36 |
map { dump_entity($_) } @parts; |
map { dump_entity($_) } @parts; |
37 |
} else { # single part... |
} else { # single part... |
39 |
# " (", scalar($ent->head->mime_type), ")\n"; |
# " (", scalar($ent->head->mime_type), ")\n"; |
40 |
if ($ent->head->mime_type =~ m,text/plain,i) { |
if ($ent->head->mime_type =~ m,text/plain,i) { |
41 |
open(I,$ent->bodyhandle->path) || die "$ent->bodyhandle->path: $!"; |
open(I,$ent->bodyhandle->path) || die "$ent->bodyhandle->path: $!"; |
42 |
while(<I>) { print $_; } |
while(<I>) { print MAIL $_; } |
43 |
close(I); |
close(I); |
44 |
unlink $ent->bodyhandle->path; |
unlink $ent->bodyhandle->path; |
45 |
} else { |
} else { |
48 |
$new=~s/ +/_/g; |
$new=~s/ +/_/g; |
49 |
$new=~s/^.*\/([^\/]+)$/$1/g; |
$new=~s/^.*\/([^\/]+)$/$1/g; |
50 |
$new=~s/[^a-zA-Z._0-9]//g; |
$new=~s/[^a-zA-Z._0-9]//g; |
|
my $md5=md5_hex($new.time()); |
|
|
mkdir "$outdir/$md5",0755 || die "mkdir $outdir/$md5: $!"; |
|
51 |
rename $file,"$outdir/$md5/$new" || die "$file -> $md5 $new: $!"; |
rename $file,"$outdir/$md5/$new" || die "$file -> $md5 $new: $!"; |
52 |
print "\nhttp://store.pliva.hr/$md5/$new\n"; |
print MAIL "\n","-" x 76,"\nhttp://store.pliva.hr/$md5/$new\n"; |
53 |
|
print LOG "$md5/$new\n"; |
54 |
} |
} |
55 |
} |
} |
56 |
} |
} |
86 |
#------------------------------------------------------------ |
#------------------------------------------------------------ |
87 |
1; |
1; |
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|