dovecot-2.2: mail-storage: Moved mailbox attributes API to separ...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 4 16:56:39 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/5f43c88e2c87
changeset: 18516:5f43c88e2c87
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Mon May 04 19:53:53 2015 +0300
description:
mail-storage: Moved mailbox attributes API to separate module.

diffstat:

 src/lib-storage/Makefile.am                 |    3 +
 src/lib-storage/mail-storage-private.h      |    8 +-
 src/lib-storage/mail-storage.c              |   97 -------------------------
 src/lib-storage/mail-storage.h              |   67 +-----------------
 src/lib-storage/mailbox-attribute-private.h |   12 +++
 src/lib-storage/mailbox-attribute.c         |  108 ++++++++++++++++++++++++++++
 src/lib-storage/mailbox-attribute.h         |   77 +++++++++++++++++++
 7 files changed, 202 insertions(+), 170 deletions(-)

diffs (truncated from 459 to 300 lines):

diff -r 6403ccd2f5f9 -r 5f43c88e2c87 src/lib-storage/Makefile.am
--- a/src/lib-storage/Makefile.am	Mon May 04 19:15:10 2015 +0300
+++ b/src/lib-storage/Makefile.am	Mon May 04 19:53:53 2015 +0300
@@ -43,6 +43,7 @@
 	mail-storage-settings.c \
 	mail-thread.c \
 	mail-user.c \
+	mailbox-attribute.c \
 	mailbox-get.c \
 	mailbox-guid-cache.c \
 	mailbox-header.c \
@@ -70,6 +71,8 @@
 	mail-storage-service.h \
 	mail-storage-settings.h \
 	mail-user.h \
+	mailbox-attribute.h \
+	mailbox-attribute-private.h \
 	mailbox-guid-cache.h \
 	mailbox-list.h \
 	mailbox-list-iter.h \
diff -r 6403ccd2f5f9 -r 5f43c88e2c87 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Mon May 04 19:15:10 2015 +0300
+++ b/src/lib-storage/mail-storage-private.h	Mon May 04 19:53:53 2015 +0300
@@ -7,6 +7,7 @@
 #include "mail-storage.h"
 #include "mail-storage-hooks.h"
 #include "mail-storage-settings.h"
+#include "mailbox-attribute-private.h"
 #include "mail-index-private.h"
 
 /* Default prefix for indexes */
@@ -602,10 +603,6 @@
 	unsigned int *idx;
 };
 
-struct mailbox_attribute_iter {
-	struct mailbox *box;
-};
-
 /* Modules should use do "my_id = mail_storage_module_id++" and
    use objects' module_contexts[id] for their own purposes. */
 extern struct mail_storage_module_register mail_storage_module_register;
@@ -678,9 +675,6 @@
 unsigned int mail_storage_get_lock_timeout(struct mail_storage *storage,
 					   unsigned int secs);
 void mail_storage_free_binary_cache(struct mail_storage *storage);
-int mailbox_attribute_value_to_string(struct mail_storage *storage,
-				      const struct mail_attribute_value *value,
-				      const char **str_r);
 
 enum mail_index_open_flags
 mail_storage_settings_to_index_flags(const struct mail_storage_settings *set);
diff -r 6403ccd2f5f9 -r 5f43c88e2c87 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Mon May 04 19:15:10 2015 +0300
+++ b/src/lib-storage/mail-storage.c	Mon May 04 19:53:53 2015 +0300
@@ -1633,103 +1633,6 @@
 		return 0;
 }
 
