dovecot-2.2: lib-storage: Added MAIL_FETCH_REFCOUNT for getting ...

dovecot at dovecot.org dovecot at dovecot.org
Sun Feb 24 16:33:35 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/5e0c1ecad4a5
changeset: 15917:5e0c1ecad4a5
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Feb 24 16:33:24 2013 +0200
description:
lib-storage: Added MAIL_FETCH_REFCOUNT for getting mail's reference count.
This is useful only for backends where mailbox_copy() increases the
refcount. With maildir&sdbox it can be looked up from the file's link count.
With mdbox the refcount is stored in the map index. Other formats don't
currently implement this.

diffstat:

 src/lib-storage/index/dbox-multi/mdbox-mail.c  |  29 +++++++++++++++++++++++++-
 src/lib-storage/index/dbox-single/sdbox-mail.c |  28 ++++++++++++++++++++++++-
 src/lib-storage/index/index-mail.c             |   1 +
 src/lib-storage/index/maildir/maildir-mail.c   |   7 ++++++
 src/lib-storage/mail-storage.h                 |   3 +-
 5 files changed, 65 insertions(+), 3 deletions(-)

diffs (139 lines):

diff -r a4f82af20821 -r 5e0c1ecad4a5 src/lib-storage/index/dbox-multi/mdbox-mail.c
--- a/src/lib-storage/index/dbox-multi/mdbox-mail.c	Sun Feb 24 16:15:23 2013 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-mail.c	Sun Feb 24 16:33:24 2013 +0200
@@ -168,6 +168,33 @@
 	return 0;
 }
 
+static int
+mdbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
+		       const char **value_r)
+{
+	struct dbox_mail *mail = (struct dbox_mail *)_mail;
+	struct mdbox_mailbox *mbox =
+		(struct mdbox_mailbox *)_mail->transaction->box;
+	struct mdbox_map_mail_index_record rec;
+	uint32_t map_uid;
+	uint16_t refcount;
+
+	switch (field) {
+	case MAIL_FETCH_REFCOUNT:
+		if (mdbox_mail_lookup(mbox, _mail->transaction->view,
+				      _mail->seq, &map_uid) < 0)
+			return -1;
+		if (mdbox_map_lookup_full(mbox->storage->map, map_uid,
+					  &rec, &refcount) < 0)
+			return -1;
+		*value_r = p_strdup_printf(mail->imail.mail.data_pool, "%u",
+					   refcount);
+		return 0;
+	default:
+		return dbox_mail_get_special(_mail, field, value_r);
+	}
+}
+
 static void
 mdbox_mail_update_flags(struct mail *mail, enum modify_type modify_type,
 			enum mail_flags flags)
@@ -208,7 +235,7 @@
 	index_mail_get_header_stream,
 	dbox_mail_get_stream,
 	index_mail_get_binary_stream,
-	dbox_mail_get_special,
+	mdbox_mail_get_special,
 	index_mail_get_real_mail,
 	mdbox_mail_update_flags,
 	index_mail_update_keywords,
diff -r a4f82af20821 -r 5e0c1ecad4a5 src/lib-storage/index/dbox-single/sdbox-mail.c
--- a/src/lib-storage/index/dbox-single/sdbox-mail.c	Sun Feb 24 16:15:23 2013 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-mail.c	Sun Feb 24 16:33:24 2013 +0200
@@ -61,6 +61,32 @@
 	}
 }
 
+static int
+sdbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
+		       const char **value_r)
+{
+	struct dbox_mail *mail = (struct dbox_mail *)_mail;
+	struct stat st;
+
+	switch (field) {
+	case MAIL_FETCH_REFCOUNT:
+		if (sdbox_mail_file_set(mail) < 0)
+			return -1;
+
+		_mail->transaction->stats.fstat_lookup_count++;
+		if (dbox_file_stat(mail->open_file, &st) < 0) {
+			if (errno == ENOENT)
+				mail_set_expunged(_mail);
+			return -1;
+		}
+		*value_r = p_strdup_printf(mail->imail.mail.data_pool, "%lu",
+					   (unsigned long)st.st_nlink);
+		return 0;
+	default:
+		return dbox_mail_get_special(_mail, field, value_r);
+	}
+}
+
 int sdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
 		    struct dbox_file **file_r)
 {
@@ -118,7 +144,7 @@
 	index_mail_get_header_stream,
 	dbox_mail_get_stream,
 	index_mail_get_binary_stream,
-	dbox_mail_get_special,
+	sdbox_mail_get_special,
 	index_mail_get_real_mail,
 	index_mail_update_flags,
 	index_mail_update_keywords,
diff -r a4f82af20821 -r 5e0c1ecad4a5 src/lib-storage/index/index-mail.c
--- a/src/lib-storage/index/index-mail.c	Sun Feb 24 16:15:23 2013 +0200
+++ b/src/lib-storage/index/index-mail.c	Sun Feb 24 16:33:24 2013 +0200
@@ -1189,6 +1189,7 @@
 	case MAIL_FETCH_GUID:
 	case MAIL_FETCH_HEADER_MD5:
 	case MAIL_FETCH_POP3_ORDER:
+	case MAIL_FETCH_REFCOUNT:
 		*value_r = "";
 		return 0;
 	case MAIL_FETCH_MAILBOX_NAME:
diff -r a4f82af20821 -r 5e0c1ecad4a5 src/lib-storage/index/maildir/maildir-mail.c
--- a/src/lib-storage/index/maildir/maildir-mail.c	Sun Feb 24 16:15:23 2013 +0200
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Sun Feb 24 16:33:24 2013 +0200
@@ -475,6 +475,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, *order;
+	struct stat st;
 
 	switch (field) {
 	case MAIL_FETCH_GUID:
@@ -559,6 +560,12 @@
 			*value_r = p_strdup(mail->mail.data_pool, order);
 		}
 		return 0;
+	case MAIL_FETCH_REFCOUNT:
+		if (maildir_mail_stat(_mail, &st) < 0)
+			return -1;
+		*value_r = p_strdup_printf(mail->mail.data_pool, "%lu",
+					   (unsigned long)st.st_nlink);
+		return 0;
 	default:
 		return index_mail_get_special(_mail, field, value_r);
 	}
diff -r a4f82af20821 -r 5e0c1ecad4a5 src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h	Sun Feb 24 16:15:23 2013 +0200
+++ b/src/lib-storage/mail-storage.h	Sun Feb 24 16:33:24 2013 +0200
@@ -153,7 +153,8 @@
 	MAIL_FETCH_MAILBOX_NAME		= 0x00080000,
 	MAIL_FETCH_SEARCH_RELEVANCY	= 0x00100000,
 	MAIL_FETCH_GUID			= 0x00200000,
-	MAIL_FETCH_POP3_ORDER		= 0x00400000
+	MAIL_FETCH_POP3_ORDER		= 0x00400000,
+	MAIL_FETCH_REFCOUNT		= 0x00800000
 };
 
 enum mailbox_transaction_flags {


More information about the dovecot-cvs mailing list