8000 Join a filename the sender split across two encoded-words by typedev · Pull Request #118 · hyprlab/hylki · GitHub
[go: up one dir, main page]

Skip to content

Join a filename the sender split across two encoded-words - #118

Closed
typedev wants to merge 1 commit into
hyprlab:mainfrom
typedev:fix/spliced-encoded-word-filenames
Closed

typedev wants to merge 1 commit into
hyprlab:mainfrom
typedev:fix/spliced-encoded-word-filenames

Conversation

@typedev
@typedev typedev commented Sep 2, 2026
Copy link
Copy Markdown
Contributor

Fixes #117.

RFC 2047 §6.2 joins adjacent encoded-words separated only by linear whitespace and discards the separator: it is there so a long word can be folded, not as part of the text. mail_parser decodes both words but keeps the whitespace inside parameter values, so a file announced as

Content-Disposition: attachment; filename="=?utf-8?q?docu?= =?utf-8?q?ment.pdf?="

arrives named docu ment.pdf. With no .pdf suffix guess_mime falls through to application/octet-stream, so the file draws no PDF thumbnail and opens in nothing. A header folded between the encoded-words leaves a tab instead of a space, with the same result.

Why it happens in the raw header

Once attachment_name() has returned the decoded string, the encoded-word boundaries are gone — and a space in a filename is often genuine, so there is nothing left to distinguish docu ment.pdf from my file.pdf. The repair has to happen while the raw header is still in hand.

MessagePart::headers exposes each header's offset_start / offset_end into the raw message, so the original bytes are reachable. attachment_name_of splices adjacent encoded-words there and hands the repaired Content-Disposition and Content-Type back to mail_parser, which keeps every charset decision in one place rather than reimplementing RFC 2047 here.

The splice scan works on bytes directly: ?=, =? and the whitespace are all ASCII, which never occurs inside a multi-byte UTF-8 sequence.

Cost

The second parse only runs when a splice actually changed something, so ordinary mail pays one comparison and nothing else.

Tests

  • a_filename_split_across_encoded_words_is_rejoined — the space form.
  • a_filename_folded_between_encoded_words_is_rejoined — the same split folded, so the separator is a tab.
  • a_space_inside_one_encoded_word_is_kept — =?utf-8?q?my=20file.pdf?= keeps its space; that one is in the name, not between words.
  • an_unencoded_filename_with_a_space_is_untouched — a plain filename="my file.pdf" is left alone.

The last two are the guard rails: the repair must not start eating real spaces.

Full suite: 251 passed, 0 failed.

Note

Arguably this belongs in mail_parser rather than here — I intend to report it upstream too. The workaround is self-contained and can come out again if that lands.

RFC 2047 §6.2 joins adjacent encoded-words separated only by linear
whitespace and discards the separator: it is there so a long word can be
folded, not as part of the text. `mail_parser` decodes both words but keeps
the whitespace inside parameter values, so a file announced as

    Content-Disposition: attachment; filename="=?utf-8?q?docu?= =?utf-8?q?ment.pdf?="

arrives named `docu ment.pdf`.

With no `.pdf` suffix `guess_mime` falls through to
`application/octet-stream`, so the file draws no PDF thumbnail and opens in
nothing. A header folded between the encoded-words leaves a tab instead of a
space, with the same result.

This can't be repaired after the fact: the decoded string no longer shows
where one encoded-word ended, and a space in a filename is often genuine.
Splice the pair in the raw header instead — reachable through the part's
public header offsets — and hand the repaired header back to `mail_parser`,
so charset handling stays in one place. The second parse only runs when a
splice actually changed something.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
hyprlab added a commit that referenced this pull request Sep 3, 2026
RFC 2047 §6.2 joins adjacent encoded-words separated only by linear
whitespace and discards the separator: it is there so a long word can
be folded, not as part of the text. `mail_parser` decodes both words
but keeps the whitespace inside parameter values, so a file announced
as two spliced encoded-words arrives named `docu ment.pdf` — no `.pdf`
suffix, so no thumbnail and nothing to open it with. A header folded
between the words leaves a tab instead of a space, same result.

Once decoding has happened the boundary is gone, and a space in a
filename is often genuine — so the repair splices the raw header bytes
(`?=` whitespace `=?` is pure ASCII, safe to scan) and hands the fixed
Content-Disposition and Content-Type back to mail_parser, keeping every
charset decision in one place. The second parse only runs when a splice
changed something.

Landed from #118, resolving a test-module conflict with #110's landing.
The contributor intends to report the underlying behaviour to
mail_parser upstream; this workaround can come out if that lands.

Co-Authored-By: Alexander Lubovenko <2742734+typedev@users.noreply.github.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ay7c8wSGyaTPNuDXShNgAw
hyprlab added a commit that referenced this pull request Sep 3, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ay7c8wSGyaTPNuDXShNgAw
hyprlab added a commit that referenced this pull request Sep 3, 2026
…andles

Feature beta previewing 1.20.0. See CHANGELOG.md for the full list:
composer spell checking with bundled dictionaries and a managed
personal word list (discussion #114), inline images in the composer
(discussion #113), replies that follow Reply-To, the split reply and
attachment drawer resized by a floating grab pill, paste-as-plain-text
by default, the wide-mail scroll fix, and the three attachment fixes
from #110, #112 and #118 with a one-time cache repair.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ay7c8wSGyaTPNuDXShNgAw
@hyprlab
hyprlab commented Sep 4, 2026
Copy link
Copy Markdown
Owner

Landed in stable 1.20.0 as commit 9ab2fa1 on main, with you as co-author. Thank you. Applied as written. Closing since the commit is on main rather than merged from the branch.

@hyprlab hyprlab closed this Sep 4, 2026
@typedev
typedev deleted the fix/spliced-encoded-word-filenames branch September 17, 2026 19:33
hyprlab added a commit that referenced this pull request Sep 24, 2026
…andles

Feature beta previewing 1.20.0. See CHANGELOG.md for the full list:
composer spell checking with bundled dictionaries and a managed
personal word list (discussion #114), inline images in the composer
(discussion #113), replies that follow Reply-To, the split reply and
attachment drawer resized by a floating grab pill, paste-as-plain-text
by default, the wide-mail scroll fix, and the three attachment fixes
from #110, #112 and #118 with a one-time cache repair.
somepaulo pushed a commit to somepaulo/hylki that referenced this pull request Sep 24, 2026
RFC 2047 §6.2 joins adjacent encoded-words separated only by linear
whitespace and discards the separator: it is there so a long word can
be folded, not as part of the text. `mail_parser` decodes both words
but keeps the whitespace inside parameter values, so a file announced
as two spliced encoded-words arrives named `docu ment.pdf` — no `.pdf`
suffix, so no thumbnail and nothing to open it with. A header folded
between the words leaves a tab instead of a space, same result.

Once decoding has happened the boundary is gone, and a space in a
filename is often genuine — so the repair splices the raw header bytes
(`?=` whitespace `=?` is pure ASCII, safe to scan) and hands the fixed
Content-Disposition and Content-Type back to mail_parser, keeping every
charset decision in one place. The second parse only runs when a splice
changed something.

Landed from hyprlab#118, resolving a test-module conflict with hyprlab#110's landing.
The contributor intends to report the underlying behaviour to
mail_parser upstream; this workaround can come out if that lands.

Co-Authored-By: Alexander Lubovenko <2742734+typedev@users.noreply.github.com>
somepaulo pushed a commit to somepaulo/hylki that referenced this pull request Sep 24, 2026
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.

A filename split across two RFC 2047 encoded-words keeps the separator, losing its extension

2 participants

0