Created
March 6, 2012 23:35
-
-
Save xupeng/1989785 to your computer and use it in GitHub Desktop.
Delete SMS from iPhone with Python
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
#!/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