summaryrefslogtreecommitdiff
path: root/alot/mail/envelope.py
diff options
context:
space:
mode:
Diffstat (limited to 'alot/mail/envelope.py')
-rw-r--r--alot/mail/envelope.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/alot/mail/envelope.py b/alot/mail/envelope.py
index a4985c7a..9af4a42b 100644
--- a/alot/mail/envelope.py
+++ b/alot/mail/envelope.py
@@ -221,11 +221,18 @@ class Envelope:
ctype = helper.guess_mimetype(data)
+ # accept only valid utf-8 as text attachments
+ if ctype.partition('/')[0] == 'text':
+ try:
+ data.decode('utf-8')
+ except UnicodeDecodeError as e:
+ raise ValueError('Attachment is not valid UTF-8') from e
+
# Set the filename parameter
if not filename:
filename = os.path.basename(path)
- attachment = Attachment(data, ctype, filename, ())
+ attachment = Attachment(data, ctype, filename, (('charset', 'utf-8')))
self.attach(attachment)
def attach(self, attachment):