diff options
author | R David Murray <rdmurray@bitdance.com> | 2012-04-13 21:27:19 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2012-04-13 21:27:19 -0400 |
commit | ea7bc055b08fb442986e0735b1b5b325b0b51ecc (patch) | |
tree | 20c2b837c787daf7e95ece075e6544627b17625a /Lib/email/_parseaddr.py | |
parent | c32365d2ce552d1d17279e30a564509235ffb1db (diff) | |
parent | c2c9c905706160bf34aea12f2348210aac3e0da2 (diff) | |
download | cpython-ea7bc055b08fb442986e0735b1b5b325b0b51ecc.tar.gz |
Merge #14399: corrected news item
Diffstat (limited to 'Lib/email/_parseaddr.py')
-rw-r--r-- | Lib/email/_parseaddr.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py index a295757281..0342469706 100644 --- a/Lib/email/_parseaddr.py +++ b/Lib/email/_parseaddr.py @@ -47,6 +47,21 @@ def parsedate_tz(data): Accounts for military timezones. """ + res = _parsedate_tz(data) + if res[9] is None: + res[9] = 0 + return tuple(res) + +def _parsedate_tz(data): + """Convert date to extended time tuple. + + The last (additional) element is the time zone offset in seconds, except if + the timezone was specified as -0000. In that case the last element is + None. This indicates a UTC timestamp that explicitly declaims knowledge of + the source timezone, as opposed to a +0000 timestamp that indicates the + source timezone really was UTC. + + """ data = data.split() # The FWS after the comma after the day-of-week is optional, so search and # adjust for this. @@ -99,6 +114,14 @@ def parsedate_tz(data): tss = '0' elif len(tm) == 3: [thh, tmm, tss] = tm + elif len(tm) == 1 and '.' in tm[0]: + # Some non-compliant MUAs use '.' to separate time elements. + tm = tm[0].split('.') + if len(tm) == 2: + [thh, tmm] = tm + tss = 0 + elif len(tm) == 3: + [thh, tmm, tss] = tm else: return None try: @@ -130,6 +153,8 @@ def parsedate_tz(data): tzoffset = int(tz) except ValueError: pass + if tzoffset==0 and tz.startswith('-'): + tzoffset = None # Convert a timezone offset into seconds ; -0500 -> -18000 if tzoffset: if tzoffset < 0: @@ -139,7 +164,7 @@ def parsedate_tz(data): tzsign = 1 tzoffset = tzsign * ( (tzoffset//100)*3600 + (tzoffset % 100)*60) # Daylight Saving Time flag is set to -1, since DST is unknown. - return yy, mm, dd, thh, tmm, tss, 0, 1, -1, tzoffset + return [yy, mm, dd, thh, tmm, tss, 0, 1, -1, tzoffset] def parsedate(data): |