Fixed date header parsing to be precise with timezone information. Also, when
writing From_ line timestamps, don't use UTC but local time, without timezone information.
This commit is contained in:
parent
5178c956bc
commit
4584dffe14
|
@ -1,3 +1,9 @@
|
||||||
|
Version 0.7.3 - UNRELEASED
|
||||||
|
|
||||||
|
* Fixed date header parsing to be precise with timezone information. Also,
|
||||||
|
when writing From_ line timestamps, don't use UTC but local time, without
|
||||||
|
timezone information.
|
||||||
|
|
||||||
Version 0.7.2 - 9 November 2007
|
Version 0.7.2 - 9 November 2007
|
||||||
|
|
||||||
* IMAP: fixed crash by working around python bug #1277098, which is still pending
|
* IMAP: fixed crash by working around python bug #1277098, which is still pending
|
||||||
|
|
|
@ -748,9 +748,9 @@ def make_mbox_from(message):
|
||||||
assert(message)
|
assert(message)
|
||||||
address = guess_return_path(message)
|
address = guess_return_path(message)
|
||||||
time_message = guess_delivery_time(message)
|
time_message = guess_delivery_time(message)
|
||||||
gm_date = time.gmtime(time_message)
|
date = time.localtime(time_message)
|
||||||
assert(gm_date)
|
assert(date)
|
||||||
date_string = time.asctime(gm_date)
|
date_string = time.asctime(date)
|
||||||
mbox_from = "From %s %s\n" % (address, date_string)
|
mbox_from = "From %s %s\n" % (address, date_string)
|
||||||
return mbox_from
|
return mbox_from
|
||||||
|
|
||||||
|
@ -779,21 +779,22 @@ def guess_delivery_time(message):
|
||||||
# get more desparate as we go through the array
|
# get more desparate as we go through the array
|
||||||
for header in ('Delivery-date', 'Date', 'Resent-Date'):
|
for header in ('Delivery-date', 'Date', 'Resent-Date'):
|
||||||
try:
|
try:
|
||||||
date = message.getdate(header)
|
date = message.getdate_tz(header)
|
||||||
if date:
|
if date:
|
||||||
time_message = time.mktime(date)
|
time_message = rfc822.mktime_tz(date)
|
||||||
vprint("using valid time found from '%s' header" % header)
|
vprint("using valid time found from '%s' header" % header)
|
||||||
return time_message
|
return time_message
|
||||||
except (IndexError, ValueError, OverflowError): pass
|
except (IndexError, ValueError, OverflowError): pass
|
||||||
# as a second-last resort, try the date from the 'From_' line (ugly)
|
# as a second-last resort, try the date from the 'From_' line (ugly)
|
||||||
# this will only work from a mbox-format mailbox
|
# this will only work from a mbox-format mailbox
|
||||||
if (message.unixfrom):
|
if (message.unixfrom):
|
||||||
header = re.sub("From \S+", "", message.unixfrom)
|
# Hmm. This will break with full-blown RFC 2822 addr-spec's.
|
||||||
header = string.strip(header)
|
header = message.unixfrom.split(None, 2)[-1]
|
||||||
date = rfc822.parsedate(header)
|
# Interpret no timezone as localtime
|
||||||
|
date = rfc822.parsedate_tz(header)
|
||||||
if date:
|
if date:
|
||||||
try:
|
try:
|
||||||
time_message = time.mktime(date)
|
time_message = rfc822.mktime_tz(date)
|
||||||
vprint("using valid time found from unix 'From_' header")
|
vprint("using valid time found from unix 'From_' header")
|
||||||
return time_message
|
return time_message
|
||||||
except (ValueError, OverflowError): pass
|
except (ValueError, OverflowError): pass
|
||||||
|
|
Loading…
Reference in New Issue