From fc007dae382750847ffcbbd2c389ed33cb347cc5 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 28 Feb 2019 18:57:06 +0100 Subject: [PATCH] plugin XEP-0280: priority and "sent" fixes: - carbon prioriy must be bigger than ones of encryption plugins, because the carbon copied messages must be unwrapped to be decrypted, this patch fixes it - "sent" carbon elements was only stored and notified to frontends, it is now unwrapped and injected in normal traffic, this way other plugin can manage it, in particular encrypted elements can be decrypted --- sat/plugins/plugin_xep_0280.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/sat/plugins/plugin_xep_0280.py b/sat/plugins/plugin_xep_0280.py index d43196f5..1360cbf9 100755 --- a/sat/plugins/plugin_xep_0280.py +++ b/sat/plugins/plugin_xep_0280.py @@ -75,7 +75,7 @@ class XEP_0280(object): log.info(_("Plugin XEP_0280 initialization")) self.host = host host.memory.updateParams(self.params) - host.trigger.add("MessageReceived", self.messageReceivedTrigger, priority=1000) + host.trigger.add("MessageReceived", self.messageReceivedTrigger, priority=200000) def getHandler(self, client): return XEP_0280_handler() @@ -138,30 +138,26 @@ class XEP_0280(object): return forwarded_elt = next(carbons_elt.elements(C.NS_FORWARD, "forwarded")) cc_message_elt = next(forwarded_elt.elements(C.NS_CLIENT, "message")) + + # we replace the wrapping message with the CCed one + # and continue the normal behaviour if carbons_elt.name == "received": - # on receive we replace the wrapping message with the CCed one - # and continue the normal behaviour message_elt["from"] = cc_message_elt["from"] - del message_elt.children[:] - for c in cc_message_elt.children: - message_elt.addChild(c) - return True elif carbons_elt.name == "sent": - # on sent we parse the message and just add it to history - # and send it to frontends (without normal sending treatments) - mess_data = client.messageProt.parseMessage(cc_message_elt) - if not mess_data["message"] and not mess_data["subject"]: - return False - client.messageAddToHistory(mess_data) - client.messageSendToBridge(mess_data) + message_elt["to"] = cc_message_elt["to"] else: log.warning( u"invalid message carbons received:\n{xml}".format( xml=message_elt.toXml() ) ) - return False + return False + del message_elt.children[:] + for c in cc_message_elt.children: + message_elt.addChild(c) + + return True class XEP_0280_handler(XMPPHandler): implements(iwokkel.IDisco)