[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: .qmail-* -> MovableType entry ?



On Sat, Aug 10, 2002 at 06:13:34PM +0200, Olivier M. wrote:
> Hello,
> 
> Just wondering if you know if there is already a tool
> available somewhere which would post automaticaly an
> incoming mail to a MovableType weblog ? (via xmlrpc, or anything)
> (cf. http://www.movabletype.org/ )

ok, auto answer... :-)
Here is the code (quite short):


----------------------------------------------------------------------
#!/usr/bin/perl

# qmail2mt.pl
# -----------
# Mail gateway from qmail to Movable Type
#
# Copyright (C) 2002  Olivier Mueller <om@omnis.ch>
# Version 0.1 - Sat Aug 10 21:51:33 CEST 2002
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License.
#
# Installation:
# ------------
# 1. add the following line to the according .qmail-xxxxx file:
#    |preline /path/to/qmail2mt.pl
# 2. update the following variables in the Settings part of the script
#    (MT_DIR = installation directory of Movable Type)
#

my($MT_DIR,$BLOG_ID,$AUTHOR_ID); BEGIN {

#############################
# Settings:
#

$MT_DIR = '/home/omnis.ch/www/dev/da2002';
$BLOG_ID = 2;
$AUTHOR_ID = 1;

#
#############################

}
use strict;
use lib "$MT_DIR/lib";
use CGI qw{:standard};
use MT;
use MT::Entry;
use MT::Blog;
$|=1; # buffering

#
# 1. parse the mail, get contents, subject and sender
#

my $mailcontents = "";

my $mailcontents = "";
my $header = 1;  my $signature = 0;
my $subject = "no subject";
my $sender = "anonymous";
 
while (my $line = <STDIN>) {
        if ($header && $line eq "\n") {
                $header = 0;
        }
        if (!$header) {
                if ($line eq "-- \n") {
                        $signature = 1;   # ignore signature
                }
                if (!$signature) {
                        $mailcontents .= $line;
                }
        } else {
                if ($line =~ /^Subject\:\ (.*)/) {
                        $subject = $1;
                }
                if ($line =~ /^From\:\ (.*)/) {
                        $sender = $1;
                }
        }
}

$sender =~ s/\>/\&gt\;/g;
$sender =~ s/\</\&lt\;/g;
$mailcontents .= "\n[ <i>Posted by mail by $sender via qmail2mt.pl</i> ]";
 
#
# 2. insert the entry to MT
#

my $MT = MT->new( Config => "$MT_DIR/mt.cfg" ) or die MT->errstr;
my $BLOG = MT::Blog->load($BLOG_ID);
my $entry = MT::Entry->new;
$entry->blog_id($BLOG->id);
$entry->author_id($AUTHOR_ID);
$entry->status(MT::Entry::RELEASE());
$entry->allow_comments($BLOG->allow_comments_default);
$entry->convert_breaks($BLOG->convert_paras);
$entry->title("$subject");
$entry->text($mailcontents);
$entry->save or die $entry->errstr;
$BLOG->save or die $BLOG->errstr;
$entry->save or die $entry->errstr;
$BLOG->save or die $BLOG->errstr;

#
# 3. rebuild pages
#

$MT->rebuild(BlogID => $BLOG_ID)
    or die $MT->errstr;
         
# end.
----------------------------------------------------------------------


comments welcome... :)
Olivier
-- 
_________________________________________________________________
 Olivier Mueller - om@8304.ch - PGPkeyID: 0E84D2EA - Switzerland
qmail projects: http://omail.omnis.ch  -  http://webmail.omnis.ch