diff --git a/src/paperless_tika/mail_template/index.html b/src/paperless_tika/mail_template/index.html index b1f332f75..f7d7fbf9d 100644 --- a/src/paperless_tika/mail_template/index.html +++ b/src/paperless_tika/mail_template/index.html @@ -12,25 +12,25 @@
From: {clean_html(parsed['metadata'].pop('Message-From', ''))} -
To: {clean_html(parsed['metadata'].pop('Message-To', ''))} -
CC: {clean_html(parsed['metadata'].pop('Message-CC', ''))} -
Date: {clean_html(parsed['metadata'].pop('dcterms:created', ''))} -
{clean_html(content)}- - - """, - ) + html_file = os.path.join(os.path.dirname(__file__), "mail_template/index.html") + css_file = os.path.join(os.path.dirname(__file__), "mail_template/output.css") + placeholder_pattern = re.compile(r"{{(.+)}}") + html = StringIO() - files = { - "html": ( - "index.html", - html, - ), - } - headers = {} + with open(html_file, "r") as html_template_handle: + with open(css_file, "rb") as css_handle: + for line in html_template_handle.readlines(): + for placeholder in placeholder_pattern.findall(line): + line = re.sub( + "{{" + placeholder + "}}", + data.get(placeholder.strip(), ""), + line, + ) + html.write(line) + html.seek(0) + files = { + "html": ( + "index.html", + html, + ), + "css": ( + "output.css", + css_handle, + ), + } + headers = {} - try: - response = requests.post(url, files=files, headers=headers) - response.raise_for_status() # ensure we notice bad responses - except Exception as err: - raise ParseError(f"Error while converting document to PDF: {err}") + try: + response = requests.post(url, files=files, headers=headers) + response.raise_for_status() # ensure we notice bad responses + except Exception as err: + raise ParseError(f"Error while converting document to PDF: {err}") with open(pdf_path, "wb") as file: file.write(response.content)