]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Emailer.php
Changes:
[friendica.git] / src / Util / Emailer.php
index ed6c7b331b29a7c4d133bb58d774848da6d0afad..f304363cab9f3073c249b7d5f7adae66469e5693 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2024, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 namespace Friendica\Util;
 
 use Friendica\App;
-use Friendica\Core\Config\IConfig;
+use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
-use Friendica\Core\PConfig\IPConfig;
+use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Object\EMail\IEmail;
 use Friendica\Protocol\Email;
@@ -38,9 +38,9 @@ use Psr\Log\LoggerInterface;
  */
 class Emailer
 {
-       /** @var IConfig */
+       /** @var IManageConfigValues */
        private $config;
-       /** @var IPConfig */
+       /** @var IManagePersonalConfigValues */
        private $pConfig;
        /** @var LoggerInterface */
        private $logger;
@@ -54,7 +54,7 @@ class Emailer
        /** @var string */
        private $siteEmailName;
 
-       public function __construct(IConfig $config, IPConfig $pConfig, App\BaseURL $baseURL, LoggerInterface $logger,
+       public function __construct(IManageConfigValues $config, IManagePersonalConfigValues $pConfig, App\BaseURL $baseURL, LoggerInterface $logger,
                                    L10n $defaultLang)
        {
                $this->config      = $config;
@@ -65,7 +65,7 @@ class Emailer
 
                $this->siteEmailAddress = $this->config->get('config', 'sender_email');
                if (empty($this->siteEmailAddress)) {
-                       $hostname = $this->baseUrl->getHostname();
+                       $hostname = $this->baseUrl->getHost();
                        if (strpos($hostname, ':')) {
                                $hostname = substr($hostname, 0, strpos($hostname, ':'));
                        }
@@ -126,7 +126,7 @@ class Emailer
         * @return bool
         * @throws InternalServerErrorException
         */
-       public function send(IEmail $email)
+       public function send(IEmail $email): bool
        {
                Hook::callAll('emailer_send_prepare', $email);
 
@@ -141,7 +141,7 @@ class Emailer
                                $countMessageId += count($value);
                        }
                }
-               if ($countMessageId > 0) {
+               if ($countMessageId > 1) {
                        $this->logger->warning('More than one Message-ID found - RFC violation', ['email' => $email]);
                }
 
@@ -151,7 +151,7 @@ class Emailer
                }
 
                $fromName       = Email::encodeHeader(html_entity_decode($email->getFromName(), ENT_QUOTES, 'UTF-8'), 'UTF-8');
-               $fromAddress      = $email->getFromAddress();
+               $fromAddress    = $email->getFromAddress();
                $replyTo        = $email->getReplyTo();
                $messageSubject = Email::encodeHeader(html_entity_decode($email->getSubject(), ENT_QUOTES, 'UTF-8'), 'UTF-8');
 
@@ -161,12 +161,17 @@ class Emailer
                                . rand(100000000, 999999999) . '=:'
                                . rand(10000, 99999);
 
+               $messageHeader = $email->getAdditionalMailHeaderString();
+               if ($countMessageId === 0) {
+                       $messageHeader .= 'Message-ID: <Friendica-Util-Emailer-' . Strings::getRandomHex() . '@' . $this->baseUrl->getHost() . '>' . "\r\n";
+               }
+
                // generate a multipart/alternative message header
-               $messageHeader = $email->getAdditionalMailHeaderString() .
-                                "From: $fromName <{$fromAddress}>\n" .
-                                "Reply-To: $fromName <{$replyTo}>\n" .
-                                "MIME-Version: 1.0\n" .
-                                "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
+               $messageHeader .=
+                       "From: $fromName <{$fromAddress}>\r\n" .
+                       "Reply-To: $fromName <{$replyTo}>\r\n" .
+                       "MIME-Version: 1.0\r\n" .
+                       "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
 
                // assemble the final multipart message body with the text and html types included
                $textBody             = chunk_split(base64_encode($email->getMessage(true)));