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

[subject]

[from]
); static const char *Address = TEMPLATE(
  • [name]
  • ); int htmlEnvelope(FILE *file, const struct Envelope *envelope) { struct Variable fragmentVars[] = { { "messageID", envelope->messageID }, {0}, }; char *fragment = templateURL("#[messageID]", fragmentVars); struct Variable mailtoVars[] = { { "mailbox", envelope->replyTo.mailbox }, { "host", envelope->replyTo.host }, { "re", (strncmp(envelope->subject, "Re: ", 4) ? "Re: " : "") }, { "subject", envelope->subject }, { "messageID", envelope->messageID }, {0}, }; char *mailto = templateURL(Mailto, mailtoVars); 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 summaryVars[] = { { "messageID", envelope->messageID }, { "fragment", fragment }, { "subject", envelope->subject }, { "mailto", mailto }, { "from", from }, { "utc", utc }, { "date", date }, {0}, }; int error = templateRender(file, Summary, summaryVars, escapeXML); free(fragment); free(mailto); if (error) return error; if (0 > fprintf(file, "
    To:
      ")) return -1; for (size_t i = 0; i < envelope->to.len; ++i) { struct Address addr = envelope->to.addrs[i]; struct Variable vars[] = { { "class", "to" }, { "name", (addr.name ? addr.name : addr.mailbox) }, {0}, }; error = templateRender(file, Address, vars, escapeXML); if (error) return error; } if (0 > fprintf(file, "
    Cc:
      ")) return -1; for (size_t i = 0; i < envelope->cc.len; ++i) { struct Address addr = envelope->cc.addrs[i]; struct Variable vars[] = { { "class", "cc" }, { "name", (addr.name ? addr.name : addr.mailbox) }, {0}, }; error = templateRender(file, Address, vars, escapeXML); if (error) return error; } if (0 > fprintf(file, "
    ")) return -1; return 0; }