Created
February 9, 2014 23:07
-
-
Save anonymous/8907498 to your computer and use it in GitHub Desktop.
mail2vanilla
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Smart::Comments; | |
use DBI; | |
use Perl6::Slurp; | |
use POSIX; | |
binmode STDIN, ':utf8'; | |
my $subject = <STDIN>; | |
my $from = <STDIN>; | |
my $body = slurp \*STDIN; | |
$from =~ s/<([^>]*)>/<$1>/; | |
$from =~ s/@[^.]*\./@*./; | |
$body = "$from\n$body"; | |
my $dbh = DBI->connect('DBI:mysql:database=vanilla;host=127.2.3.1;port=3309', 'vanillabot', 'vanillabot', { | |
RaiseError => 1, AutoCommit => 0, mysql_enable_utf8 => 1, | |
}); | |
my @row = $dbh->selectrow_array("SELECT DiscussionID FROM GDN_Discussion WHERE Name = ?", {}, $subject); | |
if (not @row) { | |
my $sth = $dbh->prepare("INSERT INTO GDN_Discussion (CategoryID, InsertUserID, Name, Body, Format, DateInserted, InsertIPAddress, DateLastComment) VALUES (?, ?, ?, ?, ?, NOW(), ?, NOW())"); | |
$sth->execute(8, 9, $subject, $body, 'Html', '0.0.0.1'); | |
} else { | |
my $id = $row[0]; | |
my $sth = $dbh->prepare("INSERT INTO GDN_Comment (DiscussionID, InsertUserID, Body, Format, DateInserted, InsertIPAddress) VALUES (?, ?, ?, ?, NOW(), ?)"); | |
$sth->execute($id, 9, $body, 'Html', '0.0.0.1'); | |
$dbh->do("UPDATE GDN_Discussion SET DateLastComment = NOW()"); | |
} | |
$dbh->commit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment