From 9df7a439e89debaf70f6d7a62ff0fcd7a9b2499e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lestin=20Matte?= Date: Sun, 3 Nov 2019 12:23:41 +0100 Subject: Add remove_get_trackers plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: CĂ©lestin Matte --- plugins/remove_get_trackers.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 plugins/remove_get_trackers.py diff --git a/plugins/remove_get_trackers.py b/plugins/remove_get_trackers.py new file mode 100644 index 00000000..9c1eb9c1 --- /dev/null +++ b/plugins/remove_get_trackers.py @@ -0,0 +1,22 @@ +""" +Remove GET trackers from URLs in sent messages. +""" +from poezio.plugin import BasePlugin +import re + +class Plugin(BasePlugin): + def init(self): + self.api.add_event_handler('muc_say', self.remove_get_trackers) + self.api.add_event_handler('conversation_say', self.remove_get_trackers) + self.api.add_event_handler('private_say', self.remove_get_trackers) + + def remove_get_trackers(self, msg, tab): + # fbclid: used globally (Facebook) + # utm_*: used globally https://en.wikipedia.org/wiki/UTM_parameters + # ncid: DoubleClick (Google) + # ref_src, ref_url: twitter + # Others exist but are excluded because they are not common. + # See https://en.wikipedia.org/wiki/UTM_parameters + msg['body'] = re.sub('&?(fbclid|dclid|ncid|utm_source|utm_medium|utm_campaign|utm_term|utm_content|ref_src|ref_url)=[^ &#]*', + '', + msg['body']) -- cgit v1.2.3