]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Email.php
Change Mastodon API documentation URL for V1 Instance type
[friendica.git] / src / Object / Email.php
index 32d1382831702985e41f82c527a847daf6b8ed7c..f6a72985231af6b58c42518f5664a5069fc1edc4 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Object;
 
@@ -28,14 +47,14 @@ class Email implements IEmail
        /** @var string */
        private $msgText;
 
-       /** @var string */
-       private $additionalMailHeader = '';
+       /** @var string[][] */
+       private $additionalMailHeader;
        /** @var int|null */
-       private $toUid = null;
+       private $toUid;
 
        public function __construct(string $fromName, string $fromAddress, string $replyTo, string $toAddress,
                                    string $subject, string $msgHtml, string $msgText,
-                                   string $additionalMailHeader = '', int $toUid = null)
+                                   array $additionalMailHeader = [], int $toUid = null)
        {
                $this->fromName             = $fromName;
                $this->fromAddress          = $fromAddress;
@@ -91,12 +110,12 @@ class Email implements IEmail
        /**
         * {@inheritDoc}
         */
-       public function getMessage(bool $plain = false)
+       public function getMessage(bool $plain = false): string
        {
                if ($plain) {
                        return $this->msgText;
                } else {
-                       return $this->msgHtml;
+                       return $this->msgHtml ?? '';
                }
        }
 
@@ -108,6 +127,26 @@ class Email implements IEmail
                return $this->additionalMailHeader;
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       public function getAdditionalMailHeaderString()
+       {
+               $headerString = '';
+
+               foreach ($this->additionalMailHeader as $name => $values) {
+                       if (!is_array($values)) {
+                               $values = [$values];
+                       }
+
+                       foreach ($values as $value) {
+                               $headerString .= "$name: $value\r\n";
+                       }
+               }
+
+               return $headerString;
+       }
+
        /**
         * {@inheritDoc}
         */
@@ -161,6 +200,7 @@ class Email implements IEmail
        /**
         * @inheritDoc
         */
+       #[\ReturnTypeWillChange]
        public function jsonSerialize()
        {
                return $this->toArray();