From 8e79ad76f36a2269b6f7a0c342fcf5a33e1d72b2 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Thu, 9 Apr 2020 21:17:56 -0400 Subject: Render HTML To and Cc lists --- html.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/html.c b/html.c index 9067450..85b6f6b 100644 --- a/html.c +++ b/html.c @@ -28,17 +28,19 @@ static const char *Mailto = { "mailto:[mailbox]@[host]?subject=[re][subject]&In-Reply-To=[messageID]" }; -static const char *Envelope = TEMPLATE( -
+static const char *Summary = TEMPLATE( +
-

[subject]

-
- [from] -
+

[subject]

+
[from]
); +static const char *Address = TEMPLATE( +
  • [name]
  • +); + int htmlEnvelope(FILE *file, const struct Envelope *envelope) { struct Variable mailtoVars[] = { { "mailbox", envelope->replyTo.mailbox }, @@ -73,7 +75,7 @@ int htmlEnvelope(FILE *file, const struct Envelope *envelope) { char date[256]; strftime(date, sizeof(date), "%c %z", &envelope->date); - struct Variable vars[] = { + struct Variable summaryVars[] = { { "messageID", envelope->messageID }, { "subject", envelope->subject }, { "mailto", mailto }, @@ -82,8 +84,33 @@ int htmlEnvelope(FILE *file, const struct Envelope *envelope) { { "date", date }, {0}, }; - error = templateRender(file, Envelope, vars, escapeXML); - + error = templateRender(file, Summary, summaryVars, escapeXML); free(mailto); - return error; + if (error) return error; + + if (0 > fprintf(file, "
    To:
      ")) return -1; + for (size_t i = 0; i < envelope->to.len; ++i) { + struct Address addr = envelope->to.addrs[i]; + struct Variable vars[] = { + { "class", "to" }, + { "name", (addr.name ? addr.name : addr.mailbox) }, + {0}, + }; + error = templateRender(file, Address, vars, escapeXML); + if (error) return error; + } + if (0 > fprintf(file, "
    Cc:
      ")) return -1; + for (size_t i = 0; i < envelope->cc.len; ++i) { + struct Address addr = envelope->cc.addrs[i]; + struct Variable vars[] = { + { "class", "cc" }, + { "name", (addr.name ? addr.name : addr.mailbox) }, + {0}, + }; + error = templateRender(file, Address, vars, escapeXML); + if (error) return error; + } + if (0 > fprintf(file, "
    ")) return -1; + + return 0; } -- cgit 1.4.1