From a7f94cf875bb7189b1082a0bc28f7d2a87d2a278 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 15 Oct 2022 20:38:33 +0200 Subject: [PATCH] plugin XEP-0374, XEP-0384: handle cases where "to" is not set in for `feedback_jid` --- sat/plugins/plugin_xep_0374.py | 5 ++++- sat/plugins/plugin_xep_0384.py | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sat/plugins/plugin_xep_0374.py b/sat/plugins/plugin_xep_0374.py index d0485a33..1256cf6c 100644 --- a/sat/plugins/plugin_xep_0374.py +++ b/sat/plugins/plugin_xep_0374.py @@ -209,7 +209,10 @@ class XEP_0374: if sender_jid.userhostJID() == client.jid.userhostJID(): # TODO: I've seen this cause an exception "builtins.KeyError: 'to'", seems # like "to" isn't always set. - feedback_jid = jid.JID(message_elt["to"]) + try: + feedback_jid = jid.JID(message_elt["to"]) + except KeyError: + feedback_jid = client.server_jid else: feedback_jid = sender_jid diff --git a/sat/plugins/plugin_xep_0384.py b/sat/plugins/plugin_xep_0384.py index e3c6c781..e0848c66 100644 --- a/sat/plugins/plugin_xep_0384.py +++ b/sat/plugins/plugin_xep_0384.py @@ -75,7 +75,6 @@ __all__ = [ # pylint: disable=unused-variable "OMEMO" ] - log = cast(Logger, getLogger(__name__)) # type: ignore[no-untyped-call] @@ -1572,7 +1571,10 @@ class OMEMO: if sender_jid.userhostJID() == client.jid.userhostJID(): # TODO: I've seen this cause an exception "builtins.KeyError: 'to'", seems # like "to" isn't always set. - feedback_jid = jid.JID(message_elt["to"]) + try: + feedback_jid = jid.JID(message_elt["to"]) + except KeyError: + feedback_jid = client.server_jid else: feedback_jid = sender_jid