Skip to content

Instantly share code, notes, and snippets.

@maedoc
Created August 28, 2013 09:55
Show Gist options
  • Save maedoc/6364298 to your computer and use it in GitHub Desktop.
Save maedoc/6364298 to your computer and use it in GitHub Desktop.
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