-int mailbox_attribute_set(struct mailbox_transaction_context *t,
-			  enum mail_attribute_type type, const char *key,
-			  const struct mail_attribute_value *value)
-{
-	return t->box->v.attribute_set(t, type, key, value);
-}
-
-int mailbox_attribute_unset(struct mailbox_transaction_context *t,
-			    enum mail_attribute_type type, const char *key)
-{
-	struct mail_attribute_value value;
-
-	memset(&value, 0, sizeof(value));
-	return t->box->v.attribute_set(t, type, key, &value);
-}
-
-int mailbox_attribute_value_to_string(struct mail_storage *storage,
-				      const struct mail_attribute_value *value,
-				      const char **str_r)
-{
-	string_t *str;
-	const unsigned char *data;
-	size_t size;
-
-	if (value->value_stream == NULL) {
-		*str_r = value->value;
-		return 0;
-	}
-	str = t_str_new(128);
-	i_stream_seek(value->value_stream, 0);
-	while (i_stream_read_data(value->value_stream, &data, &size, 0) > 0) {
-		if (memchr(data, '\0', size) != NULL) {
-			mail_storage_set_error(storage, MAIL_ERROR_PARAMS,
-				"Attribute string value has NULs");
-			return -1;
-		}
-		str_append_n(str, data, size);
-		i_stream_skip(value->value_stream, size);
-	}
-	if (value->value_stream->stream_errno != 0) {
-		mail_storage_set_critical(storage, "read(%s) failed: %s",
-			i_stream_get_name(value->value_stream),
-			i_stream_get_error(value->value_stream));
-		return -1;
-	}
-	i_assert(value->value_stream->eof);
-	*str_r = str_c(str);
-	return 0;
-}
-
-int mailbox_attribute_get(struct mailbox_transaction_context *t,
-			  enum mail_attribute_type type, const char *key,
-			  struct mail_attribute_value *value_r)
-{
-	int ret;
-
-	memset(value_r, 0, sizeof(*value_r));
-	if ((ret = t->box->v.attribute_get(t, type, key, value_r)) <= 0)
-		return ret;
-	i_assert(value_r->value != NULL);
-	return 1;
-}
-
-int mailbox_attribute_get_stream(struct mailbox_transaction_context *t,
-				 enum mail_attribute_type type, const char *key,
-				 struct mail_attribute_value *value_r)
-{
-	int ret;
-
-	memset(value_r, 0, sizeof(*value_r));
-	value_r->flags |= MAIL_ATTRIBUTE_VALUE_FLAG_INT_STREAMS;
-	if ((ret = t->box->v.attribute_get(t, type, key, value_r)) <= 0)
-		return ret;
-	i_assert(value_r->value != NULL || value_r->value_stream != NULL);
-	return 1;
-}
-
-struct mailbox_attribute_iter *
-mailbox_attribute_iter_init(struct mailbox *box, enum mail_attribute_type type,
-			    const char *prefix)
-{
-	return box->v.attribute_iter_init(box, type, prefix);
-}
-
-const char *mailbox_attribute_iter_next(struct mailbox_attribute_iter *iter)
-{
-	return iter->box->v.attribute_iter_next(iter);
-}
-
-int mailbox_attribute_iter_deinit(struct mailbox_attribute_iter **_iter)
-{
-	struct mailbox_attribute_iter *iter = *_iter;
-
-	*_iter = NULL;
-	return iter->box->v.attribute_iter_deinit(iter);
-}
-
 struct mailbox_sync_context *
 mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 {
diff -r 6403ccd2f5f9 -r 5f43c88e2c87 src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h	Mon May 04 19:15:10 2015 +0300
+++ b/src/lib-storage/mail-storage.h	Mon May 04 19:53:53 2015 +0300
@@ -10,6 +10,7 @@
 #include "mail-error.h"
 #include "mail-namespace.h"
 #include "mailbox-list.h"
+#include "mailbox-attribute.h"
 
 /* If some operation is taking long, call notify_ok every n seconds. */
 #define MAIL_STORAGE_STAYALIVE_SECS 15
@@ -205,42 +206,6 @@
 	MAILBOX_SYNC_TYPE_MODSEQ	= 0x04
 };
 
-/* RFC 5464 specifies that this is vendor/<vendor-token>/. The registered
-   vendor-tokens always begin with "vendor." so there's some redundancy.. */
-#define MAILBOX_ATTRIBUTE_PREFIX_DOVECOT "vendor/vendor.dovecot/"
-/* Prefix used for attributes reserved for Dovecot's internal use. Normal
-   users cannot access these in any way. */
-#define MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT \
-	MAILBOX_ATTRIBUTE_PREFIX_DOVECOT"pvt/"
-/* Prefix used for server attributes in INBOX. INBOX deletion won't delete
-   any attributes under this prefix. */
-#define MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER \
-	MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT"server/"
-
-enum mail_attribute_type {
-	MAIL_ATTRIBUTE_TYPE_PRIVATE,
-	MAIL_ATTRIBUTE_TYPE_SHARED
-};
-enum mail_attribute_value_flags {
-	MAIL_ATTRIBUTE_VALUE_FLAG_READONLY	= 0x01,
-	MAIL_ATTRIBUTE_VALUE_FLAG_INT_STREAMS	= 0x02
-};
-
-struct mail_attribute_value {
-	/* mailbox_attribute_set() can set either value or value_stream.
-	   mailbox_attribute_get() returns only values, but
-	   mailbox_attribute_get_stream() may return either value or
-	   value_stream. The caller must unreference the returned streams. */
-	const char *value;
-	struct istream *value_stream;
-
-	/* Last time the attribute was changed (0 = unknown). This may be
-	   returned even for values that don't exist anymore. */
-	time_t last_change;
-
-	enum mail_attribute_value_flags flags;
-};
-
 struct message_part;
 struct mail_namespace;
 struct mail_storage;
