-
Notifications
You must be signed in to change notification settings - Fork 271
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
Conversation
I'm not sold on this. If you just cleaned up your inbox you easily have more than 14 deleted emails in your trash. |
be1c5d3
to
3f63627
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 🧹
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); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
07b35dd
to
06f24e6
Compare
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
06f24e6
to
ce2f949
Compare
There was a problem hiding this 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 😄
/backport to stable5.0 |
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.