#!/usr/bin/perl #parsephoto.pl, by Matt Wallace (matt at ender.com) # mostly taken from MIME::Tools and subclass docs # designed to have iphone emails piped in via procmail. # Will drop the jpg into a file and email back the path # (which I'll be using to plop it into a blog post) my $targetdir = "/home/matt/public_html/phonephotos"; # sanity checking your path if (! -e $targetdir || ! -d $targetdir ) { die "$targetdir does not exist or is not a directory"; } else { stat($targetdir); if (! -w _) { die "$targetdir is not writable"; } } use MIME::Parser; ### Create a new parser object: my $parser = new MIME::Parser; umask(0033); $parser->output_to_core(1); ### Parse an input filehandle: $entity = $parser->parse(\*STDIN); my $fname = ''; foreach ($entity->parts()) { my $type = $_->mime_type; if ($type =~ q@image/jpeg@) { if ($fh = $_->open("r")) { $i=0; $fname = $targetdir . "/" . $i . ".jpg"; while ( -e $fname ) { $i++; $fname = $targetdir . "/" . $i . ".jpg"; } open(FH, ">$fname"); while (defined($_ = $fh->getline)) { print FH $_; } close(FH); $fh->close; } } } my $sender = $entity->head()->get('From'); chomp($sender); open(MH, "|/usr/lib/sendmail -t"); print MH "From: $sender\n"; print MH "To: $sender\n"; print MH "Subject: $fname\n"; print MH "\n$fname\n"; close(MH);