Skip to main content

io_email/search/filter/
query.rs

1//! # Search emails filter query
2//!
3//! Exposes [`SearchEmailsFilterQuery`], the recursive AST produced by
4//! [`super::parser::query`].
5
6use alloc::{boxed::Box, string::String};
7
8use chrono::NaiveDate;
9
10use crate::flag::types::Flag;
11
12/// The search emails filter query.
13///
14/// Composed of 3 operators (and, or, not) and 7 conditions (date,
15/// after date, from, to, subject, body, flag). All date-related
16/// conditions are anchored to the `Date:` header (sent-at), never to
17/// the server-side received-at timestamp.
18#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
19pub enum SearchEmailsFilterQuery {
20    /// Filter emails that match both given conditions.
21    And(Box<SearchEmailsFilterQuery>, Box<SearchEmailsFilterQuery>),
22
23    /// Filter emails that match one of the two given conditions.
24    Or(Box<SearchEmailsFilterQuery>, Box<SearchEmailsFilterQuery>),
25
26    /// Filter emails that do not match the given condition.
27    Not(Box<SearchEmailsFilterQuery>),
28
29    /// Filter emails where the `Date:` header of the message matches
30    /// the given date.
31    ///
32    /// Only the year, the month and the day are taken into
33    /// consideration.
34    Date(NaiveDate),
35
36    /// Filter emails where the `Date:` header of the message is
37    /// strictly greater than the given date.
38    ///
39    /// For example, for `2024-01-01` it matches messages with a date
40    /// starting from `2024-01-02` and above. Only the year, the month
41    /// and the day are taken into consideration.
42    AfterDate(NaiveDate),
43
44    /// Filter emails where the `From:` header of the message contains
45    /// the given pattern.
46    From(String),
47
48    /// Filter emails where the `To:` header of the message contains
49    /// the given pattern.
50    To(String),
51
52    /// Filter emails where the `Subject:` header of the message
53    /// contains the given pattern.
54    Subject(String),
55
56    /// Filter emails where one of the text bodies of the message
57    /// contains the given pattern.
58    Body(String),
59
60    /// Filter emails where the given flag is included in the email
61    /// envelope flags.
62    Flag(Flag),
63}