You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gajim-otrplugin/module.py

64 lines
2.4 KiB

## Copyright (C) 2008-2012 Kjell Braden <afflux@pentabarf.de>
## Copyright (C) 2019 Pavel R. <pd at narayana dot im>
## Copyright (C) 2022 Bohdan Horbeshko <bodqhrohro@gmail.com>
# This file is part of Gajim OTR Plugin.
#
# Gajim OTR Plugin is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; version 3 only.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can always obtain full license text at <http://www.gnu.org/licenses/>.
from nbxmpp.structs import StanzaHandler
from gajim.common.modules.base import BaseModule
from gajim.common import app
from .otr import OTR as OTRInstance
name = 'OTR'
zeroconf = False
class OTR(BaseModule):
_nbxmpp_extends = 'OTR'
def __init__(self, con):
BaseModule.__init__(self, con, plugin=True)
self.handlers = [
StanzaHandler(name='message',
callback=self._message_received,
priority=9),
]
self.available = True
self.otr = OTRInstance(con.name)
def activate(self):
""" Method called when the Plugin is activated in the PluginManager
"""
pass
def deactivate(self):
""" Method called when the Plugin is deactivated in the PluginManager
"""
pass
def _message_received(self, client, stanza, properties):
if properties.is_omemo or properties.is_openpgp or properties.is_pgp_legacy: return # skip other encryptions
if properties.from_muc: return # skip MUC messages
msgtxt = stanza.getBody() or ''
# if (event.encrypted) or (event.name[0:2] == 'gc') or not (event.msgtxt or '').startswith('?OTR'): return # skip non-OTR messages..
if not msgtxt.startswith('?OTR'): return # skip non-OTR messages..
if properties.mam != None: return stanza.setBody('') # skip MAM messages (we can not decrypt OTR out of session)..
if (app.settings.get_contact_setting(self._account,properties.jid.bare,'encryption')!=self._nbxmpp_extends): return # skip all when encryption not set to OTR
self.otr.decrypt(stanza,properties)
def get_instance(*args, **kwargs):
return OTR(*args, **kwargs), 'OTR'