summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/email/_parseaddr.py12
-rw-r--r--Lib/email/test/test_email.py13
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 29 insertions, 0 deletions
diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
index 81913a3824..ac2e524401 100644
--- a/Lib/email/_parseaddr.py
+++ b/Lib/email/_parseaddr.py
@@ -107,6 +107,18 @@ def parsedate_tz(data):
tss = int(tss)
except ValueError:
return None
+ # Check for a yy specified in two-digit format, then convert it to the
+ # appropriate four-digit format, according to the POSIX standard. RFC 822
+ # calls for a two-digit yy, but RFC 2822 (which obsoletes RFC 822)
+ # mandates a 4-digit yy. For more information, see the documentation for
+ # the time module.
+ if yy < 100:
+ # The year is between 1969 and 1999 (inclusive).
+ if yy > 68:
+ yy += 1900
+ # The year is between 2000 and 2068 (inclusive).
+ else:
+ yy += 2000
tzoffset = None
tz = tz.upper()
if tz in _timezones:
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index e1754e9f75..300fc21711 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -2234,6 +2234,19 @@ class TestMiscellaneous(TestEmailBase):
eq(time.localtime(t)[:6], timetup[:6])
eq(int(time.strftime('%Y', timetup[:9])), 2003)
+ def test_parsedate_y2k(self):
+ """Test for parsing a date with a two-digit year.
+
+ Parsing a date with a two-digit year should return the correct
+ four-digit year. RFC822 allows two-digit years, but RFC2822 (which
+ obsoletes RFC822) requires four-digit years.
+
+ """
+ self.assertEqual(Utils.parsedate_tz('25 Feb 03 13:47:26 -0800'),
+ Utils.parsedate_tz('25 Feb 2003 13:47:26 -0800'))
+ self.assertEqual(Utils.parsedate_tz('25 Feb 71 13:47:26 -0800'),
+ Utils.parsedate_tz('25 Feb 1971 13:47:26 -0800'))
+
def test_parseaddr_empty(self):
self.assertEqual(Utils.parseaddr('<>'), ('', ''))
self.assertEqual(Utils.formataddr(Utils.parseaddr('<>')), '')
diff --git a/Misc/ACKS b/Misc/ACKS
index d72427a056..f65df52134 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -247,6 +247,7 @@ Niels Ferguson
Sebastian Fernandez
Vincent Fiack
Tomer Filiba
+Jeffrey Finkelstein
Russell Finn
Nils Fischbeck
Frederik Fix
diff --git a/Misc/NEWS b/Misc/NEWS
index 70ed097c66..ed5f442551 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,9 @@ Core and Builtins
Library
-------
+- Issue #1194222: email.utils.parsedate now returns RFC2822 compliant four
+ character years even if the message contains RFC822 two character years.
+
- Issue #8750: Fixed MutableSet's methods to correctly handle
reflexive operations, namely x -= x and x ^= x.