Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
700e78f
Better parameterized test support.
bitdancer May 31, 2026
d1f58b8
Make params the default for email test cases.
bitdancer May 31, 2026
ff717b3
DROPME: temporary unittest usability hack.
bitdancer Feb 28, 2026
bfb8be7
Enhance defects assertion.
bitdancer Dec 26, 2025
40fbf96
Add defect expectation constants and functions.
bitdancer May 19, 2026
8158e1c
Fix defect copying when extending a token list.
bitdancer Jan 21, 2026
4e3dc45
Add for_each_character params filter.
bitdancer Mar 14, 2026
24d78c2
Begin converting _wsp_splitter tests to new framework.
bitdancer Jan 8, 2026
3e7357b
Do _wsp_splitter test conversion.
bitdancer Dec 28, 2025
0bab82a
Update _wsp_splitter test names.
bitdancer Dec 28, 2025
5df8183
Add tests for _validate_xtext.
bitdancer Mar 14, 2026
127b6af
Add more testing infrastructure.
bitdancer Dec 26, 2025
dc93b3a
Add tests for _get_ptext_to_endchars.
bitdancer Dec 26, 2025
3a13cae
Begin refactoring of get_fws tests.
bitdancer Jan 17, 2026
bf2746d
Rough conversion of existing get_fws tests.
bitdancer Jan 8, 2026
102da9e
Fix whitespace and test names in get_fws tests.
bitdancer Dec 26, 2025
aafe940
Convert get_fws tests to keyword form.
bitdancer Jan 8, 2026
e2a28e0
Improve the get_fws test names.
bitdancer Feb 20, 2026
d5afdf7
Improve get_fws tests.
bitdancer Dec 26, 2025
1d422b8
Begin _encoded_words test refactor.
bitdancer Jan 2, 2026
110e8c7
Rough conversion of _encoded_word tests.
bitdancer Jan 2, 2026
0f7b17f
Fix whitespace and test names in _encoded_words tests.
bitdancer Jan 2, 2026
3c6bfe3
Tidy up to finish _encoded_words test conversion.
bitdancer Jan 2, 2026
d71112d
Begin get_encoded_word test refactor.
bitdancer Jan 3, 2026
7420116
Rough conversion of get_encoded_word tests.
bitdancer Dec 27, 2025
82b6156
Fix test names and whitespace in get_encoded_word tests.
bitdancer Jan 3, 2026
f942791
Convert get_encoded_word tests to keyword form.
bitdancer Dec 27, 2025
45ff404
Begin simplifying get_encoded_word 'raise' tests.
bitdancer May 20, 2026
c2debf7
Simplify get_encoded_word raise tests further.
bitdancer May 7, 2026
65a808d
Update get_encoded_word raise tests before adding more.
bitdancer Jan 29, 2026
fbeae7d
Update fix for bpo-27397/gh-71584.
bitdancer May 14, 2026
8754d9e
Add more get_encoded_word tests.
bitdancer Jun 13, 2026
de6487e
Begin refactoring get_unstructured tests.
bitdancer Jun 13, 2026
527e9ac
Rough conversion of get_unstructured tests.
bitdancer Jan 5, 2026
89570a8
Fix whitespace/test names in get_unstructured tests.
bitdancer Jan 5, 2026
0102035
Convert get_unstructured tests to keyword form.
bitdancer Jan 5, 2026
50f90d6
Remove now redundant get_unstructured tests.
bitdancer May 17, 2026
ca58e38
Add more get_unstructured tests, specific defects.
bitdancer Jan 5, 2026
5948d0b
Begin conversion of get_qp_ctext tests.
bitdancer Jan 7, 2026
ca77c51
Convert get_qp_ctext tests.
bitdancer Jan 7, 2026
b68a369
Fix whitespace and test names in get_qp_ctext tests.
bitdancer Jan 7, 2026
8102870
Convert get_qp_ctext tests to keyword form.
bitdancer Jan 7, 2026
91e75e2
get_qp_ctext test improvements.
bitdancer Jan 7, 2026
e22c595
Begin converting get_qcontent tests to new framework.
bitdancer Jan 11, 2026
0a7bc1c
Rough conversion of get_qcontent tests.
bitdancer Jan 11, 2026
98d66aa
Fix whitespace and test names in get_qcontent tests.
bitdancer Jan 11, 2026
8960b84
Put get_qcontent tests in keyword form.
bitdancer Jan 11, 2026
b882330
Improve get_qcontent tests.
bitdancer Jan 11, 2026
0679063
Start conversion of get_atext tests.
bitdancer Jan 13, 2026
d2a32af
Rough conversion of get_atext tests.
bitdancer Jan 13, 2026
a083cd2
Fix whitespace and test names in get_atext tests.
bitdancer Jan 13, 2026
64299cf
Convert get_atext tests to keyeword form.
bitdancer Jan 13, 2026
644e855
Improve the get_atext tests.
bitdancer Jan 13, 2026
220e675
Begin refactor of get_bare_quoted_string tests.
bitdancer Jan 14, 2026
30a796e
Rough refactoring of bare_quoted_string tests.
bitdancer Jan 14, 2026
f4216ee
Fix whitespace and test names in bare_quoted_string tests.
bitdancer Jan 14, 2026
faa905f
Convert bare_quoted_string tests to keyword form.
bitdancer Jan 14, 2026
71d5488
Clarify test names, remove redundant test.
bitdancer Jan 15, 2026
b7bc1ce
Improve bare_quoted_string tests.
bitdancer Jan 15, 2026
4d20bcc
Begin refactoring get_comment tests.
bitdancer Jan 16, 2026
9d371de
Rough conversion of get_comment tests.
bitdancer Jan 17, 2026
effd1d6
Fix whitespace and test names in get_comment tests.
bitdancer Jan 18, 2026
6b38169
Convert get_comment tests to keyword form.
bitdancer Jan 18, 2026
bf27f70
Improve get_comment test names.
bitdancer Feb 28, 2026
5fe5f58
Improve the get_comment tests.
bitdancer Jan 19, 2026
1079602
Begin conversion of get_cfws tests.
bitdancer Jan 23, 2026
2fa6a8e
Remove now-redundant tests.
bitdancer Feb 28, 2026
407e6c2
Rough conversion of get_cwfs tests.
bitdancer Jan 23, 2026
62951e5
Fix whitespace in get_cfws tests.
bitdancer Jan 23, 2026
e97f868
Shorten test names in get_cfws tests.
bitdancer Jan 23, 2026
c4bf042
Convert get_cfws tests to keyword form.
bitdancer Jan 23, 2026
251adca
Add commenttree checks to get_cfws tests.
bitdancer Jan 23, 2026
226a1b1
Improve get_cfws tests.
bitdancer Jan 23, 2026
fe66529
Start conversion of get_quoted_string tests.
bitdancer Jan 23, 2026
4b890eb
Remove now redundant get_quoted_string test.
bitdancer Mar 6, 2026
a568523
Rough conversion of get_quoted_string tests.
bitdancer Jan 24, 2026
0e84644
Fix whitespace and test names in get_quoted_string tests.
bitdancer Jan 24, 2026
8c70238
Convert get_quoted_string tests to keyword form.
bitdancer Jan 26, 2026
8cac1d1
Improve get_quoted_string tests.
bitdancer Jan 26, 2026
e67faaf
Add content checking to get_quoted_string tests.
bitdancer Apr 8, 2026
420529d
Start refactoring get_atom tests.
bitdancer Jan 26, 2026
a168523
Rough conversion of get_atom tests.
bitdancer Jan 26, 2026
bf789fc
Fix whitespace and test names in get_atom tests.
bitdancer Jan 26, 2026
06d6617
Convert get_atom tests to keyword form.
bitdancer Jan 26, 2026
1aa811c
Improve the get_atom tests.
bitdancer Jan 26, 2026
d3e1d96
Start refactoring get_dot_atom_text tests.
bitdancer Feb 1, 2026
1f36294
Delete now redundant get_dot_atom_text test.
bitdancer Mar 9, 2026
8e2776a
Rough conversion of get_dot_atom_text tests.
bitdancer Feb 2, 2026
8c60d90
Fix whitespace and test names in get_dot_atom_text tests.
bitdancer Feb 2, 2026
51772f7
Convert get_dot_atom_text tests to keyword form.
bitdancer Feb 5, 2026
38db54e
Improve the get_dot_atom_text tests, step 1.
bitdancer Feb 5, 2026
b91ba59
Improve the get_dot_atom_text tests step 2.
bitdancer Mar 9, 2026
2b8c183
Improve get_dot_atom_text tests step 3: more tests.
bitdancer Mar 9, 2026
7d91c74
Begin refactoring get_dot_atom tests.
bitdancer Feb 8, 2026
0cc7e12
Rough conversion of get_dot_atom tests.
bitdancer Feb 8, 2026
3c3fdb1
Fix whitespace and test names in get_dot_atom tests.
bitdancer Feb 8, 2026
364df1e
Convert get_dot_atom tests to keyword form.
bitdancer Feb 8, 2026
e7b9020
Improve the get_dot_atom tests.
bitdancer Feb 8, 2026
38b613b
Refactor get_word tests.
bitdancer Feb 13, 2026
4f59e8f
Begin refactoring get_phrase tests.
bitdancer Feb 20, 2026
ffe9351
Rough conversion of get_phrase tests.
bitdancer Mar 11, 2026
ad2618f
Fix whitespace and test names in get_phrase tests.
bitdancer Mar 11, 2026
b467e07
Convert get_phrase tests to keyword form.
bitdancer Mar 11, 2026
4f4d5e1
Add equivalent of get_phrase test length check.
bitdancer Mar 11, 2026
ebdce1f
Improve the get_phrase test defect checking.
bitdancer Mar 11, 2026
d6fad60
Improve the get_phrase test names.
bitdancer Mar 11, 2026
bf3a9ac
Additional tests for get_phrase.
bitdancer Mar 11, 2026
50a8bc7
Begin conversion of get_local_part tests.
bitdancer Mar 28, 2026
676b998
Rough refactoring of get_local_part tests.
bitdancer Mar 30, 2026
95c4f0e
Fix whitespace and test names in get_local_part tests.
bitdancer Mar 30, 2026
1f1ed35
Convert get_local_part tests to keyword form.
bitdancer Mar 30, 2026
4093b8a
Add defect message checks to get_local_part tests.
bitdancer Mar 31, 2026
291568d
Move obs tests to new get_obs_local_part tests section.
bitdancer Apr 3, 2026
a3e93be
Move get_obs_local_part before get_local_part.
bitdancer Apr 3, 2026
62d7e8a
Enhance the get_obs_local_part tests.
bitdancer Apr 3, 2026
f8fffad
New get_obs_local_part ew test, fix bug.
bitdancer Apr 3, 2026
16a239d
More get_obs_local_part ew tests.
bitdancer Apr 4, 2026
a6fc56f
Add unicode and ew get_local_part tests.
bitdancer Apr 7, 2026
d82b5c9
Document new API pattern, add deprecation helpers.
bitdancer Dec 25, 2025
c86dabe
Deprecate NonASCIILocalPartDefect.
bitdancer May 2, 2026
66fe08b
Refactor get_fws.
bitdancer Mar 20, 2026
f0a0cc3
Add _make_xtext.
bitdancer May 10, 2026
58f523c
Preliminary deprecation of _validate_xtext.
bitdancer May 10, 2026
bdaa0f7
Add _get_xtext function.
bitdancer Jan 13, 2026
9b8e480
Factor a _decode out of decode in _encoded_words.
bitdancer Jan 2, 2026
19cc42a
Refactor get_encoded_word.
bitdancer Dec 30, 2025
f1014b6
Refactor get_unstructured into parse_unstructured.
bitdancer Jan 5, 2026
801c4ab
Deprecate _wsp_splitter.
bitdancer Jan 31, 2026
87dcb41
Start adding a content_getter helper.
bitdancer Jan 7, 2026
d598267
Implement content_getter.
bitdancer May 8, 2026
d2714a9
Deprecate _get_ptext_to_endchars.
bitdancer Mar 19, 2026
f87d59a
Refactor parse_unstructured to use content_getter.
bitdancer May 8, 2026
c6ec083
Add get_ccontent_sequence.
bitdancer Jun 6, 2026
672f357
Have get_comment reuse the get_ccontent_sequence tests.
bitdancer Jun 6, 2026
d0f031e
Preliminary deprecation of get_qp_ctext.
bitdancer May 9, 2026
59e58a6
Set up easy POSTDEP removal for get_qp_ctext.
bitdancer May 9, 2026
230f00c
Refactor get_bare_quoted_string.
bitdancer Jan 15, 2026
399cf70
Preliminary deprecation of get_qcontent.
bitdancer Mar 20, 2026
705f301
Add get_atext_sequence.
bitdancer Mar 20, 2026
45591fa
Preliminary deprecation of get_atext.
bitdancer Mar 20, 2026
0521972
Refactor get_comment.
bitdancer May 8, 2026
bfa84af
Finalize deprecation of get_qp_ctext.
bitdancer Jan 21, 2026
2435928
Refactor get_cfws.
bitdancer Jan 23, 2026
6ba71e7
Refactor get_quoted_string.
bitdancer Jan 26, 2026
464d403
Refactor get_atom.
bitdancer Jan 27, 2026
34eb525
Refactor get_dot_atom_text.
bitdancer Feb 5, 2026
1339032
Finalize deprecation of get_atext.
bitdancer May 3, 2026
2c63beb
Refactor get_dot_atom.
bitdancer Feb 8, 2026
e1b1fa4
Refactor get_word.
bitdancer Feb 16, 2026
3df6a62
Refactor get_phrase.
bitdancer Mar 14, 2026
e8fc51b
Refactor get_obs_local_part.
bitdancer May 2, 2026
9ed0e66
Refactor get_local_part.
bitdancer Jun 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Lib/email/_encoded_words.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,29 @@ def decode(ew):
the encoded_string decoded first from its Content Transfer Encoding and
then from the resulting bytes into unicode using the specified charset. If
the cte-decoded string does not successfully decode using the specified
character set, a defect is added to the defects list and the unknown octets
are replaced by the unicode 'unknown' character \\uFDFF.
character set, a defect is added to the defects list. If the charset
is invalid or not found, a defect is added to the defects list.

