# HG changeset patch # User Goffi # Date 1665064925 -7200 # Node ID 993cc8e56aef6bac2d11812a3fc8c1198ef611ee # Parent 7b2c51bcc8f5cdf8ad728cff7f8d51d180f6323b 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. diff -r 7b2c51bcc8f5 -r 993cc8e56aef sat/core/xmpp.py --- a/sat/core/xmpp.py Thu Oct 06 16:02:05 2022 +0200 +++ b/sat/core/xmpp.py Thu Oct 06 16:02:05 2022 +0200 @@ -1302,11 +1302,12 @@ 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