summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--html.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/html.c b/html.c
index fe96a37..77438a0 100644
--- a/html.c
+++ b/html.c
@@ -107,17 +107,35 @@ static char *htmlMbox(const char *messageID) {
 	return templateString("../" PATH_MESSAGE, vars, escapeURL);
 }
 
+static int htmlReplyCc(FILE *file, bool first, struct AddressList list) {
+	for (size_t i = 0; i < list.len; ++i) {
+		const char *template = "[,][mailbox]@[host]";
+		struct Variable vars[] = {
+			{ "mailbox", list.addrs[i].mailbox },
+			{ "host", list.addrs[i].host },
+			{ ",", (!first || i ? "," : "") },
+			{0},
+		};
+		int error = templateRender(file, template, vars, escapeURL);
+		if (error) return error;
+	}
+	return 0;
+}
+
 static char *htmlReply(const struct Envelope *envelope) {
+	char *buf;
+	size_t len;
+	FILE *file = open_memstream(&buf, &len);
+	if (!file) err(EX_OSERR, "open_memstream");
 	const char *template = {
 		"mailto:[mailbox]@[host]"
-		"?cc=[cc]"
-		"&subject=[re][subject]"
+		"?subject=[re][subject]"
 		"&In-Reply-To=[<][messageID][>]"
+		"&cc="
 	};
 	struct Variable vars[] = {
 		{ "mailbox", envelope->replyTo.mailbox },
 		{ "host", envelope->replyTo.host },
-		{ "cc", baseMailto },
 		{ "re", (strncmp(envelope->subject, "Re: ", 4) ? "Re: " : "") },
 		{ "subject", envelope->subject },
 		{ "messageID", envelope->messageID },
@@ -125,7 +143,13 @@ static char *htmlReply(const struct Envelope *envelope) {
 		{ ">", ">" },
 		{0},
 	};
-	return templateString(template, vars, escapeURL);
+	int error = 0
+		|| templateRender(file, template, vars, escapeURL)
+		|| htmlReplyCc(file, true, envelope->to)
+		|| htmlReplyCc(file, false, envelope->cc)
+		|| fclose(file);
+	if (error) err(EX_OSERR, "open_memstream");
+	return buf;
 }
 
 int htmlMessageNav(FILE *file, const struct Envelope *envelope) {
@@ -528,7 +552,9 @@ int htmlIndexOpen(FILE *file) {
 				[+subscribe]
 				<a href="[subscribe]">subscribe</a>
 				[-]
+				[+mailto]
 				<a href="mailto:[mailto]">write</a>
+				[-]
 			</nav>
 		</header>
 		<main class="index">