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 --- atom.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 atom.c (limited to 'atom.c') 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; +} -- cgit 1.4.1