summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-08-25 00:45:55 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2010-08-25 00:45:55 (GMT)
commit219d1c8ae320bf1b016f4a4fc5dee50f729048be (patch)
tree3ea22eb0b5ef43206c1765b95c95ead4c5a911a6 /Lib/email
parent1970b62aee9ccedd83dea0df57bf0e0e63861cbe (diff)
downloadcpython-219d1c8ae320bf1b016f4a4fc5dee50f729048be.zip
cpython-219d1c8ae320bf1b016f4a4fc5dee50f729048be.tar.gz
cpython-219d1c8ae320bf1b016f4a4fc5dee50f729048be.tar.bz2
#1194222: make parsedate always return RFC2822 four character years.
Two character years are now converted to four character years using the Posix standard rule (<68 == 2000, >=68==1900). This makes the parsed date RFC2822 compliant even if the input is not. Patch and test by Jeffrey Finkelstein.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/_parseaddr.py12
-rw-r--r--Lib/email/test/test_email.py13
2 files changed, 25 insertions, 0 deletions
diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
index 81913a3..ac2e524 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 c311469..e18ffaf 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('<>')), '')