plugin_e2ee: allow normal message to pass through again when not encrypting

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2021-07-18 00:16:07 +02:00
parent ccf9c3e4e1
commit c4ce439483

View file

@ -505,6 +505,9 @@ class E2EEPlugin(BasePlugin):
has_body = message.xml.find('{%s}%s' % (JCLIENT_NS, 'body')) is not None
if not self._encryption_enabled(tab.jid):
raise NothingToEncrypt()
# Drop all messages that don't contain a body if the plugin doesn't do
# Stanza Encryption
if not self.stanza_encryption and not has_encrypted_tag and not has_body:
@ -515,18 +518,14 @@ class E2EEPlugin(BasePlugin):
)
return None
if tab and not has_encrypted_tag:
if not self._encryption_enabled(tab.jid):
raise NothingToEncrypt()
# Call the enabled encrypt method
func = self._enabled_tabs[tab.jid]
if iscoroutinefunction(func):
# pylint: disable=unexpected-keyword-arg
await func(message, jids, tab, passthrough=True)
else:
# pylint: disable=unexpected-keyword-arg
func(message, jids, tab, passthrough=True)
# Call the enabled encrypt method
func = self._enabled_tabs[tab.jid]
if iscoroutinefunction(func):
# pylint: disable=unexpected-keyword-arg
await func(message, jids, tab, passthrough=True)
else:
# pylint: disable=unexpected-keyword-arg
func(message, jids, tab, passthrough=True)
if has_body:
# Only add EME tag if the message has a body.