-#!/usr/bin/perl
-
-use DBI;
-
-$0=~m#[^/]+$#;
-$cmdpath=$`;
-if ($cmdpath eq "") { $cmdpath="./"; }
-
-unshift(@INC,$cmdpath."lib");
-require "property.pl";
-require "log.pl";
-require "convert.pl";
-
-### configure here
-
-$config_file=$cmdpath."mail.config";
-# print $config_file,"\n";
-
-### no configuration beyond this line
-
-$props=&Property::read($config_file);
-
-### connect logfile
-
-tie *LOGFILE, 'Logfile', $$props{'public'}{'logfile'}, 'MAIL';
-print LOGFILE "starting: ".localtime(time)."\n";
-
-# print $$props{'db'}{'dsn'},$$props{'db'}{'user'},$$props{'db'}{'passwd'},"\n";
-
-
-### connect to db
-$dbh=DBI->connect($$props{'db'}{'dsn'},$$props{'db'}{'user'},$$props{'db'}{'passwd'});
-if ($dbh->errstr ne "") {
- print LOGFILE "Error while connecting DB - ".$dbh->error."\n";
- exit(0);
- }
-
-### prepare some statements
-
-$select_unsend=$dbh->prepare("select id,ort,titel,urheber,urheber_id,date_format(datum,'%d.%m.%Y') as pdatum,contentdata,abstract,islink,ishtml,link_url from ".$$props{'mail'}{'table'}." where mail_sent=0 and freigeschaltet=1 and adddate(lastchange,interval 30 MINUTE) < current_timestamp()");
-$select_urheber=$dbh->prepare("select name,email,homepage from gruppen where id=?");
-$update_unsend=$dbh->prepare("update ".$$props{'mail'}{'table'}." set mail_sent=1 where id=?");
-
-$select_unsend->execute;
-while ($hash=$select_unsend->fetchrow_hashref) {
- if (open(MAILER,"|".$$props{'public'}{'sendmail'})) {
- print MAILER "To: ".$$props{'mail'}{'to'}."\n";
- print MAILER "From: ".$$props{'mail'}{'from'}."\n";
- print MAILER "Reply-To: ".$$props{'mail'}{'reply-to'}."\n";
- print MAILER "Subject: ".$$hash{'ort'}.": ".$$hash{'titel'}."\n";
-
- print MAILER "\n"; # end of header
-
- print MAILER $$hash{'titel'}."\n";
-
- $urheber="";
- $u_email="";
- $u_homepage="";
- if ($$hash{'urheber'} eq "") {
- if ($$hash{'urheber_id'} != 0) {
- $select_urheber->execute($$hash{'urheber_id'});
- if ($line=$select_urheber->fetchrow_hashref()) {
- $urheber=$$line{'name'};
- $u_email=$$line{'email'};
- $u_hompage=$$line{'homepage'};
- }
- }
- }
- else {
- $urheber=$$hash{'urheber'};
- }
-
- if ($urheber ne "") { print MAILER "Von : ".$urheber."\n"; }
- if ($u_email ne "") { print MAILER "Email: ".$u_email."\n"; }
- if ($u_homepage ne "") { print MAILER "Page : ".$u_homepage."\n"; }
-
- print MAILER "Ort : ".$$hash{'ort'}."\n";
- print MAILER "Datum: ".$$hash{'pdatum'}."\n";
- if ($$hash{'islink'} == 1) {
- print MAILER "\n\n".$$hash{'abstract'}."\n";
- }
- else {
- if ($$hash{'ishtml'}>0) {
- print MAILER "\n\n".&html_to_text($props,$$hash{'contentdata'})."\n";
- }
- else {
- print MAILER "\n\n".$$hash{'contentdata'}."\n";
- }
- }
-
- if ($$hash{'link_url'} ne "") {
- print MAILER "Weiteres: ";
- if (substr($$hash{'link_url'},0,1) eq "/") {
- print MAILER "http://www.nadir.org";
- }
- print MAILER $$hash{'link_url'}."\n";
- }
- ### footer
- print MAILER "\n*** $LIST -- Aboliste mit Nachrichten von http://www.nadir.org\n";
- print MAILER "*** Beitraege: nadir-aktuell\@nadir.org / Redaktion: nadir-aktuell-red\@nadir.org\n";
- print MAILER "*** Unsubscribe: majordomo\@nadir.org mit unsubscribe $LIST im body\n";
-
- close(MAILER);
-
- $update_unsend->execute($$hash{'id'});
- print LOGFILE "[".$$hash{'id'}."] send\n"
- }
- else {
- print LOGFILE "Error cannot open ".$$props{'public'}{'sendmail'}." - $!\n";
- }
- }
-