comparison sat/plugins/plugin_sec_aesgcm.py @ 4023:78b5f356900c

component AP gateway: handle attachments
author Goffi <goffi@goffi.org>
date Thu, 23 Mar 2023 15:42:21 +0100
parents 0ff265725489
children 524856bd7b19
comparison
equal deleted inserted replaced
4022:cdb7de398c85 4023:78b5f356900c
154 # message limitation of OMEMO media sharing unofficial XEP. We have to remove 154 # message limitation of OMEMO media sharing unofficial XEP. We have to remove
155 # attachments from original message, and send them one by one. 155 # attachments from original message, and send them one by one.
156 # TODO: this is to be removed when a better mechanism is available with OMEMO (now 156 # TODO: this is to be removed when a better mechanism is available with OMEMO (now
157 # possible with the 0.4 version of OMEMO, it's possible to encrypt other stanza 157 # possible with the 0.4 version of OMEMO, it's possible to encrypt other stanza
158 # elements than body). 158 # elements than body).
159 attachments = data["extra"][C.MESS_KEY_ATTACHMENTS] 159 attachments = data["extra"][C.KEY_ATTACHMENTS]
160 if not data['message'] or data['message'] == {'': ''}: 160 if not data['message'] or data['message'] == {'': ''}:
161 extra_attachments = attachments[1:] 161 extra_attachments = attachments[1:]
162 del attachments[1:] 162 del attachments[1:]
163 await self._attach.upload_files(client, data, upload_cb=self._upload_cb) 163 await self._attach.upload_files(client, data, upload_cb=self._upload_cb)
164 else: 164 else:
165 # we have a message, we must send first attachment separately 165 # we have a message, we must send first attachment separately
166 extra_attachments = attachments[:] 166 extra_attachments = attachments[:]
167 attachments.clear() 167 attachments.clear()
168 del data["extra"][C.MESS_KEY_ATTACHMENTS] 168 del data["extra"][C.KEY_ATTACHMENTS]
169 169
170 body_elt = data["xml"].body 170 body_elt = data["xml"].body
171 if body_elt is None: 171 if body_elt is None:
172 body_elt = data["xml"].addElement("body") 172 body_elt = data["xml"].addElement("body")
173 173
179 await client.sendMessage( 179 await client.sendMessage(
180 to_jid=data['to'], 180 to_jid=data['to'],
181 message={'': ''}, 181 message={'': ''},
182 subject=data['subject'], 182 subject=data['subject'],
183 mess_type=data['type'], 183 mess_type=data['type'],
184 extra={C.MESS_KEY_ATTACHMENTS: [attachment]}, 184 extra={C.KEY_ATTACHMENTS: [attachment]},
185 ) 185 )
186 186
187 if ((not data['extra'] 187 if ((not data['extra']
188 and (not data['message'] or data['message'] == {'': ''}) 188 and (not data['message'] or data['message'] == {'': ''})
189 and not data['subject'])): 189 and not data['subject'])):
297 if not message: 297 if not message:
298 del data['message'][lang] 298 del data['message'][lang]
299 else: 299 else:
300 data['message'][lang] = message 300 data['message'][lang] = message
301 mess_encrypted = client.encryption.isEncrypted(data) 301 mess_encrypted = client.encryption.isEncrypted(data)
302 attachments = data['extra'].setdefault(C.MESS_KEY_ATTACHMENTS, []) 302 attachments = data['extra'].setdefault(C.KEY_ATTACHMENTS, [])
303 for link in links: 303 for link in links:
304 path = parse.urlparse(link).path 304 path = parse.urlparse(link).path
305 attachment = { 305 attachment = {
306 "url": link, 306 "url": link,
307 } 307 }
308 media_type = mimetypes.guess_type(path, strict=False)[0] 308 media_type = mimetypes.guess_type(path, strict=False)[0]
309 if media_type is not None: 309 if media_type is not None:
310 attachment[C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE] = media_type 310 attachment[C.KEY_ATTACHMENTS_MEDIA_TYPE] = media_type
311 311
312 if mess_encrypted: 312 if mess_encrypted:
313 # we don't add the encrypted flag if the message itself is not 313 # we don't add the encrypted flag if the message itself is not
314 # encrypted, because the decryption key is part of the link, 314 # encrypted, because the decryption key is part of the link,
315 # so sending it over unencrypted channel is like having no 315 # so sending it over unencrypted channel is like having no