Provide an option to disable HTML emails
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
f7d6eb9ab6
commit
7f454fea8e
|
@ -36,7 +36,7 @@ use Test\TestCase;
|
|||
class IMipPluginTest extends TestCase {
|
||||
|
||||
public function testDelivery() {
|
||||
$mailMessage = new \OC\Mail\Message(new \Swift_Message());
|
||||
$mailMessage = new \OC\Mail\Message(new \Swift_Message(), false);
|
||||
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
|
||||
$mailer = $this->getMockBuilder('OC\Mail\Mailer')->disableOriginalConstructor()->getMock();
|
||||
$mailer->method('createMessage')->willReturn($mailMessage);
|
||||
|
@ -68,7 +68,7 @@ class IMipPluginTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testFailedDelivery() {
|
||||
$mailMessage = new \OC\Mail\Message(new \Swift_Message());
|
||||
$mailMessage = new \OC\Mail\Message(new \Swift_Message(), false);
|
||||
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
|
||||
$mailer = $this->getMockBuilder('OC\Mail\Mailer')->disableOriginalConstructor()->getMock();
|
||||
$mailer->method('createMessage')->willReturn($mailMessage);
|
||||
|
@ -103,7 +103,7 @@ class IMipPluginTest extends TestCase {
|
|||
* @dataProvider dataNoMessageSendForPastEvents
|
||||
*/
|
||||
public function testNoMessageSendForPastEvents($veventParams, $expectsMail) {
|
||||
$mailMessage = new \OC\Mail\Message(new \Swift_Message());
|
||||
$mailMessage = new \OC\Mail\Message(new \Swift_Message(), false);
|
||||
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
|
||||
$mailer = $this->getMockBuilder('OC\Mail\Mailer')->disableOriginalConstructor()->getMock();
|
||||
$mailer->method('createMessage')->willReturn($mailMessage);
|
||||
|
|
|
@ -383,6 +383,18 @@ $CONFIG = array(
|
|||
*/
|
||||
'mail_smtppassword' => '',
|
||||
|
||||
/**
|
||||
* Replaces the default mail template layout. This can be utilized if the
|
||||
* options to modify the mail texts with the theming app is not enough.
|
||||
* The class must extend ``\OC\Mail\EMailTemplate``
|
||||
*/
|
||||
'mail_template_class' => '\OC\Mail\EMailTemplate',
|
||||
|
||||
/**
|
||||
* Email will be send by default with an HTML and a plain text body. This option
|
||||
* allows to only send plain text emails.
|
||||
*/
|
||||
'mail_send_plaintext_only' => false,
|
||||
|
||||
/**
|
||||
* Proxy Configurations
|
||||
|
@ -985,13 +997,6 @@ $CONFIG = array(
|
|||
*/
|
||||
'systemtags.managerFactory' => '\OC\SystemTag\ManagerFactory',
|
||||
|
||||
/**
|
||||
* Replaces the default mail template layout. This can be utilized if the
|
||||
* options to modify the mail texts with the theming app is not enough.
|
||||
* The class must extend ``\OC\Mail\EMailTemplate``
|
||||
*/
|
||||
'mail_template_class' => '\OC\Mail\EMailTemplate',
|
||||
|
||||
/**
|
||||
* Maintenance
|
||||
*
|
||||
|
|
|
@ -87,7 +87,8 @@ class Mailer implements IMailer {
|
|||
* @return Message
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,12 +33,12 @@ use Swift_Message;
|
|||
class Message {
|
||||
/** @var Swift_Message */
|
||||
private $swiftMessage;
|
||||
/** @var bool */
|
||||
private $plainTextOnly;
|
||||
|
||||
/**
|
||||
* @param Swift_Message $swiftMessage
|
||||
*/
|
||||
function __construct(Swift_Message $swiftMessage) {
|
||||
public function __construct(Swift_Message $swiftMessage, $plainTextOnly) {
|
||||
$this->swiftMessage = $swiftMessage;
|
||||
$this->plainTextOnly = $plainTextOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -229,7 +229,9 @@ class Message {
|
|||
* @return $this
|
||||
*/
|
||||
public function setHtmlBody($body) {
|
||||
$this->swiftMessage->addPart($body, 'text/html');
|
||||
if (!$this->plainTextOnly) {
|
||||
$this->swiftMessage->addPart($body, 'text/html');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -247,7 +249,9 @@ class Message {
|
|||
* @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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,6 +95,11 @@ class MailerTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testCreateMessage() {
|
||||
$this->config
|
||||
->expects($this->any())
|
||||
->method('getSystemValue')
|
||||
->with('mail_send_plaintext_only', false)
|
||||
->will($this->returnValue(false));
|
||||
$this->assertInstanceOf('\OC\Mail\Message', $this->mailer->createMessage());
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
namespace Test\Mail;
|
||||
|
||||
use OC\Mail\Message;
|
||||
use OCP\Mail\IEMailTemplate;
|
||||
use Swift_Message;
|
||||
use Test\TestCase;
|
||||
|
||||
|
@ -36,7 +37,7 @@ class MessageTest extends TestCase {
|
|||
$this->swiftMessage = $this->getMockBuilder('\Swift_Message')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
|
||||
$this->message = new Message($this->swiftMessage);
|
||||
$this->message = new Message($this->swiftMessage, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue