Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(soup): add ability to filter soup by email thread ids (#1482)

teo0550e0acf183
diff --git a/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts b/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts
index 920be897ef..6a7882ef20 100644
--- a/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts
+++ b/js/app/packages/service-clients/service-search/generated/models/emailFilters.ts
@@ -14,6 +14,8 @@ export interface EmailFilters {
bcc?: string[];
/** Email CC addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by CC. */
cc?: string[];
+ /** Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads. */
+ email_thread_ids?: string[];
/** Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */
importance?: EmailFiltersImportance;
/** Email Recipient addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by Recipient. */
diff --git a/js/app/packages/service-clients/service-search/openapi.json b/js/app/packages/service-clients/service-search/openapi.json
index 42bf0667db..248420467c 100644
--- a/js/app/packages/service-clients/service-search/openapi.json
+++ b/js/app/packages/service-clients/service-search/openapi.json
@@ -871,6 +871,13 @@
},
"description": "Email CC addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by CC."
},
+ "email_thread_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "description": "Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads."
+ },
"importance": {
"type": ["boolean", "null"],
"description": "Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts b/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts
index 33f09dd75e..dc337b0cde 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/emailFilters.ts
@@ -14,6 +14,8 @@ export interface EmailFilters {
bcc?: string[];
/** Email CC addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by CC. */
cc?: string[];
+ /** Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads. */
+ email_thread_ids?: string[];
/** Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing. */
importance?: EmailFiltersImportance;
/** Email Recipient addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by Recipient. */
diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.ts
index 85fb90bce5..e99c8a86ed 100644
--- a/js/app/packages/service-clients/service-storage/generated/zod.ts
+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts
@@ -3702,6 +3702,12 @@ export const postItemsSoupBody = zod
.describe(
"Email CC addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by CC."
),
+ email_thread_ids: zod
+ .array(zod.string())
+ .optional()
+ .describe(
+ "Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads."
+ ),
importance: zod
.boolean()
.nullish()
diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.json
index 9248e076a7..168f64b19d 100644
--- a/js/app/packages/service-clients/service-storage/openapi.json
+++ b/js/app/packages/service-clients/service-storage/openapi.json
@@ -6087,6 +6087,13 @@
},
"description": "Email CC addresses to filter by. Examples: ['[email protected]']. Empty if not filtering by CC."
},
+ "email_thread_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "description": "Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads."
+ },
"importance": {
"type": ["boolean", "null"],
"description": "Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing."
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic.rs
index a840f0deca..3480cdef83 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic.rs
@@ -14,14 +14,32 @@ use uuid::Uuid;
#[cfg(test)]
mod tests;
-/// Builds SQL WHERE conditions for email filters based on the AST.
-/// Returns a string to be appended to the WHERE clause.
-fn build_email_filter(ast: &Expr<EmailLiteral>) -> String {
+fn has_thread_literals(ast: &Expr<EmailLiteral>) -> bool {
+ ast.collapse_frames(|frame| match frame {
+ filter_ast::ExprFrame::And(a, b) | filter_ast::ExprFrame::Or(a, b) => a || b,
+ filter_ast::ExprFrame::Not(a) => a,
+ filter_ast::ExprFrame::Literal(EmailLiteral::ThreadId(_)) => true,
+ filter_ast::ExprFrame::Literal(_) => false,
+ })
+}
+
+fn has_message_literals(ast: &Expr<EmailLiteral>) -> bool {
+ ast.collapse_frames(|frame| match frame {
+ filter_ast::ExprFrame::And(a, b) | filter_ast::ExprFrame::Or(a, b) => a || b,
+ filter_ast::ExprFrame::Not(a) => a,
+ filter_ast::ExprFrame::Literal(EmailLiteral::ThreadId(_)) => false,
+ filter_ast::ExprFrame::Literal(_) => true,
+ })
+}
+
+fn build_message_email_filter(ast: &Expr<EmailLiteral>) -> String {
let formatting = ast.collapse_frames(|frame| match frame {
filter_ast::ExprFrame::And(a, b) => format!("({a} AND {b})"),
filter_ast::ExprFrame::Or(a, b) => format!("({a} OR {b})"),
filter_ast::ExprFrame::Not(a) => format!("(NOT {a})"),
+ filter_ast::ExprFrame::Literal(EmailLiteral::ThreadId(_)) => "TRUE".to_string(),
+
filter_ast::ExprFrame::Literal(EmailLiteral::Sender(email)) => match email {
Email::Complete(e) => format!(
r#"EXISTS (
@@ -154,6 +172,33 @@ fn build_email_filter(ast: &Expr<EmailLiteral>) -> String {
}
}
+/// Builds thread-level SQL WHERE conditions. Message-level literals map to TRUE.
+fn build_thread_email_filter(ast: &Expr<EmailLiteral>) -> String {
+ let formatting = ast.collapse_frames(|frame| match frame {
+ filter_ast::ExprFrame::And(a, b) => format!("({a} AND {b})"),
+ filter_ast::ExprFrame::Or(a, b) => format!("({a} OR {b})"),
+ filter_ast::ExprFrame::Not(a) => format!("(NOT {a})"),
+
+ filter_ast::ExprFrame::Literal(EmailLiteral::ThreadId(id)) => {
+ format!("t.id = '{id}'::uuid")
+ }
+
+ filter_ast::ExprFrame::Literal(
+ EmailLiteral::Sender(_)
+ | EmailLiteral::Cc(_)
+ | EmailLiteral::Bcc(_)
+ | EmailLiteral::Recipient(_)
+ | EmailLiteral::Importance(_),
+ ) => "TRUE".to_string(),
+ });
+
+ if formatting.is_empty() {
+ String::new()
+ } else {
+ format!(" AND {}", formatting)
+ }
+}
+
/// Escapes special characters in LIKE patterns to prevent SQL injection
fn escape_like_pattern(s: &str) -> String {
s.replace('\\', r"\\")
@@ -341,6 +386,10 @@ fn build_query<'a>(
builder.push(view_thread_filter);
}
+ if has_thread_literals(email_filter) {
+ builder.push(build_thread_email_filter(email_filter));
+ }
+
builder.push(
r#"
-- Cursor logic
@@ -381,10 +430,8 @@ fn build_query<'a>(
builder.push(view_message_filter);
}
- // Add dynamic email filters
- let filter_sql = build_email_filter(email_filter);
- if !filter_sql.is_empty() {
- builder.push(filter_sql);
+ if has_message_literals(email_filter) {
+ builder.push(build_message_email_filter(email_filter));
}
builder.push(
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/tests.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/tests.rs
index 7ed493f9f0..7577021266 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/tests.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/tests.rs
@@ -2,40 +2,41 @@ use super::*;
use item_filters::ast::email::{Email, EmailLiteral};
use macro_user_id::cowlike::CowLike;
use macro_user_id::email::EmailStr;
+use uuid::Uuid;
#[test]
-fn test_build_email_filter_sender_complete() {
+fn test_build_message_email_filter_sender_complete() {
let email = Email::Complete(
EmailStr::parse_from_str("[email protected]")
.unwrap()
.into_owned(),
);
let expr = Expr::Literal(EmailLiteral::Sender(email));
- let result = build_email_filter(&expr);
+ let result = build_message_email_filter(&expr);
assert!(result.contains("m.from_contact_id"));
assert!(result.contains("LOWER(c.email_address) = LOWER('[email protected]')"));
}
#[test]
-fn test_build_email_filter_sender_partial() {
+fn test_build_message_email_filter_sender_partial() {
let email = Email::Partial("example".to_string());
let expr = Expr::Literal(EmailLiteral::Sender(email));
- let result = build_email_filter(&expr);
+ let result = build_message_email_filter(&expr);
assert!(result.contains("m.from_contact_id"));
assert!(result.contains("c.email_address ILIKE '%example%'"));
}
#[test]
-fn test_build_email_filter_recipient() {
+fn test_build_message_email_filter_recipient() {
let email = Email::Complete(
EmailStr::parse_from_str("[email protected]")
.unwrap()
.into_owned(),
);
let expr = Expr::Literal(EmailLiteral::Recipient(email));
- let result = build_email_filter(&expr);
+ let result = build_message_email_filter(&expr);
assert!(result.contains("email_message_recipients"));
assert!(result.contains("recipient_type = 'TO'"));
@@ -43,33 +44,33 @@ fn test_build_email_filter_recipient() {
}
#[test]
-fn test_build_email_filter_cc() {
+fn test_build_message_email_filter_cc() {
let email = Email::Complete(
EmailStr::parse_from_str("[email protected]")
.unwrap()
.into_owned(),
);
let expr = Expr::Literal(EmailLiteral::Cc(email));
- let result = build_email_filter(&expr);
+ let result = build_message_email_filter(&expr);
assert!(result.contains("recipient_type = 'CC'"));
}
#[test]
-fn test_build_email_filter_bcc() {
+fn test_build_message_email_filter_bcc() {
let email = Email::Complete(
EmailStr::parse_from_str("[email protected]")
.unwrap()
.into_owned(),
);
let expr = Expr::Literal(EmailLiteral::Bcc(email));
- let result = build_email_filter(&expr);
+ let result = build_message_email_filter(&expr);
assert!(result.contains("recipient_type = 'BCC'"));
}
#[test]
-fn test_build_email_filter_and() {
+fn test_build_message_email_filter_and() {
let email1 = Email::Complete(
EmailStr::parse_from_str("[email protected]")
.unwrap()
@@ -84,7 +85,7 @@ fn test_build_email_filter_and() {
Expr::Literal(EmailLiteral::Sender(email1)),
Expr::Literal(EmailLiteral::Recipient(email2)),
);
- let result = build_email_filter(&expr);
+ let result = build_message_email_filter(&expr);
assert!(result.contains("AND"));
assert!(result.contains("[email protected]"));
@@ -92,7 +93,7 @@ fn test_build_email_filter_and() {
}
#[test]
-fn test_build_email_filter_or() {
+fn test_build_message_email_filter_or() {
let email1 = Email::Complete(
EmailStr::parse_from_str("[email protected]")
.unwrap()
@@ -107,7 +108,7 @@ fn test_build_email_filter_or() {
Expr::Literal(EmailLiteral::Sender(email1)),
Expr::Literal(EmailLiteral::Sender(email2)),
);
- let result = build_email_filter(&expr);
+ let result = build_message_email_filter(&expr);
assert!(result.contains("OR"));
assert!(result.contains("[email protected]"));
@@ -115,14 +116,14 @@ fn test_build_email_filter_or() {
}
#[test]
-fn test_build_email_filter_not() {
+fn test_build_message_email_filter_not() {
let email = Email::Complete(
EmailStr::parse_from_str("[email protected]")
.unwrap()
.into_owned(),
);
let expr = Expr::is_not(Expr::Literal(EmailLiteral::Sender(email)));
- let result = build_email_filter(&expr);
+ let result = build_message_email_filter(&expr);
assert!(result.contains("NOT"));
assert!(result.contains("[email protected]"));
@@ -203,3 +204,125 @@ fn test_get_sort_timestamp_field_default() {
let result = get_sort_timestamp_field(&view);
assert_eq!(result, "t.latest_non_spam_message_ts");
}
+
+#[test]
+fn test_build_thread_email_filter_single_thread_id() {
+ let id = Uuid::new_v4();
+ let expr = Expr::Literal(EmailLiteral::ThreadId(id));
+ let result = build_thread_email_filter(&expr);
+
+ assert!(result.contains(&format!("t.id = '{id}'::uuid")));
+}
+
+#[test]
+fn test_build_thread_email_filter_multiple_thread_ids() {
+ let id1 = Uuid::new_v4();
+ let id2 = Uuid::new_v4();
+ let expr = Expr::or(
+ Expr::Literal(EmailLiteral::ThreadId(id1)),
+ Expr::Literal(EmailLiteral::ThreadId(id2)),
+ );
+ let result = build_thread_email_filter(&expr);
+
+ assert!(result.contains(&format!("t.id = '{id1}'::uuid")));
+ assert!(result.contains(&format!("t.id = '{id2}'::uuid")));
+ assert!(result.contains("OR"));
+}
+
+#[test]
+fn test_build_thread_email_filter_maps_sender_to_true() {
+ let email = Email::Complete(
+ EmailStr::parse_from_str("[email protected]")
+ .unwrap()
+ .into_owned(),
+ );
+ let expr = Expr::Literal(EmailLiteral::Sender(email));
+ let result = build_thread_email_filter(&expr);
+
+ assert!(result.contains("TRUE"));
+ assert!(!result.contains("t.id"));
+}
+
+#[test]
+fn test_build_message_email_filter_maps_thread_id_to_true() {
+ let id = Uuid::new_v4();
+ let expr = Expr::Literal(EmailLiteral::ThreadId(id));
+ let result = build_message_email_filter(&expr);
+
+ assert!(result.contains("TRUE"));
+ assert!(!result.contains("t.id"));
+}
+
+#[test]
+fn test_combined_thread_id_and_sender_splits_correctly() {
+ let id = Uuid::new_v4();
+ let email = Email::Complete(
+ EmailStr::parse_from_str("[email protected]")
+ .unwrap()
+ .into_owned(),
+ );
+ let expr = Expr::and(
+ Expr::Literal(EmailLiteral::ThreadId(id)),
+ Expr::Literal(EmailLiteral::Sender(email)),
+ );
+
+ let thread_result = build_thread_email_filter(&expr);
+ assert!(thread_result.contains(&format!("t.id = '{id}'::uuid")));
+ assert!(!thread_result.contains("from_contact_id"));
+
+ let message_result = build_message_email_filter(&expr);
+ assert!(message_result.contains("from_contact_id"));
+ assert!(!message_result.contains(&format!("t.id = '{id}'")));
+}
+
+#[test]
+fn test_has_thread_literals_true_when_thread_id_present() {
+ let id = Uuid::new_v4();
+ let expr = Expr::Literal(EmailLiteral::ThreadId(id));
+ assert!(has_thread_literals(&expr));
+}
+
+#[test]
+fn test_has_thread_literals_false_when_only_message_literals() {
+ let email = Email::Complete(
+ EmailStr::parse_from_str("[email protected]")
+ .unwrap()
+ .into_owned(),
+ );
+ let expr = Expr::Literal(EmailLiteral::Sender(email));
+ assert!(!has_thread_literals(&expr));
+}
+
+#[test]
+fn test_has_message_literals_true_when_sender_present() {
+ let email = Email::Complete(
+ EmailStr::parse_from_str("[email protected]")
+ .unwrap()
+ .into_owned(),
+ );
+ let expr = Expr::Literal(EmailLiteral::Sender(email));
+ assert!(has_message_literals(&expr));
+}
+
+#[test]
+fn test_has_message_literals_false_when_only_thread_id() {
+ let id = Uuid::new_v4();
+ let expr = Expr::Literal(EmailLiteral::ThreadId(id));
+ assert!(!has_message_literals(&expr));
+}
+
+#[test]
+fn test_has_both_literals_in_combined_ast() {
+ let id = Uuid::new_v4();
+ let email = Email::Complete(
+ EmailStr::parse_from_str("[email protected]")
+ .unwrap()
+ .into_owned(),
+ );
+ let expr = Expr::and(
+ Expr::Literal(EmailLiteral::ThreadId(id)),
+ Expr::Literal(EmailLiteral::Sender(email)),
+ );
+ assert!(has_thread_literals(&expr));
+ assert!(has_message_literals(&expr));
+}
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/test.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/test.rs
index 962a14e611..b331849335 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/test.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/test.rs
@@ -722,3 +722,62 @@ async fn test_dynamic_query_with_importance_filter(pool: Pool<Postgres>) -> anyh
Ok(())
}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("email_dynamic_query"))
+)]
+async fn test_dynamic_query_with_single_thread_id(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let link_id = Uuid::parse_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")?;
+ let view = PreviewView::StandardLabel(PreviewViewStandardLabel::All);
+ let limit = 50;
+
+ let thread_id = Uuid::parse_str("20000001-0000-0000-0000-000000000001")?;
+ let filter = Arc::new(Expr::Literal(EmailLiteral::ThreadId(thread_id)));
+ let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
+
+ let results =
+ dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query).await?;
+
+ assert_eq!(results.len(), 1);
+ assert_eq!(results[0].id, thread_id);
+ assert_eq!(results[0].name.as_deref(), Some("Meeting Tomorrow"));
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("email_dynamic_query"))
+)]
+async fn test_dynamic_query_thread_id_with_sender_filter(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let link_id = Uuid::parse_str("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")?;
+ let view = PreviewView::StandardLabel(PreviewViewStandardLabel::All);
+ let limit = 50;
+
+ // Thread 1 is from john, thread 3 is from bob.
+ // AND(OR(thread1, thread3), sender=john) should only return thread 1.
+ let id1 = Uuid::parse_str("20000001-0000-0000-0000-000000000001")?;
+ let id3 = Uuid::parse_str("20000003-0000-0000-0000-000000000003")?;
+ let filter = Arc::new(Expr::and(
+ Expr::or(
+ Expr::Literal(EmailLiteral::ThreadId(id1)),
+ Expr::Literal(EmailLiteral::ThreadId(id3)),
+ ),
+ Expr::Literal(EmailLiteral::Sender(Email::Complete(
+ EmailStr::parse_from_str("[email protected]")?.into_owned(),
+ ))),
+ ));
+ let query = Query::new(None, SimpleSortMethod::UpdatedAt, filter);
+
+ let results =
+ dynamic::dynamic_email_thread_cursor(&pool, &link_id, limit, &view, query).await?;
+
+ assert_eq!(results.len(), 1);
+ assert_eq!(results[0].id, id1);
+ assert_eq!(results[0].sender_email.as_deref(), Some("[email protected]"));
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/item_filters/src/ast/email.rs b/rust/cloud-storage/item_filters/src/ast/email.rs
index 94275ae631..a8ddfe9958 100644
--- a/rust/cloud-storage/item_filters/src/ast/email.rs
+++ b/rust/cloud-storage/item_filters/src/ast/email.rs
@@ -1,6 +1,7 @@
use filter_ast::{ExpandFrame, Expr, FoldTree, TryExpandNode};
use macro_user_id::{cowlike::CowLike, email::EmailStr};
use serde::{Deserialize, Serialize};
+use uuid::Uuid;
use crate::{EmailFilters, ast::ExpandErr};
@@ -24,6 +25,8 @@ pub enum EmailLiteral {
Bcc(Email),
/// The recipient field of the email
Recipient(Email),
+ /// This value filters by email thread ID
+ ThreadId(Uuid),
/// This node value filters by email importance. false short-circuits to match nothing.
Importance(bool),
}
@@ -36,6 +39,7 @@ impl ExpandFrame<EmailLiteral> for EmailFilters {
cc,
bcc,
recipients,
+ email_thread_ids,
importance,
} = input;
@@ -63,6 +67,11 @@ impl ExpandFrame<EmailLiteral> for EmailFilters {
.map(map_email)
.expand(EmailLiteral::Recipient, Expr::or);
+ let thread_id_nodes = email_thread_ids
+ .iter()
+ .map(|s| Uuid::parse_str(s))
+ .try_expand(|r| r.map(EmailLiteral::ThreadId), Expr::or)?;
+
let importance_node = importance.map(|imp| Expr::Literal(EmailLiteral::Importance(imp)));
Ok([
@@ -70,6 +79,7 @@ impl ExpandFrame<EmailLiteral> for EmailFilters {
cc_nodes,
bcc_nodes,
recipient_nodes,
+ thread_id_nodes,
importance_node,
]
.into_iter()
diff --git a/rust/cloud-storage/item_filters/src/ast/tests.rs b/rust/cloud-storage/item_filters/src/ast/tests.rs
index 77e914ab24..535e09928b 100644
--- a/rust/cloud-storage/item_filters/src/ast/tests.rs
+++ b/rust/cloud-storage/item_filters/src/ast/tests.rs
@@ -195,3 +195,59 @@ fn it_expands_other_association() {
assert_eq!(json.trim(), include_str!("tests/other.json").trim());
}
+
+#[test]
+fn it_expands_email_thread_ids() {
+ let thread_id = Uuid::new_v4();
+ let f = EntityFilters {
+ email_filters: crate::EmailFilters {
+ email_thread_ids: vec![thread_id.to_string()],
+ ..Default::default()
+ },
+ ..Default::default()
+ };
+
+ let ast = Arc::into_inner(
+ EntityFilterAst::new_from_filters(f)
+ .unwrap()
+ .unwrap()
+ .email_filter
+ .unwrap(),
+ )
+ .unwrap();
+
+ let json = serde_json::to_value(ast).unwrap();
+ let exp = json!({
+ "l": {
+ "ThreadId": thread_id
+ }
+ });
+
+ assert_eq!(json, exp);
+}
+
+#[test]
+fn it_expands_email_thread_ids_with_sender() {
+ let thread_id = Uuid::new_v4();
+ let f = EntityFilters {
+ email_filters: crate::EmailFilters {
+ senders: vec!["[email protected]".to_string()],
+ email_thread_ids: vec![thread_id.to_string()],
+ ..Default::default()
+ },
+ ..Default::default()
+ };
+
+ let ast = Arc::into_inner(
+ EntityFilterAst::new_from_filters(f)
+ .unwrap()
+ .unwrap()
+ .email_filter
+ .unwrap(),
+ )
+ .unwrap();
+
+ let json = serde_json::to_value(ast).unwrap();
+ // Should be AND of sender and thread_id
+ assert!(json.get("&").is_some());
+}
diff --git a/rust/cloud-storage/item_filters/src/lib.rs b/rust/cloud-storage/item_filters/src/lib.rs
index 20ac547a44..9938ccb600 100644
--- a/rust/cloud-storage/item_filters/src/lib.rs
+++ b/rust/cloud-storage/item_filters/src/lib.rs
@@ -124,6 +124,10 @@ pub struct EmailFilters {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub recipients: Vec<String>,
+ /// Email thread IDs to filter by. Examples: ['thread-uuid-1']. Empty to search all threads.
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub email_thread_ids: Vec<String>,
+
/// Filter by email importance. None to ignore, true to pass through (no clause), false to short-circuit and return nothing.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub importance: Option<bool>,
@@ -136,12 +140,14 @@ impl IsEmpty for EmailFilters {
cc,
bcc,
recipients,
+ email_thread_ids,
importance,
} = self;
senders.is_empty()
&& cc.is_empty()
&& bcc.is_empty()
&& recipients.is_empty()
+ && email_thread_ids.is_empty()
&& importance.is_none()
}
}
diff --git a/rust/cloud-storage/models_search/src/email/test.rs b/rust/cloud-storage/models_search/src/email/test.rs
index 7722ba8508..e52924360d 100644
--- a/rust/cloud-storage/models_search/src/email/test.rs
+++ b/rust/cloud-storage/models_search/src/email/test.rs
@@ -12,6 +12,7 @@ fn test_email_search_request_json_serialization() {
cc: vec!["[email protected]".to_string()],
bcc: vec!["[email protected]".to_string()],
recipients: vec![],
+ email_thread_ids: vec![],
importance: None,
}),
search_on: SearchOn::Content,
@@ -97,6 +98,7 @@ fn test_email_search_request_round_trip() {
cc: vec![],
bcc: vec!["[email protected]".to_string()],
recipients: vec![],
+ email_thread_ids: vec![],
importance: None,
}),
search_on: SearchOn::Content,