7 if ($cmdpath eq "") { $cmdpath="./"; }
9 unshift(@INC,$cmdpath."lib");
10 require "property.pl";
16 $config_file=$cmdpath."mail.config";
17 # print $config_file,"\n";
19 ### no configuration beyond this line
21 $props=&Property::read($config_file);
25 tie *LOGFILE, 'Logfile', $$props{'public'}{'logfile'}, 'MAIL';
26 print LOGFILE "starting: ".localtime(time)."\n";
28 # print $$props{'db'}{'dsn'},$$props{'db'}{'user'},$$props{'db'}{'passwd'},"\n";
32 $dbh=DBI->connect($$props{'db'}{'dsn'},$$props{'db'}{'user'},$$props{'db'}{'passwd'});
33 if ($dbh->errstr ne "") {
34 print LOGFILE "Error while connecting DB - ".$dbh->error."\n";
38 ### prepare some statements
40 $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()");
41 $select_urheber=$dbh->prepare("select name,email,homepage from gruppen where id=?");
42 $update_unsend=$dbh->prepare("update ".$$props{'mail'}{'table'}." set mail_sent=1 where id=?");
44 $select_unsend->execute;
45 while ($hash=$select_unsend->fetchrow_hashref) {
46 if (open(MAILER,"|".$$props{'public'}{'sendmail'})) {
47 print MAILER "To: ".$$props{'mail'}{'to'}."\n";
48 print MAILER "From: ".$$props{'mail'}{'from'}."\n";
49 print MAILER "Reply-To: ".$$props{'mail'}{'reply-to'}."\n";
50 print MAILER "Subject: ".$$hash{'ort'}.": ".$$hash{'titel'}."\n";
52 print MAILER "\n"; # end of header
54 print MAILER $$hash{'titel'}."\n";
59 if ($$hash{'urheber'} eq "") {
60 if ($$hash{'urheber_id'} != 0) {
61 $select_urheber->execute($$hash{'urheber_id'});
62 if ($line=$select_urheber->fetchrow_hashref()) {
63 $urheber=$$line{'name'};
64 $u_email=$$line{'email'};
65 $u_hompage=$$line{'homepage'};
70 $urheber=$$hash{'urheber'};
73 if ($urheber ne "") { print MAILER "Von : ".$urheber."\n"; }
74 if ($u_email ne "") { print MAILER "Email: ".$u_email."\n"; }
75 if ($u_homepage ne "") { print MAILER "Page : ".$u_homepage."\n"; }
77 print MAILER "Ort : ".$$hash{'ort'}."\n";
78 print MAILER "Datum: ".$$hash{'pdatum'}."\n";
79 if ($$hash{'islink'} == 1) {
80 print MAILER "\n\n".$$hash{'abstract'}."\n";
83 if ($$hash{'ishtml'}>0) {
84 print MAILER "\n\n".&html_to_text($props,$$hash{'contentdata'})."\n";
87 print MAILER "\n\n".$$hash{'contentdata'}."\n";
91 if ($$hash{'link_url'} ne "") {
92 print MAILER "Weiteres: ";
93 if (substr($$hash{'link_url'},0,1) eq "/") {
94 print MAILER "http://www.nadir.org";
96 print MAILER $$hash{'link_url'}."\n";
99 print MAILER "\n*** $LIST -- Aboliste mit Nachrichten von http://www.nadir.org\n";
100 print MAILER "*** Beitraege: nadir-aktuell\@nadir.org / Redaktion: nadir-aktuell-red\@nadir.org\n";
101 print MAILER "*** Unsubscribe: majordomo\@nadir.org mit unsubscribe $LIST im body\n";
105 $update_unsend->execute($$hash{'id'});
106 print LOGFILE "[".$$hash{'id'}."] send\n"
109 print LOGFILE "Error cannot open ".$$props{'public'}{'sendmail'}." - $!\n";