/[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.1.1.1 - (show annotations) (vendor branch)
Mon Jul 16 09:57:03 2001 UTC (22 years, 8 months ago) by dpavlin
Branch: dpavlin
CVS Tags: r0
Changes since 1.1: +0 -0 lines
import

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

  ViewVC Help
Powered by ViewVC 1.1.26