]> ruin.nu Git - ndwebbie.git/blob - scripts/ndmail.pl
Use new race infrastructure for members stats
[ndwebbie.git] / scripts / ndmail.pl
1 #!/usr/bin/perl
2 q{
3 /***************************************************************************
4  *   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
20  ***************************************************************************/
21 };
22
23 use strict;
24 use warnings;
25 use local::lib;
26 use DBI;
27 use DBD::Pg qw(:pg_types);
28 use CGI qw/:standard/;
29
30 use Email::Simple;
31 use Email::StripMIME;
32 use Encode::Encoder qw(encoder);
33 use MIME::QuotedPrint;
34
35 use FindBin;
36 use lib "$FindBin::Bin/../lib";
37 use ND::DB;
38
39 my $dbh = ND::DB::DB();
40
41 my @text = <>;
42 my $text = join '',@text;
43
44 my $email = Email::Simple->new(Email::StripMIME::strip_mime($text));;
45
46 my $subject = encoder(decode_qp($email->header('Subject')))->utf8;
47 my $body = 'FROM:'.encoder(decode_qp($email->header('From')))->utf8 . "\n\n" . encoder($email->body)->utf8;
48
49
50 $dbh->begin_work;
51
52 my $new_thread = $dbh->prepare(q{INSERT INTO forum_threads (fbid,subject,uid) VALUES(25,$1,-4)});
53
54 if ($new_thread->execute(escapeHTML($subject))){
55         my $id = $dbh->last_insert_id(undef,undef,undef,undef,"forum_threads_ftid_seq");
56         my $insert = $dbh->prepare(q{INSERT INTO forum_posts (ftid,message,uid) VALUES($1,$2,-4)});
57         if ($insert->execute($id,escapeHTML($body))){
58                 $dbh->commit;
59         }else{
60                 print $dbh->errstr;
61         }
62 }else{
63         print $dbh->errstr;
64 }
65
66 $dbh->disconnect;