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"