From f83e1927a6225699522918bbdf581c2b73efbe71 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 17 Apr 2020 16:35:52 -0400 Subject: Write attachment files All this path stuff needs cleaning up. I think it's time to use the template renderer for paths. --- html.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'html.c') diff --git a/html.c b/html.c index 9e37db8..2d24ce2 100644 --- a/html.c +++ b/html.c @@ -164,6 +164,33 @@ int htmlInline(FILE *file, const struct BodyPart *part, const char *content) { return templateRender(file, template, vars, escapeXML); } +static char *htmlAttachmentURL(const struct Attachment *attach) { + struct Variable vars[] = { + { "path0", attach->path[0] }, + { "path1", attach->path[1] }, + { "path2", attach->path[2] }, + {0}, + }; + return templateURL("../attachment/[path0]/[path1]/[path2]", vars); +} + +int htmlAttachment( + FILE *file, const struct BodyPart *part, const struct Attachment *attach +) { + const char *template = TEMPLATE( + [name] + ); + char *url = htmlAttachmentURL(attach); + struct Variable vars[] = { + { "url", url }, + { "name", attach->path[2] }, // FIXME: Show intended name or type. + {0}, + }; + int error = templateRender(file, template, vars, escapeXML); + free(url); + return error; +} + int htmlMessageClose(FILE *file) { return templateRender(file, TEMPLATE(), NULL, NULL); } -- cgit 1.4.1