]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Emailer.php
Merge pull request #8147 from annando/fetch-post
[friendica.git] / src / Util / Emailer.php
index cccf8c2fab349c5573afc555e188a31e7f8239ea..41835b6609b7abe210cb91836645d71d1df2ee3f 100644 (file)
@@ -4,14 +4,13 @@
  */
 namespace Friendica\Util;
 
-use Friendica\Core\Config;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
-use Friendica\Core\PConfig;
+use Friendica\DI;
 use Friendica\Protocol\Email;
 
 /**
- * @brief class to handle emailing
+ * class to handle emailing
  */
 class Emailer
 {
@@ -29,16 +28,22 @@ class Emailer
         *                      additionalMailHeader additions to the SMTP mail header
         *                      optional             uid user id of the destination user
         *
-        * @return object
+        * @return bool
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function send($params)
+       public static function send(array $params)
        {
+               $params['sent'] = false;
+
                Hook::callAll('emailer_send_prepare', $params);
 
+               if ($params['sent']) {
+                       return true;
+               }
+
                $email_textonly = false;
                if (!empty($params['uid'])) {
-                       $email_textonly = PConfig::get($params['uid'], "system", "email_textonly");
+                       $email_textonly = DI::pConfig()->get($params['uid'], "system", "email_textonly");
                }
 
                $fromName = Email::encodeHeader(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
@@ -51,7 +56,7 @@ class Emailer
                                .rand(10000, 99999);
 
                // generate a multipart/alternative message header
-               $messageHeader = defaults($params, 'additionalMailHeader', '') .
+               $messageHeader = ($params['additionalMailHeader'] ?? '') .
                                                "From: $fromName <{$params['fromEmail']}>\n" .
                                                "Reply-To: $fromName <{$params['replyTo']}>\n" .
                                                "MIME-Version: 1.0\n" .
@@ -75,7 +80,7 @@ class Emailer
                $multipartMessageBody .=
                        "--" . $mimeBoundary . "--\n";                                  // message ending
 
-               if (Config::get("system", "sendmail_params", true)) {
+               if (DI::config()->get("system", "sendmail_params", true)) {
                        $sendmail_params = '-f ' . $params['fromEmail'];
                } else {
                        $sendmail_params = null;
@@ -87,11 +92,16 @@ class Emailer
                        'subject' => $messageSubject,
                        'body' => $multipartMessageBody,
                        'headers' => $messageHeader,
-                       'parameters' => $sendmail_params
+                       'parameters' => $sendmail_params,
+                       'sent' => false,
                ];
 
                Hook::callAll("emailer_send", $hookdata);
 
+               if ($hookdata['sent']) {
+                       return true;
+               }
+
                $res = mail(
                        $hookdata['to'],
                        $hookdata['subject'],