Skip to content

Fix inline CID attachments by using multipart/related to avoid duplicate attachment previews#1499

Open
Philodoescode wants to merge 3 commits intojenkinsci:mainfrom
Philodoescode:main
Open

Fix inline CID attachments by using multipart/related to avoid duplicate attachment previews#1499
Philodoescode wants to merge 3 commits intojenkinsci:mainfrom
Philodoescode:main

Conversation

@Philodoescode
Copy link
Copy Markdown

This change improves how inline attachments are sent so clients like Microsoft Teams render CID images correctly without also showing them as normal attachment previews. #1438 #1465

Changes:

  • Refactored email body construction in ExtendedEmailPublisher to build a MIME tree with:
    • root: multipart/mixed
    • nested body+inline block: multipart/related
  • Moved body creation into createTextContentPart(...) to make it reusable in the new MIME structure.
  • Added inline attachments to the multipart/related section instead of the root mixed section.
  • Kept regular attachments and build-log attachments on the root multipart/mixed.
  • Updated AttachmentUtils to only set Content-ID for inline attachments (not regular attachments).
  • Preserved support for project-level and trigger-level inline attachment patterns.

note: I apologize that the branch merging from is the main branch and not the feature branch from my forked repo.

@Philodoescode Philodoescode requested a review from a team as a code owner March 15, 2026 17:06
@ArpanC6
Copy link
Copy Markdown

ArpanC6 commented Mar 18, 2026

Hi @Philodoescode! The CI failure is in ExtendedEmailPublisherTest.testPlainTextAndHtml — this test is likely failing because the MIME structure change (adding multipart/related wrapper) broke an existing assertion about the email structure.
You'll need to update the test to expect the new MIME tree:

Root: multipart/mixed
Nested: multipart/related (body + inline attachments)
Regular attachments stay on root multipart/mixed

Also note: the PR is merging from your main branch instead of a feature branch — this is not ideal practice. Consider creating a dedicated feature branch for cleaner history.
The Windows CI passed with 2 tests, so the core logic seems correct. Hope this helps!

@PawanTheGod
Copy link
Copy Markdown
Contributor

Hi 👋

I took a closer look at the failing test (testPlainTextAndHtml), and it seems like the failure is due to the test still expecting the old MIME structure.

Since this change introduces a nested multipart/related structure for inline content, the assertions in the test likely need to be updated to reflect this new layout.

I’d be happy to help update the test accordingly if that sounds good.

Thanks!

@slide
Copy link
Copy Markdown
Member

slide commented Mar 23, 2026

Is this a follow-on to #1465?

@Philodoescode
Copy link
Copy Markdown
Author

Is this a follow-on to #1465?

Yes, it is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants