diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index c448fd07dfcca1..ce4776cfc3e20a 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -1519,14 +1519,14 @@ def get_obs_local_part(value): else: if (obs_local_part[0].token_type == 'dot' or (obs_local_part[0].token_type=='cfws' - and len(obs_local_part) == 1 - or obs_local_part[1].token_type=='dot')): + and len(obs_local_part) > 1 + 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 len(obs_local_part) == 1 - or obs_local_part[-2].token_type=='dot')): + and len(obs_local_part) > 1 + 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: