Skip to content

fix(mail): avoid $orderby together with $search (Graph rejects it)#12

Open
okuegow wants to merge 1 commit into
visionik:mainfrom
okuegow:fix/search-orderby
Open

fix(mail): avoid $orderby together with $search (Graph rejects it)#12
okuegow wants to merge 1 commit into
visionik:mainfrom
okuegow:fix/search-orderby

Conversation

@okuegow

@okuegow okuegow commented Jun 18, 2026

Copy link
Copy Markdown

Problem

mog mail search (and mail list, which delegates to it) sent $orderby together with $search. Microsoft Graph rejects that combination for /me/messages (SearchWithOrderBy: The query parameter '$orderby' is not supported with '$search'), so every text search (mog mail search <term>) failed outright; only * / listing worked.

Fix

  • Extract query building into buildMailSearchQuery and apply $orderby only when not doing a $search. Listing (*, empty, or whitespace-only) keeps date sorting.
  • Escape \ and " inside the $search phrase so terms like foo" bar or C:\Temp don't produce a broken/altered query.
  • Treat whitespace-only queries as a plain listing.

Tests

  • buildMailSearchQuery unit tests: search vs listing, escaping, whitespace.
  • A Run-level test asserting via the mock client that a real query sets $search and no $orderby, and * does the reverse.
  • go build ./..., go vet ./..., go test ./... pass.

Fixes #11

Microsoft Graph returns "SearchWithOrderBy: The query parameter
'$orderby' is not supported with '$search'" for /me/messages, so every
`mog mail search <query>` failed outright.

Extract query building into buildMailSearchQuery and only apply $orderby
when not searching; listing (`*`/empty/whitespace) keeps date sorting.
Escape backslash and double quote in the $search phrase so terms like
`foo" bar` or `C:\Temp` produce a valid query. Adds unit tests for the
query builder (incl. escaping/whitespace) and a Run-level test asserting
the $search/$orderby split via the mock client.

Fixes visionik#11
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.

mail search always fails: $orderby is sent together with $search (Graph rejects the combination)

1 participant