From: Timo Sirainen Date: Thu, 26 Jun 2003 16:01:31 +0000 (+0300) Subject: When assigning UIDs to mails, we tried to sort them with strcmp(), but that X-Git-Tag: 1.1.alpha1~4523 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c680e3baa8d6765325990615c42b881a24ccb36f;p=thirdparty%2Fdovecot%2Fcore.git When assigning UIDs to mails, we tried to sort them with strcmp(), but that wasn't actually working. Also we now sort properly the mails that had unix timestamp older than 1 billion (Sep 9 2001). --HG-- branch : HEAD --- diff --git a/src/lib-index/maildir/maildir-sync.c b/src/lib-index/maildir/maildir-sync.c index f1c52a6457..46a1a27743 100644 --- a/src/lib-index/maildir/maildir-sync.c +++ b/src/lib-index/maildir/maildir-sync.c @@ -443,6 +443,27 @@ static void uidlist_hash_get_filenames(void *key, void *value, void *context) buffer_append(buf, (const void *) &key, sizeof(const char *)); } +static int maildir_time_cmp(const void *p1, const void *p2) +{ + const char *s1 = *((const char **) p1); + const char *s2 = *((const char **) p2); + time_t t1 = 0, t2 = 0; + + /* we have to do numeric comparision, strcmp() will break when + there's different amount of digits (mostly the 999999999 -> + 1000000000 change in Sep 9 2001) */ + while (*s1 >= '0' && *s1 <= '9') { + t1 = t1*10 + (*s1 - '0'); + s1++; + } + while (*s2 >= '0' && *s2 <= '9') { + t2 = t2*10 + (*s2 - '0'); + s2++; + } + + return t1 < t2 ? -1 : t1 > t2 ? 1 : 0; +} + static int maildir_full_sync_finish(struct maildir_sync_context *ctx) { struct mail_index *index = ctx->index; @@ -647,7 +668,7 @@ static int maildir_full_sync_finish(struct maildir_sync_context *ctx) new_files = buffer_get_modifyable_data(buf, NULL); qsort(new_files, ctx->new_count, sizeof(const char *), - (int (*)(const void *, const void *)) strcmp); + maildir_time_cmp); if (!index->maildir_keep_new) { dir = ctx->cur_dir;