From 84aae6ed294e369c5edf755ef60fb963ce3bd7f7 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Thu, 9 Apr 2020 21:59:21 -0400 Subject: Render Atom envelopes --- Makefile | 1 + archive.c | 7 +++++++ archive.h | 2 ++ atom.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bubger.1 | 10 ++++++++++ 5 files changed, 81 insertions(+) create mode 100644 atom.c 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 + * + * 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 . + */ + +#include +#include +#include +#include +#include + +#include "archive.h" + +static const char *Envelope = TEMPLATE( + + [subject] + + [from.name] + [from.mailbox]@[from.host] + + [date] + [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 -- cgit 1.4.1