diff --git a/lib/Controller/IonosAccountsController.php b/lib/Controller/IonosAccountsController.php index 34fde227d9..f44f4eab66 100644 --- a/lib/Controller/IonosAccountsController.php +++ b/lib/Controller/IonosAccountsController.php @@ -9,6 +9,7 @@ namespace OCA\Mail\Controller; use OCA\Mail\Exception\ServiceException; +use OCA\Mail\Http\JsonResponse as MailJsonResponse; use OCA\Mail\Http\TrapError; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Attribute\OpenAPI; @@ -23,8 +24,6 @@ class IonosAccountsController extends Controller { private const ERR_ALL_FIELDS_REQUIRED = 'All fields are required'; private const ERR_CREATE_EMAIL_FAILED = 'Failed to create email account'; private const ERR_IONOS_API_ERROR = 'IONOS_API_ERROR'; - private const ERR_UNKNOWN_ERROR = 'UNKNOWN_ERROR'; - private const ERR_GENERIC_SETUP = 'There was an error while setting up your account'; public function __construct( string $appName, @@ -58,17 +57,20 @@ public function create(string $accountName, string $emailAddress): JSONResponse try { $this->logger->info('Starting IONOS email account creation', [ 'emailAddress' => $emailAddress, 'accountName' => $accountName ]); $mailConfig = $this->createIonosEmailAccount($accountName, $emailAddress); - $accountResponse = $this->createNextcloudMailAccount($accountName, $emailAddress, $mailConfig); + $this->logger->info('IONOS email account created successfully', [ 'emailAddress' => $emailAddress ]); - return new JSONResponse([ - 'success' => true, - 'message' => 'Email account created successfully via IONOS', - 'account' => $accountResponse->getData(), - ], 201); + return $this->createNextcloudMailAccount($accountName, $emailAddress, $mailConfig); } catch (ServiceException $e) { - return $this->handleServiceException($e, $emailAddress); + + $data = [ + 'emailAddress' => $emailAddress, + 'error' => self::ERR_IONOS_API_ERROR, + ]; + $this->logger->error('IONOS service error: ' . $e->getMessage(), $data); + + return MailJsonResponse::fail($data); } catch (\Exception $e) { - return $this->handleGenericException($e, $emailAddress); + return MailJsonResponse::error('Could not create account'); } } @@ -76,7 +78,7 @@ public function create(string $accountName, string $emailAddress): JSONResponse * @throws ServiceException */ private function createIonosEmailAccount(string $accountName, string $emailAddress): array { - $ionosResponse = $this->callIonosCreateEmailAPI($accountName, $emailAddress); + $ionosResponse = $this->callIonosCreateEmailAPI($emailAddress); if ($ionosResponse === null || !($ionosResponse['success'] ?? false)) { $this->logger->error('Failed to create IONOS email account', [ 'emailAddress' => $emailAddress, 'response' => $ionosResponse ]); throw new ServiceException(self::ERR_CREATE_EMAIL_FAILED); @@ -89,18 +91,10 @@ private function createIonosEmailAccount(string $accountName, string $emailAddre return $mailConfig; } - /** - * @throws ServiceException - */ private function createNextcloudMailAccount(string $accountName, string $emailAddress, array $mailConfig): JSONResponse { - if (!isset($mailConfig['imap'], $mailConfig['smtp'])) { - throw new ServiceException('Invalid mail configuration: missing IMAP or SMTP configuration'); - } $imap = $mailConfig['imap']; $smtp = $mailConfig['smtp']; - if (!is_array($imap) || !is_array($smtp)) { - throw new ServiceException('Invalid mail configuration: IMAP or SMTP configuration must be arrays'); - } + return $this->accountsController->create( $accountName, $emailAddress, @@ -117,15 +111,10 @@ private function createNextcloudMailAccount(string $accountName, string $emailAd ); } - private function handleServiceException(ServiceException $e, string $emailAddress): JSONResponse { - $this->logger->error('IONOS service error', [ 'exception' => $e, 'emailAddress' => $emailAddress ]); - return new JSONResponse(['success' => false, 'message' => $e->getMessage(), 'error' => self::ERR_IONOS_API_ERROR], 400); - } - /** * @throws ServiceException */ - protected function callIonosCreateEmailAPI(string $accountName, string $emailAddress): ?array { + protected function callIonosCreateEmailAPI(string $emailAddress): ?array { $atPosition = strrchr($emailAddress, '@'); if ($atPosition === false) { throw new ServiceException('Invalid email address: unable to extract domain'); @@ -143,21 +132,16 @@ protected function callIonosCreateEmailAPI(string $accountName, string $emailAdd 'password' => 'tmp', 'port' => 1143, // 993, 'security' => 'none', - 'username' => 'admin@strado.de' // $emailAddress, + 'username' => $emailAddress, ], 'smtp' => [ 'host' => 'mail.localhost', // 'smtp.' . $domain, 'password' => 'tmp', 'port' => 1587, // 465, 'security' => 'none', - 'username' => 'admin@strado.de' // $emailAddress, + 'username' => $emailAddress, ] ] ]; } - - private function handleGenericException(\Exception $e, string $emailAddress): JSONResponse { - $this->logger->error('Unexpected error during IONOS account creation', [ 'exception' => $e, 'emailAddress' => $emailAddress ]); - return new JSONResponse(['success' => false, 'message' => self::ERR_GENERIC_SETUP, 'error' => self::ERR_UNKNOWN_ERROR], 500); - } } diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 4bc43085ce..df82aafb34 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -210,6 +210,7 @@ public function index(): TemplateResponse { $response = new TemplateResponse($this->appName, 'index'); $this->initialStateService->provideInitialState('preferences', [ 'attachment-size-limit' => $this->config->getSystemValue('app.mail.attachment-size-limit', 0), + 'ionos-mailconfig-enabled' => $this->config->getAppValue('mail', 'ionos-mailconfig-enabled', 'no') === 'yes', 'app-version' => $this->config->getAppValue('mail', 'installed_version'), 'external-avatars' => $this->preferences->getPreference($this->currentUserId, 'external-avatars', 'true'), 'layout-mode' => $this->preferences->getPreference($this->currentUserId, 'layout-mode', 'vertical-split'), diff --git a/src/components/AccountForm.vue b/src/components/AccountForm.vue index f5a775eb49..946bf0501c 100644 --- a/src/components/AccountForm.vue +++ b/src/components/AccountForm.vue @@ -199,10 +199,14 @@ required @change="clearFeedback" /> - + + :is-valid-email="isValidEmail" + @account-created="(account) => $emit('account-created', account)" />
@@ -328,6 +332,10 @@ export default { 'microsoftOauthUrl', ]), + useIonosMailconfig() { + return this.mainStore.getPreference('ionos-mailconfig-enabled', null) + }, + settingsPage() { return this.account !== undefined }, @@ -416,6 +424,12 @@ export default { this.manualConfig.smtpPassword = this.autoConfig.password } } + if (this.mode === 'create') { + // cleanup host info in order to remove isGoogleAccount message from interface + this.manualConfig.imapHost = undefined + this.manualConfig.smtpHost = undefined + this.clearFeedback() + } }, onImapSslModeChange(value) { this.clearFeedback() diff --git a/src/components/ionos/NewEmailAddressTab.vue b/src/components/ionos/NewEmailAddressTab.vue index d0c2c9f3b3..f9076af226 100644 --- a/src/components/ionos/NewEmailAddressTab.vue +++ b/src/components/ionos/NewEmailAddressTab.vue @@ -10,6 +10,7 @@ type="text" :placeholder="t('mail', 'Name')" :disabled="loading || localLoading" + @change="clearAllFeedback" autofocus /> + @change="clearAllFeedback" /> -