The specified charset and language are returned. The default for language,
which is rarely if ever encountered, is the empty string.

"""
_, charset, cte, cte_string, _ = ew.split('?')
charset, _, lang = charset.partition('*')
string, defects = _decode(charset, cte, cte_string)
return string, charset, lang, defects


def _decode(charset, cte, cte_string):
"""Return cte_string decoded using cte and charset and a list of defects.

Use cte to turn cte_string into bytes, then decode those bytes using
charset and the surrogateescape error handler. Return a possibly empty
list of defects: return a CharsetError if the charset name is invalid or
unknown, and an UndecodableBytesDefect if there are any bytes the charset
cannot decode.

"""
cte = cte.lower()
# Recover the original bytes and do CTE decoding.
bstring = cte_string.encode('ascii', 'surrogateescape')
Expand All @@ -184,11 +198,13 @@ def decode(ew):
f"contains bytes not decodable using {charset!r} charset"))
string = bstring.decode(charset, 'surrogateescape')
except (LookupError, UnicodeEncodeError):
# In this context a UnicodeEncodeError results when the charset name is
# not a valid ASCII string.
string = bstring.decode('ascii', 'surrogateescape')
if charset.lower() != 'unknown-8bit':
defects.append(errors.CharsetError(f"Unknown charset {charset!r} "
f"in encoded word; decoded as unknown bytes"))
return string, charset, lang, defects
return string, defects


_cte_encoders = {
Expand Down
Loading
Loading