Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(email): don't drop signature when replying to a signed message (#4391)
Evan Hutnik96f9f1bf5155
diff --git a/rust/cloud-storage/email/src/domain/service/signature.rs b/rust/cloud-storage/email/src/domain/service/signature.rsindex cbc7501331..44fe562351 100644--- a/rust/cloud-storage/email/src/domain/service/signature.rs+++ b/rust/cloud-storage/email/src/domain/service/signature.rs@@ -9,18 +9,21 @@ mod test;/// Marker class wrapping an injected signature.const SIGNATURE_CLASS: &str = "macro-email-signature";-/// Whether the body already carries an injected signature, so the caller can-/// stay idempotent across a client that still bakes it in and across re-sends.+/// Whether the body already carries our signature in its own content (idempotency+/// for re-sends / an old client that still bakes it in). A signature inside a+/// quoted thread (`.macro_quote`) is the replied-to message's and is ignored.pub(crate) fn has_signature(body_html: &str) -> bool {- Selector::parse(&format!(".{SIGNATURE_CLASS}"))- .ok()- .map(|sel| {- Html::parse_fragment(body_html)- .select(&sel)- .next()- .is_some()+ let Ok(sig_sel) = Selector::parse(&format!(".{SIGNATURE_CLASS}")) else {+ return false;+ };+ Html::parse_fragment(body_html).select(&sig_sel).any(|el| {+ !el.ancestors().any(|node| {+ node.value()+ .as_element()+ .and_then(|e| e.attr("class"))+ .is_some_and(|class| class.split_whitespace().any(|c| c == "macro_quote"))})- .unwrap_or(false)+ })}/// Injects the (already-sanitized) signature into the outgoing HTML body,diff --git a/rust/cloud-storage/email/src/domain/service/signature/test.rs b/rust/cloud-storage/email/src/domain/service/signature/test.rsindex 39d710cf7e..7a763c5786 100644--- a/rust/cloud-storage/email/src/domain/service/signature/test.rs+++ b/rust/cloud-storage/email/src/domain/service/signature/test.rs@@ -37,6 +37,17 @@ fn is_idempotent_when_signature_already_present() {assert!(!has_signature("<body><p>no signature here</p></body>"));}+#[test]+fn ignores_signature_inside_quoted_thread() {+ // Replying to a previously-signed message: the quote carries that message's+ // signature, which must not count as "already signed" for this reply.+ let reply = r#"<body><p>My reply</p><div class="macro_quote"><p>Old</p><div class="macro-email-signature">Ryan</div></div></body>"#;+ assert!(!has_signature(reply));+ // A signature in the reply's own content (above the quote) still counts.+ let signed = r#"<body><div class="macro-email-signature">Me</div><div class="macro_quote"><p>Old</p></div></body>"#;+ assert!(has_signature(signed));+}+#[test]fn plain_text_joins_block_nodes_with_newlines() {// Block boundaries become newlines (not run together as "ThanksAlice").