From c3fc1730c14a81728cdfbc87cac3457956e2e616 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 27 May 2012 07:20:01 +0200 Subject: [PATCH] Insert emails into database --- parse | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/parse b/parse index 8a42fed..c0327b5 100755 --- a/parse +++ b/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..."