]> git.wh0rd.org Git - tt-rss.git/commitdiff
Additions:
authorderekmurawsky <dmurawsky@gmail.com>
Fri, 22 Mar 2013 20:25:12 +0000 (16:25 -0400)
committerderekmurawsky <dmurawsky@gmail.com>
Fri, 22 Mar 2013 20:25:12 +0000 (16:25 -0400)
classes/trssmailer.php - Created class TTRSS mailer which extends phpmailer and sets the default mail settings upon instantiation. Class includes quickmail function that allows for a quick email send with no extra configurion necessary.

Changes:
config.php-dist - Added the smtp port option

include/digest.php - Converted it to use the new ttrrssmailer class

include/sanity_config.php - Added the smtp port option to the sanity check

plugins/mail/init.php - Modified to use ttrssmailer class. This particular configuration shows a hybrid use case.

register.php = Modified to use ttrssmailer class.

All code was tested and functioned on my local machine.

.gitignore
classes/ttrssmailer.php [new file with mode: 0644]
config.php-dist
include/digest.php
include/sanity_config.php
plugins/mail/init.php
register.php

index 9c7c138e88698c0eef4bdfbf23d7803e068cc07c..d98c0efc3a52f908836f1b20d7cda69c2016bdc5 100644 (file)
@@ -9,3 +9,4 @@ lock/*
 tags
 cache/htmlpurifier/*/*ser
 lib/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer/*/*ser
+web.config\r
diff --git a/classes/ttrssmailer.php b/classes/ttrssmailer.php
new file mode 100644 (file)
index 0000000..1b450c5
--- /dev/null
@@ -0,0 +1,63 @@
+<?php\r
+/*     @class ttrssMailer\r
+*      @brief A TTRSS extension to the PHPMailer class\r
+*      Configures default values through the __construct() function\r
+*      @author Derek Murawsky\r
+*      @version .1 (alpha)\r
+*\r
+*/\r
+require_once 'lib/phpmailer/class.phpmailer.php';\r
+require_once "config.php";\r
+\r
+class ttrssMailer extends PHPMailer {\r
+\r
+               //define all items that we want to override with defaults in PHPMailer\r
+               public $From = SMTP_FROM_ADDRESS;\r
+               public $FromName = SMTP_FROM_NAME;\r
+               public $CharSet = "UTF-8";\r
+               public $PluginDir = "lib/phpmailer/";\r
+               public $ContentType = "text/html"; //default email type is HTML\r
+               public $Host;\r
+               public $Port;\r
+               public $SMTPAuth=False;\r
+               public $Username;\r
+               public $Password;\r
+       \r
+       function __construct() {\r
+               $this->SetLanguage("en", "lib/phpmailer/language/");\r
+               //if SMTP_HOST is specified, use SMTP to send mail directly\r
+               if (SMTP_HOST) {\r
+                       $Host = SMTP_HOST;\r
+                       $Mailer = "smtp";\r
+               }\r
+               //if SMTP_PORT is specified, assign it. Otherwise default to port 25\r
+               if(SMTP_PORT){\r
+                       $Port = SMTP_PORT;\r
+               }else{\r
+                       $Port = "25";\r
+               }\r
+               \r
+               //if SMTP_LOGIN is specified, set credentials and enable auth\r
+               if(SMTP_LOGIN){\r
+                       $SMTPAuth = true;\r
+                       $Username = SMTP_LOGIN;\r
+                       $Password = SMTP_PASSWORD;\r
+                       }\r
+       }\r
+       /*      @brief a simple mail function to send email using the defaults\r
+       *       This will send an HTML email using the configured defaults\r
+       *       @param $toAddress A string with the recipients email address\r
+       *       @param $toName A string with the recipients name\r
+       *       @param $subject A string with the emails subject\r
+       *       @param $body A string containing the body of the email\r
+       */\r
+       public function quickMail ($toAddress, $toName, $subject, $body, $altbody=""){\r
+               $this->addAddress($toAddress, $toName);\r
+               $this->Subject = $subject;\r
+               $this->Body = $body;\r
+               $rc=$this->send();\r
+               return $rc;\r
+       }\r
+}\r
+\r
+?>
\ No newline at end of file
index a5a7fc3e2dd727a1ec6c66828a7b0fcf3b6ba662..192cb15f923139ab6722f3d8f33bac2382670ee8 100644 (file)
 
        define('SMTP_HOST', '');
        // SMTP Host to send outgoing mail. Blank - use system MTA.
