# HG changeset patch # User Goffi # Date 1665064920 -7200 # Node ID 626629781a533b99675b76343fb84ff62576b031 # Parent 40d47cc29ea4b896006a5637a044a14d804a352d plugin XEP-0420: fix exception on missing `from` or `to`: fix exception raised on missing `from` or `to` attribute when the policy doesn't require them. Patch made by Syndace diff -r 40d47cc29ea4 -r 626629781a53 sat/plugins/plugin_xep_0420.py --- a/sat/plugins/plugin_xep_0420.py Thu Oct 06 15:19:08 2022 +0200 +++ b/sat/plugins/plugin_xep_0420.py Thu Oct 06 16:02:00 2022 +0200 @@ -339,26 +339,26 @@ if profile.to_policy is not SCEAffixPolicy.NOT_NEEDED: recipient = stanza.getAttribute("to", None) - if recipient is None: + if recipient is not None: + to_element = envelope.addElement((NS_SCE, "to")) + to_element["jid"] = jid.JID(recipient).userhost() + elif profile.to_policy is SCEAffixPolicy.REQUIRED: raise ValueError( " affix requested, but stanza doesn't have the 'to' attribute" " set." ) - to_element = envelope.addElement((NS_SCE, "to")) - to_element["jid"] = jid.JID(recipient).userhost() - if profile.from_policy is not SCEAffixPolicy.NOT_NEEDED: sender = stanza.getAttribute("from", None) - if sender is None: + if sender is not None: + from_element = envelope.addElement((NS_SCE, "from")) + from_element["jid"] = jid.JID(sender).userhost() + elif profile.from_policy is SCEAffixPolicy.REQUIRED: raise ValueError( " affix requested, but stanza doesn't have the 'from'" " attribute set." ) - from_element = envelope.addElement((NS_SCE, "from")) - from_element["jid"] = jid.JID(sender).userhost() - for affix, policy in profile.custom_policies.items(): if policy is not SCEAffixPolicy.NOT_NEEDED: envelope.addChild(affix.create(stanza))