import _ from "lodash"; import deepExtend from "deep-extend"; import { readFileSync, promises as fs } from "graceful-fs"; import moment from "moment"; import { htmlToText } from "nodemailer-html-to-text"; import { config } from "../config"; import Logger from "../logger"; import { editNodeUrl } from "../utils/urlBuilder"; import type { Transporter } from "nodemailer"; import type { MailData, Mail } from "../types"; const templateBasePath = __dirname + "/../mailTemplates"; const snippetsBasePath = templateBasePath + "/snippets"; const templateFunctions: { [key: string]: | ((name: string, data: MailData) => string) | ((data: MailData) => string) | ((href: string, text: string) => string) | ((unix: number) => string); } = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any function renderSnippet(this: any, name: string, data: MailData): string { const snippetFile = snippetsBasePath + "/" + name + ".html"; return _.template(readFileSync(snippetFile).toString())( deepExtend( {}, this, // parent data data, templateFunctions ) ); } // eslint-disable-next-line @typescript-eslint/no-explicit-any function snippet(name: string): (this: any, data: MailData) => string { // eslint-disable-next-line @typescript-eslint/no-explicit-any return function (this: any, data: MailData): string { return renderSnippet.bind(this)(name, data); }; } function renderLink(href: string, text: string): string { // noinspection HtmlUnknownTarget return _.template( '<%- text %>' )({ href: href, text: text || href, }); } function renderHR(): string { return '