Support raw Himalaya query syntax in search

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
This commit is contained in:
Bendt
2025-12-19 15:00:04 -05:00
parent a5f7e78d8d
commit 807736f808

View File

@@ -335,9 +335,33 @@ async def search_envelopes(
- Success status (True if operation was successful)
"""
try:
# 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 <pattern> or to <pattern> or subject <pattern> or body <pattern>
search_query = f"from {query} or to {query} or subject {query} or body {query}"
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"