summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--archive.c7
-rw-r--r--archive.h2
-rw-r--r--atom.c61
-rw-r--r--bubger.110
5 files changed, 81 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 74b0de4..106ceda 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,7 @@ CFLAGS += -std=c11 -Wall -Wextra -Wpedantic
 LDLIBS = -ltls
 
 OBJS += archive.o
+OBJS += atom.o
 OBJS += html.o
 OBJS += imap.o
 OBJS += mbox.o
diff --git a/archive.c b/archive.c
index ca56c8c..b045a7a 100644
--- a/archive.c
+++ b/archive.c
@@ -263,6 +263,13 @@ static void exportMessage(struct List items) {
 		|| fclose(file);
 	if (error) err(EX_IOERR, "%s", path);
 
+	path = uidPath(uid, "atom");
+	file = fopen(path, "w");
+	if (!file) err(EX_CANTCREAT, "%s", path);
+	error = atomEnvelope(file, &envelope)
+		|| fclose(file);
+	if (error) err(EX_IOERR, "%s", path);
+
 	envelopeFree(envelope);
 }
 
diff --git a/archive.h b/archive.h
index 5a80748..cc29953 100644
--- a/archive.h
+++ b/archive.h
@@ -86,3 +86,5 @@ int mboxHeader(FILE *file, char *header);
 int mboxBody(FILE *file, char *body);
 
 int htmlEnvelope(FILE *file, const struct Envelope *envelope);
+
+int atomEnvelope(FILE *file, const struct Envelope *envelope);
diff --git a/atom.c b/atom.c
new file mode 100644
index 0000000..8991ca7
--- /dev/null
+++ b/atom.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 2020  C. McEnroe <june@causal.agency>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sysexits.h>
+#include <time.h>
+
+#include "archive.h"
+
+static const char *Envelope = TEMPLATE(
+	<entry>
+	<title>[subject]</title>
+	<author>
+		<name>[from.name]</name>
+		<email>[from.mailbox]@[from.host]</email>
+	</author>
+	<updated>[date]</updated>
+	<id>[id]</id>
+);
+
+int atomEnvelope(FILE *file, const struct Envelope *envelope) {
+	const char *from = envelope->from.name;
+	if (!from) from = envelope->from.mailbox;
+
+	char date[sizeof("0000-00-00T00:00:00Z")];
+	strftime(date, sizeof(date), "%FT%TZ", gmtime(&envelope->utc));
+
+	struct Variable idVars[] = {
+		{ "messageID", envelope->messageID },
+		{0},
+	};
+	char *id = templateURL("mailto:?In-Reply-To=[messageID]", idVars);
+
+	struct Variable vars[] = {
+		{ "subject", envelope->subject },
+		{ "from.name", from },
+		{ "from.mailbox", envelope->from.mailbox },
+		{ "from.host", envelope->from.host },
+		{ "date", date },
+		{ "id", id },
+		{0},
+	};
+	int error = templateRender(file, Envelope, vars, escapeXML);
+	free(id);
+	return error;
+}
diff --git a/bubger.1 b/bubger.1
index df02b5a..68a3adb 100644
--- a/bubger.1
+++ b/bubger.1
@@ -133,6 +133,16 @@ Rendered Atom, HTML and mboxrd files for each thread.
 .Re
 .It
 .Rs
+.%A M. Nottingham
+.%A R. Sayre
+.%T The Atom Syndication Format
+.%I IETF
+.%N RFC 4287
+.%D December 2005
+.%U https://tools.ietf.org/html/rfc4287
+.Re
+.It
+.Rs
 .%A T. Berners-Lee
 .%A L. Masinter
 .%A M. McCahill