From f794fa4ec97c624ef6f36b708a84e6a81114d1b8 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 21 Nov 2022 16:20:24 +0100 Subject: [PATCH] Fix XOAUTH2 auth via SMTP Signed-off-by: Christoph Wurst --- lib/SMTP/SmtpClientFactory.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/SMTP/SmtpClientFactory.php b/lib/SMTP/SmtpClientFactory.php index 6e4d508747..60ea164345 100644 --- a/lib/SMTP/SmtpClientFactory.php +++ b/lib/SMTP/SmtpClientFactory.php @@ -29,6 +29,7 @@ use Horde_Mail_Transport; use Horde_Mail_Transport_Mail; use Horde_Mail_Transport_Smtphorde; +use Horde_Smtp_Password_Xoauth2; use OCA\Mail\Account; use OCA\Mail\Support\HostNameFactory; use OCP\IConfig; @@ -65,13 +66,12 @@ public function create(Account $account): Horde_Mail_Transport { return new Horde_Mail_Transport_Mail(); } - $password = $mailAccount->getOutboundPassword(); - $password = $this->crypto->decrypt($password); + $decryptedPassword = $this->crypto->decrypt($mailAccount->getOutboundPassword()); $security = $mailAccount->getOutboundSslMode(); $params = [ 'localhost' => $this->hostNameFactory->getHostName(), 'host' => $mailAccount->getOutboundHost(), - 'password' => $password, + 'password' => $decryptedPassword, 'port' => $mailAccount->getOutboundPort(), 'username' => $mailAccount->getOutboundUser(), 'secure' => $security === 'none' ? false : $security, @@ -83,6 +83,12 @@ public function create(Account $account): Horde_Mail_Transport { ], ], ]; + if ($account->getMailAccount()->getAuthMethod() === 'xoauth2') { + $params['xoauth2_token'] = new Horde_Smtp_Password_Xoauth2( + $account->getEmail(), + $decryptedPassword, + ); + } if ($this->config->getSystemValue('debug', false)) { $params['debug'] = $this->config->getSystemValue('datadirectory') . '/horde_smtp.log'; }