Skip to content

TF-4392 [Team Mailbox] Delete email in Trash#4416

Open
dab246 wants to merge 2 commits intomasterfrom
bugfix/tf-4392-team-mailbox-delete-email-in-trash
Open

TF-4392 [Team Mailbox] Delete email in Trash#4416
dab246 wants to merge 2 commits intomasterfrom
bugfix/tf-4392-team-mailbox-delete-email-in-trash

Conversation

@dab246
Copy link
Copy Markdown
Member

@dab246 dab246 commented Mar 26, 2026

Issue

#4392

User story 3

AS a team mailbox member
I can delete emails within the team mailbox trash
I can empty the team mailbox trash

Resolved

demo-delete-trash.mov

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced trash emptying functionality to properly support team mailboxes with appropriate permission validation.
    • Improved trash folder detection to correctly distinguish between personal and team mailbox trash.
  • New Features

    • Permission checks now prevent unauthorized users from emptying trash, ensuring only those with appropriate rights can perform this action.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

Walkthrough

This pull request refactors the empty trash operation to pass full PresentationMailbox objects instead of separate parameters (trashFolderId, totalEmails). It updates the trash mailbox detection logic to distinguish between personal mailboxes (using role) and team mailboxes (using name matching and hierarchy). Permission checks (mayRemoveItems) have been added to the empty trash action availability across the codebase, and capability checks for the jmapMailboxClear operation now exclude team trash mailboxes.

Possibly related PRs

  • linagora/tmail-flutter#4305: Modifies PresentationMailbox extension by adding mailbox-type predicates (isLabelMailbox) alongside the changes here to isTrash and the new isTrashTeamMailbox getter.

Suggested labels

customer

