File: remove_get_trackers.py

package info (click to toggle)
poezio 0.16-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,124 kB
  • sloc: python: 25,093; xml: 995; ansic: 329; makefile: 200; sh: 74; javascript: 2
file content (24 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
Remove GET trackers from URLs in sent messages.
"""
from poezio.plugin import BasePlugin
import re

class Plugin(BasePlugin):
    def init(self):
        self.api.information('This plugin is deprecated and will be replaced by \'untrackme\'.', 'Warning')

        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('(https?://[^ ]+)&?(fbclid|dclid|ncid|utm_source|utm_medium|utm_campaign|utm_term|utm_content|ref_src|ref_url)=[^ &#]*',
                             r'\1',
                             msg['body'])