I'm using sqlite with python. I'm implementing the POP3 protocol. I have a table
msg_id text date text from_sender text subject text body text hashkey text
Now I need to check for duplicate messages by checking the message id of the message retrieved against the existing msg_id's in the table. I encrypted the msg_id using md5 and put it in the hashkey column. Whenever I retrieve mail, I hash the message id and check it with the table values. Heres what I do.
def check_duplicate(new):
conn = sql.connect("mail")
c = conn.cursor()
m = hashlib.md5()
m.update(new)
c.execute("select hashkey from mail")
for row in c:
if m.hexdigest() == row:
return 0
else:
continue
return 1
It just refuses to work correctly. I tried printing the row value, it shows it in unicode, thats where the problem lies as it cannot compare properly.
Is there a better way to do this, or to improve my method?
msg_id, not encrypting it.