From be64b18b2f069b557db3721ae954917473214168 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 5 Nov 2012 14:54:33 +0000 Subject: [PATCH] =?UTF-8?q?Display=20an=20error=20and=20don=E2=80=99t=20se?= =?UTF-8?q?nd=20the=20message=20if=20gpg=20failed=20to=20encrypt=20a=20mes?= =?UTF-8?q?sage.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/gpg/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/gpg/__init__.py b/plugins/gpg/__init__.py index 00d896cd..a60cbbdb 100644 --- a/plugins/gpg/__init__.py +++ b/plugins/gpg/__init__.py @@ -131,9 +131,15 @@ class Plugin(BasePlugin): # cannot be encrypted. del message['xhtml_im'] encrypted_element = ET.Element('{%s}x' % (NS_ENCRYPTED,)) - encrypted_element.text = self.remove_gpg_headers(xml.sax.saxutils.escape(str(self.gpg.encrypt(message['body'], self.config.get(to.bare, '', section='keys'), always_trust=True)))) + text = self.gpg.encrypt(message['body'], self.config.get(to.bare, '', section='keys'), always_trust=True) + if not text: + self.core.information('Could not encrypt message to %s' % (to.full),) + # If we could not encrypt the message, don't send anything + message['body'] = '' + return + encrypted_element.text = self.remove_gpg_headers(xml.sax.saxutils.escape(str(text))) message.append(encrypted_element) - message['body'] = 'This message has been encrypted.' + message['body'] = 'This message has been encrypted using the GPG key with id: %s' % self.keyid def on_conversation_msg(self, message, tab): """