2019-11-03 11:23:41 +00:00
|
|
|
"""
|
|
|
|
Remove GET trackers from URLs in sent messages.
|
|
|
|
"""
|
|
|
|
from poezio.plugin import BasePlugin
|
|
|
|
import re
|
|
|
|
|
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
2020-08-13 23:13:36 +00:00
|
|
|
self.api.information('This plugin is deprecated and will be replaced by \'untrackme\'.', 'Warning')
|
|
|
|
|
2019-11-03 11:23:41 +00:00
|
|
|
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
|
2019-11-17 18:21:42 +00:00
|
|
|
msg['body'] = re.sub('(https?://[^ ]+)&?(fbclid|dclid|ncid|utm_source|utm_medium|utm_campaign|utm_term|utm_content|ref_src|ref_url)=[^ &#]*',
|
|
|
|
r'\1',
|
2019-11-03 11:23:41 +00:00
|
|
|
msg['body'])
|