diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-06-08 10:26:56 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-07-04 08:28:33 +0200 |
commit | be7db1573dc8c6e7309ec9db124a7a74b8b41199 (patch) | |
tree | ce507dafb77d2e2b8832ec717598235b14dbc886 /lib/private/Mail/Mailer.php | |
parent | e6e6b5648a1d47708c3fc8320ad7c3e4e2d41f84 (diff) | |
download | nextcloud-server-be7db1573dc8c6e7309ec9db124a7a74b8b41199.tar.gz nextcloud-server-be7db1573dc8c6e7309ec9db124a7a74b8b41199.zip |
Swift to \Swift_Mailer as abstraction
* \Swift_Mailer handles starting the transport etc properly
* Fixed tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Mail/Mailer.php')
-rw-r--r-- | lib/private/Mail/Mailer.php | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 8fb8188de5e..6f148bc0c6e 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -57,7 +57,7 @@ use OCP\Mail\IMessage; * @package OC\Mail */ class Mailer implements IMailer { - /** @var \Swift_SmtpTransport|\Swift_SendmailTransport Cached transport */ + /** @var \Swift_Mailer Cached mailer */ private $instance = null; /** @var IConfig */ private $config; @@ -220,27 +220,24 @@ class Mailer implements IMailer { return $name.'@'.$domain; } - /** - * Returns whatever transport is configured within the config - * - * @return \Swift_SmtpTransport|\Swift_SendmailTransport - */ - protected function getInstance() { + protected function getInstance(): \Swift_Mailer { if (!is_null($this->instance)) { return $this->instance; } + $transport = null; + switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { case 'sendmail': - $this->instance = $this->getSendMailInstance(); + $transport = $this->getSendMailInstance(); break; case 'smtp': default: - $this->instance = $this->getSmtpInstance(); + $transport = $this->getSmtpInstance(); break; } - return $this->instance; + return new \Swift_Mailer($transport); } /** @@ -262,7 +259,7 @@ class Mailer implements IMailer { if (!empty($smtpSecurity)) { $transport->setEncryption($smtpSecurity); } - $transport->start(); + return $transport; } @@ -272,7 +269,7 @@ class Mailer implements IMailer { * @return \Swift_SendmailTransport */ protected function getSendMailInstance(): \Swift_SendmailTransport { - switch ($this->config->getSystemValue('mail_smtpmode', 'smpt')) { + switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { case 'qmail': $binaryPath = '/var/qmail/bin/sendmail'; break; |