Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Archived:Delete Spam SMS using PySymbian

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Created: girishpadia (04 Mar 2011)
Last edited: hamishwillee (08 May 2013)



Have you receive any SMS at midnight while you are in deep sleep? Have you receive any SMS while you are important meeting and you lose your concentration? Are you receiving SMSes which are no use at all for you? Are you receiving SMS with the irritating contents in it? If any of the above question’s answer is YES then you are suffering of the SPAM SMSes. Please see the below contents about SMS spam from the popular site “Wikipedia”

“Fighting SMS spam is complicated by several factors, including the lower rate of SMS spam (compared to more abused services such as Internet email) has allowed many users and service providers to ignore the issue, and the limited availability of mobile phone spam-filtering software”

The SMS spam rate is lower but it may increase as the mobile user increases throughout the world. It is useless to wait from the network service provider to take necessary action on this issue when we have lots of programming weapons in our mobile to fight against the SMS SPAM. One can come out with more dedicated work and continuous efforts on this issue. I have made a small effort here to avoid SMS spam using a simple python program. Let’s see what’s there inside.

How the program works

The program is very simple. I have given two options for SMS spam removal. One is to add a Name/Number into the SPAM list and another is to run SPAM SMS. As soon as the name/number you add in the SPAM list, the name/number is saved into a text file in the mobile storage device. The text file will be created automatically if not exists. Now run the second option to start SPAM SMS. It will monitor every incoming SMS, will check the address of sender, compare it with each value in the text file and if it doesn’t match with any values in the text file then it will be welcomed into inbox. But, if the sender is in our spammer list, it will be punishment by deleting the SMS. Before deleting the SMS, a log is created showing which spam SMSes are deleted so that you can review it whenever you wish.


You need to install PySymbian in your mobile in order to run the program. There are several articles available about how to download and install it. Once you do this create a simple text file “vote.txt” on the path shown in the program. Create four lines in the program with initial values as 0.

Tested on device

This python program is tested on Nokia 5230.

Various options available

I have used simple text file reading or writing the spam SMS list. However one can use e32db or e32dbm to make it more structured.

Python Code

#import necessary libraries
import appuifw,inbox,e32,messaging,time
# setting the application title = u"SPAM SMS Blocker"
mylist = [u"Add a SPAM Number/Name",u"Start SPAM Blocker",u"Exit"]
def message_received(msg_id):
global spammer
print box.address(msg[0])
spam_adddress = box.address(msg_id)
f=open('e:\data\python\spammer.txt','r') #opens a file into read/write mode
#print data
# print "Msg Received from ",box.address(msg_id)
while True:
data= f.readline()
if data.strip() == spam_adddress.strip():
print >> fs,"Spam Message deleted from : ",spam_adddress
while True:
index = appuifw.popup_menu(mylist,u"Select")
if index==2:
if index==0:
spammer = appuifw.query(u"Type SPAM Number/Name:", "text")
f=open('e:\data\python\spammer.txt','a+') #opens a file into read/write mode
print >> f,spammer
if index==1:
box = inbox.Inbox()
box.bind(message_received) = quit
print "SPAM SMS Filter is ON"
app_lock = e32.Ao_lock()

Post Condition

Adding spam number from menu

Delspam1.jpg Delspam2.jpg

SPAM filter is ON

After spam filter is on script will automatically delete the SMS received from the spammer saved in our spam list.


Sample log file of SPAM delete SMS


This page was last modified on 8 May 2013, at 05:15.
474 page views in the last 30 days.