diff options
author | Julia Kirschenheuter <6078378+JuliaKirschenheuter@users.noreply.github.com> | 2022-06-20 12:02:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-20 12:02:32 +0300 |
commit | 1125ceea0959246de0ccead38412e7c0125c9e32 (patch) | |
tree | d11509f2a9a6e4243999abea4057d0fce55ab8dd | |
parent | 8a29e7b004b7c1fbf45a8613a248602cc465c680 (diff) | |
parent | 53489c649dce81caaf65dd6717a522f95212df22 (diff) |
Merge pull request #6286 from sazanof/enh/clear-folder-feature
Users can clear their mailboxes
-rw-r--r-- | appinfo/routes.php | 5 | ||||
-rw-r--r-- | lib/Contracts/IMailManager.php | 8 | ||||
-rw-r--r-- | lib/Controller/MailboxesController.php | 18 | ||||
-rw-r--r-- | lib/Service/MailManager.php | 21 | ||||
-rw-r--r-- | src/components/NavigationMailbox.vue | 38 | ||||
-rw-r--r-- | src/service/MailboxService.js | 7 | ||||
-rw-r--r-- | src/store/actions.js | 6 | ||||
-rw-r--r-- | src/store/mutations.js | 3 |
8 files changed, 106 insertions, 0 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php index 32a21a883..5627fb94c 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -160,6 +160,11 @@ return [ 'verb' => 'GET' ], [ + 'name' => 'mailboxes#clearMailbox', + 'url' => '/api/mailboxes/{id}/clear', + 'verb' => 'POST' + ], + [ 'name' => 'messages#downloadAttachment', 'url' => '/api/messages/{id}/attachment/{attachmentId}', 'verb' => 'GET' diff --git a/lib/Contracts/IMailManager.php b/lib/Contracts/IMailManager.php index e41ec110e..472151cf2 100644 --- a/lib/Contracts/IMailManager.php +++ b/lib/Contracts/IMailManager.php @@ -205,6 +205,14 @@ interface IMailManager { /** * @param Account $account * @param Mailbox $mailbox + * + * @throws ServiceException + */ + public function clearMailbox(Account $account, Mailbox $mailbox): void; + + /** + * @param Account $account + * @param Mailbox $mailbox * @param bool $subscribed * * @return Mailbox diff --git a/lib/Controller/MailboxesController.php b/lib/Controller/MailboxesController.php index e69232ef5..a648ebb10 100644 --- a/lib/Controller/MailboxesController.php +++ b/lib/Controller/MailboxesController.php @@ -284,4 +284,22 @@ class MailboxesController extends Controller { $this->mailManager->deleteMailbox($account, $mailbox); return new JSONResponse(); } + + /** + * @NoAdminRequired + * @TrapError + * + * @param int $id + * + * @return JSONResponse + * @throws ClientException + * @throws ServiceException + */ + public function clearMailbox(int $id): JSONResponse { + $mailbox = $this->mailManager->getMailbox($this->currentUserId, $id); + $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId()); + + $this->mailManager->clearMailbox($account, $mailbox); + return new JSONResponse(); + } } diff --git a/lib/Service/MailManager.php b/lib/Service/MailManager.php index a76901368..7b4fc8511 100644 --- a/lib/Service/MailManager.php +++ b/lib/Service/MailManager.php @@ -586,6 +586,27 @@ class MailManager implements IMailManager { } /** + * Clear messages in folder + * @param Account $account + * @param Mailbox $mailbox + * + * @throws ServiceException + */ + public function clearMailbox(Account $account, + Mailbox $mailbox): void { + $client = $this->imapClientFactory->getClient($account); + try { + $client->expunge($mailbox->getName(), [ + 'delete' => true + ]); + } finally { + $client->logout(); + } + //delete all messages in this mailbox folder + $this->dbMessageMapper->deleteAll($mailbox); + } + + /** * @param Account $account * @param Mailbox $mailbox * @param Message $message diff --git a/src/components/NavigationMailbox.vue b/src/components/NavigationMailbox.vue index 79c6ccf80..6002f2416 100644 --- a/src/components/NavigationMailbox.vue +++ b/src/components/NavigationMailbox.vue @@ -160,6 +160,16 @@ {{ t('mail', 'Sync in background') }} </ActionCheckbox> + <ActionButton + v-if="mailbox.specialRole !== 'flagged' && !account.isUnified" + :close-after-click="true" + @click="clearMailbox"> + <template #icon> + <EraserVariant :size="20" /> + </template> + {{ t('mail', 'Clear mailbox') }} + </ActionButton> + <ActionButton v-if="!account.isUnified && !mailbox.specialRole && !hasSubMailboxes" @click="deleteMailbox"> <template #icon> <IconDelete @@ -218,6 +228,7 @@ import { translate as translateMailboxName } from '../i18n/MailboxTranslator' import { showInfo } from '@nextcloud/dialogs' import { DroppableMailboxDirective as droppableMailbox } from '../directives/drag-and-drop/droppable-mailbox' import dragEventBus from '../directives/drag-and-drop/util/dragEventBus' +import EraserVariant from 'vue-material-design-icons/EraserVariant' export default { name: 'NavigationMailbox', @@ -243,6 +254,7 @@ export default { IconInbox, ImportantIcon, MoveMailboxModal, + EraserVariant, }, directives: { droppableMailbox, @@ -370,6 +382,9 @@ export default { showUnreadCounter() { return this.mailbox.unread > 0 && this.filter !== 'starred' }, + colorPrimaryElement() { + return getComputedStyle(document.body).getPropertyValue('--color-primary-element').trim() + }, }, mounted() { dragEventBus.$on('dragStart', this.onDragStart) @@ -529,6 +544,29 @@ export default { } ) }, + clearMailbox() { + const id = this.mailbox.databaseId + OC.dialogs.confirmDestructive( + t('mail', 'All messages in folder will be deleted permanently.'), + t('mail', 'Clear mailbox {name}', { name: this.mailbox.displayName }), + { + type: OC.dialogs.YES_NO_BUTTONS, + confirm: t('mail', 'Clear mailbox'), + confirmClasses: 'error', + cancel: t('mail', 'Cancel'), + }, + (result) => { + if (result) { + return this.$store + .dispatch('clearMailbox', { mailbox: this.mailbox }) + .then(() => { + logger.info(`mailbox ${id} cleared`) + }) + .catch((error) => logger.error('could not clear mailbox', { error })) + } + } + ) + }, async renameMailbox() { this.renameInput = false this.showSaving = false diff --git a/src/service/MailboxService.js b/src/service/MailboxService.js index 5f8a1e30f..8f73a5a2b 100644 --- a/src/service/MailboxService.js +++ b/src/service/MailboxService.js @@ -54,3 +54,10 @@ export async function patchMailbox(id, data) { const response = await axios.patch(url, data) return response.data } +export const clearMailbox = async(id) => { + const url = generateUrl('/apps/mail/api/mailboxes/{id}/clear', { + id, + }) + + await axios.post(url) +} diff --git a/src/store/actions.js b/src/store/actions.js index 9d310db9f..4e4ec96a5 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -54,6 +54,7 @@ import { import { create as createMailbox, deleteMailbox, + clearMailbox, fetchAll as fetchAllMailboxes, markMailboxRead, patchMailbox, @@ -184,6 +185,11 @@ export default { await deleteMailbox(mailbox.databaseId) commit('removeMailbox', { id: mailbox.databaseId }) }, + async clearMailbox({ commit }, { mailbox }) { + await clearMailbox(mailbox.databaseId) + commit('removeEnvelopes', { id: mailbox.databaseId }) + commit('setMailboxUnreadCount', { id: mailbox.databaseId }) + }, async createMailbox({ commit }, { account, name }) { const prefixed = (account.personalNamespace && !name.startsWith(account.personalNamespace)) ? account.personalNamespace + name diff --git a/src/store/mutations.js b/src/store/mutations.js index 9c7e2d897..8402c1e35 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -344,6 +344,9 @@ export default { Vue.delete(state.envelopes, id) }, + removeEnvelopes(state, { id }) { + Vue.set(state.mailboxes[id], 'envelopeLists', []) + }, addMessage(state, { message }) { Vue.set(state.messages, message.databaseId, message) }, |