From e33669c85867a823c1986e191aef42991822634d Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 27 May 2012 10:58:48 +0200 Subject: [PATCH] Add timestamp parsing --- parse | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/parse b/parse index 73e95a8..29792b9 100755 --- a/parse +++ b/parse @@ -1,6 +1,6 @@ #!/usr/bin/python -import os, argparse, hashlib, email, email.header, glob, sqlite3 +import os, argparse, hashlib, email, email.header, email.utils, glob, sqlite3, time parser = argparse.ArgumentParser(description='Parses emails into an SQLite database, and optionally renders static HTML files.') @@ -120,7 +120,11 @@ for email_file in file_list: attachment_file.write(attachment_data) attachment_file.close() - timestamp = 0 + try: + timestamp = int(time.mktime(email.utils.parsedate(message['date']))) + except TypeError: + timestamp = 0 + print "WARNING: Failed to determine unix timestamp for %s." % sha1_hash new_row = (getheader(message['message-id']), getheader(message['from']), getheader(message['to']), getheader(subject), timestamp, textbody, htmlbody, sha1_hash) cursor.execute("INSERT INTO emails VALUES (?, ?, ?, ?, ?, ?, ?, ?)", new_row)