Created
August 28, 2013 09:55
-
-
Save maedoc/6364298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cStringIO | |
import sqlite3 | |
import mailbox | |
def index_mailbox(db, mailbox, tablename): | |
# create table | |
q = "create virtual table %s using fts4(content text);" | |
q %= tablename | |
db.execute(q) | |
# insert each message from mailbox | |
q = "insert into %s (content) values (?);" | |
q %= tablename | |
for i, msg in mailbox.iteritems(): | |
db.execute("insert into gmail(content) values(?)", (repr(msg.as_string()),)) | |
if i % 1000 == 0: | |
print "%dk messages indexed" % (i/1000, ) | |
# save changes | |
db.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment