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.

fix(email): Populate null contact names (#1447)

Evan Hutnikcd4e71d41ed2
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 42461c04e7..872f2004c8 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -3255,6 +3255,10 @@ dependencies = [
[[package]]
name = "email_utils"
version = "0.1.0"
+dependencies = [
+ "lazy_static",
+ "regex",
+]
[[package]]
name = "email_validator"
diff --git a/rust/cloud-storage/email_db_client/.sqlx/query-74e411c5bdc9a4ee3f96bf4b09fd3506f32146eb21d6714d60136850e9d849bf.json b/rust/cloud-storage/email_db_client/.sqlx/query-74e411c5bdc9a4ee3f96bf4b09fd3506f32146eb21d6714d60136850e9d849bf.json
new file mode 100644
index 0000000000..9eee57760e
--- /dev/null
+++ b/rust/cloud-storage/email_db_client/.sqlx/query-74e411c5bdc9a4ee3f96bf4b09fd3506f32146eb21d6714d60136850e9d849bf.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE email_contacts\n SET name = data.name, updated_at = now()\n FROM (SELECT unnest($1::uuid[]) as id, unnest($2::text[]) as name) as data\n WHERE email_contacts.id = data.id\n AND email_contacts.name IS NULL\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "74e411c5bdc9a4ee3f96bf4b09fd3506f32146eb21d6714d60136850e9d849bf"
+}
diff --git a/rust/cloud-storage/email_db_client/fixtures/update_missing_contact_names.sql b/rust/cloud-storage/email_db_client/fixtures/update_missing_contact_names.sql
new file mode 100644
index 0000000000..e946dfbbd6
--- /dev/null
+++ b/rust/cloud-storage/email_db_client/fixtures/update_missing_contact_names.sql
@@ -0,0 +1,47 @@
+-- SQL fixture for update_missing_contact_names tests
+-- Seeds contacts with and without names across two links
+
+------------------------------------------------------------
+-- Common: links
+------------------------------------------------------------
+
+INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-00000000001a', 'macro|[email protected]', '00000000-0000-0000-0000-00000000001a',
+ '[email protected]', 'GMAIL', true, '2025-11-11 17:48:26.664688 +00:00',
+ '2025-11-11 17:48:26.664688 +00:00');
+
+INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-00000000001b', 'macro|[email protected]', '00000000-0000-0000-0000-00000000001b',
+ '[email protected]', 'GMAIL', true, '2025-11-11 17:48:26.664688 +00:00',
+ '2025-11-11 17:48:26.664688 +00:00');
+
+------------------------------------------------------------
+-- Link A contacts
+------------------------------------------------------------
+
+-- Contact with a name (should NOT be updated)
+INSERT INTO email_contacts (id, link_id, email_address, name, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-0000000c0001',
+ '00000000-0000-0000-0000-00000000001a',
+ 'Already Has Name',
+ '2025-11-11 17:48:26.664688 +00:00',
+ '2025-11-11 17:48:26.664688 +00:00');
+
+-- Contact without a name (should be updated)
+INSERT INTO email_contacts (id, link_id, email_address, name, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-0000000c0002',
+ '00000000-0000-0000-0000-00000000001a',
+ NULL,
+ '2025-11-11 17:48:26.664688 +00:00',
+ '2025-11-11 17:48:26.664688 +00:00');
+
+-- Another contact without a name
+INSERT INTO email_contacts (id, link_id, email_address, name, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-0000000c0003',
+ '00000000-0000-0000-0000-00000000001a',
+ NULL,
+ '2025-11-11 17:48:26.664688 +00:00',
+ '2025-11-11 17:48:26.664688 +00:00');
diff --git a/rust/cloud-storage/email_db_client/src/contacts/upsert_message.rs b/rust/cloud-storage/email_db_client/src/contacts/upsert_message.rs
index 30bce0bed6..d8980ecca7 100644
--- a/rust/cloud-storage/email_db_client/src/contacts/upsert_message.rs
+++ b/rust/cloud-storage/email_db_client/src/contacts/upsert_message.rs
@@ -12,6 +12,7 @@ use std::collections::HashMap;
/// upsert methods used when inserting individual threads/messages into the database.
/// wrapper around insert_email_address to format the data into a usable shape
+#[tracing::instrument(skip(pool, addresses_data), err)]
pub async fn parse_and_upsert_message_contacts(
pool: &PgPool,
link_id: Uuid,
@@ -117,6 +118,22 @@ async fn upsert_message_contacts(
.map(|r| (r.email_address, r.id))
.collect();
+ // Update names for existing contacts that don't have one yet
+ let name_updates: Vec<_> = contacts
+ .iter()
+ .filter_map(|c| {
+ c.name.as_ref().and_then(|name| {
+ result_map
+ .get(&c.email_address)
+ .map(|id| (*id, name.clone()))
+ })
+ })
+ .collect();
+
+ if !name_updates.is_empty() {
+ update_missing_contact_names(pool, &name_updates).await?;
+ }
+
// Step 2: Filter to contacts we don't have yet
let new_contacts: Vec<_> = contacts
.into_iter()
@@ -157,6 +174,7 @@ async fn upsert_message_contacts(
Ok(result_map)
}
+#[tracing::instrument(skip(pool, emails), err)]
async fn fetch_contacts_by_emails(
pool: &PgPool,
link_id: Uuid,
@@ -178,6 +196,32 @@ async fn fetch_contacts_by_emails(
Ok(results)
}
+#[tracing::instrument(skip(pool, updates), err)]
+async fn update_missing_contact_names(
+ pool: &PgPool,
+ updates: &[(Uuid, String)],
+) -> anyhow::Result<()> {
+ let ids: Vec<Uuid> = updates.iter().map(|(id, _)| *id).collect();
+ let names: Vec<String> = updates.iter().map(|(_, name)| name.clone()).collect();
+
+ sqlx::query!(
+ r#"
+ UPDATE email_contacts
+ SET name = data.name, updated_at = now()
+ FROM (SELECT unnest($1::uuid[]) as id, unnest($2::text[]) as name) as data
+ WHERE email_contacts.id = data.id
+ AND email_contacts.name IS NULL
+ "#,
+ &ids,
+ &names
+ )
+ .execute(pool)
+ .await?;
+
+ Ok(())
+}
+
+#[tracing::instrument(skip(pool, contacts), err)]
async fn insert_new_contacts(
pool: &PgPool,
contacts: &[ContactPhotoless],
diff --git a/rust/cloud-storage/email_db_client/src/contacts/upsert_message/tests.rs b/rust/cloud-storage/email_db_client/src/contacts/upsert_message/tests.rs
index 5135fa88e2..143c578d63 100644
--- a/rust/cloud-storage/email_db_client/src/contacts/upsert_message/tests.rs
+++ b/rust/cloud-storage/email_db_client/src/contacts/upsert_message/tests.rs
@@ -323,3 +323,135 @@ async fn insert_new_contacts_allows_same_email_different_links(pool: Pool<Postgr
Ok(())
}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("update_missing_contact_names"))
+)]
+// should update name for a contact that has no name
+async fn update_missing_contact_names_sets_name_when_null(pool: Pool<Postgres>) -> Result<()> {
+ const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
+
+ let contact_id = Uuid::parse_str("00000000-0000-0000-0000-0000000c0002")?;
+ let updates = vec![(contact_id, "Now Has A Name".to_string())];
+
+ update_missing_contact_names(&pool, &updates).await?;
+
+ let row = sqlx::query!("SELECT name FROM email_contacts WHERE id = $1", contact_id)
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(row.name.as_deref(), Some("Now Has A Name"));
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("update_missing_contact_names"))
+)]
+// should not overwrite an existing name
+async fn update_missing_contact_names_does_not_overwrite_existing_name(
+ pool: Pool<Postgres>,
+) -> Result<()> {
+ const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
+
+ let contact_id = Uuid::parse_str("00000000-0000-0000-0000-0000000c0001")?;
+ let updates = vec![(contact_id, "Should Not Replace".to_string())];
+
+ update_missing_contact_names(&pool, &updates).await?;
+
+ let row = sqlx::query!("SELECT name FROM email_contacts WHERE id = $1", contact_id)
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(row.name.as_deref(), Some("Already Has Name"));
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("update_missing_contact_names"))
+)]
+// should handle a batch with mixed null and non-null existing names
+async fn update_missing_contact_names_mixed_batch(pool: Pool<Postgres>) -> Result<()> {
+ const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
+
+ let has_name_id = Uuid::parse_str("00000000-0000-0000-0000-0000000c0001")?;
+ let no_name_id = Uuid::parse_str("00000000-0000-0000-0000-0000000c0002")?;
+ let no_name_2_id = Uuid::parse_str("00000000-0000-0000-0000-0000000c0003")?;
+
+ let updates = vec![
+ (has_name_id, "Should Not Replace".to_string()),
+ (no_name_id, "New Name One".to_string()),
+ (no_name_2_id, "New Name Two".to_string()),
+ ];
+
+ update_missing_contact_names(&pool, &updates).await?;
+
+ let has_name_row = sqlx::query!("SELECT name FROM email_contacts WHERE id = $1", has_name_id)
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(has_name_row.name.as_deref(), Some("Already Has Name"));
+
+ let no_name_row = sqlx::query!("SELECT name FROM email_contacts WHERE id = $1", no_name_id)
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(no_name_row.name.as_deref(), Some("New Name One"));
+
+ let no_name_2_row = sqlx::query!(
+ "SELECT name FROM email_contacts WHERE id = $1",
+ no_name_2_id
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(no_name_2_row.name.as_deref(), Some("New Name Two"));
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("update_missing_contact_names"))
+)]
+// should handle empty updates slice without error
+async fn update_missing_contact_names_empty_input(pool: Pool<Postgres>) -> Result<()> {
+ const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
+
+ let updates: Vec<(Uuid, String)> = vec![];
+
+ update_missing_contact_names(&pool, &updates).await?;
+
+ Ok(())
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("update_missing_contact_names"))
+)]
+// should update updated_at timestamp when name is set
+async fn update_missing_contact_names_updates_timestamp(pool: Pool<Postgres>) -> Result<()> {
+ const _: &sqlx::migrate::Migrator = &MACRO_DB_MIGRATIONS;
+
+ let contact_id = Uuid::parse_str("00000000-0000-0000-0000-0000000c0002")?;
+
+ let before = sqlx::query!(
+ "SELECT updated_at FROM email_contacts WHERE id = $1",
+ contact_id
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ let updates = vec![(contact_id, "Updated Name".to_string())];
+ update_missing_contact_names(&pool, &updates).await?;
+
+ let after = sqlx::query!(
+ "SELECT updated_at FROM email_contacts WHERE id = $1",
+ contact_id
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert!(after.updated_at > before.updated_at);
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/email_utils/Cargo.toml b/rust/cloud-storage/email_utils/Cargo.toml
index ece607dce1..f87982ea18 100644
--- a/rust/cloud-storage/email_utils/Cargo.toml
+++ b/rust/cloud-storage/email_utils/Cargo.toml
@@ -5,3 +5,5 @@ publish = false
edition = "2024"
[dependencies]
+lazy_static = { workspace = true }
+regex = { workspace = true }
\ No newline at end of file
diff --git a/rust/cloud-storage/email_utils/src/lib.rs b/rust/cloud-storage/email_utils/src/lib.rs
index 13229a3a78..0c7780ee14 100644
--- a/rust/cloud-storage/email_utils/src/lib.rs
+++ b/rust/cloud-storage/email_utils/src/lib.rs
@@ -1,6 +1,15 @@
+use lazy_static::lazy_static;
+use regex::Regex;
+
#[cfg(test)]
mod tests;
+lazy_static! {
+ static ref HEX_PATTERN: Regex = Regex::new(r"^[a-f0-9\-]{20,}$").unwrap();
+ static ref UUID_PATTERN: Regex =
+ Regex::new(r"^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$").unwrap();
+}
+
/// Checks if an email address is likely a generic/automated system email
///
/// This function identifies common patterns in email addresses that typically
@@ -8,170 +17,301 @@ mod tests;
pub fn is_generic_email(email: &str) -> bool {
let email_lower = email.to_lowercase();
- // if it's really long, it's probably an autogenerated email address
- if email.len() > 50 {
+ // Split into local part and domain
+ let (local_part, domain) = match email_lower.split_once('@') {
+ Some(parts) => parts,
+ None => return false, // Invalid email
+ };
+
+ // Check for automated email service domains first (most definitive)
+ if is_automated_domain(domain) {
return true;
}
- // Common automated email prefixes
- let automated_prefixes = [
- "reply",
+ // Check for obvious automated patterns in local part
+ if contains_automated_keyword(local_part) {
+ return true;
+ }
+
+ // Check if local part starts with automated prefix
+ if starts_with_automated_prefix(local_part) {
+ return true;
+ }
+
+ // Check for auto-generated local parts (numbers, UUIDs, hex strings)
+ if is_autogenerated_local_part(local_part) {
+ return true;
+ }
+
+ false
+}
+
+fn is_automated_domain(domain: &str) -> bool {
+ const SYSTEM_DOMAINS: &[&str] = &[
+ // Email service providers
+ "sendgrid.net",
+ "sendgrid.com",
+ "mailchimp.com",
+ "amazonses.com",
+ "email.amazonses.com",
+ "bounce.amazonses.com",
+ "sparkpost.com",
+ "mailgun.org",
+ "mg.mailgun.org",
+ "em.mailgun.org",
+ "mailjet.com",
+ "mandrillapp.com",
+ "postmarkapp.com",
+ "sendinblue.com",
+ "klaviyo.com",
+ "constantcontact.com",
+ // CRM/Marketing platforms
+ "salesforce.com",
+ "salesforceiq.com",
+ "hubspot.com",
+ "marketo.com",
+ "intercom.io",
+ "intercom-mail.com",
+ "campaign-archive.com",
+ // Support platforms
+ "zendesk.com",
+ "freshdesk.com",
+ // Google
+ "notifications.google.com",
+ ];
+
+ SYSTEM_DOMAINS
+ .iter()
+ .any(|d| domain == *d || domain.ends_with(&format!(".{}", d)))
+}
+
+fn contains_automated_keyword(local_part: &str) -> bool {
+ // Keywords that strongly indicate automation when present anywhere
+ const STRONG_KEYWORDS: &[&str] = &[
"noreply",
"no-reply",
+ "no.reply",
+ "no_reply",
+ "donotreply",
"do-not-reply",
+ "do.not.reply",
+ "do_not_reply",
+ "unsubscribe",
+ "unsub",
+ "automated",
+ "mailer-daemon",
+ "postmaster",
+ ];
+
+ STRONG_KEYWORDS.iter().any(|kw| local_part.contains(kw))
+}
+
+fn starts_with_automated_prefix(local_part: &str) -> bool {
+ const AUTOMATED_PREFIXES: &[&str] = &[
+ // Reply/No-reply variants
+ "reply",
+ "noreply",
+ "no-reply",
+ "no.reply",
+ "no_reply",
"donotreply",
+ "do-not-reply",
+ "do.not.reply",
+ "do_not_reply",
+ // System/Auto
"auto",
"automated",
+ "system",
+ "daemon",
+ "cron",
+ "scheduler",
+ "robot",
+ "bot",
+ // Notifications/Alerts
"alert",
"alerts",
"notification",
"notifications",
- "info",
- "information",
- "news",
- "newsletter",
- "updates",
+ "notify",
+ "digest",
+ "bulletin",
+ "announcements",
+ "weekly",
+ "daily",
+ "monthly",
+ // Support/Service
"support",
"help",
"helpdesk",
"service",
"services",
- "system",
+ "customercare",
+ "customer-care",
+ "customer.care",
+ "customerservice",
+ "customer-service",
+ "customer.service",
+ // Admin/System
"admin",
"administrator",
+ "webmaster",
+ "postmaster",
+ "sysadmin",
+ "root",
+ "ops",
+ "devops",
+ "monitor",
+ "monitoring",
+ "status",
+ "logs",
+ "error",
+ "errors",
+ // Accounts/Auth
"account",
"accounts",
- "billing",
- "contact",
- "team",
- "no_reply",
- "do_not_reply",
- "mailer",
- "mail",
- "postmaster",
- "robot",
- "confirm",
- "confirmation",
+ "auth",
+ "authentication",
+ "login",
+ "signin",
+ "password",
+ "reset",
+ "otp",
+ "2fa",
+ "mfa",
+ "token",
"verify",
"verification",
+ "confirm",
+ "confirmation",
"security",
"secure",
- "webmaster",
- "customercare",
- "customer-care",
- "customer.care",
- "customerservice",
- "customer-service",
- "customer.service",
- "feedback",
- "hello",
- "hi",
- "welcome",
- "marketing",
- "careers",
- "jobs",
- "applications",
- "receipts",
+ // Billing/Transactions
+ "billing",
+ "invoice",
+ "invoices",
+ "payment",
+ "payments",
+ "transaction",
+ "transactions",
+ "refund",
+ "subscription",
+ "subscriptions",
+ "renewal",
"receipt",
+ "receipts",
"order",
"orders",
+ // Shipping/Delivery
"shipping",
"delivery",
"track",
"tracking",
+ "booking",
+ "bookings",
+ "reservations",
+ // Marketing/Comms
+ "marketing",
+ "promo",
+ "promotions",
+ "offers",
+ "deals",
+ "news",
+ "newsletter",
+ "updates",
+ "info",
+ "information",
+ "feedback",
+ "survey",
+ // Business departments
"sales",
+ "hr",
+ "legal",
+ "finance",
+ "press",
+ "media",
+ "partnerships",
+ "partners",
+ "affiliates",
+ "careers",
+ "jobs",
+ "applications",
+ "events",
+ // Dev/API
"dev",
"developer",
"api",
"test",
"testing",
- "noreply-",
- "no-reply-",
- "no.reply.",
- "donotreply-",
- "do-not-reply-",
- "do.not.reply.",
+ "mailer",
+ "mail",
+ "bounce",
+ "bounces",
+ // Generic contact
+ "contact",
+ "team",
+ "hello",
+ "hi",
+ "welcome",
];
- // Check if email starts with any of the automated prefixes
- // We check specifically for prefix@ pattern to avoid matching personal emails
- // that might contain these words elsewhere
- for prefix in automated_prefixes {
- if email_lower.starts_with(prefix)
- && (email_lower.contains(&format!("{}@", prefix))
- || email_lower.contains(&format!("{}-", prefix))
- || email_lower.contains(&format!("{}.", prefix))
- || email_lower.contains(&format!("{}+", prefix))
- || email_lower.contains(&format!("{}=", prefix))
- || email_lower.contains(&format!("{}_", prefix)))
+ // Check if local part starts with prefix followed by a delimiter or end
+ for prefix in AUTOMATED_PREFIXES {
+ if local_part == *prefix {
+ return true;
+ }
+ if let Some(remainder) = local_part.strip_prefix(prefix)
+ && let Some(first_char) = remainder.chars().next()
+ && matches!(first_char, '@' | '-' | '.' | '+' | '=' | '_' | '0'..='9')
{
+ // Must be followed by a delimiter, not a letter (to avoid matching "support" in "supportive")
return true;
}
}
- // Check for common patterns for system accounts
- if email_lower.contains("@")
- && (email_lower.contains("noreply")
- || email_lower.contains("no-reply")
- || email_lower.contains("no.reply")
- || email_lower.contains("no_reply")
- || email_lower.contains("do-not-reply")
- || email_lower.contains("donotreply")
- || email_lower.contains("system")
- || email_lower.contains("notification")
- || email_lower.contains("automated")
- || email_lower.contains("unsub")
- || email_lower.contains("support")
- || email_lower.contains("do_not_reply"))
- {
+ false
+}
+
+fn is_autogenerated_local_part(local_part: &str) -> bool {
+ // Too long - likely autogenerated
+ if local_part.len() > 50 {
return true;
}
- // Check for specific domains or addresses that typically send automated emails
- let system_domains = [
- "@sendgrid.net",
- "@mailchimp.com",
- "@sendgrid.com",
- "@amazonses.com",
- "@email.amazonses.com",
- "@bounce.amazonses.com",
- "@sparkpost.com",
- "@mailgun.org",
- "@mg.mailgun.org",
- "@postman.com",
- "@salesforce.com",
- "@salesforceiq.com",
- "@hubspot.com",
- "@marketo.com",
- "@mailjet.com",
- "@sendgrid.net",
- "@constant.com",
- "@constantcontact.com",
- ];
-
- for domain in system_domains {
- if email_lower.ends_with(domain) {
- return true;
- }
+ // UUID pattern
+ if UUID_PATTERN.is_match(local_part) {
+ return true;
}
- // Check common automated email patterns where @ is preceded by numbers or codes
- if let Some(at_pos) = email_lower.find('@') {
- let local_part = &email_lower[0..at_pos];
+ // Long hex string pattern
+ if HEX_PATTERN.is_match(local_part) {
+ return true;
+ }
- // Check if local part consists only of numbers or contains certain patterns
- if local_part
+ // Purely numeric with delimiters (e.g., "123456", "123-456-789")
+ if !local_part.is_empty()
+ && local_part
.chars()
- .all(|c| c.is_numeric() || c == '.' || c == '-' || c == '_')
- && local_part.chars().any(|c| c.is_numeric())
- {
- return true;
- }
+ .all(|c| c.is_ascii_digit() || c == '.' || c == '-' || c == '_')
+ && local_part.chars().any(|c| c.is_ascii_digit())
+ {
+ return true;
+ }
- // Check for common notification-type IDs
- if local_part.starts_with("id") && local_part.chars().skip(2).all(|c| c.is_numeric()) {
- return true;
- }
+ // Starts with "id" followed by only numbers (e.g., "id12345")
+ if local_part.starts_with("id")
+ && local_part.len() > 2
+ && local_part[2..].chars().all(|c| c.is_ascii_digit())
+ {
+ return true;
+ }
+
+ // Starts with numbers followed by random-looking characters (e.g., "0000012345abcdef")
+ let digit_prefix_count = local_part
+ .chars()
+ .take_while(|c| c.is_ascii_digit())
+ .count();
+ if digit_prefix_count >= 6 {
+ return true;
}
false
diff --git a/rust/cloud-storage/email_utils/src/tests.rs b/rust/cloud-storage/email_utils/src/tests.rs
index dc183386b7..83673e81b1 100644
--- a/rust/cloud-storage/email_utils/src/tests.rs
+++ b/rust/cloud-storage/email_utils/src/tests.rs
@@ -61,6 +61,145 @@ fn test_is_generic_email() {
assert!(!is_generic_email("[email protected]")); // Contains "information" but not as a pattern
}
+#[test]
+fn test_is_generic_email_new_prefixes() {
+ // Authentication/Security patterns
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+
+ // Transactional patterns
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+
+ // System/DevOps patterns
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+
+ // Marketing/Communication patterns
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+
+ // Business department patterns
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+}
+
+#[test]
+fn test_is_generic_email_new_domains() {
+ // Email service providers
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+
+ // CRM/Support platforms
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+
+ // Subdomains of known providers
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+}
+
+#[test]
+fn test_is_generic_email_autogenerated_patterns() {
+ // UUID patterns
+ assert!(is_generic_email(
+ ));
+ assert!(is_generic_email(
+ ));
+
+ // Long hex strings
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email(
+ ));
+
+ // Numeric prefix patterns
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+
+ // Very long local parts (likely autogenerated)
+ assert!(is_generic_email(
+ "this-is-a-very-long-autogenerated-email-address-that-exceeds-fifty-chars@company.com"
+ ));
+}
+
+#[test]
+fn test_is_generic_email_false_positives_avoided() {
+ // Words containing prefixes but not matching the pattern
+ assert!(!is_generic_email("[email protected]"));
+ assert!(!is_generic_email("[email protected]"));
+ assert!(!is_generic_email("[email protected]"));
+ assert!(!is_generic_email("[email protected]"));
+ assert!(!is_generic_email("[email protected]"));
+
+ // Regular names with numbers
+ assert!(!is_generic_email("[email protected]"));
+ assert!(!is_generic_email("[email protected]"));
+ assert!(!is_generic_email("[email protected]"));
+
+ // Normal business emails
+ assert!(!is_generic_email("[email protected]"));
+ assert!(!is_generic_email("[email protected]"));
+}
+
+#[test]
+fn test_is_generic_email_case_insensitivity() {
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+ assert!(is_generic_email("[email protected]"));
+}
+
+#[test]
+fn test_is_generic_email_invalid_input() {
+ // Invalid emails without @ should return false, not panic
+ assert!(!is_generic_email("invalid-email-no-at-sign"));
+ assert!(!is_generic_email(""));
+ assert!(!is_generic_email("just-text"));
+}
+
#[test]
fn test_dedupe_emails() {
let emails = vec![