diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-02-12 13:53:27 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-03-16 12:47:05 +0100 |
commit | 13486a5ada62e4355473ca01e07371c162951e84 (patch) | |
tree | c079e9c53691ca14e5e1898c40a93322d6e727f5 /settings/controller | |
parent | 0d9f149dd93997085b85e2b174f5989a1b996263 (diff) | |
download | nextcloud-server-13486a5ada62e4355473ca01e07371c162951e84.tar.gz nextcloud-server-13486a5ada62e4355473ca01e07371c162951e84.zip |
Migrate to SwiftMail
Replaces the OC_Mail and phpmailer with SwiftMail allowing us to mock it properly.
Fixes the unit test execution on master on local machines and https://github.com/owncloud/core/issues/12014
Conflicts:
3rdparty
lib/private/server.php
lib/public/iservercontainer.php
tests/lib/mail.php
tests/settings/controller/mailsettingscontrollertest.php
Conflicts:
3rdparty
lib/private/mail.php
lib/private/server.php
lib/public/iservercontainer.php
settings/ajax/lostpassword.php
settings/application.php
Diffstat (limited to 'settings/controller')
-rw-r--r-- | settings/controller/mailsettingscontroller.php | 12 | ||||
-rw-r--r-- | settings/controller/userscontroller.php | 31 |
2 files changed, 22 insertions, 21 deletions
diff --git a/settings/controller/mailsettingscontroller.php b/settings/controller/mailsettingscontroller.php index 5874e644abb..43715b82237 100644 --- a/settings/controller/mailsettingscontroller.php +++ b/settings/controller/mailsettingscontroller.php @@ -16,6 +16,8 @@ use \OCP\AppFramework\Controller; use OCP\IRequest; use OCP\IL10N; use OCP\IConfig; +use OCP\Mail\IMailer; +use OCP\Mail\IMessage; /** * @package OC\Settings\Controller @@ -30,8 +32,8 @@ class MailSettingsController extends Controller { private $userSession; /** @var \OC_Defaults */ private $defaults; - /** @var \OC_Mail */ - private $mail; + /** @var IMailer */ + private $mailer; /** @var string */ private $defaultMailAddress; @@ -42,7 +44,7 @@ class MailSettingsController extends Controller { * @param IConfig $config * @param Session $userSession * @param \OC_Defaults $defaults - * @param \OC_Mail $mail + * @param IMailer $mailer * @param string $defaultMailAddress */ public function __construct($appName, @@ -51,14 +53,14 @@ class MailSettingsController extends Controller { IConfig $config, Session $userSession, \OC_Defaults $defaults, - \OC_Mail $mail, + IMailer $mailer, $defaultMailAddress) { parent::__construct($appName, $request); $this->l10n = $l10n; $this->config = $config; $this->userSession = $userSession; $this->defaults = $defaults; - $this->mail = $mail; + $this->mailer = $mailer; $this->defaultMailAddress = $defaultMailAddress; } diff --git a/settings/controller/userscontroller.php b/settings/controller/userscontroller.php index a20cbb4050a..507e57ef940 100644 --- a/settings/controller/userscontroller.php +++ b/settings/controller/userscontroller.php @@ -26,6 +26,7 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use OCP\Mail\IMailer; /** * @package OC\Settings\Controller @@ -47,8 +48,8 @@ class UsersController extends Controller { private $log; /** @var \OC_Defaults */ private $defaults; - /** @var \OC_Mail */ - private $mail; + /** @var IMailer */ + private $mailer; /** @var string */ private $fromMailAddress; /** @var IURLGenerator */ @@ -71,7 +72,7 @@ class UsersController extends Controller { * @param IL10N $l10n * @param ILogger $log * @param \OC_Defaults $defaults - * @param \OC_Mail $mail + * @param IMailer $mailer * @param string $fromMailAddress * @param IURLGenerator $urlGenerator * @param IAppManager $appManager @@ -87,7 +88,7 @@ class UsersController extends Controller { IL10N $l10n, ILogger $log, \OC_Defaults $defaults, - \OC_Mail $mail, + IMailer $mailer, $fromMailAddress, IURLGenerator $urlGenerator, IAppManager $appManager, @@ -101,7 +102,7 @@ class UsersController extends Controller { $this->l10n = $l10n; $this->log = $log; $this->defaults = $defaults; - $this->mail = $mail; + $this->mailer = $mailer; $this->fromMailAddress = $fromMailAddress; $this->urlGenerator = $urlGenerator; $this->subAdminFactory = $subAdminFactory; @@ -263,7 +264,7 @@ class UsersController extends Controller { */ public function create($username, $password, array $groups=array(), $email='') { - if($email !== '' && !$this->mail->validateAddress($email)) { + if($email !== '' && !\OCP\Mail\Util::validateMailAddress($email)) { return new DataResponse( array( 'message' => (string)$this->l10n->t('Invalid mail address') @@ -329,15 +330,13 @@ class UsersController extends Controller { $subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]); try { - $this->mail->send( - $email, - $username, - $subject, - $mailContent, - $this->fromMailAddress, - $this->defaults->getName(), - 1, - $plainTextMailContent); + $message = $this->mailer->createMessage(); + $message->setTo([$email => $username]); + $message->setSubject($subject); + $message->setHtmlBody($mailContent); + $message->setPlainBody($plainTextMailContent); + $message->setFrom([$this->fromMailAddress => $this->defaults->getName()]); + $this->mailer->send($message); } catch(\Exception $e) { $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings')); } @@ -444,7 +443,7 @@ class UsersController extends Controller { ); } - if($mailAddress !== '' && !$this->mail->validateAddress($mailAddress)) { + if($mailAddress !== '' && ! \OCP\Mail\Util::validateMailAddress($mailAddress)) { return new DataResponse( array( 'status' => 'error', |