changeset de8e9bc4f357 in /home/hg/repos/gajim-plugins
author: Yann Leboulanger asterix@lagaule.org branches: details:gajim-plugins?cmd=changeset;node=de8e9bc4f357 description: and a message size limit to anti-spam plugin
diffstat:
anti_spam/anti_spam.py | 22 +++++++++++++++++- anti_spam/config_dialog.ui | 55 +++++++++++++++++++++++++++++++++++++++++---- anti_spam/manifest.ini | 2 +- 3 files changed, 72 insertions(+), 7 deletions(-)
diffs (192 lines):
diff -r 9fa9ce820249 -r de8e9bc4f357 anti_spam/anti_spam.py --- a/anti_spam/anti_spam.py Sat Jun 20 21:26:53 2015 +0200 +++ b/anti_spam/anti_spam.py Fri Jul 24 23:35:55 2015 +0200 @@ -44,6 +44,8 @@ 'atom-entry-received': (ged.POSTCORE, self._nec_atom_entry_received), 'message-received': (ged.PRECORE, + self._nec_message_received_received), + 'decrypted-message-received': (ged.PRECORE, self._nec_decrypted_message_received_received), 'subscribe-presence-received': (ged.POSTCORE, self._nec_subscribe_presence_received), @@ -54,6 +56,7 @@ 'disable_xhtml_muc': (False, ''), 'disable_xhtml_pm': (False, ''), 'block_subscription_requests': (False, ''), + 'msgtxt_limit': (-1, ''), }
@log_calls('AntiSpamPlugin') @@ -63,7 +66,7 @@ return True
@log_calls('AntiSpamPlugin') - def _nec_decrypted_message_received_received(self, obj): + def _nec_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 \ @@ -72,6 +75,15 @@ return False
@log_calls('AntiSpamPlugin') + def _nec_decrypted_message_received_received(self, obj): + if not obj.msgtxt: + return False + limit = self.config['msgtxt_limit'] + if limit > -1 and len(obj.msgtxt) > limit: + return True + 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): @@ -109,6 +121,8 @@ 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']) + widget = self.xml.get_object('message_size_limit_entry') + widget.set_text(str(self.plugin.config['msgtxt_limit']))
def on_block_pubsub_messages_checkbutton_toggled(self, button): self.plugin.config['block_pubsub_messages'] = button.get_active() @@ -121,3 +135,9 @@
def on_block_subscription_requests_checkbutton_toggled(self, button): self.plugin.config['block_subscription_requests'] = button.get_active() + + def on_message_size_limit_entry_changed(self, entry): + try: + self.plugin.config['msgtxt_limit'] = int(entry.get_text()) + except Exception: + pass diff -r 9fa9ce820249 -r de8e9bc4f357 anti_spam/config_dialog.ui --- a/anti_spam/config_dialog.ui Sat Jun 20 21:26:53 2015 +0200 +++ b/anti_spam/config_dialog.ui Fri Jul 24 23:35:55 2015 +0200 @@ -3,11 +3,12 @@ <requires lib="gtk+" version="2.16"/> <!-- interface-naming-policy toplevel-contextual --> <object class="GtkWindow" id="window1"> + <property name="can_focus">False</property> <child> <object class="GtkVBox" id="anti_spam_config_vbox"> <property name="visible">True</property> + <property name="can_focus">False</property> <property name="border_width">9</property> - <property name="orientation">vertical</property> <property name="spacing">4</property> <child> <object class="GtkCheckButton" id="block_pubsub_messages_checkbutton"> @@ -16,11 +17,13 @@ <property name="can_focus">False</property> <property name="receives_default">False</property> <property name="tooltip_text" translatable="yes">If checked, Gajim will block incoming messages from pubsub.</property> + <property name="xalign">0.5</property> <property name="draw_indicator">True</property> - <signal name="toggled" handler="on_block_pubsub_messages_checkbutton_toggled"/> + <signal name="toggled" handler="on_block_pubsub_messages_checkbutton_toggled" swapped="no"/> </object> <packing> <property name="expand">False</property> + <property name="fill">True</property> <property name="position">0</property> </packing> </child> @@ -31,11 +34,13 @@ <property name="can_focus">False</property> <property name="receives_default">False</property> <property name="tooltip_text" translatable="yes">If checked, Gajim will remove XHTML from incoming multi-user chat messages</property> + <property name="xalign">0.5</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" swapped="no"/> </object> <packing> <property name="expand">False</property> + <property name="fill">True</property> <property name="position">1</property> </packing> </child> @@ -46,11 +51,13 @@ <property name="can_focus">False</property> <property name="receives_default">False</property> <property name="tooltip_text" translatable="yes">If checked, Gajim will remove XHTML from incoming private messages</property> + <property name="xalign">0.5</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" swapped="no"/> </object> <packing> <property name="expand">False</property> + <property name="fill">True</property> <property name="position">2</property> </packing> </child> @@ -61,14 +68,52 @@ <property name="can_focus">False</property> <property name="receives_default">False</property> <property name="tooltip_text" translatable="yes">If checked, Gajim will block incoming subscription requests</property> + <property name="xalign">0.5</property> <property name="draw_indicator">True</property> - <signal name="toggled" handler="on_block_subscription_requests_checkbutton_toggled"/> + <signal name="toggled" handler="on_block_subscription_requests_checkbutton_toggled" swapped="no"/> </object> <packing> <property name="expand">False</property> + <property name="fill">True</property> <property name="position">3</property> </packing> </child> + <child> + <object class="GtkHBox" id="box1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">6</property> + <child> + <object class="GtkLabel" id="label1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Message size limit:</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="message_size_limit_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <signal name="changed" handler="on_message_size_limit_entry_changed" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">4</property> + </packing> + </child> </object> </child> </object> diff -r 9fa9ce820249 -r de8e9bc4f357 anti_spam/manifest.ini --- a/anti_spam/manifest.ini Sat Jun 20 21:26:53 2015 +0200 +++ b/anti_spam/manifest.ini Fri Jul 24 23:35:55 2015 +0200 @@ -1,7 +1,7 @@ [info] name: Anti Spam short_name: anti_spam -version: 0.3.1 +version: 0.4.1 description: Block some incoming messages. authors = Yann Leboulanger asterix@lagaule.org Denis Fomin fominde@gmail.com