Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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 Link
INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active, created_at, updated_at)
Expand All @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 images
pub 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.
Expand Down
Loading