Browse Source

Insert emails into database

master
Sven Slootweg 10 years ago
parent
commit
c3fc1730c1
  1. 16
      parse

16
parse

@ -13,11 +13,12 @@ parser.add_argument('-r', '--render', dest='render', action='store_true',
args = parser.parse_args()
options = vars(args)
database = sqlite3.connect('emails.db').cursor()
database = sqlite3.connect('emails.db')
cursor = database.cursor()
try:
# Try to create the table
database.execute("CREATE TABLE emails (`message_id`, `from`, `to`, `subject`, `date`, `body`, `html`, `hash`)")
cursor.execute("CREATE TABLE emails (`message_id`, `from`, `to`, `subject`, `date`, `body`, `html`, `hash`)")
except sqlite3.OperationalError:
# Table already exists
pass
@ -36,5 +37,14 @@ for email_file in file_list:
subject = message['subject']
sha1_hash = hashlib.sha1("%s/%s/%s/%s" % (message['from'], message['to'], message['message-id'], subject)).hexdigest()
timestamp = 0
textbody = ""
htmlbody = ""
new_row = (message['message-id'], message['from'], message['to'], subject, timestamp, textbody, htmlbody, sha1_hash)
cursor.execute("INSERT INTO emails VALUES (?, ?, ?, ?, ?, ?, ?, ?)", new_row)
print "Successfully parsed and inserted e-mail with SHA1 hash %s." % sha1_hash
database.commit()
print "Changes successfully committed to database, exiting..."
Loading…
Cancel
Save