gh-95087: Fix IndexError in parsing invalid date in the email module (GH-95201)

Co-authored-by: wouter bolsterlee <wouter@bolsterl.ee>
(cherry picked from commit ea5ed0ba51)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-07-24 23:40:17 -07:00 committed by GitHub
parent 49d038496e
commit 3ec139fa4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 23 deletions

View file

@ -95,6 +95,8 @@ def _parsedate_tz(data):
return None
data = data[:5]
[dd, mm, yy, tm, tz] = data
if not (dd and mm and yy):
return None
mm = mm.lower()
if mm not in _monthnames:
dd, mm = mm, dd.lower()
@ -110,6 +112,8 @@ def _parsedate_tz(data):
yy, tm = tm, yy
if yy[-1] == ',':
yy = yy[:-1]
if not yy:
return None
if not yy[0].isdigit():
yy, tz = tz, yy
if tm[-1] == ',':