From 9eac81968270f5835188d687f576d0410f08f2f7 Mon Sep 17 00:00:00 2001 From: Fredrik Svantes Date: Mon, 2 Sep 2024 15:08:28 +0200 Subject: [PATCH] Fixed attachment issue --- server.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server.py b/server.py index ad59a12..3c41068 100644 --- a/server.py +++ b/server.py @@ -78,23 +78,26 @@ def create_email(to_email, identifier, text, all_attachments): """ plain_text = text.replace('
', '\n') message = Mail( - from_email=FROMEMAIL, - to_emails=to_email, - subject=f'Secure Form Submission {identifier}', - plain_text_content=plain_text - ) + from_email=FROMEMAIL, + to_emails=to_email, + subject=f'Secure Form Submission {identifier}', + plain_text_content=plain_text) + + for item in all_attachments: + filename = item['filename'] + attachment = item['attachment'] - for filename, attachment in all_attachments: encoded_file = base64.b64encode(attachment.encode("utf-8")).decode() - attached_file = Attachment( + attachedFile = Attachment( FileContent(encoded_file), FileName(filename + '.pgp'), FileType('application/pgp-encrypted'), Disposition('attachment') ) - message.add_attachment(attached_file) + message.add_attachment(attachedFile) return message + def validate_recaptcha(recaptcha_response): """ Validates the ReCaptcha response.