diff --git a/anti_spam/anti_spam.py b/anti_spam/anti_spam.py
index 1e6dfc8..f1ee065 100644
--- a/anti_spam/anti_spam.py
+++ b/anti_spam/anti_spam.py
@@ -46,12 +46,15 @@ class AntiSpamPlugin(GajimPlugin):
self._nec_atom_entry_received),
'message-received': (ged.PRECORE,
self._nec_decrypted_message_received_received),
+ 'subscribe-presence-received': (ged.POSTCORE,
+ self._nec_subscribe_presence_received),
}
self.config_default_values = {
'block_pubsub_messages': (False, 'If True, Gajim will block incoming messages from pubsub.'),
'disable_xhtml_muc': (False, ''),
'disable_xhtml_pm': (False, ''),
+ 'block_subscription_requests': (False, ''),
}
@log_calls('AntiSpamPlugin')
@@ -69,6 +72,13 @@ class AntiSpamPlugin(GajimPlugin):
self.remove_xhtml(obj)
return False
+ @log_calls('AntiSpamPlugin')
+ def _nec_subscribe_presence_received(self, obj):
+ if self.config['block_subscription_requests'] and \
+ not gajim.contacts.get_contacts(obj.conn.name, obj.jid):
+ log.info('discarding subscription request from %s' % obj.jid)
+ return True
+
def remove_xhtml(self, obj):
html_node = obj.stanza.getTag('html')
if html_node:
@@ -98,6 +108,8 @@ class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
widget.set_active(self.plugin.config['disable_xhtml_muc'])
widget = self.xml.get_object('disable_xhtml_pm_checkbutton')
widget.set_active(self.plugin.config['disable_xhtml_pm'])
+ widget = self.xml.get_object('block_subscription_requests_checkbutton')
+ widget.set_active(self.plugin.config['block_subscription_requests'])
def on_block_pubsub_messages_checkbutton_toggled(self, button):
self.plugin.config['block_pubsub_messages'] = button.get_active()
@@ -107,3 +119,6 @@ class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
def on_disable_xhtml_pm_checkbutton_toggled(self, button):
self.plugin.config['disable_xhtml_pm'] = button.get_active()
+
+ def on_block_subscription_requests_checkbutton_toggled(self, button):
+ self.plugin.config['block_subscription_requests'] = button.get_active()
diff --git a/anti_spam/config_dialog.ui b/anti_spam/config_dialog.ui
index 034202d..14f3850 100644
--- a/anti_spam/config_dialog.ui
+++ b/anti_spam/config_dialog.ui
@@ -30,7 +30,7 @@
True
True
False
- If checked, Gajim will remove XHTML from incomming multi-user chat messages
+ If checked, Gajim will remove XHTML from incoming multi-user chat messages
True
@@ -45,7 +45,7 @@
True
True
False
- If checked, Gajim will remove XHTML from incomming private messages
+ If checked, Gajim will remove XHTML from incoming private messages
True
@@ -54,6 +54,21 @@
2
+
+
+
+ False
+ 3
+
+