Skip to content

fix: don't show important or unread emails in trash #11002

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
merged 1 commit into from
Apr 29, 2025

Conversation

kesselb
Copy link
Contributor

@kesselb kesselb commented Apr 15, 2025

Fix #7475
Fix #8849

To exclude messages in the trash or junk, we need to pass the IDs of those mailboxes to the search. Previously, MailSearch.findMessagesGlobally expected a filter string like "is:unread" and fed it through a parser to create a SearchQuery object. I've changed the API to expect a SearchQuery object directly. The parsing is now handled a step earlier when processing the incoming search request.

The SearchQuery is used for searching across all mailboxes and for a given mailbox. To distinguish these cases more clearly, we now have GlobalSearchQuery. For example excluding certain mailbox IDs doesn't make sense when searching within a specific mailbox anyway. The MailSearch API still feels a bit unfinished, but this PR is already large enough, and the current state looks good to me.

Note: The special_use (e.g., trash or junk) is stored as a JSON string in the database. It might also work to select those rows using LIKE and toggle a flag like ignoreJunk for the SearchQuery object instead of using the actual mailbox ID.

@kesselb kesselb requested a review from GretaD as a code owner April 15, 2025 17:27
@kesselb kesselb self-assigned this Apr 15, 2025
@ChristophWurst
Copy link
Member

simply requests 14 items instead of 7 and filters out the items in the trash, hoping for the best.

I'm not sold on this. If you just cleaned up your inbox you easily have more than 14 deleted emails in your trash.

Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

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

🔧 🧹

Comment on lines 94 to 117
public function testGetItemsWithSince(): void {
$user = $this->createMock(IUser::class);
$this->userManager->expects($this->once())
->method('get')
->willReturn($user);

$message1 = new Message();
$message1->setSubject('Important');
$message1->setMailboxId(1);

$message2 = new Message();
$message2->setSubject('Also important');
$message2->setMailboxId(2);

$this->mailSearch->expects($this->once())
->method('findMessagesGlobally')
->with($user, $this->callback(function (MailSearchQuery $query) {
self::assertCount(1, $query->getFlags());
self::assertNotNull($query->getStart());
return true;
}))
->willReturn([$message1, $message2]);

$mailAccount = new MailAccount();
$account = new Account($mailAccount);

$this->accountService->expects($this->once())
->method('findByUserId')
->willReturn([$account]);

$items = $this->widget->getItems('bob', '1745340000', 7);

$this->assertCount(2, $items);
}
Copy link
Member

Choose a reason for hiding this comment

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

Tip for readable unit tests: structure them into three blocks: arrange, act and assert. Separate the blocks by one newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mentioned AAA a couple of times, yes 😉 I've changed the tests to follow the AAA pattern, even though I'm not a fan of it and find them rather difficult to read. Most of our tests have complex "Arrange" sections, and understanding them is quite hard when the code isn't at least somewhat structured.

@kesselb kesselb force-pushed the bug/8849/hide-trash-widget branch from 07b35dd to 06f24e6 Compare April 28, 2025 15:10
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
@kesselb kesselb force-pushed the bug/8849/hide-trash-widget branch from 06f24e6 to ce2f949 Compare April 28, 2025 15:16
Copy link
Member

@st3iny st3iny left a comment

Choose a reason for hiding this comment

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

The new API looks good. Long live OOP 😄

@kesselb kesselb merged commit 2fd5134 into main Apr 29, 2025
35 of 36 checks passed
@kesselb kesselb deleted the bug/8849/hide-trash-widget branch April 29, 2025 13:48
@ChristophWurst
Copy link
Member

/backport to stable5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants