Skip to content

fix: save correctly any match when closing search modal#13099

Open
GretaD wants to merge 2 commits into
mainfrom
fix/shortcut-search-field
Open

fix: save correctly any match when closing search modal#13099
GretaD wants to merge 2 commits into
mainfrom
fix/shortcut-search-field

Conversation

@GretaD

@GretaD GretaD commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

fixes #13068

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Signed-off-by: greta <gretadoci@gmail.com>
@ChristophWurst

Copy link
Copy Markdown
Member

Can you please explain what the fix does and why?

Signed-off-by: greta <gretadoci@gmail.com>
@GretaD

GretaD commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Can you please explain what the fix does and why?

The initial proposal didnt work well. I pushed a different approach.

The problem is that the body was not populated from the simple search box, and now it is.

@ChristophWurst

Copy link
Copy Markdown
Member

I don't get it :/

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Two changes address a bug where the search box returns no results for body-only matches. In SearchMessages.vue, the query watcher removes the conditional on searchBody and now always assigns this.query to searchInMessageBody. In MailSearch.php, getIdsLocally() gains two guards: it returns local-only results immediately when the account's getSearchBody() is false (equivalent to no body criteria), and after performing IMAP body search it returns local-only results instead of merging when $fromImap is empty.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title refers to saving match mode when closing search modal, which aligns with the core issue (#13068) about search query logic.
Description check ✅ Passed The description references the linked issue #13068 and indicates AI-assisted content, appropriately relating to the changeset.
Linked Issues check ✅ Passed The changes address the root cause identified in #13068: modifying search logic to use OR ('anyof') for single-term searches instead of AND ('allof').
Out of Scope Changes check ✅ Passed All changes directly address issue #13068: SearchMessages.vue modifies query watcher to handle search body filtering, and MailSearch.php optimizes IMAP search logic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cadecb34-947a-46f6-beec-f9ef05740d0f

📥 Commits

Reviewing files that changed from the base of the PR and between b133d88 and 50cf0ea.

📒 Files selected for processing (2)
  • lib/Service/Search/MailSearch.php
  • src/components/SearchMessages.vue

return $this->messageMapper->findIdsByQuery($mailbox, $query, $sortOrder, $limit);
}

return $this->messageMapper->findIdsByQuery($mailbox, $query, $sortOrder, $limit, $fromImap);

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Find and examine the MessageMapper::findIdsByQuery implementation

# Locate MessageMapper and extract the findIdsByQuery method
ast-grep --pattern $'class MessageMapper {
  $$$
  findIdsByQuery($$$) {
    $$$
  }
  $$$
}'

# Also search for how the $fromImap parameter is used
rg -nP -A 20 'function findIdsByQuery\(' --glob '**/MessageMapper.php'

Repository: nextcloud/mail

Length of output: 1595


🏁 Script executed:

# Read the complete findIdsByQuery method from MessageMapper.php
sed -n '807,900p' lib/Db/MessageMapper.php

Repository: nextcloud/mail

Length of output: 4427


🏁 Script executed:

# Continue reading to see how $uids is handled and the rest of the method
sed -n '900,1000p' lib/Db/MessageMapper.php

Repository: nextcloud/mail

Length of output: 3947


🏁 Script executed:

# Continue reading to see parameter binding
sed -n '995,1020p' lib/Db/MessageMapper.php

Repository: nextcloud/mail

Length of output: 920


🏁 Script executed:

# Check the MailSearch.php file around line 167 to see how findIdsByQuery is called
sed -n '150,180p' lib/Service/Search/MailSearch.php

Repository: nextcloud/mail

Length of output: 1146


The merge uses AND logic instead of OR when no subjects are specified, breaking the intended behavior.

When $uids (IMAP body results) is provided without subject criteria (lines 923-930), the UIDs are merged using andWhere(), creating AND logic instead of OR. This breaks the expected behavior for anyof match mode.

Example: A search for "test" in body + from="user@example.com" with anyof mode should return messages from that email OR containing "test" in the body. Instead, it returns only messages that match BOTH criteria—filtering out messages that match body criteria but have a different sender.

The condition at line 927 adds UIDs to $textOrs (OR logic) only when subjects exist; otherwise it uses andWhere() (AND logic). For consistency with anyof semantics, UIDs should be added to $textOrs in all cases when body search is performed with other header criteria, not just when subjects are specified.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search box finds nothing unless I clear every field except "body"

2 participants