@@ -583,36 +548,6 @@
    (as opposed to flags shared between users). */
 enum mail_flags mailbox_get_private_flags_mask(struct mailbox *box);
 
-/* Set mailbox attribute key to value. The key should be compatible with
-   IMAP METADATA, so for Dovecot-specific keys use
-   MAILBOX_ATTRIBUTE_PREFIX_DOVECOT. */
-int mailbox_attribute_set(struct mailbox_transaction_context *t,
-			  enum mail_attribute_type type, const char *key,
-			  const struct mail_attribute_value *value);
-/* Delete mailbox attribute key. This is just a wrapper to
-   mailbox_attribute_set() with value->value=NULL. */
-int mailbox_attribute_unset(struct mailbox_transaction_context *t,
-			    enum mail_attribute_type type, const char *key);
-/* Returns value for mailbox attribute key. Returns 1 if value was returned,
-   0 if value wasn't found (set to NULL), -1 if error */
-int mailbox_attribute_get(struct mailbox_transaction_context *t,
-			  enum mail_attribute_type type, const char *key,
-			  struct mail_attribute_value *value_r);
-/* Same as mailbox_attribute_get(), but the returned value may be either an
-   input stream or a string. */
-int mailbox_attribute_get_stream(struct mailbox_transaction_context *t,
-				 enum mail_attribute_type type, const char *key,
-				 struct mail_attribute_value *value_r);
-
-/* Iterate through mailbox attributes of the given type. The prefix can be used
-   to restrict what attributes are returned. */
-struct mailbox_attribute_iter *
-mailbox_attribute_iter_init(struct mailbox *box, enum mail_attribute_type type,
-			    const char *prefix);
-/* Returns the attribute key or NULL if there are no more attributes. */
-const char *mailbox_attribute_iter_next(struct mailbox_attribute_iter *iter);
-int mailbox_attribute_iter_deinit(struct mailbox_attribute_iter **iter);
-
 /* Synchronize the mailbox. */
 struct mailbox_sync_context *
 mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags);
diff -r 6403ccd2f5f9 -r 5f43c88e2c87 src/lib-storage/mailbox-attribute-private.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-storage/mailbox-attribute-private.h	Mon May 04 19:53:53 2015 +0300
@@ -0,0 +1,12 @@
+#ifndef MAILBOX_ATTRIBUTE_PRIVATE_H
+#define MAILBOX_ATTRIBUTE_PRIVATE_H
+
+struct mailbox_attribute_iter {
+	struct mailbox *box;
+};
+
+int mailbox_attribute_value_to_string(struct mail_storage *storage,
+				      const struct mail_attribute_value *value,
+				      const char **str_r);
+
+#endif
diff -r 6403ccd2f5f9 -r 5f43c88e2c87 src/lib-storage/mailbox-attribute.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-storage/mailbox-attribute.c	Mon May 04 19:53:53 2015 +0300
@@ -0,0 +1,108 @@
+/* Copyright (c) 2003-2015 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "str.h"
+#include "istream.h"
+#include "mail-storage-private.h"
+
+/*
+ * Attribute API
+ */
+
+int mailbox_attribute_set(struct mailbox_transaction_context *t,
+			  enum mail_attribute_type type, const char *key,
+			  const struct mail_attribute_value *value)
+{
+	return t->box->v.attribute_set(t, type, key, value);
+}
+
+int mailbox_attribute_unset(struct mailbox_transaction_context *t,
+			    enum mail_attribute_type type, const char *key)
+{
+	struct mail_attribute_value value;
+
+	memset(&value, 0, sizeof(value));
+	return t->box->v.attribute_set(t, type, key, &value);
+}
+
+int mailbox_attribute_value_to_string(struct mail_storage *storage,
+				      const struct mail_attribute_value *value,
+				      const char **str_r)


More information about the dovecot-cvs mailing list