From 77dc80bbbe942eef0453fc1e3b7782a2ddf29879 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 13 Apr 2020 13:13:37 -0400 Subject: Preserve original Date header in envelope --- archive.h | 3 ++- atom.c | 2 +- html.c | 9 +++++---- parse.c | 14 ++++++++------ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/archive.h b/archive.h index 0dac623..9ea15f4 100644 --- a/archive.h +++ b/archive.h @@ -40,7 +40,8 @@ struct AddressList { }; struct Envelope { - time_t date; + time_t time; + const char *date; char *subject; struct Address from, sender, replyTo; struct AddressList to, cc, bcc; diff --git a/atom.c b/atom.c index aa98406..98f5866 100644 --- a/atom.c +++ b/atom.c @@ -33,7 +33,7 @@ static char *atomID(const char *messageID) { int atomEntryOpen(FILE *file, const struct Envelope *envelope) { char *id = atomID(envelope->messageID); char date[sizeof("0000-00-00T00:00:00Z")]; - strftime(date, sizeof(date), "%FT%TZ", gmtime(&envelope->date)); + strftime(date, sizeof(date), "%FT%TZ", gmtime(&envelope->time)); struct Variable vars[] = { { "subject", envelope->subject }, { "from.name", addressName(envelope->from) }, diff --git a/html.c b/html.c index 808e799..1d28541 100644 --- a/html.c +++ b/html.c @@ -89,15 +89,16 @@ int htmlMessageHead(FILE *file, const struct Envelope *envelope) { ); char *mbox = templateURL("../message/[pathID].mbox", urlVars); - char date[sizeof("0000-00-00T00:00:00Z")]; - strftime(date, sizeof(date), "%FT%TZ", gmtime(&envelope->date)); + char utc[sizeof("0000-00-00T00:00:00Z")]; + strftime(utc, sizeof(utc), "%FT%TZ", gmtime(&envelope->time)); struct Variable vars[] = { { "messageID", envelope->messageID }, { "fragment", fragment }, { "subject", envelope->subject }, { "mailto", mailto }, { "from", addressName(envelope->from) }, - { "date", date }, + { "date", envelope->date }, + { "utc", utc }, { "mbox", mbox }, {0}, }; @@ -106,7 +107,7 @@ int htmlMessageHead(FILE *file, const struct Envelope *envelope) { [subject]
[from]
- + mbox
); diff --git a/parse.c b/parse.c index 8d3205d..ff97789 100644 --- a/parse.c +++ b/parse.c @@ -66,20 +66,22 @@ void parseEnvelope(struct Envelope *envelope, struct List list) { errx(EX_PROTOCOL, "missing envelope structure fields"); } - struct tm tm; + + struct tm time; const char *date = dataCheck(list.ptr[Date], String).string; + envelope->date = date; if (isalpha(date[0])) { - date = strptime(date, "%a, %e %b %Y %H:%M:%S ", &tm); + date = strptime(date, "%a, %e %b %Y %H:%M:%S ", &time); } else { - date = strptime(date, "%e %b %Y %H:%M:%S ", &tm); + date = strptime(date, "%e %b %Y %H:%M:%S ", &time); } if (date && (date[0] == '+' || date[0] == '-')) { - date = strptime(date, "%z", &tm); + date = strptime(date, "%z", &time); } else if (date) { - date = strptime(date, "%Z", &tm); + date = strptime(date, "%Z", &time); } if (!date) errx(EX_PROTOCOL, "invalid envelope date format"); - envelope->date = mktime(&tm); + envelope->time = mktime(&time); // TODO: Decode UTF-8 in subject. envelope->subject = strdup(dataCheck(list.ptr[Subject], String).string); -- cgit 1.4.1