From f838e660185ecf91dea9808ddbd862205fbca87a Mon Sep 17 00:00:00 2001 From: rustmailer Date: Mon, 18 Aug 2025 00:54:41 +0800 Subject: [PATCH] feat(email): add thread_id field to EmailAddedToFolder --- src/modules/cache/imap/sync/flow.rs | 2 ++ src/modules/hook/events/mod.rs | 1 + src/modules/hook/events/payload.rs | 3 +++ 3 files changed, 6 insertions(+) diff --git a/src/modules/cache/imap/sync/flow.rs b/src/modules/cache/imap/sync/flow.rs index 86a2813..aef0a00 100644 --- a/src/modules/cache/imap/sync/flow.rs +++ b/src/modules/cache/imap/sync/flow.rs @@ -774,6 +774,7 @@ async fn process_email_added_events( ) -> RustMailerResult<()> { for fetch in fetches { let envelope = extract_envelope(fetch, account.id, &remote.name)?; + let thread_id = envelope.compute_thread_id(); let message_content = match envelope.body_meta { Some(sections) => { let request = MessageContentRequest { @@ -823,6 +824,7 @@ async fn process_email_added_events( .attachments .as_ref() .map(|atts| atts.iter().cloned().map(Attachment::from).collect()), + thread_id, }), ), )) diff --git a/src/modules/hook/events/mod.rs b/src/modules/hook/events/mod.rs index 667676f..e3af82e 100644 --- a/src/modules/hook/events/mod.rs +++ b/src/modules/hook/events/mod.rs @@ -185,6 +185,7 @@ impl RustMailerEvent { html: Some(String::from("

Welcome to use rustmailer!

")), }, thread_name: Some("Meeting Thread".into()), + thread_id: id!(64), reply_to: Some(vec![addr("reply@example.com")]), to: Some(vec![addr("recipient@example.com")]), attachments: Some(vec![Attachment { diff --git a/src/modules/hook/events/payload.rs b/src/modules/hook/events/payload.rs index 3905b22..068769e 100644 --- a/src/modules/hook/events/payload.rs +++ b/src/modules/hook/events/payload.rs @@ -44,6 +44,9 @@ pub struct EmailAddedToFolder { pub subject: Option, /// Content of the email, including body and related metadata. pub message: MessageContent, + /// The identifier of the thread this email belongs to. + /// This is computed based on `in_reply_to` / `references` / `message_id`. + pub thread_id: u64, /// Optional name of the thread to which the email belongs. pub thread_name: Option, /// Optional list of reply-to addresses for the email.