[Anti-Spam] add ability to block subscription request

This commit is contained in:
Yann Leboulanger
2012-08-25 23:10:55 +02:00
parent ab23296207
commit 5c97bb1b35
2 changed files with 32 additions and 2 deletions

View File

@@ -46,12 +46,15 @@ class AntiSpamPlugin(GajimPlugin):
self._nec_atom_entry_received), self._nec_atom_entry_received),
'message-received': (ged.PRECORE, 'message-received': (ged.PRECORE,
self._nec_decrypted_message_received_received), self._nec_decrypted_message_received_received),
'subscribe-presence-received': (ged.POSTCORE,
self._nec_subscribe_presence_received),
} }
self.config_default_values = { self.config_default_values = {
'block_pubsub_messages': (False, 'If True, Gajim will block incoming messages from pubsub.'), 'block_pubsub_messages': (False, 'If True, Gajim will block incoming messages from pubsub.'),
'disable_xhtml_muc': (False, ''), 'disable_xhtml_muc': (False, ''),
'disable_xhtml_pm': (False, ''), 'disable_xhtml_pm': (False, ''),
'block_subscription_requests': (False, ''),
} }
@log_calls('AntiSpamPlugin') @log_calls('AntiSpamPlugin')
@@ -69,6 +72,13 @@ class AntiSpamPlugin(GajimPlugin):
self.remove_xhtml(obj) self.remove_xhtml(obj)
return False 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): def remove_xhtml(self, obj):
html_node = obj.stanza.getTag('html') html_node = obj.stanza.getTag('html')
if html_node: if html_node:
@@ -98,6 +108,8 @@ class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
widget.set_active(self.plugin.config['disable_xhtml_muc']) widget.set_active(self.plugin.config['disable_xhtml_muc'])
widget = self.xml.get_object('disable_xhtml_pm_checkbutton') widget = self.xml.get_object('disable_xhtml_pm_checkbutton')
widget.set_active(self.plugin.config['disable_xhtml_pm']) 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): def on_block_pubsub_messages_checkbutton_toggled(self, button):
self.plugin.config['block_pubsub_messages'] = button.get_active() 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): def on_disable_xhtml_pm_checkbutton_toggled(self, button):
self.plugin.config['disable_xhtml_pm'] = button.get_active() 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()

View File

@@ -30,7 +30,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</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> <property name="draw_indicator">True</property>
<signal name="toggled" handler="on_disable_xhtml_muc_checkbutton_toggled"/> <signal name="toggled" handler="on_disable_xhtml_muc_checkbutton_toggled"/>
</object> </object>
@@ -45,7 +45,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</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> <property name="draw_indicator">True</property>
<signal name="toggled" handler="on_disable_xhtml_pm_checkbutton_toggled"/> <signal name="toggled" handler="on_disable_xhtml_pm_checkbutton_toggled"/>
</object> </object>
@@ -54,6 +54,21 @@
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </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> </object>
</child> </child>
</object> </object>