diff options
author | Branko Kokanovic <branko@kokanovic.org> | 2018-11-30 21:06:44 +0100 |
---|---|---|
committer | Branko Kokanovic <branko@kokanovic.org> | 2018-11-30 22:36:03 +0100 |
commit | 72d97b44a752dc850f35c5ba830ae49bf3471815 (patch) | |
tree | b5ec24fa2c5c517b99024f1b98bc3eedf3ca66f7 | |
parent | cae600d205572d38f6215e5e250f9bf5d89e64ff (diff) | |
download | nextcloud-server-72d97b44a752dc850f35c5ba830ae49bf3471815.tar.gz nextcloud-server-72d97b44a752dc850f35c5ba830ae49bf3471815.zip |
Expose Swift Mailer streaming options in config, fixes #12702
Signed-off-by: Branko Kokanovic <branko@kokanovic.org>
-rw-r--r-- | config/config.sample.php | 7 | ||||
-rw-r--r-- | lib/private/Mail/Mailer.php | 4 | ||||
-rw-r--r-- | tests/lib/Mail/MailerTest.php | 22 |
3 files changed, 33 insertions, 0 deletions
diff --git a/config/config.sample.php b/config/config.sample.php index 7a86070c18f..299e67c98fe 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -422,6 +422,13 @@ $CONFIG = array( 'mail_send_plaintext_only' => false, /** + * This depends on ``mail_smtpmode``. Array of additional streams options that + * will be passed to underlying Swift mailer implementation. + * Defaults to an empty array. + */ +'mail_smtpstreamoptions' => array(), + +/** * Which mode is used for sendmail/qmail: ``smtp`` or ``pipe``. * * For ``smtp`` the sendmail binary is started with the parameter ``-bs``: diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 7a8b4ad2599..2dad72b5b12 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -259,6 +259,10 @@ class Mailer implements IMailer { if (!empty($smtpSecurity)) { $transport->setEncryption($smtpSecurity); } + $streamingOptions = $this->config->getSystemValue('mail_smtpstreamoptions', array()); + if (is_array($streamingOptions) && count($streamingOptions) > 0) { + $transport->setStreamOptions($streamingOptions); + } return $transport; } diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index 4117498885c..8c309335ab8 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -167,4 +167,26 @@ class MailerTest extends TestCase { $this->assertSame(EMailTemplate::class, get_class($this->mailer->createEMailTemplate('tests.MailerTest'))); } + + public function testStreamingOptions() { + $this->config->method('getSystemValue') + ->will($this->returnValueMap([ + ['mail_smtpmode', 'smtp', 'smtp'], + ['mail_smtpstreamoptions', array(), array('foo' => 1)] + ])); + $mailer = self::invokePrivate($this->mailer, 'getInstance'); + $this->assertEquals(1, count($mailer->getTransport()->getStreamOptions())); + $this->assertTrue(isset($mailer->getTransport()->getStreamOptions()['foo'])); + + } + + public function testStreamingOptionsWrongType() { + $this->config->method('getSystemValue') + ->will($this->returnValueMap([ + ['mail_smtpmode', 'smtp', 'smtp'], + ['mail_smtpstreamoptions', array(), 'bar'] + ])); + $mailer = self::invokePrivate($this->mailer, 'getInstance'); + $this->assertEquals(0, count($mailer->getTransport()->getStreamOptions())); + } } |