From: <mn...@us...> - 2008-07-03 11:23:21
|
Revision: 53 http://panda-admin.svn.sourceforge.net/panda-admin/?rev=53&view=rev Author: mnencia Date: 2008-07-03 04:23:18 -0700 (Thu, 03 Jul 2008) Log Message: ----------- Body of newsletter emails are now a bytea field Modified Paths: -------------- trunk/nwadmin/backend/functions.php trunk/nwadmin/moderation.php trunk/nwadmin/send.php trunk/setup/bin/newsletter trunk/setup/sql/create.sql Modified: trunk/nwadmin/backend/functions.php =================================================================== --- trunk/nwadmin/backend/functions.php 2008-03-21 18:29:18 UTC (rev 52) +++ trunk/nwadmin/backend/functions.php 2008-07-03 11:23:18 UTC (rev 53) @@ -119,7 +119,7 @@ // Utility to create links based on cmdline variables function make_get_link($fields) { // Take the fields to copy as array argument if($_SERVER['HTTPS'] == 'on') { $is_https = "s"; } else { $is_https = ""; }; - + $link = "http" . $is_https . "://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?"; // Build my own url for ($i = 0; $i < sizeof($fields); $i++) { // For each field $field = $fields[$i]; @@ -190,33 +190,33 @@ global $dbh; // Get the full email body, comprehensive of headers - $fullbody = $dbh->getOne('SELECT body FROM newsletter_mails WHERE id = ? AND nwl_id = get_nwl_id(?)',array($mailid,$nwl)); + $fullbody = stripcslashes($dbh->getOne('SELECT body FROM newsletter_mails WHERE id = ? AND nwl_id = get_nwl_id(?)',array($mailid,$nwl))); // Prepare an object for the decoded full body - $obj = new Mail_mimeDecode($fullbody); + $decoder = new Mail_mimeDecode($fullbody); - // Empty args - $decode_args = array(); + $parts = $decoder->getSendArray(); + + if (!PEAR::isError($parts)) { + list($recipents,$headers,$body) = $parts; + + // Get SMTP hostname from config.php + $params['host'] = SMTP_SMARTHOST; + + // Prepare the mail to be sent + $mail_object =& Mail::factory('smtp',$params); - // Set options for the decoding operation - $decode_args['decode_headers'] = true; - $decode_args['decode_bodies'] = true; - $decode_args['include_bodies'] = true; - $result = $obj->decode($decode_args); // Decode the full body + // Send the mail + $mail_object->send($stack,$headers,$body); - // Delete the first line from the headers (From blah blah) - array_shift($result->headers); + } + else { + echo "<pre>\n"; + echo "{$parts->message}\n"; + echo "</pre>\n"; + die; + } - // Get SMTP hostname from config.php - $params['host'] = SMTP_SMARTHOST; - - // Prepare the mail to be sent - $mail_object =& Mail::factory('smtp',$params); - - // Send the mail - $mail_object->send($stack,$result->headers,$result->body); - - } // send_stacked_mail() ?> Modified: trunk/nwadmin/moderation.php =================================================================== --- trunk/nwadmin/moderation.php 2008-03-21 18:29:18 UTC (rev 52) +++ trunk/nwadmin/moderation.php 2008-07-03 11:23:18 UTC (rev 53) @@ -17,15 +17,14 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -require_once('backend/functions.php'); -define('XML_HTMLSAX3', "backend/classes/"); -require_once('backend/classes/safehtml.php'); - // If the script invoked by the browser has the same name of the real file if (isset($_SERVER['SCRIPT_FILENAME']) && (__FILE__ == $_SERVER['SCRIPT_FILENAME'])) { exit(_("Direct access not allowed")) ; // Die brutally (invoked script should always be index.php) } +define('XML_HTMLSAX3', "backend/classes/"); +require_once('backend/classes/safehtml.php'); + $safehtml =& new safehtml(); // Store the mail ID into a local variable @@ -40,7 +39,7 @@ <li><b>Data</b>: <?= $mails[$num]['arrived'] ?></li> <br /> <pre> -<?= $safehtml->parse($mails[$num]['body']) ?> +<?= $safehtml->parse(stripcslashes($mails[$num]['body'])) ?> </pre> <br /> Modified: trunk/nwadmin/send.php =================================================================== --- trunk/nwadmin/send.php 2008-03-21 18:29:18 UTC (rev 52) +++ trunk/nwadmin/send.php 2008-07-03 11:23:18 UTC (rev 53) @@ -22,6 +22,11 @@ exit(_("Direct access not allowed")) ; // Die brutally (invoked script should always be index.php) } +define('XML_HTMLSAX3', "backend/classes/"); +require_once('backend/classes/safehtml.php'); + +$safehtml =& new safehtml(); + // Store the mail id into a local variable $num = $_GET['mail']; @@ -38,7 +43,7 @@ <li><b><?= _("Date") ?></b>: <?= $mails[$num]['arrived'] ?></li> <br /> <pre> -<?= $mails[$num]['body'] ?> +<?= $safehtml->parse(stripcslashes($mails[$num]['body'])) ?> </pre> [<a href="<?= make_get_link(array('mode', 'mail')) . "&scookie=" . $_SESSION['scookie'] ?> ">ok</a>] [<a href="index.php?mode=moderation&mail=<?= $num ?>"><?= _("cancel") ?></a>] Modified: trunk/setup/bin/newsletter =================================================================== --- trunk/setup/bin/newsletter 2008-03-21 18:29:18 UTC (rev 52) +++ trunk/setup/bin/newsletter 2008-07-03 11:23:18 UTC (rev 53) @@ -17,9 +17,10 @@ use strict; use Mail::Internet; # Debian: libmailtools-perl -use DBI; # Debian: libdbi-perl, libdbd-pg-perl; +use DBI; # Debian: libdbi-perl, libdbd-pg-perl use Date::Parse; # Debian: libtimedate-perl use Date::Format; # Debian: libtimedate-perl +use DBD::Pg qw(:pg_types); # Debian: libdbd-pg-perl my $configfile = "/srv/vmail/etc/newsletter.conf"; @@ -69,7 +70,13 @@ $date = time2str("%Y-%m-%d %H:%M:%S", str2time($date)); $sth = $dbh->prepare("INSERT INTO $table (nwl_id, sender, subject, arrived, body) VALUES (?,?,?,?,?)"); -unless ($sth->execute($newsletter_id, $sender, $subject, $date, $fullText)) { +$sth->bind_param(1, $newsletter_id); +$sth->bind_param(2, $sender); +$sth->bind_param(3, $subject); +$sth->bind_param(4, $date); +$sth->bind_param(5, $fullText, { pg_type => PG_BYTEA }); + +unless ($sth->execute) { print "CRITICAL: Cannot store email for newsletter $destination: " . $DBI::errstr . "\n" ; exit 75; # EX_TEMPFAIL } Modified: trunk/setup/sql/create.sql =================================================================== --- trunk/setup/sql/create.sql 2008-03-21 18:29:18 UTC (rev 52) +++ trunk/setup/sql/create.sql 2008-07-03 11:23:18 UTC (rev 53) @@ -73,12 +73,12 @@ ); CREATE TABLE newsletter_mails ( - id serial PRIMARY KEY NOT NULL, + id serial PRIMARY KEY NOT NULL, nwl_id integer REFERENCES newsletter_maps(id) ON DELETE CASCADE NOT NULL, sender text NOT NULL, subject text, arrived timestamp NOT NULL, - body text, - sent boolean NOT NULL DEFAULT FALSE + body bytea, + sent boolean NOT NULL DEFAULT FALSE ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |