Skip to content

Commit accd1c0

Browse files
committed
#1162477: accept '.' in addition to ':' when parsing time in date header.
Some non-compliant MUAs use '.'s, so by the Postel Principle we should accept them. Patch by Thomas Herve.
1 parent 0cfc237 commit accd1c0

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Lib/email/_parseaddr.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def parsedate_tz(data):
9999
tss = '0'
100100
elif len(tm) == 3:
101101
[thh, tmm, tss] = tm
102+
elif len(tm) == 1 and '.' in tm[0]:
103+
# Some non-compliant MUAs use '.' to separate time elements.
104+
tm = tm[0].split('.')
105+
if len(tm) == 2:
106+
[thh, tmm] = tm
107+
tss = 0
108+
elif len(tm) == 3:
109+
[thh, tmm, tss] = tm
102110
else:
103111
return None
104112
try:

Lib/email/test/test_email.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,13 @@ def test_parsedate_no_space_before_negative_offset(self):
23282328
(2002, 4, 3, 14, 58, 26, 0, 1, -1, -28800))
23292329

23302330

2331+
def test_parsedate_accepts_time_with_dots(self):
2332+
eq = self.assertEqual
2333+
eq(utils.parsedate_tz('5 Feb 2003 13.47.26 -0800'),
2334+
(2003, 2, 5, 13, 47, 26, 0, 1, -1, -28800))
2335+
eq(utils.parsedate_tz('5 Feb 2003 13.47 -0800'),
2336+
(2003, 2, 5, 13, 47, 0, 0, 1, -1, -28800))
2337+
23312338
def test_parsedate_acceptable_to_time_functions(self):
23322339
eq = self.assertEqual
23332340
timetup = utils.parsedate('5 Feb 2003 13:47:26 -0800')

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ Core and Builtins
6868
Library
6969
-------
7070

71+
- Issue #1162477: Postel Principal adjustment to email date parsing: handle the
72+
fact that some non-compliant MUAs use '.' instead of ':' in time specs.
73+
7174
- Issue #11131: Fix sign of zero in decimal.Decimal plus and minus
7275
operations when the rounding mode is ROUND_FLOOR.
7376

0 commit comments

Comments
 (0)