#!/usr/bin/env python """ Anti MSN Spam for Pidgin version 1.0 by Natt Piyapramote -------------------------------------------------------------- How it works? it will classify all messages received into 2 categories. 1. IM that contains URL 2. Normal IM This script will count number of Normal IM for each user in your contact list. If someone that didn't send you any "Normal IM", but send you an "IM that contains URL" as a first message. Then, this IM is most likely to be a SPAM. This software will reject. """ # Anti MSN spam for pidgin import time import re url_re = re.compile('.*(http://|www.).*') purple = None last_normal = {} # timestamp of last Normal IMs num_normal = {} # number of Normal IMs def receiving_msg(account, sender, message, conversation, flags): "Receiving message handler" global purple, last_normal, num_normal, url_re # Initialize or reset last_normal, num_normal values if not last_normal.has_key(sender): last_normal[sender] = 0 if not num_normal.has_key(sender) or time.time() - last_normal[sender] > 3600: num_normal[sender] = 0 # test if message contains URL m = message.replace("\n", "").replace("\r", "") if url_re.match(m): # it's an URL message if num_normal[sender] == 0: # if first message contains URL, it's most likely to be a SPAM purple.PurpleConversationDestroy(conversation) print 'message ', message, ' from ', sender, ' canceled' else: # it's a normal message num_normal[sender] += 1 last_normal[sender] = time.time() import dbus, gobject from dbus.mainloop.glib import DBusGMainLoop dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) bus = dbus.SessionBus() obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") bus.add_signal_receiver(receiving_msg, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="DisplayingImMsg") loop = gobject.MainLoop() loop.run()