From 7aab36b6f9c968627d627e08a67c0ba758460d33 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 21 Jun 2021 14:42:35 +0200 Subject: mail/envelope: fix setting attachment params Actually pass them as a tuple of tuples. Also, set the charset param only for text attachments. --- alot/mail/envelope.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/alot/mail/envelope.py b/alot/mail/envelope.py index 4d388aac..ad5f2ee4 100644 --- a/alot/mail/envelope.py +++ b/alot/mail/envelope.py @@ -221,6 +221,8 @@ class Envelope: ctype = helper.guess_mimetype(data) + params = [] + # accept only valid utf-8 as text attachments if ctype.partition('/')[0] == 'text': try: @@ -228,11 +230,13 @@ class Envelope: except UnicodeDecodeError as e: raise ValueError('Attachment is not valid UTF-8') from e + params.append(('charset', 'utf-8')) + # Set the filename parameter if not filename: filename = os.path.basename(path) - attachment = Attachment(data, ctype, filename, (('charset', 'utf-8'))) + attachment = Attachment(data, ctype, filename, tuple(params)) self.attach(attachment) def attach(self, attachment): -- cgit v1.2.3