[PATCH] RFC: all deleting all properties with a given key

David Bremner david at tethera.net
Sat Jul 16 03:32:54 PDT 2016


---

I think I somewhat prefer this way of providing the same
functionality, because the control flow is simpler. If it seems
useful, we could forward remove_property with a NULL value to
remove_all_properties

 lib/message-property.cc | 11 +++++++++--
 lib/notmuch.h           |  5 ++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/message-property.cc b/lib/message-property.cc
index edc6f2f..c6cff33 100644
--- a/lib/message-property.cc
+++ b/lib/message-property.cc
@@ -98,16 +98,23 @@ notmuch_message_remove_property (notmuch_message_t *message, const char *key, co
 }
 
 notmuch_status_t
-notmuch_message_remove_all_properties (notmuch_message_t *message)
+notmuch_message_remove_all_properties (notmuch_message_t *message, const char *key)
 {
     notmuch_status_t status;
+    const char * term_prefix;
+
     status = _notmuch_database_ensure_writable (_notmuch_message_database (message));
     if (status)
 	return status;
 
     _notmuch_message_invalidate_metadata (message, "property");
+    if (key)
+	term_prefix = talloc_asprintf (message, "%s%s=", _find_prefix ("property"), key);
+    else
+	term_prefix = _find_prefix ("property");
+
     /* XXX better error reporting ? */
-    _notmuch_message_remove_terms (message, _find_prefix ("property"));
+    _notmuch_message_remove_terms (message, term_prefix);
 
     return NOTMUCH_STATUS_SUCCESS;
 }
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 41aee3c..cf5de3e 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1712,6 +1712,9 @@ notmuch_message_remove_property (notmuch_message_t *message, const char *key, co
 /**
  * Remove all (key,value) pairs from the given message.
  *
+ * @param[in,out] message  message to operate on.
+ * @param[in]     key      key to delete properties for. If NULL, delete
+ *			   properties for all keys
  * @returns
  * - NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in
  *   read-only mode so message cannot be modified.
@@ -1719,7 +1722,7 @@ notmuch_message_remove_property (notmuch_message_t *message, const char *key, co
  *
  */
 notmuch_status_t
-notmuch_message_remove_all_properties (notmuch_message_t *message);
+notmuch_message_remove_all_properties (notmuch_message_t *message, const char *key);
 
 /**@}*/
 
-- 
2.8.1



More information about the notmuch mailing list