Skip to content

Instantly share code, notes, and snippets.

Created February 9, 2014 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/8907498 to your computer and use it in GitHub Desktop.
Save anonymous/8907498 to your computer and use it in GitHub Desktop.
mail2vanilla
#!/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/<([^>]*)>/&lt;$1&gt;/;
$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