Suggested reviewers

  • hoangdat
  • tddang-linagora
  • zatteo
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: implementing deletion of emails in team mailbox trash, which aligns with the core functionality across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/tf-4392-team-mailbox-delete-email-in-trash

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart`:
- Around line 1833-1869: Inside emptyTrashFolderAction, add a final permission
gate that checks trashFolder.myRights?.mayRemoveItems == true before attempting
clearMailbox or calling _emptyTrashFolderInteractor.execute; if the check fails,
short-circuit by calling consumeState with a Left(EmptyTrashFolderFailure(...))
containing an appropriate "not allowed" permission error and return. Place this
check after resolving trashFolder and before the existing
CapabilityIdentifier.jmapMailboxClear branch so both clearMailbox and
_emptyTrashFolderInteractor paths honor mayRemoveItems.

In `@model/lib/extensions/presentation_mailbox_extension.dart`:
- Around line 43-54: isTrashTeamMailbox currently returns true for any
descendant named "trash" because it only checks isChildOfTeamMailboxes (presence
of any parent) and the folder name; update isTrashTeamMailbox to only match the
first-level team trash mailbox by verifying the folder's immediate parent is a
team mailbox root (not any ancestor) and the folder's name equals
PresentationMailbox.trashRole (case-insensitive). Locate isTrashTeamMailbox and
replace the broad parent check (isChildOfTeamMailboxes/hasParentId) with a check
that the direct parent is a team mailbox root (e.g., compare parent type/id to
the team mailbox identifier or use an isImmediateChildOfTeamMailbox helper) so
isTrash consumers only get true for the top-level team Trash.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 78c26d54-6faa-4fcb-8ac1-447539b2c57f

📥 Commits

Reviewing files that changed from the base of the PR and between c17782b and fd13b5b.

📒 Files selected for processing (5)
  • lib/features/base/mixin/mailbox_action_handler_mixin.dart
  • lib/features/mailbox/presentation/mailbox_controller.dart
  • lib/features/mailbox/presentation/mixin/mailbox_widget_mixin.dart
  • lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart
  • model/lib/extensions/presentation_mailbox_extension.dart

Comment on lines 1833 to 1869
void emptyTrashFolderAction({
Function? onCancelSelectionEmail,
MailboxId? trashFolderId,
int totalEmails = 0,
PresentationMailbox? trashMailbox,
}) {
onCancelSelectionEmail?.call();

final trashMailboxId = trashFolderId ?? mapDefaultMailboxIdByRole[PresentationMailbox.roleTrash];
final trashFolder = trashMailbox
?? (selectedMailbox.value?.isTrash == true ? selectedMailbox.value : null)
?? mapMailboxById[mapDefaultMailboxIdByRole[PresentationMailbox.roleTrash]];
final accountId = this.accountId.value;
final session = sessionCurrent;

if (accountId == null || sessionCurrent == null) {
if (accountId == null || session == null) {
consumeState(Stream.value(Left(EmptyTrashFolderFailure(NotFoundSessionException()))));
return;
}

if (trashMailboxId == null) {
if (trashFolder == null) {
consumeState(Stream.value(Left(EmptyTrashFolderFailure(NotFoundMailboxException()))));
return;
}

if (CapabilityIdentifier.jmapMailboxClear.isSupported(sessionCurrent!, accountId)) {
if (CapabilityIdentifier.jmapMailboxClear.isSupported(session, accountId) &&
trashFolder.isTrashTeamMailbox != true) {
clearMailbox(
sessionCurrent!,
session,
accountId,
trashMailboxId,
trashFolder.id,
PresentationMailbox.roleTrash,
);
} else {
final totalEmailsInTrash = totalEmails == 0
? mapMailboxById[trashMailboxId]?.countTotalEmails ?? 0
: totalEmails;

consumeState(_emptyTrashFolderInteractor.execute(
sessionCurrent!,
session,
accountId,
trashMailboxId,
totalEmailsInTrash,
trashFolder.id,
trashFolder.countTotalEmails,
progressStateController,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Enforce mayRemoveItems inside emptyTrashFolderAction.

Lines 1839-1869 resolve and execute against any trash mailbox, but never verify trashFolder.myRights?.mayRemoveItems == true. lib/features/mailbox/presentation/mixin/mailbox_widget_mixin.dart still adds MailboxActions.emptyTrash for default trash mailboxes without that guard, so some callers can reach this path and only fail after the server rejects the request. Add the permission check here as the final gate.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart`
around lines 1833 - 1869, Inside emptyTrashFolderAction, add a final permission
gate that checks trashFolder.myRights?.mayRemoveItems == true before attempting
clearMailbox or calling _emptyTrashFolderInteractor.execute; if the check fails,
short-circuit by calling consumeState with a Left(EmptyTrashFolderFailure(...))
containing an appropriate "not allowed" permission error and return. Place this
check after resolving trashFolder and before the existing
CapabilityIdentifier.jmapMailboxClear branch so both clearMailbox and
_emptyTrashFolderInteractor paths honor mayRemoveItems.

Comment on lines +43 to +54
bool get isTrash {
if (isPersonal) {
return role == PresentationMailbox.roleTrash;
} else {
return isTrashTeamMailbox;
}
}

bool get isTrashTeamMailbox {
return isChildOfTeamMailboxes &&
name?.name.toLowerCase() == PresentationMailbox.trashRole.toLowerCase();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

isTrashTeamMailbox matches any descendant named trash.

Line 52 only checks hasParentId() via isChildOfTeamMailboxes, so folders like Team A/Projects/Trash will also return true. Line 43 then propagates that broader match to every isTrash consumer, which can expose empty-trash and permanent-delete behavior on ordinary folders. Tighten this to the actual first-level team trash mailbox.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@model/lib/extensions/presentation_mailbox_extension.dart` around lines 43 -
54, isTrashTeamMailbox currently returns true for any descendant named "trash"
because it only checks isChildOfTeamMailboxes (presence of any parent) and the
folder name; update isTrashTeamMailbox to only match the first-level team trash
mailbox by verifying the folder's immediate parent is a team mailbox root (not
any ancestor) and the folder's name equals PresentationMailbox.trashRole
(case-insensitive). Locate isTrashTeamMailbox and replace the broad parent check
(isChildOfTeamMailboxes/hasParentId) with a check that the direct parent is a
team mailbox root (e.g., compare parent type/id to the team mailbox identifier
or use an isImmediateChildOfTeamMailbox helper) so isTrash consumers only get
true for the top-level team Trash.

@github-actions
Copy link
Copy Markdown

This PR has been deployed to https://linagora.github.io/tmail-flutter/4416.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant