forked from nextcloud/mail
-
Notifications
You must be signed in to change notification settings - Fork 0
Implement frontend logic #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
printminion-co
merged 10 commits into
feature/create-ionos-mail
from
mk/dev/ionos_implement_frontend
Oct 23, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4ea8e5a
IONOS(ionos-mail): replace instance methods with direct calls for tra…
printminion-co 460b6db
IONOS(ionos-mail): remove password field from new email creation form
printminion-co 94a2a26
IONOS(ionos-mail): unify feedback clearing methods in email form
printminion-co 26c13e6
IONOS(ionos-mail): add feedback clearing on email input change
printminion-co 00c7b02
IONOS(ionos-mail): cleanup host info on account creation to improve i…
printminion-co 22a4c90
IONOS(ionos-mail): add support for IONOS mail configuration in accoun…
printminion-co ab81688
IONOS(ionos-mail): update email account creation to remove account na…
printminion-co c08a422
IONOS(ionos-mail): refactor email account creation to streamline resp…
printminion-co 1232c2a
IONOS(ionos-mail): improve error handling in email account creation
printminion-co 57fdfd8
IONOS(ionos-mail): refine error handling for account creation feedback
printminion-co File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,25 +57,28 @@ 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'); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @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' => '[email protected]' // $emailAddress, | ||
| 'username' => $emailAddress, | ||
| ], | ||
| 'smtp' => [ | ||
| 'host' => 'mail.localhost', // 'smtp.' . $domain, | ||
| 'password' => 'tmp', | ||
| 'port' => 1587, // 465, | ||
| 'security' => 'none', | ||
| 'username' => '[email protected]' // $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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| type="text" | ||
| :placeholder="t('mail', 'Name')" | ||
| :disabled="loading || localLoading" | ||
| @change="clearAllFeedback" | ||
| autofocus /> | ||
| <NcInputField id="ionos-email-address" | ||
| v-model="emailAddress" | ||
|
|
@@ -18,18 +19,11 @@ | |
| :placeholder="t('mail', 'Mail address')" | ||
| :disabled="loading || localLoading" | ||
| required | ||
| @change="clearFeedback" /> | ||
| @change="clearAllFeedback" /> | ||
| <p v-if="emailAddress && !isValidEmail(emailAddress)" class="account-form--error"> | ||
| {{ t('mail', 'Please enter an email of the format [email protected]') }} | ||
| </p> | ||
| <span class="email-domain-hint">@myworkspace.com</span> | ||
| <NcPasswordField id="ionos-password" | ||
| v-model="password" | ||
| :disabled="loading || localLoading" | ||
| type="password" | ||
| :label="t('mail', 'Password')" | ||
| :placeholder="t('mail', 'Password')" | ||
| required /> | ||
| <div class="account-form__submit-buttons"> | ||
| <NcButton class="account-form__submit-button" | ||
| type="primary" | ||
|
|
@@ -49,16 +43,20 @@ | |
| </template> | ||
|
|
||
| <script> | ||
| import { NcInputField, NcPasswordField, NcButton, NcLoadingIcon as IconLoading } from '@nextcloud/vue' | ||
| import { NcInputField, NcButton, NcLoadingIcon as IconLoading } from '@nextcloud/vue' | ||
| import IconCheck from 'vue-material-design-icons/Check.vue' | ||
| import { generateUrl } from '@nextcloud/router' | ||
| import axios from '@nextcloud/axios' | ||
| import { translate as t } from '@nextcloud/l10n' | ||
| import logger from '../../logger.js' | ||
| import { fixAccountId } from '../../service/AccountService.js' | ||
| import { mapStores } from 'pinia' | ||
| import useMainStore from '../../store/mainStore.js' | ||
|
|
||
| export default { | ||
| name: 'NewEmailAddressTab', | ||
| components: { | ||
| NcInputField, | ||
| NcPasswordField, | ||
| NcButton, | ||
| IconLoading, | ||
| IconCheck, | ||
|
|
@@ -81,61 +79,78 @@ export default { | |
| return { | ||
| accountName: '', | ||
| emailAddress: '', | ||
| password: '', | ||
| localLoading: false, | ||
| feedback: null, | ||
| } | ||
| }, | ||
| computed: { | ||
| ...mapStores(useMainStore), | ||
| isFormValid() { | ||
| return this.accountName | ||
| && this.isValidEmail(this.emailAddress) | ||
| && this.password | ||
| }, | ||
|
|
||
| buttonText() { | ||
| return this.localLoading | ||
| ? this.t('mail', 'Creating account...') | ||
| : this.t('mail', 'Create & Connect') | ||
| ? t('mail', 'Creating account...') | ||
| : t('mail', 'Create & Connect') | ||
| }, | ||
| }, | ||
| methods: { | ||
| async submitForm() { | ||
| this.clearLocalFeedback() | ||
| this.clearFeedback() | ||
| this.clearAllFeedback() | ||
| this.localLoading = true | ||
|
|
||
| try { | ||
| const response = await this.callIonosAPI({ | ||
| const account = await this.callIonosAPI({ | ||
| accountName: this.accountName, | ||
| emailAddress: this.emailAddress, | ||
| password: this.password, | ||
| }) | ||
|
|
||
| this.feedback = response.data.message || this.t('mail', 'Account created successfully') | ||
| logger.debug(`account ${account.id} created`, { account }) | ||
|
|
||
| this.feedback = t('mail', 'Account created successfully') | ||
|
|
||
| this.loadingMessage = t('mail', 'Loading account') | ||
| await this.mainStore.finishAccountSetup({ account }) | ||
| this.$emit('account-created', account) | ||
| } catch (error) { | ||
| console.error('Account creation failed:', error) | ||
|
|
||
| this.feedback = error.response?.data?.message | ||
| || this.t('mail', 'There was an error while setting up your account') | ||
| if (error.data?.error === 'IONOS_API_ERROR') { | ||
| this.feedback = t('mail', 'There was an error while setting up your account') | ||
| } else { | ||
| this.feedback = t('mail', 'There was an error while setting up your account') | ||
| } | ||
| } finally { | ||
| this.localLoading = false | ||
| } | ||
| }, | ||
|
|
||
| async callIonosAPI({ accountName, emailAddress, password }) { | ||
| async callIonosAPI({ accountName, emailAddress }) { | ||
| const url = generateUrl('/apps/mail/api/ionos/accounts') | ||
| return await axios.post(url, { | ||
| accountName, | ||
| emailAddress, | ||
| password, | ||
| }) | ||
|
|
||
| return axios | ||
| .post(url, { accountName, emailAddress }) | ||
| .then((resp) => resp.data.data) | ||
| .then(fixAccountId) | ||
| .catch((e) => { | ||
| if (e.response && e.response.status === 400) { | ||
| throw e.response.data | ||
| } | ||
|
|
||
| throw e | ||
| }) | ||
| }, | ||
|
|
||
| clearLocalFeedback() { | ||
| this.feedback = null | ||
| }, | ||
|
|
||
| clearAllFeedback() { | ||
| this.clearLocalFeedback() | ||
| this.clearFeedback() | ||
| }, | ||
| }, | ||
| } | ||
| </script> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.