16 |
16 |
import base64
|
17 |
17 |
import re
|
18 |
18 |
|
19 |
|
from email import encoders
|
20 |
|
from email.mime.audio import MIMEAudio
|
21 |
19 |
from email.mime.base import MIMEBase
|
22 |
|
from email.mime.image import MIMEImage
|
23 |
20 |
from email.mime.multipart import MIMEMultipart
|
24 |
21 |
from email.mime.text import MIMEText
|
25 |
22 |
|
... | ... | |
140 |
137 |
part = MIMEText(content, _subtype=subtype)
|
141 |
138 |
else:
|
142 |
139 |
part = MIMEBase(maintype, subtype, name=filename)
|
143 |
|
part.set_payload(content)
|
|
140 |
attachment['real_bytes'] = content
|
|
141 |
attachment['fake_bytes'] = '\ue000%s\ue000' % num
|
|
142 |
part.set_payload(attachment['fake_bytes'])
|
144 |
143 |
part.add_header('Content-Transfer-Encoding', 'binary')
|
145 |
|
encoders.encode_noop(part)
|
146 |
144 |
part.add_header('Content-Disposition', 'attachment', name=filename, filename=filename)
|
147 |
145 |
part.add_header('Content-ID', '<%s>' % filename)
|
148 |
146 |
message.attach(part)
|
... | ... | |
163 |
161 |
request.message = message.as_string(unixfrom=False
|
164 |
162 |
).replace(boundary + '\n', boundary + '\r\n'
|
165 |
163 |
).replace('\n--' + boundary, '\r\n--' + boundary).encode('utf-8')
|
|
164 |
for attachment in attachments:
|
|
165 |
# substitute binary parts
|
|
166 |
if attachment.get('fake_bytes'):
|
|
167 |
request.message = request.message.replace(
|
|
168 |
attachment['fake_bytes'].encode('utf-8'),
|
|
169 |
attachment['real_bytes'])
|
|
170 |
|
166 |
171 |
request.headers.update(dict(message._headers))
|
167 |
172 |
request.headers['Authorization'] = self.instance.get_token()
|
168 |
173 |
resp = self.instance.requests.post(request.url, data=request.message,
|
169 |
|
-
|