#!/usr/bin/perl -w use MIME::Entity; ####################### # # Define the varibles for the test # ######################## $toAddress ='me@localhost'; $fromAddress ='me@localhost'; $Subject ="Some Random Subject"; $message = ["This is a test message that witters on about some random stuff
\n", "Why? I dunno, i guess it just feels like doing so
\n", "Anyway it's doing no harm is it?
\n", "Somewebsite"]; $aFileName = "someimage.gif"; $aType = "image/gif"; $aEncoding = "-SUGGEST"; ############################### # # The Donkey Work Part..... # ################################ ## Create the top-level, and set up the mail headers: $top = MIME::Entity->build(Type => "text/html", From => $fromAddress, To => $toAddress, Subject => $Subject, Data => $message); ## for plaine text e-mail change Type to "text/plain", # Attach a Signature.... $top->attach(Path=>"signature.txt", Disposition => "inline", Encoding => "8bit"); # Attach the Image.... $top->attach(Path => $aFileName, Type => $aType, Encoding => $aEncoding, Disposition => "attachment"); # Send the message open (MAIL,"|/usr/sbin/sendmail -t -oi"); $top->print(\*MAIL); close MAIL; #### use MIME::Parser; sub read_email { my $dir = "/home/me/webtest/mail/attachments"; my $url = "http://127.0.0.1/mail/attachments"; my $parser = new MIME::Parser; $parser->output_dir($dir); my $entity = $parser->read(\*STDIN) || die "couldn't parse MIME stream"; my $head = $entity->head; my $content = $head->as_string . "\n"; my @parts = $entity->parts; my $body = $entity->bodyhandle; $content .= $body->as_string if defined $body; my $part; for $part (@parts) { my $path = ($part->bodyhandle) ? $part->bodyhandle->path : undef; if ($path =~ /msg-\d+.*\.doc/) { open(IN, $path) || warn "Couldn't open $path\n"; local $/ = undef; $content .= . "\n"; close IN; unlink ($path) || warn "Couldn't unlink $path\n"; } else { my $file = $path; $file =~ s/$dir//o; $content .= "\n--\nSaved attachment: $url$file\n--\n"; } } return $content; } #### perl strip.pl