Browse Source

Add timestamp parsing

master
Sven Slootweg 10 years ago
parent
commit
e33669c858
  1. 8
      parse

8
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)

Loading…
Cancel
Save