]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
When assigning UIDs to mails, we tried to sort them with strcmp(), but that
authorTimo Sirainen <tss@iki.fi>
Thu, 26 Jun 2003 16:01:31 +0000 (19:01 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 26 Jun 2003 16:01:31 +0000 (19:01 +0300)
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

src/lib-index/maildir/maildir-sync.c

index f1c52a6457ef61e30035d52eace4571fba85f8e3..46a1a2774363520908c623fe59af3edec52c76f3 100644 (file)
@@ -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;