From cfa1bfc5b297a2fd01ff794a6976534fe101a40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 18 Jul 2021 00:56:11 +0200 Subject: plugin_e2ee: quit _encrypt filter as soon as we seen encrypted tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/plugin_e2ee.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'poezio/plugin_e2ee.py') diff --git a/poezio/plugin_e2ee.py b/poezio/plugin_e2ee.py index a1ea1f9e..ba0e6cd7 100644 --- a/poezio/plugin_e2ee.py +++ b/poezio/plugin_e2ee.py @@ -444,8 +444,10 @@ class E2EEPlugin(BasePlugin): for (namespace, tag) in self.encrypted_tags: tmp = tmp and message.xml.find('{%s}%s' % (namespace, tag)) is not None has_encrypted_tag = tmp - if has_encrypted_tag: - log.debug('Message already contains encrypted tags') + + if has_encrypted_tag: + log.debug('Message already contains encrypted tags.') + raise NothingToEncrypt() # Find who to encrypt to. If in a groupchat this can be multiple JIDs. # It is possible that we are not able to find a jid (e.g., semi-anon @@ -459,13 +461,10 @@ class E2EEPlugin(BasePlugin): if tab is None: # Possible message sent directly by the e2ee lib? log.debug( 'A message we do not have a tab for ' - 'is being sent to \'%s\'. %s. \n%r.', + 'is being sent to \'%s\'. \n%r.', message['to'], - 'Dropping' if not has_encrypted_tag else '', message, ) - if not has_encrypted_tag: - return None parent = None if isinstance(tab, PrivateTab): @@ -510,10 +509,10 @@ class E2EEPlugin(BasePlugin): # 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: + if not self.stanza_encryption and not has_body: log.debug( - '%s plugin: Dropping message as it\'s not already encrypted, ' - 'contains no body, and doesn\'t do stanza encryption', + '%s plugin: Dropping message as it contains no body, and ' + 'doesn\'t do stanza encryption', self.encryption_name, ) return None -- cgit v1.2.3