#!/usr/local/bin/perl # qmail2mt.pl # ----------- # Mail gateway from qmail to Movable Type # # Copyright (C) 2002 Olivier Mueller # 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,$ENCODE,$CATEGORY,$PING); BEGIN { ############################# # Settings: # $MT_DIR = '/Users/yoshiki/Sites/mt'; $BLOG_ID = 2; $AUTHOR_ID = 1; $ENCODE = 'euc'; $CATEGORY = 2; $PING = 1; # ############################# } use strict; use lib qw(/Users/yoshiki/Sites/mt/lib /Users/yoshiki/Sites/mt/extlib); use CGI qw{:standard}; use MT; use MT::Entry; use MT::Blog; use Jcode; $|=1; # buffering # # 1. parse the mail, get contents, subject and sender # my $mailcontents = ""; my $header = 1; my $signature = 0; my $subject = "no subject"; my $sender = "anonymous"; while (my $line = ) { 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/\>/\>\;/g; $sender =~ s/\Posted by mail by $sender via qmail2mt.pl ]"; # # 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(Jcode->new($mailcontents)->$ENCODE()); $entry->category_id($CATEGORY); $entry->allow_pings($PING); $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;