@@ -1045,7 +1045,7 @@ def get_fws(value):
10451045 fws = WhiteSpaceTerminal (value [:len (value )- len (newvalue )], 'fws' )
10461046 return fws , newvalue
10471047
1048- def get_encoded_word (value ):
1048+ def get_encoded_word (value , terminal_type = 'vtext' ):
10491049 """ encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
10501050
10511051 """
@@ -1084,7 +1084,7 @@ def get_encoded_word(value):
10841084 ew .append (token )
10851085 continue
10861086 chars , * remainder = _wsp_splitter (text , 1 )
1087- vtext = ValueTerminal (chars , 'vtext' )
1087+ vtext = ValueTerminal (chars , terminal_type )
10881088 _validate_xtext (vtext )
10891089 ew .append (vtext )
10901090 text = '' .join (remainder )
@@ -1126,7 +1126,7 @@ def get_unstructured(value):
11261126 valid_ew = True
11271127 if value .startswith ('=?' ):
11281128 try :
1129- token , value = get_encoded_word (value )
1129+ token , value = get_encoded_word (value , 'utext' )
11301130 except _InvalidEwError :
11311131 valid_ew = False
11321132 except errors .HeaderParseError :
@@ -1155,7 +1155,7 @@ def get_unstructured(value):
11551155 # the parser to go in an infinite loop.
11561156 if valid_ew and rfc2047_matcher .search (tok ):
11571157 tok , * remainder = value .partition ('=?' )
1158- vtext = ValueTerminal (tok , 'vtext ' )
1158+ vtext = ValueTerminal (tok , 'utext ' )
11591159 _validate_xtext (vtext )
11601160 unstructured .append (vtext )
11611161 value = '' .join (remainder )
@@ -2789,7 +2789,7 @@ def _refold_parse_tree(parse_tree, *, policy):
27892789 continue
27902790 tstr = str (part )
27912791 if not want_encoding :
2792- if part .token_type == 'ptext' :
2792+ if part .token_type in ( 'ptext' , 'vtext' ) :
27932793 # Encode if tstr contains special characters.
27942794 want_encoding = not SPECIALSNL .isdisjoint (tstr )
27952795 else :
0 commit comments