changeset 3944:748094d5a74d

plugin XEP-0374, XEP-0384: handle cases where "to" is not set in <message> for `feedback_jid`
author Goffi <goffi@goffi.org>
date Sat, 15 Oct 2022 20:38:33 +0200
parents 8dc6a4cfda4b
children 2b2856ae5eeb
files sat/plugins/plugin_xep_0374.py sat/plugins/plugin_xep_0384.py
diffstat 2 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0374.py	Sat Oct 15 20:38:33 2022 +0200
+++ b/sat/plugins/plugin_xep_0374.py	Sat Oct 15 20:38:33 2022 +0200
@@ -209,7 +209,10 @@
             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
 
--- a/sat/plugins/plugin_xep_0384.py	Sat Oct 15 20:38:33 2022 +0200
+++ b/sat/plugins/plugin_xep_0384.py	Sat Oct 15 20:38:33 2022 +0200
@@ -75,7 +75,6 @@
     "OMEMO"
 ]
 
-
 log = cast(Logger, getLogger(__name__))  # type: ignore[no-untyped-call]
 
 
@@ -1572,7 +1571,10 @@
             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