diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-04-16 15:55:39 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-04-18 16:59:34 +0200 |
commit | 01278056a568d987a5119573d9831832bd122d6f (patch) | |
tree | ddfa7dbb6d70a268899f9140ac66c1e7c123bd96 /lib | |
parent | fa65aaf1fc8836e1a0e5ee1ffe38ee032a487892 (diff) | |
download | nextcloud-server-01278056a568d987a5119573d9831832bd122d6f.tar.gz nextcloud-server-01278056a568d987a5119573d9831832bd122d6f.zip |
Provide an option to disable HTML emails
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-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 0590f3db12a..542d452afe8 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -92,7 +92,8 @@ class Mailer implements IMailer { * @return IMessage */ public function createMessage() { - 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 4d9458fbd40..4b42b640356 100644 --- a/lib/private/Mail/Message.php +++ b/lib/private/Mail/Message.php @@ -38,12 +38,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, $plainTextOnly) { $this->swiftMessage = $swiftMessage; + $this->plainTextOnly = $plainTextOnly; } /** @@ -245,7 +245,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; } @@ -263,7 +265,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; } @@ -274,7 +278,9 @@ class Message implements IMessage { public function useTemplate(IEMailTemplate $emailTemplate) { $this->setSubject($emailTemplate->renderSubject()); $this->setPlainBody($emailTemplate->renderText()); - $this->setHtmlBody($emailTemplate->renderHtml()); + if (!$this->plainTextOnly) { + $this->setHtmlBody($emailTemplate->renderHtml()); + } return $this; } } |