aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolaus Schulz <microschulz@web.de>2007-11-13 02:59:31 +0000
committerNikolaus Schulz <microschulz@web.de>2007-11-13 02:59:31 +0000
commit4584dffe14705d8e47a04dfbfd2fcf1d997123e8 (patch)
treecf6a2750461cae429a0b617449a4ce7611d61233
parent5178c956bc83422311d09c4f662c25bd240ba561 (diff)
downloadarchivemail-4584dffe14705d8e47a04dfbfd2fcf1d997123e8.tar.gz
archivemail-4584dffe14705d8e47a04dfbfd2fcf1d997123e8.tar.bz2
archivemail-4584dffe14705d8e47a04dfbfd2fcf1d997123e8.zip
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.
-rw-r--r--CHANGELOG6
-rwxr-xr-xarchivemail.py19
2 files changed, 16 insertions, 9 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 4f3947f..5fbe4d7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
* IMAP: fixed crash by working around python bug #1277098, which is still pending
diff --git a/archivemail.py b/archivemail.py
index 0427336..ae4a7a0 100755
--- a/archivemail.py
+++ b/archivemail.py
@@ -748,9 +748,9 @@ def make_mbox_from(message):
assert(message)
address = guess_return_path(message)
time_message = guess_delivery_time(message)
- gm_date = time.gmtime(time_message)
- assert(gm_date)
- date_string = time.asctime(gm_date)
+ date = time.localtime(time_message)
+ assert(date)
+ date_string = time.asctime(date)
mbox_from = "From %s %s\n" % (address, date_string)
return mbox_from
@@ -779,21 +779,22 @@ def guess_delivery_time(message):
# get more desparate as we go through the array
for header in ('Delivery-date', 'Date', 'Resent-Date'):
try:
- date = message.getdate(header)
+ date = message.getdate_tz(header)
if date:
- time_message = time.mktime(date)
+ time_message = rfc822.mktime_tz(date)
vprint("using valid time found from '%s' header" % header)
return time_message
except (IndexError, ValueError, OverflowError): pass
# as a second-last resort, try the date from the 'From_' line (ugly)
# this will only work from a mbox-format mailbox
if (message.unixfrom):
- header = re.sub("From \S+", "", message.unixfrom)
- header = string.strip(header)
- date = rfc822.parsedate(header)
+ # Hmm. This will break with full-blown RFC 2822 addr-spec's.
+ header = message.unixfrom.split(None, 2)[-1]
+ # Interpret no timezone as localtime
+ date = rfc822.parsedate_tz(header)
if date:
try:
- time_message = time.mktime(date)
+ time_message = rfc822.mktime_tz(date)
vprint("using valid time found from unix 'From_' header")
return time_message
except (ValueError, OverflowError): pass