/* 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 #include #include "archive.h" static const char *Mailto = { "mailto:[mailbox]@[host]?subject=[re][subject]&In-Reply-To=[messageID]" }; static const char *Envelope = TEMPLATE(

[subject]

[from]
); int htmlEnvelope(FILE *file, const struct Envelope *envelope) { struct Variable mailtoVars[] = { { "mailbox", envelope->from.mailbox }, { "host", envelope->from.host }, { "re", (strncmp(envelope->subject, "Re: ", 4) ? "Re: " : "") }, { "subject", envelope->subject }, { "messageID", envelope->messageID }, {0}, }; size_t cap = sizeof(Mailto); for (struct Variable *var = mailtoVars; var->value; ++var) { cap += ESCAPE_URL_CAP(strlen(var->value)); } char *mailto = malloc(cap); if (!mailto) err(EX_OSERR, "malloc"); FILE *url = fmemopen(mailto, cap, "w"); if (!url) err(EX_OSERR, "fmemopen"); int error = 0 || templateRender(url, Mailto, mailtoVars, escapeURL) || fclose(url); assert(!error); const char *from = envelope->from.name; if (!from) from = envelope->from.mailbox; char utc[sizeof("0000-00-00T00:00:00Z")]; strftime(utc, sizeof(utc), "%FT%TZ", gmtime(&envelope->utc)); char date[256]; strftime(date, sizeof(date), "%c %z", &envelope->date); struct Variable vars[] = { { "messageID", envelope->messageID }, { "subject", envelope->subject }, { "mailto", mailto }, { "from", from }, { "utc", utc }, { "date", date }, {0}, }; error = templateRender(file, Envelope, vars, escapeXML); free(mailto); return error; }