Fix: Handle email headers as strings if the are Header type (#1850)

This commit is contained in:
Adrià Casajús 2023-08-29 12:37:26 +02:00 committed by GitHub
parent 5714403976
commit c04f5102d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import urllib
from email.header import Header
from email.message import Message
from app.email import headers
@ -33,6 +34,8 @@ class UnsubscribeGenerator:
if not unsubscribe_data:
LOG.info("Email has no unsubscribe header")
return message
if isinstance(unsubscribe_data, Header):
unsubscribe_data = str(unsubscribe_data.encode)
raw_methods = [method.strip() for method in unsubscribe_data.split(",")]
mailto_unsubs = None
other_unsubs = []

View File

@ -71,7 +71,7 @@ def load_eml_file(
if not template_values:
template_values = {}
rendered = template.render(**template_values)
return email.message_from_string(rendered)
return email.message_from_bytes(rendered.encode("utf-8"))
def random_email() -> str: