From 149aeb8e0dba8591b6fc239dd1755841a2608adb Mon Sep 17 00:00:00 2001 From: Ken Murchison Date: Thu, 16 Jan 2025 15:50:00 -0500 Subject: [PATCH] index.c: use struct timespec to store internaldate in MsgData --- imap/index.c | 29 ++++++++++++++++------------- imap/index.h | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/imap/index.c b/imap/index.c index c4613790a0..8f5fcc3a20 100644 --- a/imap/index.c +++ b/imap/index.c @@ -6333,7 +6333,8 @@ MsgData **index_msgdata_load(struct index_state *state, cur->sentdate = record.gmtime; /* fall through */ case SORT_ARRIVAL: - cur->internaldate = record.internaldate.tv_sec; + cur->internaldate.tv_sec = record.internaldate.tv_sec; + cur->internaldate.tv_nsec = record.internaldate.tv_nsec; break; case SORT_FROM: cur->from = get_localpart_addr(cacheitem_base(&record, CACHE_FROM)); @@ -6376,7 +6377,8 @@ MsgData **index_msgdata_load(struct index_state *state, } else { /* If not in mailboxId, we use receivedAt */ - cur->internaldate = record.internaldate.tv_sec; + cur->internaldate.tv_sec = record.internaldate.tv_sec; + cur->internaldate.tv_nsec = record.internaldate.tv_nsec; } break; case SORT_SNOOZEDUNTIL: @@ -6402,7 +6404,8 @@ MsgData **index_msgdata_load(struct index_state *state, #endif if (!cur->savedate) { /* If not snoozed in mailboxId, we use receivedAt */ - cur->internaldate = record.internaldate.tv_sec; + cur->internaldate.tv_sec = record.internaldate.tv_sec; + cur->internaldate.tv_nsec = record.internaldate.tv_nsec; } break; case LOAD_IDS: @@ -6768,21 +6771,21 @@ static int index_sort_compare(MsgData *md1, MsgData *md2, ret = numcmp(md1->msgno, md2->msgno); break; case SORT_ARRIVAL: - ret = numcmp(md1->internaldate, md2->internaldate); + ret = numcmp(md1->internaldate.tv_sec, md2->internaldate.tv_sec); break; case SORT_CC: ret = strcmpsafe(md1->cc, md2->cc); break; case SORT_DATE: { - time_t d1 = md1->sentdate ? md1->sentdate : md1->internaldate; - time_t d2 = md2->sentdate ? md2->sentdate : md2->internaldate; + time_t d1 = md1->sentdate ? md1->sentdate : md1->internaldate.tv_sec; + time_t d2 = md2->sentdate ? md2->sentdate : md2->internaldate.tv_sec; ret = numcmp(d1, d2); break; } case SORT_SNOOZEDUNTIL: case SORT_SAVEDATE: { - time_t d1 = md1->savedate ? md1->savedate : md1->internaldate; - time_t d2 = md2->savedate ? md2->savedate : md2->internaldate; + time_t d1 = md1->savedate ? md1->savedate : md1->internaldate.tv_sec; + time_t d2 = md2->savedate ? md2->savedate : md2->internaldate.tv_sec; ret = numcmp(d1, d2); break; } @@ -6982,7 +6985,7 @@ static int index_sort_compare_arrival(const void *v1, const void *v2) MsgData *md2 = *(MsgData **)v2; int ret; - ret = md1->internaldate - md2->internaldate; + ret = md1->internaldate.tv_sec - md2->internaldate.tv_sec; if (ret) return ret; ret = md1->createdmodseq - md2->createdmodseq; @@ -7004,7 +7007,7 @@ static int index_sort_compare_reverse_arrival(const void *v1, const void *v2) MsgData *md2 = *(MsgData **)v2; int ret; - ret = md2->internaldate - md1->internaldate; + ret = md2->internaldate.tv_sec - md1->internaldate.tv_sec; if (ret) return ret; ret = md2->createdmodseq - md1->createdmodseq; @@ -7029,7 +7032,7 @@ static int index_sort_compare_reverse_flagged(const void *v1, const void *v2) ret = md2->hasflag - md1->hasflag; if (ret) return ret; - ret = md2->internaldate - md1->internaldate; + ret = md2->internaldate.tv_sec - md1->internaldate.tv_sec; if (ret) return ret; ret = md2->createdmodseq - md1->createdmodseq; @@ -7937,8 +7940,8 @@ static void find_most_recent(Thread *thread, MsgData *recent) Thread *child; /* test the head node */ - if (thread->msgdata->internaldate > recent->internaldate) - recent->internaldate = thread->msgdata->internaldate; + if (thread->msgdata->internaldate.tv_sec > recent->internaldate.tv_sec) + recent->internaldate.tv_sec = thread->msgdata->internaldate.tv_sec; /* test the children recursively */ child = thread->child; diff --git a/imap/index.h b/imap/index.h index dc9283eadc..e39a3deed7 100644 --- a/imap/index.h +++ b/imap/index.h @@ -163,7 +163,7 @@ typedef struct msgdata { strarray_t ref; /* array of references */ time_t sentdate; /* sent date & time of message from Date: header (adjusted by time zone) */ - time_t internaldate; /* internaldate */ + struct timespec internaldate;/* internaldate */ time_t savedate; /* savedate */ size_t size; /* message size */ modseq_t modseq; /* modseq of record*/