aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Mail/Message.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Mail/Message.php')
-rw-r--r--lib/private/Mail/Message.php90
1 files changed, 34 insertions, 56 deletions
diff --git a/lib/private/Mail/Message.php b/lib/private/Mail/Message.php
index 01beefcc6d6..523a4836760 100644
--- a/lib/private/Mail/Message.php
+++ b/lib/private/Mail/Message.php
@@ -1,33 +1,10 @@
<?php
declare(strict_types=1);
-
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arne Hamann <kontakt+github@arne.email>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Jared Boone <jared.boone@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Mail;
@@ -46,28 +23,21 @@ use Symfony\Component\Mime\Exception\RfcComplianceException;
* @package OC\Mail
*/
class Message implements IMessage {
- private Email $symfonyEmail;
- private bool $plainTextOnly;
-
- private array $to;
- private array $from;
- private array $replyTo;
- private array $cc;
- private array $bcc;
-
- public function __construct(Email $symfonyEmail, bool $plainTextOnly) {
- $this->symfonyEmail = $symfonyEmail;
- $this->plainTextOnly = $plainTextOnly;
- $this->to = [];
- $this->from = [];
- $this->replyTo = [];
- $this->cc = [];
- $this->bcc = [];
+ private array $to = [];
+ private array $from = [];
+ private array $replyTo = [];
+ private array $cc = [];
+ private array $bcc = [];
+
+ public function __construct(
+ private Email $symfonyEmail,
+ private bool $plainTextOnly,
+ ) {
}
/**
- * @return $this
* @since 13.0.0
+ * @return $this
*/
public function attach(IAttachment $attachment): IMessage {
/** @var Attachment $attachment */
@@ -76,6 +46,22 @@ class Message implements IMessage {
}
/**
+ * Can be used to "attach content inline" as message parts with specific MIME type and encoding.
+ * {@inheritDoc}
+ * @since 26.0.0
+ */
+ public function attachInline(string $body, string $name, ?string $contentType = null): IMessage {
+ # To be sure this works with iCalendar messages, we encode with 8bit instead of
+ # quoted-printable encoding. We save the current encoder, replace the current
+ # encoder with an 8bit encoder and after we've finished, we reset the encoder
+ # to the previous one. Originally intended to be added after the message body,
+ # as it is curently unknown if all mail clients handle this properly if added
+ # before.
+ $this->symfonyEmail->embed($body, $name, $contentType);
+ return $this;
+ }
+
+ /**
* Converts the [['displayName' => 'email'], ['displayName2' => 'email2']] arrays to valid Adresses
*
* @param array $addresses Array of mail addresses
@@ -122,7 +108,6 @@ class Message implements IMessage {
/**
* Set the Reply-To address of this message
- *
* @return $this
*/
public function setReplyTo(array $addresses): IMessage {
@@ -192,8 +177,6 @@ class Message implements IMessage {
}
/**
- * Set the subject of this message.
- *
* @return $this
*/
public function setSubject(string $subject): IMessage {
@@ -209,7 +192,6 @@ class Message implements IMessage {
}
/**
- * Set the plain-text body of this message.
* @return $this
*/
public function setPlainBody(string $body): IMessage {
@@ -227,7 +209,6 @@ class Message implements IMessage {
}
/**
- * Set the HTML body of this message. Consider also sending a plain-text body instead of only an HTML one.
* @return $this
*/
public function setHtmlBody(string $body): IMessage {
@@ -238,7 +219,7 @@ class Message implements IMessage {
}
/**
- * Set the underlying Email intance
+ * Set the underlying Email instance
*/
public function setSymfonyEmail(Email $symfonyEmail): void {
$this->symfonyEmail = $symfonyEmail;
@@ -281,10 +262,9 @@ class Message implements IMessage {
* we wrap the calls here. We then have the validation errors all in one place and can
* throw shortly before \OC\Mail\Mailer::send
*
- * @return void
* @throws InvalidArgumentException|RfcComplianceException
*/
- public function setRecipients() {
+ public function setRecipients(): void {
$this->symfonyEmail->to(...$this->convertAddresses($this->getTo()));
$this->symfonyEmail->from(...$this->convertAddresses($this->getFrom()));
$this->symfonyEmail->replyTo(...$this->convertAddresses($this->getReplyTo()));
@@ -332,13 +312,11 @@ class Message implements IMessage {
/**
* Get the current value of the Auto-Submitted header. Defaults to "no"
* which is equivalent to the header not existing at all
- *
- * @return string
*/
public function getAutoSubmitted(): string {
$headers = $this->symfonyEmail->getHeaders();
- return $headers->has(AutoSubmitted::HEADER) ?
- $headers->get(AutoSubmitted::HEADER)->getBodyAsString() : AutoSubmitted::VALUE_NO;
+ return $headers->has(AutoSubmitted::HEADER)
+ ? $headers->get(AutoSubmitted::HEADER)->getBodyAsString() : AutoSubmitted::VALUE_NO;
}
}