changeset 1583:e5bd44be3f5a HEAD

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).
author Timo Sirainen <tss@iki.fi>
date Thu, 26 Jun 2003 19:01:31 +0300
parents 498a9b7797f2
children c7578350f135
files src/lib-index/maildir/maildir-sync.c
diffstat 1 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/maildir/maildir-sync.c	Thu Jun 26 17:59:23 2003 +0300
+++ b/src/lib-index/maildir/maildir-sync.c	Thu Jun 26 19:01:31 2003 +0300
@@ -443,6 +443,27 @@
 		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 @@
 
 	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;