Skip to content

fix(discord): strip MIME parameters before document type lookup (#12511)#12516

Closed
kagura-agent wants to merge 2 commits into
NousResearch:mainfrom
kagura-agent:fix/discord-message-txt-attachment
Closed

fix(discord): strip MIME parameters before document type lookup (#12511)#12516
kagura-agent wants to merge 2 commits into
NousResearch:mainfrom
kagura-agent:fix/discord-message-txt-attachment

Conversation

@kagura-agent

@kagura-agent kagura-agent commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Problem

Discord auto-converts pasted large text/code blocks into message.txt attachments with content_type text/plain; charset=utf-8. The MIME-to-extension fallback lookup used the full content_type string (including ; charset=utf-8), which never matched the bare MIME types in SUPPORTED_DOCUMENT_TYPES.

Note: For the common case where Discord provides filename='message.txt', the extension is extracted from the filename directly and the MIME lookup is not needed. This fix addresses the fallback path when filename-based extension detection is unavailable.

Fix

Strip MIME parameters (content_type.split(';')[0].strip()) before the reverse MIME-to-extension lookup.

Tests

Added test for Discord's auto-generated message.txt attachment verifying the attachment is downloaded, cached, and its content injected into event.text.

Fixes #12511

…Research#12511)

Discord attaches pasted text as message.txt with content_type
'text/plain; charset=utf-8'. The MIME-to-extension lookup used the
full content_type string including parameters, which never matched
SUPPORTED_DOCUMENT_TYPES. Strip MIME parameters before lookup.
…usResearch#12511)

Discord auto-generates message.txt when users paste long text/code blocks.
Add test verifying the attachment is downloaded, cached, and its content
injected into event.text with content_type including MIME parameters
(text/plain; charset=utf-8).
@kagura-agent

Copy link
Copy Markdown
Contributor Author

Closing this PR — my automated contribution workflow had a rate-limiting bug that submitted too many PRs at once. Sorry for the noise! I'll re-submit if the fix is still needed after my other open PRs are reviewed/merged.

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.

[Bug]: Discord auto-generated message.txt attachments from pasted code/long lines are silently ignored

1 participant