changeset 885:1b3c679d2c6d HEAD

Make sure UIDs won't wrap around unexpectedly.
author Timo Sirainen <tss@iki.fi>
date Thu, 02 Jan 2003 13:29:24 +0200
parents c5897896c4f1
children 3a4f468a53c6
files src/lib-index/mail-index-open.c src/lib-index/mail-index.c src/lib-index/mail-index.h
diffstat 3 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-open.c	Thu Jan 02 13:06:36 2003 +0200
+++ b/src/lib-index/mail-index-open.c	Thu Jan 02 13:29:24 2003 +0200
@@ -139,7 +139,7 @@
 		index->first_recent_uid = hdr->last_nonrecent_uid+1;
 	}
 
-	if (hdr->next_uid >= INT_MAX-1024) {
+	if (hdr->next_uid >= MAX_ALLOWED_UID - 1000) {
 		/* UID values are getting too high, rebuild index */
 		index->set_flags |= MAIL_INDEX_FLAG_REBUILD;
 	}
--- a/src/lib-index/mail-index.c	Thu Jan 02 13:06:36 2003 +0200
+++ b/src/lib-index/mail-index.c	Thu Jan 02 13:29:24 2003 +0200
@@ -980,6 +980,13 @@
 {
 	i_assert(rec->uid == 0);
 
+	if (index->header->next_uid == MAX_ALLOWED_UID) {
+		index->set_flags |= MAIL_INDEX_FLAG_REBUILD;
+		index_set_error(index, "Reached maximum UID in mailbox %s, "
+				"rebuilding index", index->filepath);
+		return FALSE;
+	}
+
 	index->header->messages_count++;
 	rec->uid = index->header->next_uid++;
 
--- a/src/lib-index/mail-index.h	Thu Jan 02 13:06:36 2003 +0200
+++ b/src/lib-index/mail-index.h	Thu Jan 02 13:29:24 2003 +0200
@@ -478,6 +478,9 @@
 int mail_index_compress_data(MailIndex *index);
 int mail_index_truncate(MailIndex *index);
 
+/* Maximum allowed UID number. */
+#define MAX_ALLOWED_UID 4294967295U /* 2^32 - 1 */
+
 /* Max. mmap()ed size for a message */
 #define MAIL_MMAP_BLOCK_SIZE (1024*256)
 /* Block size when read()ing message. */