| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | |
|---|
| 6 | use MIME::Parser; |
|---|
| 7 | use Net::Blogger::Engine::Base; |
|---|
| 8 | |
|---|
| 9 | my $parser = new MIME::Parser(); |
|---|
| 10 | $parser->output_to_core(1); |
|---|
| 11 | $parser->decode_headers(1); |
|---|
| 12 | |
|---|
| 13 | my $top = $parser->parse(\*STDIN); |
|---|
| 14 | |
|---|
| 15 | my $type = $top->effective_type(); |
|---|
| 16 | die "Cannot handle top-level type \"$type\"\n" |
|---|
| 17 | unless ($type eq 'text/plain'); |
|---|
| 18 | |
|---|
| 19 | my $header = $top->head(); |
|---|
| 20 | my $io = $top->open('r') |
|---|
| 21 | or die "Cannot read message body\n"; |
|---|
| 22 | my $body = ''; |
|---|
| 23 | my $any_trailing_spaces; |
|---|
| 24 | while (defined($_ = $io->getline())) { |
|---|
| 25 | if (/\S/ && ($body =~ / \r?\n\Z/)) { |
|---|
| 26 | chomp($body); |
|---|
| 27 | $any_trailing_spaces = 1; |
|---|
| 28 | } |
|---|
| 29 | $body .= $_; |
|---|
| 30 | } |
|---|
| 31 | $io->close(); |
|---|
| 32 | |
|---|
| 33 | if (!$any_trailing_spaces) { |
|---|
| 34 | $body =~ s/([^\s\r\n])\r?\n([^\s\r\n*-])/$1 $2/g; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | $body =~ s/\A[\r\n]+//; |
|---|
| 38 | $body =~ s/[\r\n]+\Z//; |
|---|
| 39 | |
|---|
| 40 | my $blogger = new Net::Blogger::Engine::Base({blogid => 1, |
|---|
| 41 | username => 'xxx', |
|---|
| 42 | password => 'xxx'}); |
|---|
| 43 | $blogger->Proxy('http://your.blog/xmlrpc.php'); |
|---|
| 44 | |
|---|
| 45 | my $postbody = join('', |
|---|
| 46 | '<title>', |
|---|
| 47 | $header->get('subject'), |
|---|
| 48 | '</title>', |
|---|
| 49 | $body); |
|---|
| 50 | |
|---|
| 51 | $blogger->newPost({postbody => \$postbody, |
|---|
| 52 | publish => 1}); |
|---|