@@ -1053,7 +1053,7 @@ def get_fws(value):
10531053 fws = WhiteSpaceTerminal (value [:len (value )- len (newvalue )], 'fws' )
10541054 return fws , newvalue
10551055
1056- def get_encoded_word (value ):
1056+ def get_encoded_word (value , terminal_type = 'vtext' ):
10571057 """ encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
10581058
10591059 """
@@ -1092,7 +1092,7 @@ def get_encoded_word(value):
10921092 ew .append (token )
10931093 continue
10941094 chars , * remainder = _wsp_splitter (text , 1 )
1095- vtext = ValueTerminal (chars , 'vtext' )
1095+ vtext = ValueTerminal (chars , terminal_type )
10961096 _validate_xtext (vtext )
10971097 ew .append (vtext )
10981098 text = '' .join (remainder )
@@ -1134,7 +1134,7 @@ def get_unstructured(value):
11341134 valid_ew = True
11351135 if value .startswith ('=?' ):
11361136 try :
1137- token , value = get_encoded_word (value )
1137+ token , value = get_encoded_word (value , 'utext' )
11381138 except _InvalidEwError :
11391139 valid_ew = False
11401140 except errors .HeaderParseError :
@@ -1163,7 +1163,7 @@ def get_unstructured(value):
11631163 # the parser to go in an infinite loop.
11641164 if valid_ew and rfc2047_matcher .search (tok ):
11651165 tok , * remainder = value .partition ('=?' )
1166- vtext = ValueTerminal (tok , 'vtext ' )
1166+ vtext = ValueTerminal (tok , 'utext ' )
11671167 _validate_xtext (vtext )
11681168 unstructured .append (vtext )
11691169 value = '' .join (remainder )
@@ -2813,7 +2813,7 @@ def _refold_parse_tree(parse_tree, *, policy):
28132813 continue
28142814 tstr = str (part )
28152815 if not want_encoding :
2816- if part .token_type == 'ptext' :
2816+ if part .token_type in ( 'ptext' , 'vtext' ) :
28172817 # Encode if tstr contains special characters.
28182818 want_encoding = not SPECIALSNL .isdisjoint (tstr )
28192819 else :
0 commit comments