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): sync the other contacts when an address is not a user id (#8423)

teob6f5fb61bd4c
diff --git a/services/email_service/AGENTS.md b/services/email_service/AGENTS.md
index 6f56eded4a..7d63d3c21b 100644
--- a/services/email_service/AGENTS.md
+++ b/services/email_service/AGENTS.md
@@ -60,6 +60,9 @@ the gateway `/email` prefix.
calendar refresh so unrelated invitation updates retain teammates' OOO rows.
- Spawn `run_transfers` regardless of the Outlook flags. Gmail inbox moves
finish there; with writes off it pauses only the Outlook retire step.
+- Header addresses that Gmail accepts can fail `MacroUserIdStr::try_from_email`.
+ Skip the bad address with a WARN that omits it (the parse error echoes it)
+ instead of failing the step; see `pubsub::util::build_contact_connections`.
## Related
diff --git a/services/email_service/src/backfill_completion_service.rs b/services/email_service/src/backfill_completion_service.rs
index 010c0033a3..27ef400c7d 100644
--- a/services/email_service/src/backfill_completion_service.rs
+++ b/services/email_service/src/backfill_completion_service.rs
@@ -1,9 +1,7 @@
use crate::pubsub::context::PubSubContext;
-use crate::pubsub::util::cg_refresh_email;
-use contacts::domain::models::messages::ContactConnection;
+use crate::pubsub::util::{build_contact_connections, cg_refresh_email};
use contacts::domain::ports::ContactsIngress;
use email_db_client::backfill::job::update::BackfillCompletion;
-use macro_user_id::user_id::MacroUserIdStr;
use models_email::api::refresh::{BackfillStatus, RefreshEmailEvent};
use models_email::db::address::EmailRecipientType;
use models_email::service::attachment::{
@@ -396,19 +394,11 @@ async fn handle_contacts_sync(ctx: &PubSubContext, link: &Link) -> Result<(), Pr
link.macro_id
);
- let connections = email_addresses
- .iter()
- .map(|email| {
- MacroUserIdStr::try_from_email(email)
- .map(|contact| ContactConnection::new(link.macro_id.clone(), contact))
- })
- .collect::<Result<Vec<_>, _>>()
- .map_err(|e| {
- ProcessingError::NonRetryable(DetailedError {
- reason: FailureReason::SqsEnqueueFailed,
- source: anyhow::anyhow!(e).context("invalid user email for contacts"),
- })
- })?;
+ let connections = build_contact_connections(
+ &link.macro_id,
+ link.id,
+ email_addresses.iter().map(String::as_str),
+ );
ctx.contacts_ingress
.enqueue_contact_connections(connections)
@@ -417,8 +407,8 @@ async fn handle_contacts_sync(ctx: &PubSubContext, link: &Link) -> Result<(), Pr
ProcessingError::NonRetryable(DetailedError {
reason: FailureReason::SqsEnqueueFailed,
source: anyhow::anyhow!("{e:?}").context(format!(
- "Failed to enqueue contacts message for {}",
- email_addresses.join(", ")
+ "Failed to enqueue {length} contact connections for link {}",
+ link.id
)),
})
})?;
diff --git a/services/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs b/services/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
index c20a86ece3..1e19b197ff 100644
--- a/services/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
+++ b/services/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs
@@ -1,12 +1,12 @@
use crate::pubsub::context::PubSubContext;
use crate::pubsub::inbox_sync::email_api_error::handle_operation_error;
use crate::pubsub::util::{
- CrmContactRecipient, build_notification_recipients, enqueue_populate_crm_contacts,
+ CrmContactRecipient, build_contact_connections, build_notification_recipients,
+ enqueue_populate_crm_contacts,
};
use crate::pubsub::util::{cg_refresh_email, publish_email_event};
use crate::util::process_pre_insert::{process_message_pre_insert, process_threads_pre_insert};
use crate::util::upload_attachment::{UploadAttachmentContext, upload_attachment};
-use contacts::domain::models::messages::ContactConnection;
use contacts::domain::ports::ContactsIngress;
use email::domain::events::{
EmailEventOrigin, EmailMacroEvent, MessageDraftSyncedMetadata, MessageReceivedMetadata,
@@ -510,24 +510,12 @@ async fn handle_contacts_sync(
sender_email.into_iter().collect()
};
- if connection_emails.is_empty() {
+ let connections = build_contact_connections(&link.macro_id, link.id, connection_emails);
+
+ if connections.is_empty() {
return Ok(());
}
- let connections = connection_emails
- .iter()
- .map(|email| {
- MacroUserIdStr::try_from_email(email)
- .map(|contact| ContactConnection::new(link.macro_id.clone(), contact))
- })
- .collect::<Result<Vec<_>, _>>()
- .map_err(|e| {
- ProcessingError::NonRetryable(DetailedError {
- reason: FailureReason::SqsEnqueueFailed,
- source: anyhow::anyhow!(e).context("invalid user email for contacts"),
- })
- })?;
-
ctx.contacts_ingress
.enqueue_contact_connections(connections)
.await
diff --git a/services/email_service/src/pubsub/util.rs b/services/email_service/src/pubsub/util.rs
index 814e42c51e..77b0ee649c 100644
--- a/services/email_service/src/pubsub/util.rs
+++ b/services/email_service/src/pubsub/util.rs
@@ -1,6 +1,7 @@
use crate::pubsub::context::PubSubContext;
use chrono::{DateTime, Utc};
use connection_gateway_client::client::ConnectionGatewayClient;
+use contacts::domain::models::messages::ContactConnection;
use email::domain::events::EmailMacroEvent;
use macro_event_broker::MacroEventBroker;
use macro_user_id::user_id::MacroUserIdStr;
@@ -44,6 +45,30 @@ pub fn build_notification_recipients(
recipient_ids
}
+/// Contact connections from a link's owner to each address. Addresses that fail
+/// to parse as a macro user id are skipped, so one malformed header address
+/// doesn't drop the connections to the others.
+pub fn build_contact_connections<'a>(
+ owner: &MacroUserIdStr<'static>,
+ link_id: Uuid,
+ emails: impl IntoIterator<Item = &'a str>,
+) -> Vec<ContactConnection> {
+ emails
+ .into_iter()
+ .filter_map(|email| match MacroUserIdStr::try_from_email(email) {
+ Ok(contact) => Some(ContactConnection::new(owner.clone(), contact)),
+ // The parse error echoes the address, so it stays out of the log.
+ Err(_) => {
+ tracing::warn!(
+ %link_id,
+ "skipping contact address that failed to parse as a macro user id"
+ );
+ None
+ }
+ })
+ .collect()
+}
+
/// One recipient tuple `(email, name, first_at, last_at)` fed into
/// [`enqueue_populate_crm_contacts`]. Per-message paths use the same
/// timestamp for both endpoints; the historical seed passes the
diff --git a/services/email_service/src/pubsub/util/test.rs b/services/email_service/src/pubsub/util/test.rs
index 0b589e66ed..56a7625bd4 100644
--- a/services/email_service/src/pubsub/util/test.rs
+++ b/services/email_service/src/pubsub/util/test.rs
@@ -1,5 +1,6 @@
-use super::build_notification_recipients;
+use super::{build_contact_connections, build_notification_recipients};
use macro_user_id::user_id::MacroUserIdStr;
+use uuid::Uuid;
fn id(s: &str) -> MacroUserIdStr<'static> {
MacroUserIdStr::try_from(s.to_string()).expect("valid macro user id")
@@ -43,3 +44,23 @@ fn skips_primaries_that_fail_to_parse() {
assert!(recipients.contains(&owner));
assert!(recipients.contains(&id("macro|[email protected]")));
}
+
+#[test]
+fn contact_connections_skip_addresses_that_fail_to_parse() {
+ let owner = id("macro|[email protected]");
+ let emails = [
+ ];
+
+ let connections = build_contact_connections(&owner, Uuid::nil(), emails);
+
+ let contacts: Vec<_> = connections.iter().map(|c| c.second.clone()).collect();
+ assert_eq!(
+ contacts,
+ vec![id("macro|[email protected]"), id("macro|[email protected]")]
+ );
+ assert!(connections.iter().all(|c| c.first == owner));
+}