diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-04-16 15:55:39 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-04-16 19:00:05 +0200 |
commit | 9ee1febf629fa4180c483fb4a2c82559f5c50392 (patch) | |
tree | fc9723ef0eba3b5dad8830cd725169231a35292d /lib/private | |
parent | 056660bf7ce0e587be7276e640e424280ff66804 (diff) | |
download | nextcloud-server-9ee1febf629fa4180c483fb4a2c82559f5c50392.tar.gz nextcloud-server-9ee1febf629fa4180c483fb4a2c82559f5c50392.zip |
Provide an option to disable HTML emails
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Mail/Mailer.php | 3 | ||||
-rw-r--r-- | lib/private/Mail/Message.php | 20 |
2 files changed, 15 insertions, 8 deletions
diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index d55546769ee..001f7bd75c9 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -93,7 +93,8 @@ class Mailer implements IMailer { * @return IMessage */ public function createMessage(): IMessage { - return new Message(new \Swift_Message()); + $plainTextOnly = $this->config->getSystemValue('mail_send_plaintext_only', false); + return new Message(new \Swift_Message(), $plainTextOnly); } /** diff --git a/lib/private/Mail/Message.php b/lib/private/Mail/Message.php index 7c7ecae8578..8a13e2c108c 100644 --- a/lib/private/Mail/Message.php +++ b/lib/private/Mail/Message.php @@ -39,12 +39,12 @@ use Swift_Message; class Message implements IMessage { /** @var Swift_Message */ private $swiftMessage; + /** @var bool */ + private $plainTextOnly; - /** - * @param Swift_Message $swiftMessage - */ - public function __construct(Swift_Message $swiftMessage) { + public function __construct(Swift_Message $swiftMessage, bool $plainTextOnly) { $this->swiftMessage = $swiftMessage; + $this->plainTextOnly = $plainTextOnly; } /** @@ -246,7 +246,9 @@ class Message implements IMessage { * @return $this */ public function setHtmlBody($body) { - $this->swiftMessage->addPart($body, 'text/html'); + if (!$this->plainTextOnly) { + $this->swiftMessage->addPart($body, 'text/html'); + } return $this; } @@ -264,7 +266,9 @@ class Message implements IMessage { * @return $this */ public function setBody($body, $contentType) { - $this->swiftMessage->setBody($body, $contentType); + if (!$this->plainTextOnly || $contentType !== 'text/html') { + $this->swiftMessage->setBody($body, $contentType); + } return $this; } @@ -275,7 +279,9 @@ class Message implements IMessage { public function useTemplate(IEMailTemplate $emailTemplate): IMessage { $this->setSubject($emailTemplate->renderSubject()); $this->setPlainBody($emailTemplate->renderText()); - $this->setHtmlBody($emailTemplate->renderHtml()); + if (!$this->plainTextOnly) { + $this->setHtmlBody($emailTemplate->renderHtml()); + } return $this; } } |