From 4d35c86401b4a947689eac375ec4ba29b3c99d6d Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 19 Apr 2020 11:27:26 -0400 Subject: Use template system for paths and URLs This probably still needs a lot of cleaning up. --- html.c | 60 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index 2d24ce2..403caef 100644 --- a/html.c +++ b/html.c @@ -94,10 +94,11 @@ static char *htmlFragment(const struct Envelope *envelope) { static char *htmlMbox(const struct Envelope *envelope) { struct Variable vars[] = { - { "name", pathSafe(envelope->messageID) }, + { "messageID", envelope->messageID }, + { "type", "mbox" }, {0}, }; - return templateURL("../message/[name].mbox", vars); + return templateURL("../" PATH_MESSAGE, vars); } int htmlMessageOpen(FILE *file, const struct Envelope *envelope) { @@ -164,26 +165,20 @@ 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 + FILE *file, const struct BodyPart *part, const struct Variable *path ) { const char *template = TEMPLATE( - [name] + [name][type][/][subtype] ); - char *url = htmlAttachmentURL(attach); + char *url = templateURL("../" PATH_ATTACHMENT, path); + const char *name = paramGet(part->disposition.params, "filename"); struct Variable vars[] = { { "url", url }, - { "name", attach->path[2] }, // FIXME: Show intended name or type. + { "name", (name ? name : "") }, + { "type", (name ? "" : part->type) }, + { "/", (name ? "" : "/") }, + { "subtype", (name ? "" : part->subtype) }, {0}, }; int error = templateRender(file, template, vars, escapeXML); @@ -197,12 +192,13 @@ int htmlMessageClose(FILE *file) { const char *htmlTitle; -static char *htmlThreadURL(const struct Envelope *envelope) { +static char *htmlThreadURL(const struct Envelope *envelope, const char *type) { struct Variable vars[] = { - { "name", pathSafe(envelope->messageID) }, + { "messageID", envelope->messageID }, + { "type", type }, {0}, }; - return templateURL("[name]", vars); + return templateURL("../" PATH_THREAD, vars); } int htmlThreadHead(FILE *file, const struct Envelope *envelope) { @@ -210,18 +206,21 @@ int htmlThreadHead(FILE *file, const struct Envelope *envelope) { [subject] · [title] - - + + ); - char *url = htmlThreadURL(envelope); + char *atom = htmlThreadURL(envelope, "atom"); + char *mbox = htmlThreadURL(envelope, "mbox"); struct Variable vars[] = { { "subject", envelope->subject }, { "title", htmlTitle }, - { "url", url }, + { "atom", atom }, + { "mbox", mbox }, {0}, }; int error = templateRender(file, template, vars, escapeXML); - free(url); + free(atom); + free(mbox); return error; } @@ -231,21 +230,24 @@ int htmlThreadOpen(FILE *file, const struct Envelope *envelope) {

[subject]

); - char *url = htmlThreadURL(envelope); + char *atom = htmlThreadURL(envelope, "atom"); + char *mbox = htmlThreadURL(envelope, "mbox"); struct Variable vars[] = { { "subject", envelope->subject }, - { "url", url }, + { "atom", atom }, + { "mbox", mbox }, {0}, }; int error = templateRender(file, template, vars, escapeXML); - free(url); + free(atom); + free(mbox); return error; } -- cgit 1.4.1