#!/usr/bin/perl # curvr # curvrmail # Richard Crowley # $Id$ # This works with my Nokia N73. I don't care if it works on your phone. # Tread lightly. use strict; use MIME::Base64; use Flickr::Upload::Dopplr; # Flickr API goodness my $FLICKR_API_KEY = ''; my $FLICKR_SECRET = ''; my $FLICKR_TOKEN = ''; # Dopplr API token my $DOPPLR_TOKEN = ''; my $CURVR_BIN = '/home/rcrowley/bin/curvr'; my $CURVR_PROCESS = 'curve'; my $CURVR_VERSION = '0.2'; # Tags to add to every photo my $TAGS = "curvr curvr:process=$CURVR_PROCESS curvr:version=$CURVR_VERSION"; # Get the raw email body from procmail my @lines = ; my $boundary = ''; my $content_type = ''; my $blank = 0; my @body; my @jpeg; foreach (@lines) { chomp; # First we have to find the boundary if (!$boundary && '--' eq substr($_, 0, 2)) { $boundary = $_; } # Seeing another boundary indicates the end of a part elsif ($boundary eq $_) { $content_type = ''; $blank = 0; } # Note the content type if this line specifies it elsif (/^Content-Type: ([a-z\/]+)/) { $content_type = $1; } # Now find the blank line that indicates the beginning of content elsif (!$blank && /^\s*$/) { $blank = 1; } # The body elsif ($blank && 'text/plain' eq $content_type) { push @body, $_; } # The JPEG attachment elsif ($blank && 'image/jpeg' eq $content_type) { push @jpeg, $_; } } my $body = join '', @body; # Curvr ur JPEG my $ts = time(); my $in = "/tmp/curvrmail_$ts.jpg"; my $out = "/tmp/curvrmail_${ts}_curve.jpg"; unlink $in; open JPEG, '>', $in; print JPEG decode_base64(join('', @jpeg)); close JPEG; `$CURVR_BIN $in $CURVR_PROCESS $out`; # Sneaky rotate syntax # Why doesn't my phone have an accelerometer in it? my $tags = ''; if ($body =~ /^([lr])\s+/i) { my $rotate = lc($1); my $degrees = '0'; if ('l' eq $rotate) { $degrees = '-90'; $tags = 'curvr:rotate=left'; } elsif ('r' eq $rotate) { $degrees = '90'; $tags = 'curvr:rotate=right'; } `gm convert $out -rotate $degrees $out`; $body =~ s/^[lr]\s+//i; } # Pick apart title and tags my $title = ''; if ($body =~ /^(.*)tags:(.*)$/i) { $title = $1; $tags = "$2 $tags"; } else { $title = $body; } $title =~ s/^\s+//; $title =~ s/\s+$//; $tags =~ s/^\s+//; $tags =~ s/\s+$//; $tags .= " $TAGS"; # Upload with the Dopplr my %dopplr = ( 'auth_token' => $DOPPLR_TOKEN, 'tagify' => 'delicious' ); my %flickr = ( 'key' => $FLICKR_API_KEY, 'secret' => $FLICKR_SECRET, 'dopplr' => \%dopplr ); my $uploadr = Flickr::Upload::Dopplr->new(\%flickr); my $photo_id = $uploadr->upload( 'photo' => $out, 'auth_token' => $FLICKR_TOKEN, 'title' => $title, 'tags' => $tags );