From f8b3e3760b831745cf10d97aeae64e9c00a136a9 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 16 Sep 2024 18:06:49 +0200 Subject: [PATCH] Handle undecodable message content --- sbapp/ui/messages.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/sbapp/ui/messages.py b/sbapp/ui/messages.py index 7c370cb..bfc0954 100644 --- a/sbapp/ui/messages.py +++ b/sbapp/ui/messages.py @@ -357,10 +357,14 @@ class Messages(): for m in self.new_messages: if not m["hash"] in self.added_item_hashes: - if not self.is_trusted: - message_input = str( escape_markup(m["content"].decode("utf-8")) ).encode("utf-8") - else: - message_input = m["content"] + try: + if not self.is_trusted: + message_input = str( escape_markup(m["content"].decode("utf-8")) ).encode("utf-8") + else: + message_input = m["content"] + except Exception as e: + RNS.log(f"Message content could not be decoded: {e}", RNS.LOG_DEBUG) + message_input = b"" if message_input.strip() == b"": if not ("lxm" in m and m["lxm"] != None and m["lxm"].fields != None and LXMF.FIELD_COMMANDS in m["lxm"].fields): @@ -966,7 +970,7 @@ class Messages(): "viewclass": "OneLineListItem", "text": "Copy message text", "height": dp(40), - "on_release": gen_copy(m["content"].decode("utf-8"), item) + "on_release": gen_copy(message_input.decode("utf-8"), item) }, { "text": "Delete", @@ -1000,7 +1004,7 @@ class Messages(): "viewclass": "OneLineListItem", "text": "Copy message text", "height": dp(40), - "on_release": gen_copy(m["content"].decode("utf-8"), item) + "on_release": gen_copy(message_input.decode("utf-8"), item) }, { "text": "Delete", @@ -1018,7 +1022,7 @@ class Messages(): "viewclass": "OneLineListItem", "text": "Copy", "height": dp(40), - "on_release": gen_copy(m["content"].decode("utf-8"), item) + "on_release": gen_copy(message_input.decode("utf-8"), item) }, { "text": "Delete", @@ -1035,7 +1039,7 @@ class Messages(): "viewclass": "OneLineListItem", "text": "Copy", "height": dp(40), - "on_release": gen_copy(m["content"].decode("utf-8"), item) + "on_release": gen_copy(message_input.decode("utf-8"), item) }, { "viewclass": "OneLineListItem", @@ -1058,7 +1062,7 @@ class Messages(): "viewclass": "OneLineListItem", "text": "Copy", "height": dp(40), - "on_release": gen_copy(m["content"].decode("utf-8"), item) + "on_release": gen_copy(message_input.decode("utf-8"), item) }, { "text": "Delete",