Skip to content

Commit

Permalink
Expose Swift Mailer streaming options in config, fixes nextcloud#12702
Browse files Browse the repository at this point in the history
  • Loading branch information
stalker314314 committed Nov 30, 2018
1 parent cae600d commit 8b7fc09
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@
*/
'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``.
*
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ protected function getSmtpInstance(): \Swift_SmtpTransport {
if (!empty($smtpSecurity)) {
$transport->setEncryption($smtpSecurity);
}
$streamingOptions = $this->config->getSystemValue('mail_smtpstreamoptions', array());
if (count($streamingOptions) > 0) {
$transport->setStreamOptions($streamingOptions);
}

return $transport;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/Mail/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,15 @@ public function testCreateEMailTemplate() {

$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']));
}
}

0 comments on commit 8b7fc09

Please sign in to comment.