Skip to content

search_messages text query returns zero results on macOS Ventura+ (attributedBody bug) #5

@DarrellTang

Description

@DarrellTang

Bug

search_messages returns zero results when a text query is provided because the SQL WHERE m.text LIKE ? clause excludes messages stored in attributedBody. On macOS Ventura and later, iMessage stores message content in attributedBody (a binary blob) rather than in the plaintext m.text column, so m.text is often NULL for these rows.

Date-range-only searches work correctly because they don't filter on m.text, and attributedBody is decoded after the query. But keyword searches silently drop every row where m.text IS NULL.

Fix

Three changes in packages/imessage/src/messages.ts:

  1. SQL WHERE clause: Change AND m.text LIKE ? to AND (m.text LIKE ? OR m.text IS NULL) so attributedBody-only rows are included in the result set.
  2. Application-level filter: After decoding attributedBody into plaintext, filter rows whose decoded text doesn't contain the query string.
  3. Pagination: When a text query is present, skip SQL LIMIT/OFFSET (row count isn't known until after post-decode filtering) and paginate in application code instead. Total count is derived from the filtered set.

Tested

Confirmed 8 results returned for a known keyword vs 0 with upstream, on macOS Sequoia with chat.db containing attributedBody-encoded messages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions