summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-11-22 14:45:14 +0300
committerAndrew Dolgov <[email protected]>2018-11-22 14:45:14 +0300
commit57932e183745bada9c6183056597cb5276f68d10 (patch)
tree7d64a815dd4bbf40dec51ee95be16c4ef7f7a212 /classes
parent643d1919cc27a80aff424970b337e83be72720d1 (diff)
remove PHPMailer and related directives from config.php-dist; add pluggable Mailer class
Diffstat (limited to 'classes')
-rw-r--r--classes/digest.php15
-rwxr-xr-xclasses/handler/public.php11
-rw-r--r--classes/mailer.php43
-rwxr-xr-xclasses/pluginhost.php1
-rw-r--r--classes/pref/users.php14
-rw-r--r--classes/ttrssmailer.php63
6 files changed, 64 insertions, 83 deletions
diff --git a/classes/digest.php b/classes/digest.php
index 75dda4984..641fbe97f 100644
--- a/classes/digest.php
+++ b/classes/digest.php
@@ -11,8 +11,6 @@ class Digest
*/
static function send_headlines_digests($debug = false) {
- 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
@@ -56,11 +54,16 @@ class Digest
if ($headlines_count > 0) {
- $mail = new ttrssMailer();
+ $mailer = new Mailer();
+
+ //$rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text);
- $rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text);
+ $rc = $mailer->mail(["to" => $line["login"] . " <" . $line["email"] . ">",
+ "subject" => DIGEST_SUBJECT,
+ "message" => $digest_text,
+ "message_html" => $digest]);
- if (!$rc && $debug) _debug("ERROR: " . $mail->ErrorInfo);
+ //if (!$rc && $debug) _debug("ERROR: " . $mailer->lastError());
if ($debug) _debug("RC=$rc");
@@ -198,4 +201,4 @@ class Digest
return array($tmp, $headlines_count, $affected_ids, $tmp_t);
}
-} \ No newline at end of file
+}
diff --git a/classes/handler/public.php b/classes/handler/public.php
index dbed3fee6..cadb9873d 100755
--- a/classes/handler/public.php
+++ b/classes/handler/public.php
@@ -777,7 +777,6 @@ class Handler_Public extends Handler {
$resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
"&login=" . urlencode($login);
- require_once 'classes/ttrssmailer.php';
require_once "lib/MiniTemplator.class.php";
$tpl = new MiniTemplator;
@@ -793,13 +792,13 @@ class Handler_Public extends Handler {
$tpl->generateOutputToString($message);
- $mail = new ttrssMailer();
+ $mailer = new Mailer();
- $rc = $mail->quickMail($email, $login,
- __("[tt-rss] Password reset request"),
- $message, false);
+ $rc = $mailer->mail(["to" => "$login <$email>",
+ "subject" => __("[tt-rss] Password reset request"),
+ "message" => $message]);
- if (!$rc) print_error($mail->ErrorInfo);
+ if (!$rc) print_error($mailer->error());
$resetpass_token_full = time() . ":" . $resetpass_token;
diff --git a/classes/mailer.php b/classes/mailer.php
new file mode 100644
index 000000000..ae22776d4
--- /dev/null
+++ b/classes/mailer.php
@@ -0,0 +1,43 @@
+<?php
+class Mailer {
+ // TODO: support HTML mail (i.e. MIME messages)
+
+ private $last_error = "Unable to send mail: check local configuration.";
+
+ function mail($params) {
+
+ $to = $params["to"];
+ $subject = $params["subject"];
+ $message = $params["message"];
+ $message_html = $params["message_html"];
+ $from = $params["from"] ? $params["from"] : SMTP_FROM_NAME . " <" . SMTP_FROM_ADDRESS . ">";
+ $additional_headers = $params["headers"] ? $params["headers"] : [];
+
+ $headers[] = "From: $from";
+
+ Logger::get()->log("Sending mail from $from to $to [$subject]: $message");
+
+ // HOOK_SEND_MAIL plugin instructions:
+ // 1. return 1 or true if mail is handled
+ // 2. return -1 if there's been a fatal error and no further action is allowed
+ // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function
+ // 4. set error message if needed via passed Mailer instance function set_error()
+
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) {
+ $rc = $p->hook_send_mail($this, $params);
+
+ if ($rc == 1 || $rc == -1)
+ return $rc;
+ }
+
+ return mail($to, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers)));
+ }
+
+ function set_error($message) {
+ $this->last_error = $message;
+ }
+
+ function error($value) {
+ return $this->last_error;
+ }
+}
diff --git a/classes/pluginhost.php b/classes/pluginhost.php
index 5c545d18b..f40705dd1 100755
--- a/classes/pluginhost.php
+++ b/classes/pluginhost.php
@@ -57,6 +57,7 @@ class PluginHost {
const HOOK_FEED_BASIC_INFO = 36;
const HOOK_SEND_LOCAL_FILE = 37;
const HOOK_UNSUBSCRIBE_FEED = 38;
+ const HOOK_SEND_MAIL = 39;
const KIND_ALL = 1;
const KIND_SYSTEM = 2;
diff --git a/classes/pref/users.php b/classes/pref/users.php
index ab8ac775b..ad48e7a72 100644
--- a/classes/pref/users.php
+++ b/classes/pref/users.php
@@ -287,8 +287,6 @@ class Pref_Users extends Handler_Protected {
print_notice(T_sprintf("Sending new password of user <b>%s</b> to <b>%s</b>", $login, $email));
}
- require_once 'classes/ttrssmailer.php';
-
if ($email) {
require_once "lib/MiniTemplator.class.php";
@@ -305,13 +303,13 @@ class Pref_Users extends Handler_Protected {
$tpl->generateOutputToString($message);
- $mail = new ttrssMailer();
+ $mailer = new Mailer();
- $rc = $mail->quickMail($email, $login,
- __("[tt-rss] Password change notification"),
- $message, false);
+ $rc = $mailer->mail(["to" => "$login <$email>",
+ "subject" => __("[tt-rss] Password change notification"),
+ "message" => $message]);
- if (!$rc) print_error($mail->ErrorInfo);
+ if (!$rc) print_error($mailer->error());
}
}
@@ -458,4 +456,4 @@ class Pref_Users extends Handler_Protected {
print "</div>"; #container
}
- } \ No newline at end of file
+ }
diff --git a/classes/ttrssmailer.php b/classes/ttrssmailer.php
deleted file mode 100644
index cd10b7cb3..000000000
--- a/classes/ttrssmailer.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-/* @class ttrssMailer
-* @brief A TTRSS extension to the PHPMailer class
-* Configures default values through the __construct() function
-* @author Derek Murawsky
-* @version .1 (alpha)
-*
-*/
-require_once 'lib/phpmailer/class.phpmailer.php';
-require_once 'lib/phpmailer/class.smtp.php';
-require_once "config.php";
-
-class ttrssMailer extends PHPMailer {
-
- //define all items that we want to override with defaults in PHPMailer
- public $From = SMTP_FROM_ADDRESS;
- public $FromName = SMTP_FROM_NAME;
- public $CharSet = "UTF-8";
- public $PluginDir = "lib/phpmailer/";
- public $ContentType = "text/html"; //default email type is HTML
-
- function __construct() {
- $this->SetLanguage("en", "lib/phpmailer/language/");
-
- if (SMTP_SERVER) {
- $pair = explode(":", SMTP_SERVER, 2);
- $this->Mailer = "smtp";
-
- $this->Host = $pair[0];
- $this->Port = $pair[1];
-
- if (!$this->Port) $this->Port = 25;
- } else {
- $this->Host = '';
- $this->Port = '';
- }
-
-
- //if SMTP_LOGIN is specified, set credentials and enable auth
- if(SMTP_LOGIN){
- $this->SMTPAuth = true;
- $this->Username = SMTP_LOGIN;
- $this->Password = SMTP_PASSWORD;
- }
- if(SMTP_SECURE)
- $this->SMTPSecure = SMTP_SECURE;
- }
- /* @brief a simple mail function to send email using the defaults
- * This will send an HTML email using the configured defaults
- * @param $toAddress A string with the recipients email address
- * @param $toName A string with the recipients name
- * @param $subject A string with the emails subject
- * @param $body A string containing the body of the email
- */
- public function quickMail ($toAddress, $toName, $subject, $body, $altbody=""){
- $this->addAddress($toAddress, $toName);
- $this->Subject = $subject;
- $this->Body = $body;
- $this->IsHTML($altbody != '');
- $rc=$this->send();
- return $rc;
- }
-} \ No newline at end of file