[PATCH/RFC 1/3] David Bremner's patch for custom maildir flags
Igor Almeida
igor.contato at gmail.com
Wed Nov 25 18:16:29 PST 2015
---
lib/database.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/notmuch.h | 18 +++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/lib/database.cc b/lib/database.cc
index 3b342f1..592cbcc 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1329,6 +1329,67 @@ notmuch_database_get_version (notmuch_database_t *notmuch)
return version;
}
+notmuch_status_t
+notmuch_database_get_maildir_keyword (notmuch_database_t *notmuch,
+ int index, const char **tag)
+{
+ string tag_string;
+ const char *key;
+ const char *str;
+
+ if (!notmuch || !tag)
+ return NOTMUCH_STATUS_NULL_POINTER;
+
+ if (index < 0 || index > ('z' - 'a'))
+ return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
+
+ key = talloc_asprintf(notmuch, "maildir_keyword_%c", 'a' + index);
+ if (!key)
+ return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
+ *tag = NULL;
+ tag_string = notmuch->xapian_db->get_metadata (key);
+ if (tag_string.empty ())
+ return NOTMUCH_STATUS_SUCCESS;
+
+ str = tag_string.c_str ();
+ if (str == NULL || *str == '\0')
+ return NOTMUCH_STATUS_SUCCESS;
+
+ *tag = str;
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
+notmuch_status_t
+notmuch_database_set_maildir_keyword (notmuch_database_t *notmuch,
+ int index, const char *tag)
+{
+ string tag_string;
+ const char *key;
+ notmuch_status_t ret;
+ Xapian::WritableDatabase *db;
+
+ if (!notmuch || !tag)
+ return NOTMUCH_STATUS_NULL_POINTER;
+
+ ret = _notmuch_database_ensure_writable (notmuch);
+ if (ret)
+ return ret;
+
+ if (index < 0 || index > ('z' - 'a'))
+ return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
+
+ key = talloc_asprintf(notmuch, "maildir_keyword_%c", 'a' + index);
+ if (!key)
+ return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
+ db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
+ db->set_metadata (key, tag);
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
notmuch_bool_t
notmuch_database_needs_upgrade (notmuch_database_t *notmuch)
{
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 310a8b8..779a5ea 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -674,6 +674,24 @@ notmuch_tags_t *
notmuch_database_get_all_tags (notmuch_database_t *db);
/**
+ * Return the tag corresponding to a maildir keyword.
+ *
+ */
+notmuch_status_t
+notmuch_database_get_maildir_keyword(notmuch_database_t *db,
+ int index, const char **tag);
+
+/**
+ * Set the tag corresponding to a maildir keyword.
+ *
+ * Note that no messages have their tags modified by this call.
+ */
+
+notmuch_status_t
+notmuch_database_set_maildir_keyword(notmuch_database_t *db,
+ int index, const char *tag);
+
+/**
* Create a new query for 'database'.
*
* Here, 'database' should be an open database, (see
--
2.5.3
More information about the notmuch
mailing list