/* 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 int htmlAddress(FILE *file, const char *class, struct Address addr) { struct Variable vars[] = { { "class", class }, { "name", addressName(addr) }, { "mailbox", addr.mailbox }, {0}, }; if (addr.host) { return templateRender( file, TEMPLATE(
  • [name]
  • ), vars, escapeXML ); } else if (addr.mailbox) { return templateRender( file, TEMPLATE(
  • [mailbox]
      ), vars, escapeXML ); } else { return templateRender( file, TEMPLATE(
  • ), vars, escapeXML ); } } static int htmlAddressList(FILE *file, const char *class, struct AddressList list) { if (!list.len) return 0; struct Variable vars[] = { { "class", class }, {0}, }; int error = templateRender( file, TEMPLATE(
      ), vars, escapeXML ); if (error) return error; for (size_t i = 0; i < list.len; ++i) { error = htmlAddress(file, class, list.addrs[i]); if (error) return error; } return templateRender(file, TEMPLATE(
    ), vars, escapeXML); } int htmlMessageHead(FILE *file, const struct Envelope *envelope) { struct Variable urlVars[] = { { "mailbox", envelope->replyTo.mailbox }, { "host", envelope->replyTo.host }, { "re", (strncmp(envelope->subject, "Re: ", 4) ? "Re: " : "") }, { "subject", envelope->subject }, { "messageID", envelope->messageID }, {0}, }; char *fragment = templateURL("#[messageID]", urlVars); char *mailto = templateURL( "mailto:[mailbox]@[host]?subject=[re][subject]&In-Reply-To=[messageID]", urlVars ); char *mbox = templateURL("../message/[messageID].mbox", urlVars); char date[256]; char utc[sizeof("0000-00-00T00:00:00Z")]; strftime(date, sizeof(date), "%c %z", &envelope->date); strftime(utc, sizeof(utc), "%FT%TZ", gmtime(&envelope->utc)); struct Variable vars[] = { { "messageID", envelope->messageID }, { "fragment", fragment }, { "subject", envelope->subject }, { "mailto", mailto }, { "from", addressName(envelope->from) }, { "date", date }, { "utc", utc }, { "mbox", mbox }, {0}, }; const char *Summary = TEMPLATE(
    [subject]
    [from]
    mbox
    ); int error = templateRender(file, Summary, vars, escapeXML); free(fragment); free(mailto); free(mbox); if (error) return error; return 0 || htmlAddressList(file, "to", envelope->to) || htmlAddressList(file, "cc", envelope->cc); } int htmlMessageTail(FILE *file) { int n = fprintf(file, "
    \n"); return (n < 0 ? n : 0); }