component AP gateway: handle attachments

This commit is contained in:
Goffi 2023-03-23 15:42:21 +01:00
commit c3f97ec712

View file

@ -156,7 +156,7 @@ class AESGCM(object):
# TODO: this is to be removed when a better mechanism is available with OMEMO (now
# possible with the 0.4 version of OMEMO, it's possible to encrypt other stanza
# elements than body).
attachments = data["extra"][C.MESS_KEY_ATTACHMENTS]
attachments = data["extra"][C.KEY_ATTACHMENTS]
if not data['message'] or data['message'] == {'': ''}:
extra_attachments = attachments[1:]
del attachments[1:]
@ -165,7 +165,7 @@ class AESGCM(object):
# we have a message, we must send first attachment separately
extra_attachments = attachments[:]
attachments.clear()
del data["extra"][C.MESS_KEY_ATTACHMENTS]
del data["extra"][C.KEY_ATTACHMENTS]
body_elt = data["xml"].body
if body_elt is None:
@ -181,7 +181,7 @@ class AESGCM(object):
message={'': ''},
subject=data['subject'],
mess_type=data['type'],
extra={C.MESS_KEY_ATTACHMENTS: [attachment]},
extra={C.KEY_ATTACHMENTS: [attachment]},
)
if ((not data['extra']
@ -299,7 +299,7 @@ class AESGCM(object):
else:
data['message'][lang] = message
mess_encrypted = client.encryption.isEncrypted(data)
attachments = data['extra'].setdefault(C.MESS_KEY_ATTACHMENTS, [])
attachments = data['extra'].setdefault(C.KEY_ATTACHMENTS, [])
for link in links:
path = parse.urlparse(link).path
attachment = {
@ -307,7 +307,7 @@ class AESGCM(object):
}
media_type = mimetypes.guess_type(path, strict=False)[0]
if media_type is not None:
attachment[C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE] = media_type
attachment[C.KEY_ATTACHMENTS_MEDIA_TYPE] = media_type
if mess_encrypted:
# we don't add the encrypted flag if the message itself is not