File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 383383 */
384384'mail_smtppassword ' => '' ,
385385
386+ /**
387+ * Replaces the default mail template layout. This can be utilized if the
388+ * options to modify the mail texts with the theming app is not enough.
389+ * The class must extend ``\OC\Mail\EMailTemplate``
390+ */
391+ 'mail_template_class ' => '\OC\Mail\EMailTemplate ' ,
392+
393+ /**
394+ * Email will be send by default with an HTML and a plain text body. This option
395+ * allows to only send plain text emails.
396+ */
397+ 'mail_send_plaintext_only ' => false ,
386398
387399/**
388400 * Proxy Configurations
985997 */
986998'systemtags.managerFactory ' => '\OC\SystemTag\ManagerFactory ' ,
987999
988- /**
989- * Replaces the default mail template layout. This can be utilized if the
990- * options to modify the mail texts with the theming app is not enough.
991- * The class must extend ``\OC\Mail\EMailTemplate``
992- */
993- 'mail_template_class ' => '\OC\Mail\EMailTemplate ' ,
994-
9951000/**
9961001 * Maintenance
9971002 *
Original file line number Diff line number Diff line change @@ -87,7 +87,8 @@ public function __construct(IConfig $config,
8787 * @return Message
8888 */
8989 public function createMessage () {
90- return new Message (new \Swift_Message ());
90+ $ plainTextOnly = $ this ->config ->getSystemValue ('mail_send_plaintext_only ' , false );
91+ return new Message (new \Swift_Message (), $ plainTextOnly );
9192 }
9293
9394 /**
Original file line number Diff line number Diff line change 3333class Message {
3434 /** @var Swift_Message */
3535 private $ swiftMessage ;
36+ /** @var bool */
37+ private $ plainTextOnly ;
3638
37- /**
38- * @param Swift_Message $swiftMessage
39- */
40- function __construct (Swift_Message $ swiftMessage ) {
39+ public function __construct (Swift_Message $ swiftMessage , $ plainTextOnly ) {
4140 $ this ->swiftMessage = $ swiftMessage ;
41+ $ this ->plainTextOnly = $ plainTextOnly ;
4242 }
4343
4444 /**
@@ -229,7 +229,9 @@ public function getPlainBody() {
229229 * @return $this
230230 */
231231 public function setHtmlBody ($ body ) {
232- $ this ->swiftMessage ->addPart ($ body , 'text/html ' );
232+ if (!$ this ->plainTextOnly ) {
233+ $ this ->swiftMessage ->addPart ($ body , 'text/html ' );
234+ }
233235 return $ this ;
234236 }
235237
@@ -247,7 +249,9 @@ public function getSwiftMessage() {
247249 * @return $this
248250 */
249251 public function setBody ($ body , $ contentType ) {
250- $ this ->swiftMessage ->setBody ($ body , $ contentType );
252+ if (!$ this ->plainTextOnly || $ contentType !== 'text/html ' ) {
253+ $ this ->swiftMessage ->setBody ($ body , $ contentType );
254+ }
251255 return $ this ;
252256 }
253257}
Original file line number Diff line number Diff line change @@ -95,6 +95,11 @@ public function testGetInstanceSendmail() {
9595 }
9696
9797 public function testCreateMessage () {
98+ $ this ->config
99+ ->expects ($ this ->any ())
100+ ->method ('getSystemValue ' )
101+ ->with ('mail_send_plaintext_only ' , false )
102+ ->will ($ this ->returnValue (false ));
98103 $ this ->assertInstanceOf ('\OC\Mail\Message ' , $ this ->mailer ->createMessage ());
99104 }
100105
Original file line number Diff line number Diff line change 99namespace Test \Mail ;
1010
1111use OC \Mail \Message ;
12+ use OCP \Mail \IEMailTemplate ;
1213use Swift_Message ;
1314use Test \TestCase ;
1415
@@ -36,7 +37,7 @@ function setUp() {
3637 $ this ->swiftMessage = $ this ->getMockBuilder ('\Swift_Message ' )
3738 ->disableOriginalConstructor ()->getMock ();
3839
39- $ this ->message = new Message ($ this ->swiftMessage );
40+ $ this ->message = new Message ($ this ->swiftMessage , false );
4041 }
4142
4243 /**
You can’t perform that action at this time.
0 commit comments