From 3781246111699d96e7cc1433efa0d185fe2c3f42 Mon Sep 17 00:00:00 2001 From: Denis Fomin Date: Mon, 20 Aug 2012 12:33:38 +0400 Subject: [PATCH] AntiSpam Plugin. Add option to disable XHTML in pm and muc --- anti_spam/anti_spam.py | 29 +++++++++++++++++++++++++++++ anti_spam/config_dialog.ui | 30 ++++++++++++++++++++++++++++++ anti_spam/manifest.ini | 6 +++--- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/anti_spam/anti_spam.py b/anti_spam/anti_spam.py index e537f42..1e6dfc8 100644 --- a/anti_spam/anti_spam.py +++ b/anti_spam/anti_spam.py @@ -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() diff --git a/anti_spam/config_dialog.ui b/anti_spam/config_dialog.ui index 63a57e3..034202d 100644 --- a/anti_spam/config_dialog.ui +++ b/anti_spam/config_dialog.ui @@ -24,6 +24,36 @@ 0 + + + Disable xhtml in MUCs + True + True + False + If checked, Gajim will remove XHTML from incomming multi-user chat messages + True + + + + False + 1 + + + + + Disable xhtml in private messages + True + True + False + If checked, Gajim will remove XHTML from incomming private messages + True + + + + False + 2 + + diff --git a/anti_spam/manifest.ini b/anti_spam/manifest.ini index b5fc4be..087306a 100644 --- a/anti_spam/manifest.ini +++ b/anti_spam/manifest.ini @@ -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 +authors = Yann Leboulanger + Denis Fomin homepage = http://trac-plugins.gajim.org/wiki/AntiSpamPlugin -