diff --git a/lib/Controller/AccountsController.php b/lib/Controller/AccountsController.php index 81cb19067f..393da826bf 100644 --- a/lib/Controller/AccountsController.php +++ b/lib/Controller/AccountsController.php @@ -338,6 +338,12 @@ public function create(string $accountName, $this->logger->info('Creating account disabled by admin.'); return MailJsonResponse::error('Could not create account'); } + if (empty($this->accountService->findByUserIdAndAddress($this->userId, $emailAddress)) === false) { + $this->logger->info('Trying to create already existing account.'); + return MailJsonResponse::fail([ + 'error' => 'ACCOUNT_EXISTS', + ]); + } if (!$this->hostValidator->isValid($imapHost)) { $this->logger->debug('Prevented access to invalid IMAP host', [ 'host' => $imapHost, diff --git a/src/components/AccountForm.vue b/src/components/AccountForm.vue index 217a214c1f..ec5b9c566d 100644 --- a/src/components/AccountForm.vue +++ b/src/components/AccountForm.vue @@ -692,6 +692,8 @@ export default { } else if (error.data.service === 'SMTP') { this.feedback = t('mail', 'SMTP server is not reachable') } + } else if (error.data?.error === 'ACCOUNT_EXISTS') { + this.feedback = t('mail', 'Account already exists') } else if (error.data?.error === 'AUTHENTICATION_WRONG_PASSWORD') { if (error.data.service === 'IMAP') { this.feedback = t('mail', 'IMAP username or password is wrong')