forked from cool-RR/python_toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonkeypatch_envelopes.py
More file actions
29 lines (21 loc) · 1.17 KB
/
monkeypatch_envelopes.py
File metadata and controls
29 lines (21 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright 2009-2017 Ram Rachum.
# This program is distributed under the MIT license.
'''Module for monkeypatching our own copy of `envelopes`.'''
### Monkeypatching envelopes: #################################################
# #
from python_toolbox.third_party import envelopes
from python_toolbox import monkeypatching_tools
@monkeypatching_tools.monkeypatch(envelopes.Envelope)
def add_attachment_from_string(self, file_data, file_name,
mimetype='application/octet-stream'):
from python_toolbox.third_party.envelopes.envelope import \
MIMEBase, email_encoders, os
type_maj, type_min = mimetype.split('/')
part = MIMEBase(type_maj, type_min)
part.set_payload(file_data)
email_encoders.encode_base64(part)
part.add_header('Content-Disposition',
f'attachment; filename="{file_name}"')
self._parts.append((mimetype, part))
# #
### Finished monkeypatching envelopes. ########################################