From feda48624bd8e5a321e81fbe19e45afa959d1367 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 1 Sep 2020 21:39:45 +0200 Subject: [PATCH] upas/fs: extract proper date from unix header do not try to parse the m->unixfrom field, it only contains the unix mail address. instead, have parseunix() save a pointer into the unixheader after the unix mail address for the unixdate, and later use it to derive the mails timestamp. --- sys/src/cmd/upas/fs/cache.c | 1 + sys/src/cmd/upas/fs/dat.h | 1 + sys/src/cmd/upas/fs/mbox.c | 7 +++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/src/cmd/upas/fs/cache.c b/sys/src/cmd/upas/fs/cache.c index 2b82e7967..1624835d9 100644 --- a/sys/src/cmd/upas/fs/cache.c +++ b/sys/src/cmd/upas/fs/cache.c @@ -77,6 +77,7 @@ cachefree(Mailbox *mb, Message *m) } free(m->unixfrom); m->unixfrom = nil; + m->unixdate = nil; free(m->unixheader); m->unixheader = nil; free(m->boundary); diff --git a/sys/src/cmd/upas/fs/dat.h b/sys/src/cmd/upas/fs/dat.h index 85958d638..d94479162 100644 --- a/sys/src/cmd/upas/fs/dat.h +++ b/sys/src/cmd/upas/fs/dat.h @@ -118,6 +118,7 @@ struct Message { /* mail info */ char *unixheader; char *unixfrom; + char *unixdate; char *references[Nref]; /* nil terminated unless full */ /* mime info */ diff --git a/sys/src/cmd/upas/fs/mbox.c b/sys/src/cmd/upas/fs/mbox.c index 7bb58b555..5b57dba41 100644 --- a/sys/src/cmd/upas/fs/mbox.c +++ b/sys/src/cmd/upas/fs/mbox.c @@ -365,7 +365,7 @@ datesec(Mailbox *mb, Message *m) if(m->fileid > 1000000ull<<8) return; - if(m->unixfrom && strtotm(m->unixfrom, &tm) >= 0) + if(m->unixdate && strtotm(m->unixdate, &tm) >= 0) v = tm2sec(&tm); else if(m->date822 && strtotm(m->date822, &tm) >= 0) v = tm2sec(&tm); @@ -482,13 +482,14 @@ parseunix(Message *m) char *s, *p; m->unixheader = smprint("%.*s", utfnlen(m->start, m->header - m->start), m->start); - s = m->start + 5; + s = m->unixheader + 5; if((p = strchr(s, ' ')) == nil) return; *p = 0; free(m->unixfrom); m->unixfrom = strdup(s); *p = ' '; + m->unixdate = ++p; } void @@ -572,6 +573,8 @@ parseheaders(Mailbox *mb, Message *m, int addfrom, int justmime) p = "???"; m->unixheader = smprint("From %s %Δ\n", p, m->fileid); } + m->unixdate = nil; + m->cstate |= Cheader; sanembmsg(mb, m); }