diff --git a/mail-to-pdf.mjs b/mail-to-pdf.mjs index fdbf514..6e978c7 100755 --- a/mail-to-pdf.mjs +++ b/mail-to-pdf.mjs @@ -25,21 +25,23 @@ function parse_mail(sexp_string) { const mail_obj = parse_mail(mail_body); -let html = mail_obj["body-html"] - ? mail_obj["body-html"] - : /* HTML */ ` -
- - - -${mail_obj["body-txt"]}
-
- `;
+let html =
+ mail_obj["body-html"] && mail_obj["body-html"].match(/body/i) !== null
+ ? mail_obj["body-html"]
+ : /* HTML */ `
+
+
+
+
+ ${mail_obj["body-txt"]}
+
+ `;
const attachments = (await $`mu extract ${path}`).stdout;
function getSimpleHeader(body, header_name) {
const regexp = new RegExp(`:${header_name} (.*)\n`);
+ console.log("get simple header", header_name, body);
return body.match(regexp)[1];
}
@@ -57,11 +59,17 @@ function escape(str) {
return str.replace(/ {
+ //someimtes images have the wrong mime type, like for example in photos from straż miejska confirmation emails
+ if (line.includes(".jpg") && line.includes("application/octet-stream")) {
+ return line.replace("application/octet-stream", "image/jpg");
+ } else {
+ return line;
+ }
+ })
.filter((line) => line.includes("image"))
.map((line) => {
return {
@@ -119,7 +127,7 @@ const date = await formatDate(getSimpleHeader(mail_body, "date"));
html = html.replace(
//i,
- `` +
+ `` +
/* HTML */ `