]> 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;
33 use Encoding::FixLatin qw(fix_latin);
34 use MIME::QuotedPrint;
35
36 use FindBin;
37 use lib "$FindBin::Bin/../lib";
38 use ND::DB;
39
40 my $dbh = ND::DB::DB();
41
42 my @text = <>;
43 my $text = join '',@text;
44
45 my $email = Email::Simple->new(Email::StripMIME::strip_mime($text));;
46
47 my $subject = decode('MIME-Header', $email->header('Subject'));
48 my $body = 'FROM:' . decode('MIME-Header', $email->header('From')) . "\n\n" . fix_latin($email->body);
49
50
51 $dbh->begin_work;
52
53 my $new_thread = $dbh->prepare(q{INSERT INTO forum_threads (fbid,subject,uid) VALUES(25,$1,-4)});
54
55 if ($new_thread->execute(escapeHTML($subject))){
56         my $id = $dbh->last_insert_id(undef,undef,undef,undef,"forum_threads_ftid_seq");
57         my $insert = $dbh->prepare(q{INSERT INTO forum_posts (ftid,message,uid) VALUES($1,$2,-4)});
58         if ($insert->execute($id,escapeHTML($body))){
59                 $dbh->commit;
60         }else{
61                 print $dbh->errstr;
62         }
63 }else{
64         print $dbh->errstr;
65 }
66
67 $dbh->disconnect;