fix encoding issues
This commit is contained in:
@@ -90,6 +90,66 @@ setattr(email._header_value_parser, "DisplayName", DisplayName)
|
||||
setattr(email._header_value_parser, "get_name_addr", get_name_addr)
|
||||
|
||||
|
||||
# https://bugs.python.org/issue42484
|
||||
#
|
||||
# fix: https://github.com/python/cpython/pull/24669
|
||||
|
||||
from email._header_value_parser import DOT, ObsLocalPart, ValueTerminal, get_word
|
||||
|
||||
|
||||
def get_obs_local_part(value):
|
||||
""" obs-local-part = word *("." word)
|
||||
"""
|
||||
obs_local_part = ObsLocalPart()
|
||||
last_non_ws_was_dot = False
|
||||
while value and (value[0]=='\\' or value[0] not in PHRASE_ENDS):
|
||||
if value[0] == '.':
|
||||
if last_non_ws_was_dot:
|
||||
obs_local_part.defects.append(errors.InvalidHeaderDefect(
|
||||
"invalid repeated '.'"))
|
||||
obs_local_part.append(DOT)
|
||||
last_non_ws_was_dot = True
|
||||
value = value[1:]
|
||||
continue
|
||||
elif value[0]=='\\':
|
||||
obs_local_part.append(ValueTerminal(value[0],
|
||||
'misplaced-special'))
|
||||
value = value[1:]
|
||||
obs_local_part.defects.append(errors.InvalidHeaderDefect(
|
||||
"'\\' character outside of quoted-string/ccontent"))
|
||||
last_non_ws_was_dot = False
|
||||
continue
|
||||
if obs_local_part and obs_local_part[-1].token_type != 'dot':
|
||||
obs_local_part.defects.append(errors.InvalidHeaderDefect(
|
||||
"missing '.' between words"))
|
||||
try:
|
||||
token, value = get_word(value)
|
||||
last_non_ws_was_dot = False
|
||||
except errors.HeaderParseError:
|
||||
if value[0] not in CFWS_LEADER:
|
||||
raise
|
||||
token, value = get_cfws(value)
|
||||
obs_local_part.append(token)
|
||||
if not obs_local_part:
|
||||
return obs_local_part, value
|
||||
if (obs_local_part[0].token_type == 'dot' or
|
||||
obs_local_part[0].token_type=='cfws' and
|
||||
obs_local_part[1].token_type=='dot'):
|
||||
obs_local_part.defects.append(errors.InvalidHeaderDefect(
|
||||
"Invalid leading '.' in local part"))
|
||||
if (obs_local_part[-1].token_type == 'dot' or
|
||||
obs_local_part[-1].token_type=='cfws' and
|
||||
obs_local_part[-2].token_type=='dot'):
|
||||
obs_local_part.defects.append(errors.InvalidHeaderDefect(
|
||||
"Invalid trailing '.' in local part"))
|
||||
if obs_local_part.defects:
|
||||
obs_local_part.token_type = 'invalid-obs-local-part'
|
||||
return obs_local_part, value
|
||||
|
||||
|
||||
setattr(email._header_value_parser, "get_obs_local_part", get_obs_local_part)
|
||||
|
||||
|
||||
# https://bugs.python.org/issue30681
|
||||
#
|
||||
# fix: https://github.com/python/cpython/pull/22090
|
||||
|
||||
Reference in New Issue
Block a user