From a89311235c1fab36fda167f69f5f814e84a5f1c6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 26 Aug 2007 11:32:48 +0100 Subject: [PATCH] improve digest sending (closes #138) --- README | 2 ++ config.php-dist | 18 +++++++--- functions.php | 43 +++++++++++++++++++++--- phpmailer/language/phpmailer.lang-en.php | 23 +++++++++++++ sanity_check.php | 4 +++ 5 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 phpmailer/language/phpmailer.lang-en.php diff --git a/README b/README index e540b90b7..a040066a9 100644 --- a/README +++ b/README @@ -12,6 +12,7 @@ Portions (C): Bob Osola (pngfix.js) Sundar Dorai-Raj (isNumeric() in functions.js) + Sean M. Burke. (xsl_mop-up.js) Other bundled libraries: @@ -19,6 +20,7 @@ Other bundled libraries: Script.aculo.us javascript library, http://http://script.aculo.us/ MagpieRSS feed parser, http://magpierss.sourceforge.net/ SimplePie feed parser, http://simplepie.org/ + PHPMailer class, http://phpmailer.sourceforge.net/ Licensed under GNU GPL version 2 diff --git a/config.php-dist b/config.php-dist index ecacf2028..8601f5628 100644 --- a/config.php-dist +++ b/config.php-dist @@ -73,9 +73,6 @@ define('MAIL_RESET_PASS', true); // Send mail to user on password reset - define('MAIL_FROM', 'TT-RSS Daemon '); - // Pretty obvious, I suppose. Used for email digests & password notifications. - define('ENABLE_FEED_BROWSER', true); // Enable or disable local feed browser @@ -132,7 +129,7 @@ define('DIGEST_ENABLE', true); // Global option to enable daily digests - define('DIGEST_HOSTNAME', 'some.ttrss.host.dom'); + define('DIGEST_HOSTNAME', 'your.domain.dom'); // Hostname for email digest signature define('DIGEST_EMAIL_LIMIT', 10); @@ -177,6 +174,19 @@ // parameter to speed up tt-rss when having a huge number of articles // in the database (better yet, enable purging!) + define('DIGEST_FROM_NAME', 'Tiny Tiny RSS'); + define('DIGEST_FROM_ADDRESS', 'noreply@your.domain.dom'); + // Name and address for sending email digests from. + + define('DIGEST_SMTP_HOST', ''); + // SMTP Host to send digests. When blank tt-rss uses + // PHP's default mail() function. + + define('DIGEST_SMTP_LOGIN', ''); + define('DIGEST_SMTP_PASSWORD', ''); + // These two options enable SMTP authentication when sending + // digests. Require DIGEST_SMTP_HOST. + define('CONFIG_VERSION', 9); // Expected config version. Please update this option in config.php // if necessary (after migrating all new options from this file). diff --git a/functions.php b/functions.php index d82cb38ea..e2915aa00 100644 --- a/functions.php +++ b/functions.php @@ -61,6 +61,8 @@ require_once 'errors.php'; require_once 'version.php'; + require_once 'phpmailer/class.phpmailer.php'; + define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')'); define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); @@ -3156,12 +3158,42 @@ $headlines_count = $tuple[1]; if ($headlines_count > 0) { - $rc = mail($line["login"] . " <" . $line["email"] . ">", - "[tt-rss] New headlines for last 24 hours", $digest, - "From: " . MAIL_FROM . "\n". - "Content-Type: text/plain; charset=\"utf-8\"\n". - "Content-Transfer-Encoding: 8bit\n"); + + if (!DIGEST_SMTP_HOST) { + + $rc = mail($line["login"] . " <" . $line["email"] . ">", + "[tt-rss] New headlines for last 24 hours", $digest, + "From: " . DIGEST_FROM_NAME . " <" . DIGEST_FROM_ADDRESS . ">\n". + "Content-Type: text/plain; charset=\"utf-8\"\n". + "Content-Transfer-Encoding: 8bit\n"); + + } else { + + $mail = new PHPMailer(); + + $mail->PluginDir = "phpmailer/"; + $mail->SetLanguage("en", "phpmailer/language/"); + + $mail->From = DIGEST_FROM_ADDRESS; + $mail->FromName = DIGEST_FROM_NAME; + $mail->AddAddress($line["email"], $line["login"]); + $mail->Host = DIGEST_SMTP_HOST; + $mail->Mailer = "smtp"; + + $mail->Username = DIGEST_SMTP_LOGIN; + $mail->Password = DIGEST_SMTP_PASSWORD; + + $mail->Subject = "[tt-rss] New headlines for last 24 hours"; + $mail->Body = $digest; + + $rc = $mail->Send(); + + if (!$rc) print "ERROR: " . $mail->ErrorInfo; + + } + print "RC=$rc\n"; + db_query($link, "UPDATE ttrss_users SET last_digest_sent = NOW() WHERE id = " . $line["id"]); } else { @@ -3195,6 +3227,7 @@ ref_id = ttrss_entries.id AND feed_id = ttrss_feeds.id AND include_in_digest = true AND $interval_query + AND hidden = false AND ttrss_user_entries.owner_uid = $user_id AND unread = true ORDER BY ttrss_feeds.title, date_entered DESC LIMIT $limit"); diff --git a/phpmailer/language/phpmailer.lang-en.php b/phpmailer/language/phpmailer.lang-en.php new file mode 100644 index 000000000..14b677ff1 --- /dev/null +++ b/phpmailer/language/phpmailer.lang-en.php @@ -0,0 +1,23 @@ + diff --git a/sanity_check.php b/sanity_check.php index 33b433d0b..1f5c0210c 100644 --- a/sanity_check.php +++ b/sanity_check.php @@ -66,6 +66,10 @@ $err_msg = __("config: DATABASE_BACKED_SESSIONS are currently broken with MySQL"); } + if (defined('MAIL_FROM')) { + $err_msg = __("config: MAIL_FROM has been split into DIGEST_FROM_NAME and DIGEST_FROM_ADDRESS"); + } + if ($err_msg) { print "".__("Fatal Error").": $err_msg\n"; exit;