changeset 12988:bf0a80c91536

lib-storage: Added MAIL_FETCH_POP3_ORDER special field and implemented for Maildir. The idea is that this specifies the order of messages when accessing via POP3. This is useful when migrating both POP3 and IMAP users from servers where their message ordering differes and they still want to be preserved.
author Timo Sirainen <tss@iki.fi>
date Wed, 04 May 2011 11:42:17 +0200
parents 869795a295b5
children fac2d4fe86b1
files src/lib-storage/index/index-mail.c src/lib-storage/index/maildir/maildir-mail.c src/lib-storage/index/maildir/maildir-uidlist.h src/lib-storage/mail-storage.h
diffstat 4 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-mail.c	Wed May 04 10:17:27 2011 +0200
+++ b/src/lib-storage/index/index-mail.c	Wed May 04 11:42:17 2011 +0200
@@ -1076,6 +1076,7 @@
 	case MAIL_FETCH_SEARCH_SCORE:
 	case MAIL_FETCH_GUID:
 	case MAIL_FETCH_HEADER_MD5:
+	case MAIL_FETCH_POP3_ORDER:
 		*value_r = "";
 		return 0;
 	case MAIL_FETCH_MAILBOX_NAME:
--- a/src/lib-storage/index/maildir/maildir-mail.c	Wed May 04 10:17:27 2011 +0200
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Wed May 04 11:42:17 2011 +0200
@@ -471,7 +471,7 @@
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
 	struct maildir_mailbox *mbox = (struct maildir_mailbox *)_mail->box;
-	const char *path, *fname = NULL, *end, *guid, *uidl;
+	const char *path, *fname = NULL, *end, *guid, *uidl, *order;
 
 	switch (field) {
 	case MAIL_FETCH_GUID:
@@ -536,6 +536,15 @@
 			*value_r = p_strdup(mail->data_pool, uidl);
 		}
 		return 0;
+	case MAIL_FETCH_POP3_ORDER:
+		order = maildir_uidlist_lookup_ext(mbox->uidlist, _mail->uid,
+					MAILDIR_UIDLIST_REC_EXT_POP3_ORDER);
+		if (order == NULL) {
+			*value_r = "";
+		} else {
+			*value_r = p_strdup(mail->data_pool, order);
+		}
+		return 0;
 	default:
 		return index_mail_get_special(_mail, field, value_r);
 	}
--- a/src/lib-storage/index/maildir/maildir-uidlist.h	Wed May 04 10:17:27 2011 +0200
+++ b/src/lib-storage/index/maildir/maildir-uidlist.h	Wed May 04 11:42:17 2011 +0200
@@ -48,6 +48,11 @@
 	MAILDIR_UIDLIST_REC_EXT_VSIZE		= 'W',
 	/* POP3 UIDL overriding the default format */
 	MAILDIR_UIDLIST_REC_EXT_POP3_UIDL	= 'P',
+	/* POP3 message ordering number. Lower numbered messages are listed
+	   first. Messages without ordering number are listed after them.
+	   The idea is to be able to preserve POP3 UIDL list and IMAP UIDs
+	   perfectly when migrating from other servers. */
+	MAILDIR_UIDLIST_REC_EXT_POP3_ORDER	= 'O',
 	/* Message GUID (default is the base filename) */
 	MAILDIR_UIDLIST_REC_EXT_GUID		= 'G'
 };
--- a/src/lib-storage/mail-storage.h	Wed May 04 10:17:27 2011 +0200
+++ b/src/lib-storage/mail-storage.h	Wed May 04 11:42:17 2011 +0200
@@ -125,7 +125,8 @@
 	MAIL_FETCH_UIDL_BACKEND		= 0x00040000,
 	MAIL_FETCH_MAILBOX_NAME		= 0x00080000,
 	MAIL_FETCH_SEARCH_SCORE		= 0x00100000,
-	MAIL_FETCH_GUID			= 0x00200000
+	MAIL_FETCH_GUID			= 0x00200000,
+	MAIL_FETCH_POP3_ORDER		= 0x00400000
 };
 
 enum mailbox_transaction_flags {