Renderer content disposition encoding#7
Open
romsahel wants to merge 2 commits intoparser-rfc-2822-memory-optimizationfrom
Open
Renderer content disposition encoding#7romsahel wants to merge 2 commits intoparser-rfc-2822-memory-optimizationfrom
romsahel wants to merge 2 commits intoparser-rfc-2822-memory-optimizationfrom
Conversation
…ype parameters RFC 2047 encoded-words are forbidden in MIME parameter values. This change implements RFC 2231 encoding (charset'language'percent-encoded) for Content-Type and Content-Disposition parameters while preserving RFC 2047 for other headers.
Fix parser to correctly handle simple RFC 2231 extended parameters (e.g., filename*=UTF-8''value) by using `trim: true` in String.split.
romsahel
commented
Feb 4, 2026
Owner
Author
There was a problem hiding this comment.
The parser currently only supported Parameter Value Continuations which has the format key*index="value"
Content-Type: message/external-body; access-type=URL;
URL*0="ftp://";
URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
The non-continuation version is simply: key*="value"
romsahel
commented
Feb 4, 2026
Comment on lines
+167
to
+177
| defp render_subtypes([{key, value} | subtypes], :rfc_2231) do | ||
| key = String.replace(key, "_", "-") | ||
| value = encode_header_value(value, :quoted_printable) | ||
|
|
||
| value = | ||
| if value =~ ~r/[\s()<>@,;:\\<\/\[\]?=]/ do | ||
| "\"#{value}\"" | ||
| else | ||
| value | ||
| end | ||
| if contains_non_ascii?(value) do | ||
| value = encode_header_value(value, :rfc_2231) | ||
| ["#{key}*=UTF-8''#{value}" | render_subtypes(subtypes, :rfc_2231)] | ||
| else | ||
| value = maybe_wrap_in_quotes(value) | ||
| ["#{key}=#{value}" | render_subtypes(subtypes, :rfc_2231)] | ||
| end | ||
| end |
Owner
Author
There was a problem hiding this comment.
new handler is here.
The logic of the other handler is untouched
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Statement
RFC 2047 defines "encoded-words" (the
=?UTF-8?Q?encoded-text?=format) for encoding non-ASCII characters in email headers. However, RFC 2047 explicitly states:This means:
Subject: =?UTF-8?Q?caf=C3=A9?=From: =?UTF-8?Q?Jos=C3=A9?= <jose@example.com>Content-Disposition: attachment; filename="=?UTF-8?Q?caf=C3=A9.pdf?="These headers must be encoded using the rfc2231 specifications:
parameter*=charset'language'encoded-value*) suffix when encoding is usedExamples:
Current implementation
In
lib/mail/renderers/rfc_2822.ex, therender_subtypes/1function is using RFC 2047 encoding for all header parameters.The proposed fix
Introduce a new
render_subtypesthat handles those headers (@rfc2231_headers) and apply the proper encoding when necessary (ie if it contains non-ASCII characters