]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/views/__init__.py
Don't use total_seconds for python < 2.7
[patchwork] / apps / patchwork / views / __init__.py
index cb35c1fda7f145e3c6854e7ad6916d265117b527..a823388a089171e2443540b61d2e2beb7c20fc0b 100644 (file)
@@ -190,12 +190,11 @@ def patch_to_mbox(patch):
     if patch.content:
         body += '\n' + patch.content
 
-    utc_timestamp = (patch.date -
-            datetime.datetime.utcfromtimestamp(0)).total_seconds()
+    delta = patch.date - datetime.datetime.utcfromtimestamp(0)
+    utc_timestamp = delta.seconds + delta.days*24*3600
 
     mail = PatchMbox(body)
     mail['Subject'] = patch.name
-    mail['Date'] = email.utils.formatdate(utc_timestamp)
     mail['From'] = email.utils.formataddr((
                     str(Header(patch.submitter.name, mail.patch_charset)),
                     patch.submitter.email))
@@ -204,10 +203,13 @@ def patch_to_mbox(patch):
     mail.set_unixfrom('From patchwork ' + patch.date.ctime())
 
 
-    copied_headers = ['To', 'Cc']
+    copied_headers = ['To', 'Cc', 'Date']
     orig_headers = HeaderParser().parsestr(str(patch.headers))
     for header in copied_headers:
         if header in orig_headers:
             mail[header] = orig_headers[header]
 
+    if 'Date' not in mail:
+        mail['Date'] = email.utils.formatdate(utc_timestamp)
+
     return mail