diff options
author | June McEnroe <june@causal.agency> | 2020-04-09 21:17:56 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-04-09 21:17:56 -0400 |
commit | 8e79ad76f36a2269b6f7a0c342fcf5a33e1d72b2 (patch) | |
tree | 2cc583d4bcbddae8e663089024d88ec7d5d42e49 | |
parent | Use replyTo for mailto URL (diff) | |
download | bubger-8e79ad76f36a2269b6f7a0c342fcf5a33e1d72b2.tar.gz bubger-8e79ad76f36a2269b6f7a0c342fcf5a33e1d72b2.zip |
Render HTML To and Cc lists
Diffstat (limited to '')
-rw-r--r-- | html.c | 47 |
1 files 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( - <details id="[messageID]"> +static const char *Summary = TEMPLATE( + <details class="message" id="[messageID]"> <summary> - <h1><a href="#[messageID]">[subject]</a></h1> - <address> - <a href="[mailto]">[from]</a> - </address> + <h1 class="subject"><a href="#[messageID]">[subject]</a></h1> + <address class="from"><a href="[mailto]">[from]</a></address> <time datetime="[utc]">[date]</time> </summary> ); +static const char *Address = TEMPLATE( + <li><address class="[class]">[name]</address></li> +); + 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, "<dl><dt>To:</dt><dd><ul>")) 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, "</ul></dd><dt>Cc:</dt><dd><ul>")) 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, "</ul></dd></dl>")) return -1; + + return 0; } |