Skip to content

Instantly share code, notes, and snippets.

@xupeng
Created March 6, 2012 23:35
Show Gist options
  • Save xupeng/1989785 to your computer and use it in GitHub Desktop.
Save xupeng/1989785 to your computer and use it in GitHub Desktop.
Delete SMS from iPhone with Python
#!/usr/bin/env python
#coding=utf8
import os
from sqlite3 import dbapi2 as sqlite
def message_read(flags):
"""reimplementation of an sqlite user defined function called by a trigger
on the messages table.
the trigger checks the message flags to see if a message has been read to
see if the counter of unread messages in another needs to be updated when
a message is deleted.
"""
# second bit is the "was read" flag
return (int(flags) & 0x02) >> 1
db = sqlite.connect('/var/mobile/Library/SMS/sms.db')
# register the user-defined function used by delete trigger
db.create_function('read', 1, message_read)
c = db.cursor()
c.execute("delete from message where address like '0532%';")
c.execute("delete from message where text like '%回复本短信即回复邮件%';")
c.execute("delete from message where text like '%nagios%';")
db.commit()
os.system('killall -KILL MobileSMS')
# vim:set ts=4 sw=4 ai et tw=80 :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment