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): Upload both inline and attached email images to sfs (#591)
Evan Hutnik409d9217bc06
diff --git a/rust/cloud-storage/email_db_client/fixtures/fetch_new_email_media.sql b/rust/cloud-storage/email_db_client/fixtures/fetch_new_email_media.sqlindex 1ad56dd750..a99d34a2b4 100644--- a/rust/cloud-storage/email_db_client/fixtures/fetch_new_email_media.sql+++ b/rust/cloud-storage/email_db_client/fixtures/fetch_new_email_media.sql@@ -94,7 +94,7 @@ VALUES ('00000000-0000-0000-0000-0000003a3003',NOW());--------------------------------------------------------------- Thread 3: Email with inline images (should be filtered)+-- Thread 3: Email with inline images------------------------------------------------------------INSERT INTO email_messages (id, thread_id, link_id, provider_id, is_sent, from_contact_id, internal_date_ts,@@ -108,7 +108,7 @@ VALUES ('00000000-0000-0000-0000-0000000e3003','2025-01-01 12:00:00 +00:00',true, false, false, false, NOW(), NOW());--- Inline image (should NOT be included)+-- Inline image (should be included)INSERT INTO email_attachments (id, message_id, provider_attachment_id, filename, mime_type, content_id, created_at)VALUES ('00000000-0000-0000-0000-0000003a3004','00000000-0000-0000-0000-0000000e3003',diff --git a/rust/cloud-storage/email_db_client/fixtures/fetch_thread_media_for_backfill.sql b/rust/cloud-storage/email_db_client/fixtures/fetch_thread_media_for_backfill.sqlindex ddf47ae002..ac22ffb75d 100644--- a/rust/cloud-storage/email_db_client/fixtures/fetch_thread_media_for_backfill.sql+++ b/rust/cloud-storage/email_db_client/fixtures/fetch_thread_media_for_backfill.sql@@ -1,7 +1,7 @@-- SQL fixture for thread_media_atts_for_backfill tests-- This fixture tests that media attachments (images, videos) are fetched--- regardless of thread conditions, and that inline images are properly filtered out+-- regardless of thread conditions-- User LinkINSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active, created_at, updated_at)@@ -21,7 +21,7 @@ VALUES ('00000000-0000-0000-0000-000000000201','00000000-0000-0000-0000-00000000002a',false, false, NOW(), NOW());--- Thread 2: Contains inline images (should be filtered out)+-- Thread 2: Contains inline images (should not be filtered out)INSERT INTO email_threads (id, link_id, inbox_visible, is_read, created_at, updated_at)VALUES ('00000000-0000-0000-0000-000000000202','00000000-0000-0000-0000-00000000002a',@@ -85,7 +85,7 @@ VALUES ('00000000-0000-0000-0000-0000002a2003',NOW());--------------------------------------------------------------- Thread 2: Contains inline images (should be filtered out)+-- Thread 2: Contains inline images (should not be filtered out)------------------------------------------------------------INSERT INTO email_messages (id, thread_id, link_id, provider_id, is_sent, from_contact_id, internal_date_ts,@@ -99,7 +99,7 @@ VALUES ('00000000-0000-0000-0000-0000000e2002','2025-01-01 11:00:00 +00:00',true, false, false, false, NOW(), NOW());--- Inline image (should NOT be included due to content_id)+-- Inline image (should be included)INSERT INTO email_attachments (id, message_id, provider_attachment_id, filename, mime_type, content_id, created_at)VALUES ('00000000-0000-0000-0000-0000002a2004','00000000-0000-0000-0000-0000000e2002',diff --git a/rust/cloud-storage/email_db_client/src/attachments/provider/upload.rs b/rust/cloud-storage/email_db_client/src/attachments/provider/upload.rsindex 16d9a9a4ea..47ef94830a 100644--- a/rust/cloud-storage/email_db_client/src/attachments/provider/upload.rs+++ b/rust/cloud-storage/email_db_client/src/attachments/provider/upload.rs@@ -79,7 +79,7 @@ pub async fn thread_document_atts_for_backfill(Ok(attachments)}-/// fetch videos and non-inline images from a thread for insertion into sfs. we insert them into+/// fetch videos and images from a thread for insertion into sfs. we insert them into/// sfs so we can display thumbnails for them in the FE.#[tracing::instrument(skip(db), err)]pub async fn thread_media_atts_for_backfill(@@ -388,7 +388,7 @@ pub async fn new_email_document_atts(Ok(attachments)}-/// fetch videos and non-inline images for a new email for insertion into sfs. we insert them into+/// fetch videos and inline images for a new email for insertion into sfs. we insert them into/// sfs so we can display thumbnails for them in the FE.#[tracing::instrument(skip(db), err)]pub async fn new_email_media_atts(diff --git a/rust/cloud-storage/email_db_client/src/attachments/provider/upload/test.rs b/rust/cloud-storage/email_db_client/src/attachments/provider/upload/test.rsindex d2a6d7b75b..39ed24b390 100644--- a/rust/cloud-storage/email_db_client/src/attachments/provider/upload/test.rs+++ b/rust/cloud-storage/email_db_client/src/attachments/provider/upload/test.rs@@ -419,8 +419,8 @@ async fn thread_media_for_backfill_filters_inline_images(pool: Pool<Postgres>) -let thread_id = Uuid::parse_str("00000000-0000-0000-0000-000000000202")?;let res = thread_media_atts_for_backfill(&pool, thread_id).await?;- // Should return 0 attachments (inline image is filtered out)- assert_eq!(res.len(), 0);+ // Should return 1 attachments (inline image is not filtered out)+ assert_eq!(res.len(), 1);Ok(())}@@ -519,11 +519,13 @@ async fn new_email_media_filters_inline_images(pool: Pool<Postgres>) -> Result<(let message_provider_id = "new-media-msg-303";let res = new_email_media_atts(&pool, message_provider_id).await?;- // Should return 1 attachment: attachment_image.png- // Should NOT include inline_image.png (has content_id)- assert_eq!(res.len(), 1);- assert_eq!(res[0].filename, "attachment_image.png");+ // Should return 2 attachment: attachment_image.png+ // Should include inline_image.png (has content_id)+ assert_eq!(res.len(), 2);+ assert_eq!(res[0].filename, "inline_image.png");assert_eq!(res[0].mime_type, "image/png");+ assert_eq!(res[1].filename, "attachment_image.png");+ assert_eq!(res[1].mime_type, "image/png");Ok(())}diff --git a/rust/cloud-storage/email_db_client/src/attachments/provider/upload_filters.rs b/rust/cloud-storage/email_db_client/src/attachments/provider/upload_filters.rsindex 24db136444..053ac0b3f3 100644--- a/rust/cloud-storage/email_db_client/src/attachments/provider/upload_filters.rs+++ b/rust/cloud-storage/email_db_client/src/attachments/provider/upload_filters.rs@@ -16,9 +16,9 @@ pub const ATTACHMENT_MIME_TYPE_FILTERS: &str = r#")"#;-/// Attachment mime type filters including videos and non-inline images+/// Attachment mime type filters including videos and inline imagespub const ATTACHMENT_MIME_TYPE_FILTERS_WITH_MEDIA: &str = r#"- ((a.mime_type LIKE 'image/%' AND a.content_id IS NULL) OR a.mime_type LIKE 'video/%')+ (a.mime_type LIKE 'image/%' OR a.mime_type LIKE 'video/%')"#;/// always insert attachments sent from these domains.