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-service): Contacts upload - exclude emails with a plus in them (#283)
Evan Hutnik427716373f4e
diff --git a/rust/cloud-storage/email_db_client/src/contacts/get.rs b/rust/cloud-storage/email_db_client/src/contacts/get.rsindex 0f795232e4..875d3cbc17 100644--- a/rust/cloud-storage/email_db_client/src/contacts/get.rs+++ b/rust/cloud-storage/email_db_client/src/contacts/get.rs@@ -1,6 +1,7 @@use crate::parse::db_to_service::map_db_contact_to_service;use anyhow::Context;use chrono::{DateTime, Utc};+use email_utils::{dedupe_emails, is_generic_email};use models_email::service::address;use models_email::{db, service};use sqlx::PgPool;@@ -358,10 +359,10 @@ pub async fn fetch_contacts_emails_by_link_id(.await.context("Failed to fetch contacts for link ID")?;- Ok(rows+ let deduped = dedupe_emails(rows.into_iter().map(|row| row.email_address).collect());+ Ok(deduped.into_iter()- .map(|row| row.email_address)- .filter(|e| !email_utils::is_generic_email(e))+ .filter(|e| !is_generic_email(e)).collect())}diff --git a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rsindex a14d653893..5a361eba3e 100644--- a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs+++ b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs@@ -5,6 +5,7 @@ use crate::pubsub::webhook::process;use crate::util::process_pre_insert::{process_message_pre_insert, process_threads_pre_insert};use email_db_client::threads;use email_db_client::threads::get::get_outbound_threads_by_thread_ids;+use email_utils::dedupe_emails;use futures::future::join_all;use insight_service_client::InsightContextProvider;use model::contacts::ConnectionsMessage;@@ -73,15 +74,17 @@ pub async fn upsert_message(let is_sent = message.is_sent;// deduped list of all non-generic emails the message was sent to- let recipient_emails = message- .cc- .iter()- .map(|c| c.email.clone())- .chain(message.to.iter().map(|t| t.email.clone()))- .collect::<std::collections::HashSet<_>>()- .into_iter()- .filter(|e| !email_utils::is_generic_email(e))- .collect::<Vec<_>>();+ let recipient_emails = dedupe_emails(+ message+ .cc+ .iter()+ .map(|c| c.email.clone())+ .chain(message.to.iter().map(|t| t.email.clone()))+ .collect(),+ )+ .into_iter()+ .filter(|e| !email_utils::is_generic_email(e))+ .collect::<Vec<_>>();// determine if message's thread already exists in the databaselet thread_provider_to_db_map = threads::get::get_threads_by_link_id_and_provider_ids(diff --git a/rust/cloud-storage/email_utils/src/lib.rs b/rust/cloud-storage/email_utils/src/lib.rsindex 38074b91d7..13229a3a78 100644--- a/rust/cloud-storage/email_utils/src/lib.rs+++ b/rust/cloud-storage/email_utils/src/lib.rs@@ -176,3 +176,22 @@ pub fn is_generic_email(email: &str) -> bool {false}++/// Deduplicates a list of email addresses by normalizing them (removing + aliases)+pub fn dedupe_emails(emails: Vec<String>) -> Vec<String> {+ emails+ .into_iter()+ .map(|mut email| {+ // Remove everything from + to @ if + exists+ if let (Some(plus_pos), Some(at_pos)) = (email.find('+'), email.find('@'))+ && plus_pos < at_pos+ {+ email.drain(plus_pos..at_pos);+ }++ })+ .collect::<std::collections::HashSet<_>>()+ .into_iter()+ .collect()+}diff --git a/rust/cloud-storage/email_utils/src/tests.rs b/rust/cloud-storage/email_utils/src/tests.rsindex 2100c47579..dc183386b7 100644--- a/rust/cloud-storage/email_utils/src/tests.rs+++ b/rust/cloud-storage/email_utils/src/tests.rs@@ -1,4 +1,4 @@-use crate::is_generic_email;+use crate::{dedupe_emails, is_generic_email};#[test]fn test_is_generic_email() {@@ -60,3 +60,90 @@ fn test_is_generic_email() {assert!(!is_generic_email("[email protected]")); // Contains "reply" but not as a prefix/patternassert!(!is_generic_email("[email protected]")); // Contains "information" but not as a pattern}++#[test]+fn test_dedupe_emails() {+ let emails = vec![+ // Basic duplicates+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ // Plus aliases that should normalize to the same email+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ // Different emails that should remain separate+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ // Plus aliases for different base emails+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ // Edge cases+ "[email protected]".to_string(), // Empty plus part+ "[email protected]".to_string(), // Multiple plus signs+ "[email protected]".to_string(), // Plus in the tag part+ "[email protected]".to_string(),+ // Plus sign after @ (shouldn't be processed)+ "user@example+tag.com".to_string(),+ "user@example+tag.com".to_string(),+ // Complex cases+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ ];++ let mut result = dedupe_emails(emails);+ result.sort();++ let expected = vec![+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ "user@example+tag.com".to_string(), // Plus after @ should remain+ "[email protected]".to_string(),+ ];++ assert_eq!(result, expected);+ assert_eq!(result.len(), 6);+}++#[test]+fn test_dedupe_emails_empty() {+ let emails: Vec<String> = vec![];+ let result = dedupe_emails(emails);+ assert_eq!(result, Vec::<String>::new());+}++#[test]+fn test_dedupe_emails_no_duplicates() {+ let emails = vec![+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ ];+ let mut result = dedupe_emails(emails);+ result.sort();++ let expected = vec![+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ ];++ assert_eq!(result, expected);+}++#[test]+fn test_dedupe_emails_all_same_base() {+ let emails = vec![+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ ];+ let result = dedupe_emails(emails);++ assert_eq!(result.len(), 1);+ assert_eq!(result[0], "[email protected]");+}