Skip to content

[SDESK-7913] Handle str attachments in core email send#3240

Merged
eos87 merged 1 commit into
developfrom
hg/fix-email-attachment-str
Jun 24, 2026
Merged

[SDESK-7913] Handle str attachments in core email send#3240
eos87 merged 1 commit into
developfrom
hg/fix-email-attachment-str

Conversation

@eos87

@eos87 eos87 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Purpose

EmailAttachment.data is typed str | bytes, but the send path only worked for bytes. Passing a str attachment raised TypeError: set_text_content() got an unexpected keyword argument 'maintype', breaking email delivery for that path. flask-mail accepted both.

What has changed

  • _get_message_from_request now encodes str payloads to bytes before handing them to the email library.
  • Added a regression test covering a str attachment.

SDESK-7913

_get_message_from_request passed attachment data straight to
add_attachment/add_related with maintype/subtype. The email library
dispatches on the data type: a str routes to set_text_content(), which
rejects maintype/subtype and raises a TypeError, breaking any str
attachment despite EmailAttachment.data being typed str | bytes.

Encode str payloads to bytes so they route through set_bytes_content,
which accepts maintype/subtype and base64-encodes the part, matching the
previous flask-mail behaviour. Regression introduced by the flask-mail to
aiosmtplib migration (SDESK-7913).
@eos87 eos87 changed the title [SDESK-7913] Handle str attachments in core email send path [SDESK-7913] Handle str attachments in core email send Jun 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the core email sending path to correctly handle EmailAttachment.data when it is provided as a str (not just bytes), preventing a TypeError during attachment handling and restoring parity with the previous flask-mail behavior.

Changes:

  • Encode str attachment payloads to UTF-8 bytes before passing them to EmailMessage.add_attachment() / add_related().
  • Add a regression test that sends an email with a str attachment and asserts it is delivered with the expected MIME metadata and content.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
superdesk/core/emails.py Normalizes attachment payloads (str → UTF-8 bytes) so the stdlib email APIs take the bytes attachment path and don’t raise on maintype/subtype.
tests/send_email_test.py Adds regression coverage for sending an email with a str attachment and verifying the resulting MIME part.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@eos87 eos87 merged commit de98767 into develop Jun 24, 2026
31 checks passed
@eos87 eos87 deleted the hg/fix-email-attachment-str branch June 24, 2026 12:45
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.

3 participants