diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2018-07-06 10:39:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-06 10:39:09 +0200 |
commit | 3ade347b0d072a287dbc183d3651ff59fd36f537 (patch) | |
tree | 2cf5886ebd2a0e385ee8bcff7c3863df00653572 /lib/private | |
parent | 8969e100a0f6115319b10c656ffaf343d1aff11f (diff) | |
parent | 6a0c54d5bfd70baeed2438ac05278a9b4cb73d88 (diff) | |
download | nextcloud-server-3ade347b0d072a287dbc183d3651ff59fd36f537.tar.gz nextcloud-server-3ade347b0d072a287dbc183d3651ff59fd36f537.zip |
Merge pull request #9791 from nextcloud/3rdparty/noid/bump_swiftmailer
Upgrade to swiftmailer-6
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Mail/Mailer.php | 53 | ||||
-rw-r--r-- | lib/private/Settings/Admin/Mail.php | 4 |
2 files changed, 24 insertions, 33 deletions
diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 001f7bd75c9..6f148bc0c6e 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -26,6 +26,8 @@ declare(strict_types=1); namespace OC\Mail; +use Egulias\EmailValidator\EmailValidator; +use Egulias\EmailValidator\Validation\RFCValidation; use OCP\Defaults; use OCP\IConfig; use OCP\IL10N; @@ -55,7 +57,7 @@ use OCP\Mail\IMessage; * @package OC\Mail */ class Mailer implements IMailer { - /** @var \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport Cached transport */ + /** @var \Swift_Mailer Cached mailer */ private $instance = null; /** @var IConfig */ private $config; @@ -105,7 +107,7 @@ class Mailer implements IMailer { * @since 13.0.0 */ public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment { - return new Attachment(\Swift_Attachment::newInstance($data, $filename, $contentType)); + return new Attachment(new \Swift_Attachment($data, $filename, $contentType)); } /** @@ -194,7 +196,10 @@ class Mailer implements IMailer { * @return bool True if the mail address is valid, false otherwise */ public function validateMailAddress(string $email): bool { - return \Swift_Validate::email($this->convertEmail($email)); + $validator = new EmailValidator(); + $validation = new RFCValidation(); + + return $validator->isValid($this->convertEmail($email), $validation); } /** @@ -215,32 +220,24 @@ class Mailer implements IMailer { return $name.'@'.$domain; } - /** - * Returns whatever transport is configured within the config - * - * @return \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport - */ - protected function getInstance() { + protected function getInstance(): \Swift_Mailer { if (!is_null($this->instance)) { return $this->instance; } - switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { - case 'smtp': - $this->instance = $this->getSmtpInstance(); - break; + $transport = null; + + switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { case 'sendmail': - // FIXME: Move into the return statement but requires proper testing - // for SMTP and mail as well. Thus not really doable for a - // minor release. - $this->instance = \Swift_Mailer::newInstance($this->getSendMailInstance()); + $transport = $this->getSendMailInstance(); break; + case 'smtp': default: - $this->instance = $this->getMailInstance(); + $transport = $this->getSmtpInstance(); break; } - return $this->instance; + return new \Swift_Mailer($transport); } /** @@ -249,7 +246,7 @@ class Mailer implements IMailer { * @return \Swift_SmtpTransport */ protected function getSmtpInstance(): \Swift_SmtpTransport { - $transport = \Swift_SmtpTransport::newInstance(); + $transport = new \Swift_SmtpTransport(); $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1')); $transport->setPort($this->config->getSystemValue('mail_smtpport', 25)); @@ -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', 'php')) { + switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { case 'qmail': $binaryPath = '/var/qmail/bin/sendmail'; break; @@ -281,16 +278,6 @@ class Mailer implements IMailer { break; } - return \Swift_SendmailTransport::newInstance($binaryPath . ' -bs'); + return new \Swift_SendmailTransport($binaryPath . ' -bs'); } - - /** - * Returns the mail transport - * - * @return \Swift_MailTransport - */ - protected function getMailInstance(): \Swift_MailTransport { - return \Swift_MailTransport::newInstance(); - } - } diff --git a/lib/private/Settings/Admin/Mail.php b/lib/private/Settings/Admin/Mail.php index 74a94a4c7a0..fc20b7eeb3f 100644 --- a/lib/private/Settings/Admin/Mail.php +++ b/lib/private/Settings/Admin/Mail.php @@ -63,6 +63,10 @@ class Mail implements ISettings { $parameters['mail_smtppassword'] = '********'; } + if ($parameters['mail_smtpmode'] === '' || $parameters['mail_smtpmode'] === 'php') { + $parameters['mail_smtpmode'] = 'smtp'; + } + return new TemplateResponse('settings', 'settings/admin/additional-mail', $parameters, ''); } |