changeset 7593:2d367594b41c HEAD

dbox: Use POP3 UIDLs from metadata if they exist.
author Timo Sirainen <tss@iki.fi>
date Mon, 02 Jun 2008 20:01:42 +0300
parents c53e20911f07
children 8ae5268762b5
files src/lib-storage/index/dbox/dbox-file-maildir.c src/lib-storage/index/dbox/dbox-file.h src/lib-storage/index/dbox/dbox-mail.c src/lib-storage/index/dbox/dbox-sync-file.c
diffstat 4 files changed, 50 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-file-maildir.c	Mon Jun 02 20:00:45 2008 +0300
+++ b/src/lib-storage/index/dbox/dbox-file-maildir.c	Mon Jun 02 20:01:42 2008 +0300
@@ -73,6 +73,7 @@
 					      &size))
 			value = dec2str(size);
 		break;
+	case DBOX_METADATA_POP3_UIDL:
 	case DBOX_METADATA_EXPUNGED:
 	case DBOX_METADATA_EXT_REF:
 	case DBOX_METADATA_SPACE:
--- a/src/lib-storage/index/dbox/dbox-file.h	Mon Jun 02 20:00:45 2008 +0300
+++ b/src/lib-storage/index/dbox/dbox-file.h	Mon Jun 02 20:01:42 2008 +0300
@@ -54,15 +54,17 @@
 	DBOX_METADATA_FLAGS		= 'F',
 	/* Space separated list of keywords */
 	DBOX_METADATA_KEYWORDS		= 'K',
-	/* Pointer to external message data. Format is:
-	   1*(<start offset> <byte count> <ref>) */
-	DBOX_METADATA_EXT_REF		= 'P',
+	/* POP3 UIDL overriding the default format */
+	DBOX_METADATA_POP3_UIDL		= 'P',
 	/* Received UNIX timestamp in hex */
 	DBOX_METADATA_RECEIVED_TIME	= 'R',
 	/* Saved UNIX timestamp in hex */
 	DBOX_METADATA_SAVE_TIME		= 'S',
 	/* Virtual message size in hex (line feeds counted as CRLF) */
 	DBOX_METADATA_VIRTUAL_SIZE	= 'V',
+	/* Pointer to external message data. Format is:
+	   1*(<start offset> <byte count> <ref>) */
+	DBOX_METADATA_EXT_REF		= 'X',
 
 	/* End of metadata block. The spaces can be used for writing more
 	   metadata. */
--- a/src/lib-storage/index/dbox/dbox-mail.c	Mon Jun 02 20:00:45 2008 +0300
+++ b/src/lib-storage/index/dbox/dbox-mail.c	Mon Jun 02 20:01:42 2008 +0300
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "ioloop.h"
 #include "istream.h"
+#include "str.h"
 #include "index-mail.h"
 #include "dbox-storage.h"
 #include "dbox-file.h"
@@ -177,6 +178,47 @@
 }
 
 static int
+dbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
+		      const char **value_r)
+{
+	struct dbox_mail *mail = (struct dbox_mail *)_mail;
+	struct index_mail *imail = &mail->imail;
+	const unsigned int pop3_uidl_cache_field =
+		imail->ibox->cache_fields[MAIL_CACHE_POP3_UIDL].idx;
+	struct dbox_file *file;
+	const char *value;
+	string_t *str;
+
+	switch (field) {
+	case MAIL_FETCH_UIDL_BACKEND:
+		/* keep the UIDL in cache file, otherwise POP3 would open all
+		   mail files and read the metadata */
+		str = str_new(imail->data_pool, 64);
+		if (mail_cache_lookup_field(imail->trans->cache_view, str,
+					    _mail->seq,
+					    pop3_uidl_cache_field) > 0) {
+			*value_r = str_c(str);
+			return 0;
+		}
+
+		if (dbox_mail_metadata_seek(mail, &file) < 0)
+			return -1;
+
+		value = dbox_file_metadata_get(file, DBOX_METADATA_POP3_UIDL);
+		if (value == NULL)
+			value = "";
+		index_mail_cache_add_idx(imail, pop3_uidl_cache_field,
+					 value, strlen(value)+1);
+		*value_r = value;
+		return 0;
+	default:
+		break;
+	}
+
+	return index_mail_get_special(_mail, field, value_r);
+}
+							
+static int
 dbox_mail_get_stream(struct mail *_mail, struct message_size *hdr_size,
 		     struct message_size *body_size, struct istream **stream_r)
 {
@@ -236,7 +278,7 @@
 	index_mail_get_headers,
 	index_mail_get_header_stream,
 	dbox_mail_get_stream,
-	index_mail_get_special,
+	dbox_mail_get_special,
 	index_mail_update_flags,
 	index_mail_update_keywords,
 	index_mail_expunge,
--- a/src/lib-storage/index/dbox/dbox-sync-file.c	Mon Jun 02 20:00:45 2008 +0300
+++ b/src/lib-storage/index/dbox/dbox-sync-file.c	Mon Jun 02 20:01:42 2008 +0300
@@ -200,6 +200,7 @@
 		DBOX_METADATA_VIRTUAL_SIZE,
 		DBOX_METADATA_RECEIVED_TIME,
 		DBOX_METADATA_SAVE_TIME,
+		DBOX_METADATA_POP3_UIDL
 	};
 	struct dbox_index_append_context *append_ctx;
 	struct dbox_file *out_file;