From d031cf5f00de4bf6b33396f1a448833a6de33c5f Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 13 Apr 2020 12:43:56 -0400 Subject: Use UTC date everywhere I thought I could preserve the original time zone but it turns out that libc is just too shit to do that. --- archive.h | 3 +-- atom.c | 2 +- html.c | 9 +++------ parse.c | 13 ++++++------- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/archive.h b/archive.h index 6342236..0dac623 100644 --- a/archive.h +++ b/archive.h @@ -40,8 +40,7 @@ struct AddressList { }; struct Envelope { - time_t utc; - struct tm date; + time_t date; char *subject; struct Address from, sender, replyTo; struct AddressList to, cc, bcc; diff --git a/atom.c b/atom.c index 83a4457..aa98406 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->utc)); + strftime(date, sizeof(date), "%FT%TZ", gmtime(&envelope->date)); struct Variable vars[] = { { "subject", envelope->subject }, { "from.name", addressName(envelope->from) }, diff --git a/html.c b/html.c index e92ab0a..808e799 100644 --- a/html.c +++ b/html.c @@ -89,10 +89,8 @@ int htmlMessageHead(FILE *file, const struct Envelope *envelope) { ); char *mbox = templateURL("../message/[pathID].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)); + char date[sizeof("0000-00-00T00:00:00Z")]; + strftime(date, sizeof(date), "%FT%TZ", gmtime(&envelope->date)); struct Variable vars[] = { { "messageID", envelope->messageID }, { "fragment", fragment }, @@ -100,7 +98,6 @@ int htmlMessageHead(FILE *file, const struct Envelope *envelope) { { "mailto", mailto }, { "from", addressName(envelope->from) }, { "date", date }, - { "utc", utc }, { "mbox", mbox }, {0}, }; @@ -109,7 +106,7 @@ int htmlMessageHead(FILE *file, const struct Envelope *envelope) { [subject]
[from]
- + mbox
); diff --git a/parse.c b/parse.c index 6f1a56b..8d3205d 100644 --- a/parse.c +++ b/parse.c @@ -66,21 +66,20 @@ void parseEnvelope(struct Envelope *envelope, struct List list) { errx(EX_PROTOCOL, "missing envelope structure fields"); } + struct tm tm; const char *date = dataCheck(list.ptr[Date], String).string; if (isalpha(date[0])) { - date = strptime(date, "%a, %e %b %Y %H:%M:%S ", &envelope->date); + date = strptime(date, "%a, %e %b %Y %H:%M:%S ", &tm); } else { - date = strptime(date, "%e %b %Y %H:%M:%S ", &envelope->date); + date = strptime(date, "%e %b %Y %H:%M:%S ", &tm); } if (date && (date[0] == '+' || date[0] == '-')) { - date = strptime(date, "%z", &envelope->date); + date = strptime(date, "%z", &tm); } else if (date) { - date = strptime(date, "%Z", &envelope->date); + date = strptime(date, "%Z", &tm); } if (!date) errx(EX_PROTOCOL, "invalid envelope date format"); - - envelope->date.tm_isdst = -1; - envelope->utc = mktime(&envelope->date); + envelope->date = mktime(&tm); // TODO: Decode UTF-8 in subject. envelope->subject = strdup(dataCheck(list.ptr[Subject], String).string); -- cgit 1.4.1