Mercurial > libervia-backend
annotate sat/plugins/plugin_misc_attach.py @ 3219:2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
attachment handling has been simplified, and now use a "register" method similar as the
ones used for download or upload.
A default method (for unencrypted messages) will try a simple upload and will copy the
links to body.
AESGCM plugin has been adapted to be used for encrypted files. If more than one file is
sent with AESGCM plugin, they will be split in several messages as current de-facto
standard (OMEMO media sharing) doesn't support several files per message.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 18 Mar 2020 20:25:02 +0100 |
parents | 2e892f9f54f6 |
children | 163014f09bf4 |
rev | line source |
---|---|
3181 | 1 #!/usr/bin/env python3 |
2 | |
3 # SàT plugin for attaching files | |
4 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 from functools import partial | |
20 from pathlib import Path | |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
21 from collections import namedtuple |
3181 | 22 from twisted.internet import defer |
23 from sat.core.i18n import _ | |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
24 from sat.core import exceptions |
3181 | 25 from sat.core.constants import Const as C |
26 from sat.core.log import getLogger | |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
27 from sat.tools import utils |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
28 |
3181 | 29 |
30 log = getLogger(__name__) | |
31 | |
32 | |
33 PLUGIN_INFO = { | |
34 C.PI_NAME: "File Attach", | |
35 C.PI_IMPORT_NAME: "ATTACH", | |
36 C.PI_TYPE: C.PLUG_TYPE_MISC, | |
37 C.PI_DEPENDENCIES: ["UPLOAD"], | |
38 C.PI_MAIN: "AttachPlugin", | |
39 C.PI_HANDLER: "no", | |
40 C.PI_DESCRIPTION: _("""Attachments handler"""), | |
41 } | |
42 | |
43 | |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
44 AttachmentHandler = namedtuple('AttachmentHandler', ['can_handle', 'attach', 'priority']) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
45 |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
46 |
3181 | 47 class AttachPlugin: |
48 | |
49 def __init__(self, host): | |
50 log.info(_("plugin Attach initialization")) | |
51 self.host = host | |
52 self._u = host.plugins["UPLOAD"] | |
53 host.trigger.add("sendMessage", self._sendMessageTrigger) | |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
54 self._attachments_handlers = {'clear': [], 'encrypted': []} |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
55 self.register(self.defaultCanHandle, self.defaultAttach, False, -1000) |
3181 | 56 |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
57 def register(self, can_handle, attach, encrypted=False, priority=0): |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
58 """Register an attachments handler |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
59 |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
60 @param can_handle(callable, coroutine, Deferred): a method which must return True |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
61 if this plugin can handle the upload, otherwise next ones will be tried. |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
62 This method will get client and mess_data as arguments, before the XML is |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
63 generated |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
64 @param attach(callable, coroutine, Deferred): attach the file |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
65 this method will get client and mess_data as arguments, after XML is |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
66 generated. Upload operation must be handled |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
67 hint: "UPLOAD" plugin can be used |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
68 @param encrypted(bool): True if the handler manages encrypted files |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
69 A handler can be registered twice if it handle both encrypted and clear |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
70 attachments |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
71 @param priority(int): priority of this handler, handler with higher priority will |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
72 be tried first |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
73 """ |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
74 handler = AttachmentHandler(can_handle, attach, priority) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
75 handlers = ( |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
76 self._attachments_handlers['encrypted'] |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
77 if encrypted else self._attachments_handlers['clear'] |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
78 ) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
79 if handler in handlers: |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
80 raise exceptions.InternalError( |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
81 'Attachment handler has been registered twice, this should never happen' |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
82 ) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
83 |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
84 handlers.append(handler) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
85 handlers.sort(key=lambda h: h.priority, reverse=True) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
86 log.debug(f"new attachments handler: {handler}") |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
87 |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
88 async def attachFiles(self, client, data): |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
89 if client.encryption.isEncryptionRequested(data): |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
90 handlers = self._attachments_handlers['encrypted'] |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
91 else: |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
92 handlers = self._attachments_handlers['clear'] |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
93 |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
94 for handler in handlers: |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
95 can_handle = await utils.asDeferred(handler.can_handle, client, data) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
96 if can_handle: |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
97 break |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
98 else: |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
99 raise exceptions.NotFound( |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
100 _("No plugin can handle attachment with {destinee}").format( |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
101 destinee = data['to'] |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
102 )) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
103 |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
104 await utils.asDeferred(handler.attach, client, data) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
105 |
3181 | 106 return data |
107 | |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
108 async def uploadFiles(self, client, data, upload_cb=None): |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
109 """Upload file, and update attachments |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
110 |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
111 invalid attachments will be removed |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
112 @param client: |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
113 @param data(dict): message data |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
114 @param upload_cb(coroutine, Deferred, None): method to use for upload |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
115 if None, upload method from UPLOAD plugin will be used. |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
116 Otherwise, following kwargs will be use with the cb: |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
117 - client |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
118 - filepath |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
119 - filename |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
120 - options |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
121 the method must return a tuple similar to UPLOAD plugin's upload method, |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
122 it must contain: |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
123 - progress_id |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
124 - a deferred which fire download URL |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
125 """ |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
126 if upload_cb is None: |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
127 upload_cb = self._u.upload |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
128 |
3181 | 129 uploads_d = [] |
130 to_delete = [] | |
131 attachments = data["extra"]["attachments"] | |
132 | |
133 for attachment in attachments: | |
134 try: | |
3202
2e892f9f54f6
plugin attachment: remove "path" from attachment once used:
Goffi <goffi@goffi.org>
parents:
3192
diff
changeset
|
135 # we pop path because we don't want it to be stored, as the image can be |
2e892f9f54f6
plugin attachment: remove "path" from attachment once used:
Goffi <goffi@goffi.org>
parents:
3192
diff
changeset
|
136 # only in a temporary location |
2e892f9f54f6
plugin attachment: remove "path" from attachment once used:
Goffi <goffi@goffi.org>
parents:
3192
diff
changeset
|
137 path = Path(attachment.pop("path")) |
3181 | 138 except KeyError: |
139 log.warning("no path in attachment: {attachment}") | |
140 to_delete.append(attachment) | |
141 continue | |
142 | |
143 if "url" in attachment: | |
3202
2e892f9f54f6
plugin attachment: remove "path" from attachment once used:
Goffi <goffi@goffi.org>
parents:
3192
diff
changeset
|
144 url = attachment.pop('url') |
2e892f9f54f6
plugin attachment: remove "path" from attachment once used:
Goffi <goffi@goffi.org>
parents:
3192
diff
changeset
|
145 log.warning( |
2e892f9f54f6
plugin attachment: remove "path" from attachment once used:
Goffi <goffi@goffi.org>
parents:
3192
diff
changeset
|
146 f"unexpected URL in attachment: {url!r}\nattachment: {attachment}" |
2e892f9f54f6
plugin attachment: remove "path" from attachment once used:
Goffi <goffi@goffi.org>
parents:
3192
diff
changeset
|
147 ) |
3181 | 148 |
149 try: | |
150 name = attachment["name"] | |
151 except KeyError: | |
152 name = attachment["name"] = path.name | |
153 | |
154 options = {} | |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
155 progress_id = attachment.pop("progress_id", None) |
3182
f2bb57348587
plugin attach, XEP-0363: progress id can now be specified:
Goffi <goffi@goffi.org>
parents:
3181
diff
changeset
|
156 if progress_id: |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
157 options["progress_id"] = progress_id |
3192
883fb4981958
plugin attach: disable TLS check if "check_certificate" is disabled
Goffi <goffi@goffi.org>
parents:
3182
diff
changeset
|
158 check_certificate = self.host.memory.getParamA( |
883fb4981958
plugin attach: disable TLS check if "check_certificate" is disabled
Goffi <goffi@goffi.org>
parents:
3182
diff
changeset
|
159 "check_certificate", "Connection", profile_key=client.profile) |
883fb4981958
plugin attach: disable TLS check if "check_certificate" is disabled
Goffi <goffi@goffi.org>
parents:
3182
diff
changeset
|
160 if not check_certificate: |
883fb4981958
plugin attach: disable TLS check if "check_certificate" is disabled
Goffi <goffi@goffi.org>
parents:
3182
diff
changeset
|
161 options['ignore_tls_errors'] = True |
883fb4981958
plugin attach: disable TLS check if "check_certificate" is disabled
Goffi <goffi@goffi.org>
parents:
3182
diff
changeset
|
162 log.warning( |
883fb4981958
plugin attach: disable TLS check if "check_certificate" is disabled
Goffi <goffi@goffi.org>
parents:
3182
diff
changeset
|
163 _("certificate check disabled for upload, this is dangerous!")) |
3181 | 164 |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
165 __, upload_d = await upload_cb( |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
166 client=client, |
3181 | 167 filepath=path, |
168 filename=name, | |
3182
f2bb57348587
plugin attach, XEP-0363: progress id can now be specified:
Goffi <goffi@goffi.org>
parents:
3181
diff
changeset
|
169 options=options, |
3181 | 170 ) |
171 uploads_d.append(upload_d) | |
172 | |
173 for attachment in to_delete: | |
174 attachments.remove(attachment) | |
175 | |
176 upload_results = await defer.DeferredList(uploads_d) | |
177 for idx, (success, ret) in enumerate(upload_results): | |
178 attachment = attachments[idx] | |
179 | |
180 if not success: | |
181 # ret is a failure here | |
182 log.warning(f"error while uploading {attachment}: {ret}") | |
183 continue | |
184 | |
185 attachment["url"] = ret | |
186 | |
187 return data | |
188 | |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
189 def _attachFiles(self, client, data): |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
190 return defer.ensureDeferred(self.attachFiles(client, data)) |
3181 | 191 |
192 def _sendMessageTrigger( | |
193 self, client, mess_data, pre_xml_treatments, post_xml_treatments): | |
194 if mess_data['extra'].get(C.MESS_KEY_ATTACHMENTS): | |
195 post_xml_treatments.addCallback(partial(self._attachFiles, client)) | |
196 return True | |
3219
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
197 |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
198 async def defaultCanHandle(self, client, data): |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
199 return True |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
200 |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
201 async def defaultAttach(self, client, data): |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
202 await self.uploadFiles(client, data) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
203 # TODO: handle xhtml-im |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
204 body_elt = next(data["xml"].elements((C.NS_CLIENT, "body"))) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
205 attachments = data["extra"][C.MESS_KEY_ATTACHMENTS] |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
206 if attachments: |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
207 body_links = '\n'.join(a['url'] for a in attachments) |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
208 if str(body_elt).strip(): |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
209 # if there is already a body, we add a line feed before the first link |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
210 body_elt.addContent('\n') |
2ba602aef90e
plugin attach, aesgcm: attachments refactoring:
Goffi <goffi@goffi.org>
parents:
3202
diff
changeset
|
211 body_elt.addContent(body_links) |