Commit 5c97bb1b authored by Yann Leboulanger's avatar Yann Leboulanger

[Anti-Spam] add ability to block subscription request

parent ab232962
......@@ -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()
......@@ -30,7 +30,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If checked, Gajim will remove XHTML from incomming multi-user chat messages</property>
<property name="tooltip_text" translatable="yes">If checked, Gajim will remove XHTML from incoming multi-user chat messages</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_disable_xhtml_muc_checkbutton_toggled"/>
</object>
......@@ -45,7 +45,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If checked, Gajim will remove XHTML from incomming private messages</property>
<property name="tooltip_text" translatable="yes">If checked, Gajim will remove XHTML from incoming private messages</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_disable_xhtml_pm_checkbutton_toggled"/>
</object>
......@@ -54,6 +54,21 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="block_subscription_requests_checkbutton">
<property name="label" translatable="yes">Block incoming subscription requests</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If checked, Gajim will block incoming subscription requests</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_block_subscription_requests_checkbutton_toggled"/>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment