diff --git a/pgp/modules/pgp_legacy.py b/pgp/modules/pgp_legacy.py index f8dd46b..6372532 100644 --- a/pgp/modules/pgp_legacy.py +++ b/pgp/modules/pgp_legacy.py @@ -324,11 +324,16 @@ class PGPLegacy(BaseModule): def _cleanup_stanza(message: OutgoingMessage) -> None: """We make sure only allowed tags are in the stanza""" original_stanza = message.get_stanza() - stanza = nbxmpp.Message( - to=original_stanza.getTo(), typ=original_stanza.getType() - ) - stanza.setID(original_stanza.getID()) - stanza.setThread(original_stanza.getThread()) + m_type = original_stanza.getType() + assert m_type in ("chat", "groupchat", "normal") + stanza = nbxmpp.Message(to=original_stanza.getTo(), typ=m_type) + + if message_id := original_stanza.getID(): + stanza.setID(message_id) + + if thread := original_stanza.getThread(): + stanza.setThread(thread) + for tag, ns in ALLOWED_TAGS: node = original_stanza.getTag(tag, namespace=ns) if node: diff --git a/pgp/plugin.py b/pgp/plugin.py index 02ec4ae..578341e 100644 --- a/pgp/plugin.py +++ b/pgp/plugin.py @@ -129,6 +129,7 @@ class PGPPlugin(GajimPlugin): def _on_encryption_dialog(self, chat_control: ChatControl): account = chat_control.account + assert chat_control.contact is not None jid = chat_control.contact.jid transient = app.window KeyDialog(self, account, jid, transient) @@ -162,6 +163,7 @@ class PGPPlugin(GajimPlugin): def _before_sendmessage(self, chat_control: ChatControl) -> None: account = chat_control.account + assert chat_control.contact is not None jid = str(chat_control.contact.jid) pgp = self.get_pgp_module(account)