+       
+       define('SMTP_PORT','');
+       // SMTP port to sent outgoing mail. Default is 25.
 
        define('SMTP_LOGIN', '');
        define('SMTP_PASSWORD', '');
index 93ce373a2b8616ffb71e539f13414894e6fcd652..ab29d94326756bc2cb1a6b2b5a645b5e7b10de3f 100644 (file)
@@ -8,7 +8,7 @@
         */
        function send_headlines_digests($link, $debug = false) {
 
-               require_once 'lib/phpmailer/class.phpmailer.php';
+               require_once 'classes/ttrssmailer.php';
 
                $user_limit = 15; // amount of users to process (e.g. emails to send out)
                $limit = 1000; // maximum amount of headlines to include
 
                                        if ($headlines_count > 0) {
 
-                                               $mail = new PHPMailer();
+                                               $mail = new ttrssMailer();
 
-                                               $mail->PluginDir = "lib/phpmailer/";
-                                               $mail->SetLanguage("en", "lib/phpmailer/language/");
-
-                                               $mail->CharSet = "UTF-8";
-
-                                               $mail->From = SMTP_FROM_ADDRESS;
-                                               $mail->FromName = SMTP_FROM_NAME;
-                                               $mail->AddAddress($line["email"], $line["login"]);
-
-                                               if (SMTP_HOST) {
-                                                       $mail->Host = SMTP_HOST;
-                                                       $mail->Mailer = "smtp";
-                                                       $mail->SMTPAuth = SMTP_LOGIN != '';
-                                                       $mail->Username = SMTP_LOGIN;
-                                                       $mail->Password = SMTP_PASSWORD;
-                                               }
-
-                                               $mail->IsHTML(true);
-                                               $mail->Subject = DIGEST_SUBJECT;
-                                               $mail->Body = $digest;
-                                               $mail->AltBody = $digest_text;
-
-                                               $rc = $mail->Send();
+                                               $rc = $mail->quickMail($line["email"], $line["login"] , DIGEST_SUBJECT, $digest, $digest_text);
 
                                                if (!$rc && $debug) print "ERROR: " . $mail->ErrorInfo;
 
index d4a468f6d4079524bbe23b323638ec30baecc14e..80be1434e76e0b5c97df76251d4a40caa9dbca80 100644 (file)
@@ -1,3 +1,3 @@
 <?php # This file has been generated at:  Sat Feb 9 22:34:30 MSK 2013
 define('GENERATED_CONFIG_CHECK', 26);
-$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'AUTH_AUTO_CREATE', 'AUTH_AUTO_LOGIN', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'SPHINX_ENABLED', 'SPHINX_INDEX', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_EXPIRE_TIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_HOST', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'CHECK_FOR_NEW_VERSION', 'ENABLE_GZIP_OUTPUT', 'PLUGINS', 'CONFIG_VERSION'); ?>
+$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'AUTH_AUTO_CREATE', 'AUTH_AUTO_LOGIN', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'SPHINX_ENABLED', 'SPHINX_INDEX', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_EXPIRE_TIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_HOST', 'SMTP_PORT', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'CHECK_FOR_NEW_VERSION', 'ENABLE_GZIP_OUTPUT', 'PLUGINS', 'CONFIG_VERSION'); ?>
index 30a417a1b44104b2caa38f3b57e2580cb962c469..9d92781d70eda70cf30dd204033a5b1071cd4b09 100644 (file)
@@ -137,7 +137,7 @@ class Mail extends Plugin {
        function sendEmail() {
                $secretkey = $_REQUEST['secretkey'];
 
-               require_once 'lib/phpmailer/class.phpmailer.php';
+               require_once 'classes/ttrssmailer.php';
 
                $reply = array();
 
@@ -146,35 +146,18 @@ class Mail extends Plugin {
 
                        $_SESSION['email_secretkey'] = '';
 
-                       $destination = $_REQUEST['destination'];
-                       $subject = $_REQUEST['subject'];
-                       $content = $_REQUEST['content'];
-
                        $replyto = strip_tags($_SESSION['email_replyto']);
                        $fromname = strip_tags($_SESSION['email_fromname']);
 
-                       $mail = new PHPMailer();
-
-                       $mail->PluginDir = "lib/phpmailer/";
-                       $mail->SetLanguage("en", "lib/phpmailer/language/");
-
-                       $mail->CharSet = "UTF-8";
+                       $mail = new ttrssMailer();
 
                        $mail->From = $replyto;
                        $mail->FromName = $fromname;
-                       $mail->AddAddress($destination);
-
-                       if (SMTP_HOST) {
-                               $mail->Host = SMTP_HOST;
-                               $mail->Mailer = "smtp";
-                               $mail->SMTPAuth = SMTP_LOGIN != '';
-                               $mail->Username = SMTP_LOGIN;
-                               $mail->Password = SMTP_PASSWORD;
-                       }
+                       $mail->AddAddress($_REQUEST['destination']);
 
                        $mail->IsHTML(false);
-                       $mail->Subject = $subject;
-                       $mail->Body = $content;
+                       $mail->Subject = $_REQUEST['subject'];
+                       $mail->Body = $_REQUEST['content'];
 
                        $rc = $mail->Send();
 
index 678b3c31785ee4f4a55c9075ac9cda0c5f5f492e..8c9869a52157da6036abd49e3379ae84cd0c0c63 100644 (file)
@@ -7,7 +7,7 @@
        set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
                get_include_path());
 
-       require_once 'lib/phpmailer/class.phpmailer.php';
+       require_once 'classes/ttrssmailer.php';
 
        require_once "functions.php";
        require_once "sessions.php";
                                                "\n".
                                                "If that wasn't you, just ignore this message. Thanks.";
 
-                                       $mail = new PHPMailer();
-
-                                       $mail->PluginDir = "lib/phpmailer/";
-                                       $mail->SetLanguage("en", "lib/phpmailer/language/");
-
-                                       $mail->CharSet = "UTF-8";
-
-                                       $mail->From = SMTP_FROM_ADDRESS;
-                                       $mail->FromName = SMTP_FROM_NAME;
-                                       $mail->AddAddress($email);
-
-                                       if (SMTP_HOST) {
-                                               $mail->Host = SMTP_HOST;
-                                               $mail->Mailer = "smtp";
-                                               $mail->Username = SMTP_LOGIN;
-                                               $mail->Password = SMTP_PASSWORD;
-                                       }
-
-                       //              $mail->IsHTML(true);
-                                       $mail->Subject = "Registration information for Tiny Tiny RSS";
-                                       $mail->Body = $reg_text;
-                       //              $mail->AltBody = $digest_text;
-
-                                       $rc = $mail->Send();
+                                       $mail = new ttrssMailer();
+                                       $mail->IsHTML(false);
+                                       $rc = $mail->quickMail($email, "", "Registration information for Tiny Tiny RSS", $reg_text, false);
 
                                        if (!$rc) print_error($mail->ErrorInfo);
-
+                                       
+                                       unset($reg_text);
+                                       unset($mail);
+                                       unset($rc);
                                        $reg_text = "Hi!\n".
                                                "\n".
                                                "New user had registered at your Tiny Tiny RSS installation.\n".
                                                "\n".
                                                "Login: $login\n".
                                                "Email: $email\n";
-
-                                       $mail = new PHPMailer();
-
-                                       $mail->PluginDir = "lib/phpmailer/";
-                                       $mail->SetLanguage("en", "lib/phpmailer/language/");
-
-                                       $mail->CharSet = "UTF-8";
-
-                                       $mail->From = SMTP_FROM_ADDRESS;
-                                       $mail->FromName = SMTP_FROM_NAME;
-                                       $mail->AddAddress(REG_NOTIFY_ADDRESS);
-
-                                       if (SMTP_HOST) {
-                                               $mail->Host = SMTP_HOST;
-                                               $mail->Mailer = "smtp";
-                                               $mail->Username = SMTP_LOGIN;
-                                               $mail->Password = SMTP_PASSWORD;
-                                       }
-
-                       //              $mail->IsHTML(true);
-                                       $mail->Subject = "Registration notice for Tiny Tiny RSS";
-                                       $mail->Body = $reg_text;
-                       //              $mail->AltBody = $digest_text;
-
-                                       $rc = $mail->Send();
-
+                                       
+                                       
+                                       $mail = new ttrssMailer();
+                                       $mail->IsHTML(false);
+                                       $rc = $mail->quickMail(REG_NOTIFY_ADDRESS, "", "Registration notice for Tiny Tiny RSS", $reg_text, false);
+                                       if (!$rc) print_error($mail->ErrorInfo);
+                                       
                                        print_notice(__("Account created successfully."));
 
                                        print "<p><form method=\"GET\" action=\"index.php\">