From cecad168d0de4177b4f61610dbda6ef8a65d22df Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Fri, 7 Jun 2024 14:40:54 +0200 Subject: [PATCH] Improve email encoding --- hedgedoc-expire.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hedgedoc-expire.py b/hedgedoc-expire.py index 857881c..fbcc805 100644 --- a/hedgedoc-expire.py +++ b/hedgedoc-expire.py @@ -229,10 +229,12 @@ class HedgedocExpire: The admin team for {self.config.url} - '''))) - md = MIMEBase('text', 'markdown') - md.add_header('Content-Disposition', f'attachment; filename={note["title"]}.md') - md.set_payload(note["content"].encode(encoding='utf-8')) + '''), 'plain', 'utf-8')) + md = MIMEText(note["content"], 'markdown', 'utf-8') + filename = note['title'].encode('ascii', 'ignore').decode('utf-8') + if len(filename) == 0: + filename = 'note' + md.add_header('Content-Disposition', f'attachment; filename={filename}.md') msg.attach(md) self.email_sender.send(msg)