summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-12 19:43:59 -0400
committerJune McEnroe <june@causal.agency>2020-04-12 19:43:59 -0400
commit0939007c9361b99ebf0cc52a57f71e136c657556 (patch)
tree44c4ae6c0b6f894031d9f3517ea30067a9802a8f
parentAllow missing DOW and obsolete zone in date (diff)
downloadbubger-0939007c9361b99ebf0cc52a57f71e136c657556.tar.gz
bubger-0939007c9361b99ebf0cc52a57f71e136c657556.zip
Handle address groups in HTML rendering
-rw-r--r--html.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/html.c b/html.c
index ac1411d..de64ed8 100644
--- a/html.c
+++ b/html.c
@@ -23,6 +23,37 @@
 
 #include "archive.h"
 
+static int htmlAddress(FILE *file, const char *class, struct Address addr) {
+	struct Variable vars[] = {
+		{ "class", class },
+		{ "name", addressName(addr) },
+		{ "mailbox", addr.mailbox },
+		{0},
+	};
+	if (addr.host) {
+		return templateRender(
+			file,
+			TEMPLATE(<li><address class="[class]">[name]</address></li>),
+			vars,
+			escapeXML
+		);
+	} else if (addr.mailbox) {
+		return templateRender(
+			file,
+			TEMPLATE(<li><address class="[class] group">[mailbox]<ul>),
+			vars,
+			escapeXML
+		);
+	} else {
+		return templateRender(
+			file,
+			TEMPLATE(</ul></address></li>),
+			vars,
+			escapeXML
+		);
+	}
+}
+
 static int
 htmlAddressList(FILE *file, const char *class, struct AddressList list) {
 	if (!list.len) return 0;
@@ -35,17 +66,7 @@ htmlAddressList(FILE *file, const char *class, struct AddressList list) {
 	);
 	if (error) return error;
 	for (size_t i = 0; i < list.len; ++i) {
-		struct Variable vars[] = {
-			{ "class", class },
-			{ "name", addressName(list.addrs[i]) },
-			{0},
-		};
-		error = templateRender(
-			file,
-			TEMPLATE(<li><address class="[class]">[name]</address></li>),
-			vars,
-			escapeXML
-		);
+		error = htmlAddress(file, class, list.addrs[i]);
 		if (error) return error;
 	}
 	return templateRender(file, TEMPLATE(</ul>), vars, escapeXML);