# HG changeset patch # User Goffi # Date 1582728874 -3600 # Node ID e8ce30798d15ba91f4a69ea60800c4b78e1ebd84 # Parent 8565af2092349a3f8b59b84012a3d055cb34bc46 core (xmpp): use pathlib.Path to complete attachments names, and use name to guess type diff -r 8565af209234 -r e8ce30798d15 sat/core/xmpp.py --- a/sat/core/xmpp.py Sun Feb 23 17:49:21 2020 +0100 +++ b/sat/core/xmpp.py Wed Feb 26 15:54:34 2020 +0100 @@ -23,6 +23,7 @@ import mimetypes from urllib.parse import urlparse, unquote from functools import partial +from pathlib import Path import shortuuid from sat.core.i18n import _ from sat.core.constants import Const as C @@ -1133,10 +1134,11 @@ """Complete missing metadata of attachments""" for attachment in data['extra'].get(C.MESS_KEY_ATTACHMENTS, []): if "name" not in attachment: - name = unquote(urlparse(attachment['url']).path.rsplit('/', 1)[-1]) + name = (Path(unquote(urlparse(attachment['url']).path)).name + or C.FILE_DEFAULT_NAME) attachment["name"] = name if C.MESS_KEY_MEDIA_TYPE not in attachment: - media_type = mimetypes.guess_type(attachment['url'], strict=False)[0] + media_type = mimetypes.guess_type(attachment['name'], strict=False)[0] if media_type: attachment[C.MESS_KEY_MEDIA_TYPE] = media_type return data