/[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

Contents of /mimex

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Mon Jul 16 10:07:31 2001 UTC (22 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.1: +9 -11 lines
extract attachments and store them

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

  ViewVC Help
Powered by ViewVC 1.1.26