]> ruin.nu Git - ndwebbie.git/blob - scripts/ndmail.pl
Added the ndreport script and updated ndmail so it uses DB.pm
[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 DBI;
26 use DBD::Pg qw(:pg_types);
27 use CGI qw/:standard/;
28
29 use Email::Simple;
30 use Email::StripMIME;
31 use Encode::Encoder qw(encoder);
32 use MIME::QuotedPrint;
33
34 use FindBin;
35 use lib "$FindBin::Bin/../lib";
36 use ND::DB;
37
38 my $dbh = ND::DB::DB();
39
40 my @text = <>;
41 my $text = join '',@text;
42
43 my $email = Email::Simple->new(Email::StripMIME::strip_mime($text));;
44
45 my $subject = encoder(decode_qp($email->header('Subject')))->utf8;
46 my $body = 'FROM:'.encoder(decode_qp($email->header('From')))->utf8 . "\n\n" . encoder($email->body)->utf8;
47
48
49 $dbh->begin_work;
50
51 my $new_thread = $dbh->prepare(q{INSERT INTO forum_threads (fbid,subject,uid) VALUES(25,$1,-4)});
52
53 if ($new_thread->execute(escapeHTML($subject))){
54         my $id = $dbh->last_insert_id(undef,undef,undef,undef,"forum_threads_ftid_seq");
55         my $insert = $dbh->prepare(q{INSERT INTO forum_posts (ftid,message,uid) VALUES($1,$2,-4)});
56         if ($insert->execute($id,escapeHTML($body))){
57                 $dbh->commit;
58         }else{
59                 print $dbh->errstr;
60         }
61 }else{
62         print $dbh->errstr;
63 }
64
65 $dbh->disconnect;