You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Advanced mail search across one or multiple folders.
175
+
176
+
* **operator**: str, 'AND' (default) or 'OR' - how the criteria below are combined.
177
+
With 'AND' every provided criterion must match, with 'OR' at least one must match.
178
+
* **text**: str, full text search in subject/sender/recipients/body
179
+
* **folders**: list[str], list of folder paths to search in (e.g. ["INBOX", "Sent"] or ["all"] for all folders)
180
+
* **include_subfolders**: bool, default True - when True, also search the subfolders of each folder listed in "folders"; when False, search only the exact folders listed. Ignored when "folders" is empty or ["all"].
181
+
* **date_range**: dict, date range for the search (e.g. {"from": "2023-01-01", "to": "2023-01-31"})
182
+
* **has_attachments**: bool, whether to search for emails with attachments
183
+
* **to**: str, email address to search for in either the recipient (To) or copy (Cc) headers
184
+
* **bcc**: str, blind copy (Bcc) email address to search for
185
+
* **from**: list[str], list of sender email addresses to search for
186
+
* **subject** : str, keywords to search for in the email subject
187
+
* **attachment_type**: list[str], list of attachment types to search for (e.g. ["pdf", "jpg"])
188
+
* **is_read**: bool, whether to search for read or unread emails
189
+
* **labels**: list[str], list of labels/tags to search for
190
+
191
+
All search criteria are optional and combined using the "operator" field (AND by default, OR to match any criterion).
192
+
Pagination, sorting and field filtering are controlled via query parameters (page, page_size, sort_by, sort_order, fields, fields_action).
193
+
"""
194
+
logger_api.debug("Calling ApiMailBoxesAccountSearch.post for account_id: %s with params: %s", account_id, search_params)
Copy file name to clipboardExpand all lines: app/api/v1/mail/schemas/mailbox.py
+99Lines changed: 99 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -604,3 +604,102 @@ def example(cls) -> dict:
604
604
}
605
605
}
606
606
607
+
classDateRangeSchema(Schema):
608
+
"""
609
+
Schema for date range filter in advanced search
610
+
"""
611
+
start=fields.String(required=False, allow_none=True, metadata={"description": "Start date in ISO 8601 format (e.g. 2026-05-01T00:00:00Z)"})
612
+
end=fields.String(required=False, allow_none=True, metadata={"description": "End date in ISO 8601 format (e.g. 2026-05-19T23:59:59Z)"})
613
+
614
+
@classmethod
615
+
defexample(cls) ->dict:
616
+
return {
617
+
"start": "2026-05-01T00:00:00Z",
618
+
"end": "2026-05-19T23:59:59Z"
619
+
}
620
+
621
+
622
+
classMailboxSearchSchema(Schema):
623
+
"""
624
+
Schema for POST /mailboxes/<account_id>/search - Advanced mail search.
625
+
626
+
All fields are optional. When multiple criteria are provided, they are combined
627
+
using the "operator" field: "AND" (default, every criterion must match) or
628
+
"OR" (at least one criterion must match).
629
+
"""
630
+
operator=fields.String(
631
+
required=False,
632
+
allow_none=True,
633
+
load_default="AND",
634
+
validate=validate.OneOf(["AND", "OR"]),
635
+
metadata={"description": "Logical operator combining the search criteria below: 'AND' (default) requires every provided criterion to match, 'OR' requires at least one to match"}
636
+
)
637
+
text=fields.String(required=False, allow_none=True, load_default=None, metadata={"description": "Full-text search in body and headers"})
638
+
from_=fields.String(required=False, allow_none=True, load_default=None, data_key="from", metadata={"description": "Filter by sender email address"})
639
+
to=fields.String(required=False, allow_none=True, load_default=None, metadata={"description": "Filter by recipient email address (matches either the To or the Cc header)"})
640
+
bcc=fields.String(required=False, allow_none=True, load_default=None, metadata={"description": "Filter by Bcc recipient email address"})
641
+
subject=fields.String(required=False, allow_none=True, load_default=None, metadata={"description": "Filter by subject (substring match)"})
642
+
has_attachment=fields.Boolean(required=False, allow_none=True, load_default=None, metadata={"description": "Filter mails that have (or don't have) attachments"})
date_range=fields.Nested(DateRangeSchema, required=False, allow_none=True, load_default=None, metadata={"description": "Filter by date range"})
645
+
is_read=fields.Boolean(required=False, allow_none=True, load_default=None, metadata={"description": "Filter by read/unread status"})
646
+
is_flagged=fields.Boolean(required=False, allow_none=True, load_default=None, metadata={"description": "Filter by starred (flagged) status"})
647
+
folders=fields.List(fields.String(), required=False, allow_none=True, load_default=None, metadata={"description": "Folders to search in (use ['all'] for entire mailbox)"})
648
+
include_subfolders=fields.Boolean(required=False, allow_none=True, load_default=True, metadata={"description": "If True (default), also search in the subfolders of each folder listed in 'folders'. If False, search only in the exact folders listed"})
649
+
labels=fields.List(fields.String(), required=False, allow_none=True, load_default=None, metadata={"description": "Filter by IMAP keyword labels"})
0 commit comments