From 5b40d71f403e3ced528c4ddd0b3e621971ce39f0 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 6 Oct 2022 16:02:05 +0200 Subject: [PATCH] core (xmpp): check presence of some keys in attachment before using them: in `completeAttachments` `url` was used to complete a missing name, but it may be missing with some attachments, thus its presence is now checked. --- sat/core/xmpp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sat/core/xmpp.py b/sat/core/xmpp.py index d86daa5f..04a68a08 100644 --- a/sat/core/xmpp.py +++ b/sat/core/xmpp.py @@ -1302,11 +1302,12 @@ class SatMessageProtocol(xmppim.MessageProtocol): def completeAttachments(self, data): """Complete missing metadata of attachments""" for attachment in data['extra'].get(C.MESS_KEY_ATTACHMENTS, []): - if "name" not in attachment: + if "name" not in attachment and "url" in attachment: name = (Path(unquote(urlparse(attachment['url']).path)).name or C.FILE_DEFAULT_NAME) attachment["name"] = name - if C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE not in attachment: + if ((C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE not in attachment + and "name" in attachment)): media_type = mimetypes.guess_type(attachment['name'], strict=False)[0] if media_type: attachment[C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE] = media_type