AntiSpam Plugin. Add option to disable XHTML in pm and muc
This commit is contained in:
@@ -44,10 +44,14 @@ class AntiSpamPlugin(GajimPlugin):
|
||||
self.events_handlers = {
|
||||
'atom-entry-received': (ged.POSTCORE,
|
||||
self._nec_atom_entry_received),
|
||||
'message-received': (ged.PRECORE,
|
||||
self._nec_decrypted_message_received_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, ''),
|
||||
}
|
||||
|
||||
@log_calls('AntiSpamPlugin')
|
||||
@@ -56,6 +60,21 @@ class AntiSpamPlugin(GajimPlugin):
|
||||
log.info('discarding pubdubd message')
|
||||
return True
|
||||
|
||||
@log_calls('AntiSpamPlugin')
|
||||
def _nec_decrypted_message_received_received(self, obj):
|
||||
if self.config['disable_xhtml_muc'] and obj.mtype == 'groupchat':
|
||||
self.remove_xhtml(obj)
|
||||
if self.config['disable_xhtml_pm'] and obj.gc_control and \
|
||||
obj.resource and obj.mtype == 'chat':
|
||||
self.remove_xhtml(obj)
|
||||
return False
|
||||
|
||||
def remove_xhtml(self, obj):
|
||||
html_node = obj.stanza.getTag('html')
|
||||
if html_node:
|
||||
obj.stanza.delChild(html_node)
|
||||
|
||||
|
||||
class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
|
||||
def init(self):
|
||||
self.GTK_BUILDER_FILE_PATH = self.plugin.local_file_path(
|
||||
@@ -75,6 +94,16 @@ class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
|
||||
def on_run(self):
|
||||
self.block_pubsub_messages_checkbutton.set_active(self.plugin.config[
|
||||
'block_pubsub_messages'])
|
||||
widget = self.xml.get_object('disable_xhtml_muc_checkbutton')
|
||||
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'])
|
||||
|
||||
def on_block_pubsub_messages_checkbutton_toggled(self, button):
|
||||
self.plugin.config['block_pubsub_messages'] = button.get_active()
|
||||
|
||||
def on_disable_xhtml_muc_checkbutton_toggled(self, button):
|
||||
self.plugin.config['disable_xhtml_muc'] = button.get_active()
|
||||
|
||||
def on_disable_xhtml_pm_checkbutton_toggled(self, button):
|
||||
self.plugin.config['disable_xhtml_pm'] = button.get_active()
|
||||
|
||||
@@ -24,6 +24,36 @@
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="disable_xhtml_muc_checkbutton">
|
||||
<property name="label" translatable="yes">Disable xhtml in MUCs</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 remove XHTML from incomming multi-user chat messages</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<signal name="toggled" handler="on_disable_xhtml_muc_checkbutton_toggled"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="disable_xhtml_pm_checkbutton">
|
||||
<property name="label" translatable="yes">Disable xhtml in private messages</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 remove XHTML from incomming private messages</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<signal name="toggled" handler="on_disable_xhtml_pm_checkbutton_toggled"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[info]
|
||||
name: Anti Spam
|
||||
short_name: anti_spam
|
||||
version: 0.1.1
|
||||
version: 0.2
|
||||
description: Block some incoming messages.
|
||||
authors = Yann Leboulanger <asterix@lagaule.org>
|
||||
authors = Yann Leboulanger <asterix@lagaule.org>
|
||||
Denis Fomin <fominde@gmail.com>
|
||||
homepage = http://trac-plugins.gajim.org/wiki/AntiSpamPlugin
|
||||
|
||||
|
||||
Reference in New Issue
Block a user