Skip to content

Commit

Permalink
index.c: use struct timespec to store internaldate in MsgData
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison committed Jan 16, 2025
1 parent 4bcfc06 commit 149aeb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions imap/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion imap/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand Down

0 comments on commit 149aeb8

Please sign in to comment.