From 93aa78f326683d14f243f74809f7bf000d7faebf Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 10 Apr 2020 17:22:13 -0400 Subject: Concatenate Atom threads --- atom.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'atom.c') 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, "\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]> + + [subject] + + [from.name] + [from.mailbox]@[from.host] + + [date] + [id] + ); + int error = templateRender(file, Feed, vars, escapeXML); + free(id); + return error; +} + +int atomFeedTail(FILE *file) { + int n = fprintf(file, "\n"); + return (n < 0 ? n : 0); +} -- cgit 1.4.1