#!/usr/bin/perl -w use strict; use LWP::Simple; use MIME::Parser; use MIME::Lite; my $from = 'rich@lafferty.ca'; my $to = 'mysecretaddress@photos.flickr.com'; my $tags = 'phone untagged'; # read the message, keep the HTML part - the text part doesn't # include the text in the MMS. my $parser = new MIME::Parser; $parser->output_under("/tmp"); my $entity = $parser->parse(\*STDIN); for ($entity->parts) { if ($_->mime_type eq 'multipart/alternative') { for ($_->parts) { if ($_->mime_type eq 'text/html') { process($_->body); } } } } $parser->filer->purge(); # follow the trail of URLs that eventually lead to the full-size image sub process { my $body = shift; my $nearby = 0; my $message; my $thumburl; # pull out text and thumb URL for (@{$body}) { if ($nearby == 0) { $nearby = 1 if /just PXT'ed you/; } elsif ($nearby == 1 and m|
(.*?)
|) { $message = $1; } elsif ($nearby == 1 and m|href="(http://pxt.*?share.*?)"|) { $thumburl = $1; last; } } die "Image URL is missing" unless defined $thumburl; # get thumbnail page my $thumbpage = get($thumburl); die "Thumbnail page failed" unless defined $thumbpage; die "Can't find image page URL in thumbnail page" unless $thumbpage =~ m|(/guest/view/message/large.do.*INBOX)|smi; # get large image page # my $imagepageurl = "http://pxt.virginmobile.ca${1}&slide=0&pictureCount=1&fromMessage=true"; my $imagepage = get($imagepageurl); die "Image page failed" unless defined $imagepage; die "Can't find image URL in image page" unless $imagepage =~ m|; } close CURL; # send message my $msg = MIME::Lite->new( From => $from, To => $to, Subject => $message, Type => 'TEXT', Data => "tags: $tags" ); $msg->attach( Type => "image/jpeg", Data => $image, ); $msg->send; } __END__ ### HTML from message: ### 6132657876 just PXT'ed youTesting automatic flickr posting
### From thumbnail page: function displayViewLargeLink(show,whichImg){ //show only for images var viewLargeURL = viewLargeURL = '/guest/view/message/large.do?fromAddress=6132 657876&invite=nEIr4nJK2YhNchTz70u8&msgNo=0&folderFullName=INBOX&slide=' + whichI mg + '&pictureCount=' + pictureCount + '&fromMessage=true'; ### From image page: