#!/usr/local/bin/perl -w

use strict;
use Frontier::Client;
use Data::Dumper;
use Mail::Internet;
use Mail::Header;

## Configuration
my $url = 'http://www.your-url.com/mt/mt-xmlrpc.cgi';
my $user = 'your_blog_username';
my $password = 'your_blog_password';
my $blog_id = 2;  ## your blog ID
my $appkey = 'idonthaveanappykey';

## Parse the email
my $m = new Mail::Internet( \*STDIN );
my $body = join("", @{ $m->body() });
my $headers = $m->head()->header_hashref();  
my $subject = ( @{ $headers->{Subject} } )[0];

## Clean up the content
$subject =~ s/^\s+//s;
$subject =~ s/\s+$//s;
$body =~ s/^\s+//s;
$body =~ s/\s+$//s;
$body =~ s|(http://\S+)\b|<A HREF="$1">$1</A>|sgi;

my $content=<<"__CONTENT__";
<h3 class="title">$subject</h3>$body  
__CONTENT__
  

# Make an object to represent the XML-RPC server.
my $server = Frontier::Client->new(url => $url);
my $result = $server->call('blogger.newPost',
                           $appkey,
                           $blog_id,
                           $user,
                           $password,
                           $content,
                           $server->boolean(1) );

                           
                           
