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:
- 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.
- Application-level filter: After decoding
attributedBody into plaintext, filter rows whose decoded text doesn't contain the query string.
- 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.
Bug
search_messagesreturns zero results when a text query is provided because the SQLWHERE m.text LIKE ?clause excludes messages stored inattributedBody. On macOS Ventura and later, iMessage stores message content inattributedBody(a binary blob) rather than in the plaintextm.textcolumn, som.textis often NULL for these rows.Date-range-only searches work correctly because they don't filter on
m.text, andattributedBodyis decoded after the query. But keyword searches silently drop every row wherem.text IS NULL.Fix
Three changes in
packages/imessage/src/messages.ts:AND m.text LIKE ?toAND (m.text LIKE ? OR m.text IS NULL)so attributedBody-only rows are included in the result set.attributedBodyinto plaintext, filter rows whose decoded text doesn't contain the query string.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.