nextcloud / nextcloud/mail

Gracefully fail when unable to access a mailbox

Open
#4,997 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1. to develop bug papercut
Dominant language
JavaScript
Stars
1k
Forks
348
Avg merge
12h 28m
Merged PRs (30d)
91

Description

Expected behavior

If the apps/mail/api/mailboxes?accountId={accountId} endpoint is unable to access a mailbox for whatever reason, the fail should be handled gracefully and the user should be notified.

Actual behavior

The exception is thrown in MailboxSync::sync but isn't handled in MailManager but instead ignored.

To do
  • Handle the exception upwards to the controller
  • Add a JSONResponse::fail with the correct response data
  • Add an indication to the frontend that notifies the user of an issue with this account

In lib/Service/MailManager.php

	/**
	 * @param Account $account
	 *
	 * @return Mailbox[]
	 * @throws ServiceException
	 */
	public function getMailboxes(Account $account): array {
		try {
			$this->mailboxSync->sync($account, $this->logger);
		} catch( ServiceException $e) {
			throw $e;
		}

		return $this->mailboxMapper->findAll($account);
	}

Some code from debugging this a bit:

In lib/Controller/MailboxesController.php

	/**
	 * @NoAdminRequired
	 * @TrapError
	 *
	 * @param int $accountId
	 *
	 * @return JSONResponse
	 *
	 * @throws ClientException
	 * @throws ServiceException
	 */
	public function index(int $accountId): JSONResponse {
		$account = $this->accountService->find($this->currentUserId, $accountId);
		try {
			$mailboxes = $this->mailManager->getMailboxes($account);
		} catch(ServiceException $e) {
			return HttpJsonResponse::fail(['Could not access mailbox for account ' . $account->getEMailAddress()]);
		}

		return new JSONResponse([
			'id' => $accountId,
			'email' => $account->getEmail(),
			'mailboxes' => $mailboxes,
			'delimiter' => reset($mailboxes)->getDelimiter(),
		]);
	}

src/components/Dashboard.vue needs to handle this error as well as the mail app.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/Service/MailManager.php and lib/Controller/MailboxesController.php for the apps/mail/api/mailboxes?accountId={accountId} flow, then inspect src/components/Dashboard.vue. Trace the ServiceException from MailboxSync::sync and determine the expected failure response and frontend notification behavior. Done means the exception reaches the controller, the endpoint returns the appropriate JSON failure, and both the dashboard and mail app notify the user.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php
Domain
api, backend, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.