From 807736f808a0e3519641639945366721609ef970 Mon Sep 17 00:00:00 2001 From: Bendt Date: Fri, 19 Dec 2025 15:00:04 -0500 Subject: [PATCH] Support raw Himalaya query syntax in search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Detect when user types a query starting with Himalaya keywords (from, to, subject, body, date, before, after, flag, not, order by) and pass it through as-is instead of wrapping it in the compound search pattern. This allows both: - Simple searches: 'edson' → searches from/to/subject/body - Raw queries: 'from edson' → uses Himalaya syntax directly --- src/services/himalaya/client.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/services/himalaya/client.py b/src/services/himalaya/client.py index 3e05720..65313ab 100644 --- a/src/services/himalaya/client.py +++ b/src/services/himalaya/client.py @@ -335,9 +335,33 @@ async def search_envelopes( - Success status (True if operation was successful) """ try: - # Build a compound query to search from, to, subject, and body - # Himalaya query syntax: from or to or subject or body - search_query = f"from {query} or to {query} or subject {query} or body {query}" + # Himalaya query keywords that indicate the user is writing a raw query + query_keywords = ( + "from ", + "to ", + "subject ", + "body ", + "date ", + "before ", + "after ", + "flag ", + "not ", + "order by ", + ) + + # Check if user is using raw query syntax + query_lower = query.lower() + is_raw_query = any(query_lower.startswith(kw) for kw in query_keywords) + + if is_raw_query: + # Pass through as-is (user knows what they're doing) + search_query = query + else: + # Build a compound query to search from, to, subject, and body + # Himalaya query syntax: from or to or subject or body + search_query = ( + f"from {query} or to {query} or subject {query} or body {query}" + ) # Build command with options before the query (query must be at the end, quoted) cmd = "himalaya envelope list -o json"