about summary refs log tree commit diff
path: root/atom.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-10 17:22:13 -0400
committerJune McEnroe <june@causal.agency>2020-04-10 17:22:13 -0400
commit93aa78f326683d14f243f74809f7bf000d7faebf (patch)
tree31226dad12ccc6dac51d6649d514a84cf9132a61 /atom.c
parentConcatenate mbox threads (diff)
downloadbubger-93aa78f326683d14f243f74809f7bf000d7faebf.tar.gz
bubger-93aa78f326683d14f243f74809f7bf000d7faebf.zip
Concatenate Atom threads
Diffstat (limited to 'atom.c')
-rw-r--r--atom.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/atom.c b/atom.c
index 6692acc..2851e3c 100644
--- a/atom.c
+++ b/atom.c
@@ -22,13 +22,16 @@
 
 #include "archive.h"
 
-int atomEnvelope(FILE *file, const struct Envelope *envelope) {
-	struct Variable idVars[] = {
-		{ "messageID", envelope->messageID },
+static char *atomID(const char *messageID) {
+	struct Variable vars[] = {
+		{ "messageID", messageID },
 		{0},
 	};
-	char *id = templateURL("mailto:?In-Reply-To=[messageID]", idVars);
+	return templateURL("mailto:?In-Reply-To=[messageID]", vars);
+}
 
+int atomEntryHead(FILE *file, const struct Envelope *envelope) {
+	char *id = atomID(envelope->messageID);
 	char date[sizeof("0000-00-00T00:00:00Z")];
 	strftime(date, sizeof(date), "%FT%TZ", gmtime(&envelope->utc));
 	struct Variable vars[] = {
@@ -54,3 +57,43 @@ int atomEnvelope(FILE *file, const struct Envelope *envelope) {
 	free(id);
 	return error;
 }
+
+int atomEntryTail(FILE *file) {
+	int n = fprintf(file, "</entry>\n");
+	return (n < 0 ? n : 0);
+}
+
+int atomFeedHead(FILE *file, const struct Envelope *envelope) {
+	char *id = atomID(envelope->messageID);
+	char date[sizeof("0000-00-00T00:00:00Z")];
+	strftime(date, sizeof(date), "%FT%TZ", gmtime(&(time_t) { time(NULL) }));
+	struct Variable vars[] = {
+		{ "subject", envelope->subject },
+		{ "from.name", addressName(envelope->from) },
+		{ "from.mailbox", envelope->from.mailbox },
+		{ "from.host", envelope->from.host },
+		{ "date", date },
+		{ "id", id },
+		{ "q", "?" },
+		{0},
+	};
+	const char *Feed = TEMPLATE(
+		<[q]xml version="1.0" encoding="utf-8"[q]>
+		<feed xmlns="http://www.w3.org/2005/Atom">
+		<title>[subject]</title>
+		<author>
+			<name>[from.name]</name>
+			<email>[from.mailbox]@[from.host]</email>
+		</author>
+		<updated>[date]</updated>
+		<id>[id]</id>
+	);
+	int error = templateRender(file, Feed, vars, escapeXML);
+	free(id);
+	return error;
+}
+
+int atomFeedTail(FILE *file) {
+	int n = fprintf(file, "</feed>\n");
+	return (n < 0 ? n : 0);
+}