Insert emails into database

master
Sven Slootweg 12 years ago
parent 1aa988d9d6
commit c3fc1730c1

14
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
@ -37,4 +38,13 @@ for email_file in file_list:
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