The incoming mail will be posted to a Mantis project named ‘PROJECT’ on behave of user ‘REPORTER’. The mail subject will become the bug summary and the mail content will become the bug description.
Note that this script does not understand MIME multipart encoding and may have problems on mail contents besides plain-ASCII encoding.
#!/usr/bin/perl# mantis-mail-gateway.pl# Mantis Mail Gateway# Shen Cheng-Da (cdsheen AT gmail.com)# require DBI to connect MySQL database# http://blog.urdada.net/2008/11/11/95/use DBI;use POSIX qw(strftime);my$db_host='localhost';my$db_name='mantis';my$db_user='monitor';my$db_pass='monitorpass';my$debug=0;my$db="dbi:mysql:dbname=${db_name};host=${db_host}";die"Usage: $0 [project-name] [reporter]\n"unless@ARGV>1;my$project_name=$ARGV[0];my$reporter_name=$ARGV[1];my$dbh;my$sql;my$sth;my$project=-1;my$reporter=-1;$dbh= DBI->connect($db,$db_user,$db_pass)||die'ERROR: '.$dbh->errstr;$sql="SELECT id,name FROM mantis_project_table
WHERE name LIKE '$project_name'";$sth=$dbh->prepare($sql)||die'ERROR: '.$dbh->errstr;$sth->execute()||die'ERROR: '.$dbh->errstr;while(@data=$sth->fetchrow_array()){$project=$data[0];}$sth->finish;die"ERROR: project \`$project_name' does not exist\n"unless$project>0;print"project: $project_name ($project)\n"if$debug;$sql="SELECT id,username FROM mantis_user_table
WHERE username = '$reporter_name'";$sth=$dbh->prepare($sql)||die'ERROR: '.$dbh->errstr;$sth->execute()||die'ERROR: '.$dbh->errstr;while(@data=$sth->fetchrow_array()){$reporter=$data[0];}$sth->finish;die"ERROR: user \`$reporter_name' does not exist\n"unless$reporter>0;print"reporter: $reporter_name ($reporter)\n"if$debug;my$subject='';my$content='';while(<STDIN>){s/\s+$//;lastif$_eq'';$subject=$1if/^Subject: (.+)$/;}while(<STDIN>){$content.=$_;}$sql='INSERT INTO mantis_bug_text_table (description) VALUES (?)';$sth=$dbh->prepare($sql)||die'ERROR: '.$dbh->errstr;$sth->execute($content)||die'ERROR: '.$dbh->errstr;$sth->finish;my$textid=$dbh->{q{mysql_insertid}};print"bug text id: $textid\n"if$debug;$sql='INSERT INTO mantis_bug_table
( project_id, reporter_id,
date_submitted, last_updated,
bug_text_id, summary )
VALUES (?,?,?,?,?,?)';my$now= strftime('%Y-%m-%d %H:%M:%S',localtime(time));$sth=$dbh->prepare($sql)||die'ERROR: '.$dbh->errstr;$sth->execute($project,$reporter,$now,$now,$textid,$subject)||die'ERROR: '.$dbh->errstr;$sth->finish;$dbh->disconnect;
#!/usr/bin/perl
# mantis-mail-gateway.pl
# Mantis Mail Gateway
# Shen Cheng-Da (cdsheen AT gmail.com)
# require DBI to connect MySQL database
# http://blog.urdada.net/2008/11/11/95/
use DBI;
use POSIX qw(strftime);
my $db_host = 'localhost';
my $db_name = 'mantis';
my $db_user = 'monitor';
my $db_pass = 'monitorpass';
my $debug = 0;
my $db = "dbi:mysql:dbname=${db_name};host=${db_host}";
die "Usage: $0 [project-name] [reporter]\n" unless @ARGV > 1;
my $project_name = $ARGV[0];
my $reporter_name = $ARGV[1];
my $dbh;
my $sql;
my $sth;
my $project = -1;
my $reporter = -1;
$dbh = DBI->connect($db, $db_user, $db_pass)
|| die 'ERROR: '.$dbh->errstr;
$sql = "SELECT id,name FROM mantis_project_table
WHERE name LIKE '$project_name'";
$sth = $dbh->prepare($sql) || die 'ERROR: '.$dbh->errstr;
$sth->execute() || die 'ERROR: '.$dbh->errstr;
while( @data = $sth->fetchrow_array() ) {
$project = $data[0];
}
$sth->finish;
die "ERROR: project \`$project_name' does not exist\n" unless $project > 0;
print "project: $project_name ($project)\n" if $debug;
$sql = "SELECT id,username FROM mantis_user_table
WHERE username = '$reporter_name'";
$sth = $dbh->prepare($sql) || die 'ERROR: '.$dbh->errstr;
$sth->execute() || die 'ERROR: '.$dbh->errstr;
while( @data = $sth->fetchrow_array() ) {
$reporter = $data[0];
}
$sth->finish;
die "ERROR: user \`$reporter_name' does not exist\n" unless $reporter > 0;
print "reporter: $reporter_name ($reporter)\n" if $debug;
my $subject = '';
my $content = '';
while(<STDIN>) {
s/\s+$//;
last if $_ eq '';
$subject = $1 if /^Subject: (.+)$/;
}
while(<STDIN>) {
$content .= $_;
}
$sql = 'INSERT INTO mantis_bug_text_table (description) VALUES (?)';
$sth = $dbh->prepare($sql) || die 'ERROR: '.$dbh->errstr;
$sth->execute($content) || die 'ERROR: '.$dbh->errstr;
$sth->finish;
my $textid = $dbh->{ q{mysql_insertid} };
print "bug text id: $textid\n" if $debug;
$sql = 'INSERT INTO mantis_bug_table
( project_id, reporter_id,
date_submitted, last_updated,
bug_text_id, summary )
VALUES (?,?,?,?,?,?)';
my $now = strftime('%Y-%m-%d %H:%M:%S', localtime(time));
$sth = $dbh->prepare($sql) || die 'ERROR: '.$dbh->errstr;
$sth->execute($project, $reporter, $now, $now, $textid, $subject)
|| die 'ERROR: '.$dbh->errstr;
$sth->finish;
$dbh->disconnect;
大約是2007年11月底抱著好玩的心裡加入 BloggerAds 的,主要使用的位置是放在我的 Blog 右方側欄的廣告,我的 Blog 流量並不多,但根據報表,平均每天還是約有200~300次的廣告曝光,大約是新台幣5~6元的收入。經過9個月的累積之後,收益終於到達 BloggerAds 訂的收益匯款門檻1000元了 🙂
其實這一年來實在太忙,寫文章也是斷斷續續的,心血來潮就寫一篇,忙的時候停筆一兩個月也是常有的事,從開始寫 Blog 到現在也只累積了不到百篇文章。這幾天到上海出差,下班後回到飯店,想說連上自己的 Blog 看看有沒有被「和諧」掉(還好沒有),突然發現 PageRank 升到 5 了。今年三月的時候,PageRank 還是只有 3 而已,大約四月底升到 4,然後到現在八月中左右就升到 5 了.. 不曉得 Google 怎麼算的
不過雖然 PageRank 升到 5 了,但是我發現原來在無名小站的舊 Blog 每日訪問數都還是比新的這邊高,而且其實舊的 Blog 內的文章大部分已經被我拿掉了,但是每日訪問數還是較多。更重要的是,從 Bloglines 的訂閱數目來看,新的 Blog 還是沒有超越原來我無名小站 Blog 的訂閱數 (其實都很少 XD)
但是呢,在大陸這邊,訪問我新的 Blog 是沒問題的,而無名小站的 Blog 卻被和諧掉了… 必須要 VPN 連回台灣才看得到 🙄