unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
To: Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH] n_m_remove_property(msg, key, NULL) should removes all properties with key
Date: Fri,  8 Jul 2016 06:36:50 +0200	[thread overview]
Message-ID: <1467952610-27015-1-git-send-email-dkg@fifthhorseman.net> (raw)
In-Reply-To: <1465779955-5539-4-git-send-email-david@tethera.net>

We should not require value to be non-NULL when there is a perfectly
sensible semantic:

    notmuch_message_remove_property(msg, key, NULL)

should mean "remove all properties with the given key from msg"
---
 lib/message-property.cc | 28 ++++++++++++++++++++--------
 lib/notmuch.h           |  5 +++--
 2 files changed, 23 insertions(+), 10 deletions(-)

This should apply on top of bremner's "properties" series, making the
semantics slightly more useful.

diff --git a/lib/message-property.cc b/lib/message-property.cc
index 4fa6cac..338f3fb 100644
--- a/lib/message-property.cc
+++ b/lib/message-property.cc
@@ -48,22 +48,34 @@ _notmuch_message_modify_property (notmuch_message_t *message, const char *key, c
     if (status)
 	return status;
 
-    if (key == NULL || value == NULL)
+    if (key == NULL)
 	return NOTMUCH_STATUS_NULL_POINTER;
 
     if (index (key, '='))
 	return NOTMUCH_STATUS_ILLEGAL_ARGUMENT;
 
-    term = talloc_asprintf (message, "%s=%s", key, value);
+    if (value == NULL)
+    {
+	if (!delete_it)
+	    return NOTMUCH_STATUS_NULL_POINTER;
 
-    if (delete_it)
-	private_status = _notmuch_message_remove_term (message, "property", term);
+	term = talloc_asprintf (message, "%s%s=", _find_prefix ("property"), key);
+	_notmuch_message_remove_terms (message, term);
+    }
     else
-	private_status = _notmuch_message_add_term (message, "property", term);
+    {
+	term = talloc_asprintf (message, "%s=%s", key, value);
+
+	if (delete_it)
+	    private_status = _notmuch_message_remove_term (message, "property", term);
+	else
+	    private_status = _notmuch_message_add_term (message, "property", term);
+
+	if (private_status)
+	    return COERCE_STATUS (private_status,
+				  "Unhandled error modifying message property");
+    }
 
-    if (private_status)
-	return COERCE_STATUS (private_status,
-			      "Unhandled error modifying message property");
     if (! _notmuch_message_frozen (message))
 	_notmuch_message_sync (message);
 
diff --git a/lib/notmuch.h b/lib/notmuch.h
index f6bad67..0d667f5 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1698,11 +1698,12 @@ notmuch_message_add_property (notmuch_message_t *message, const char *key, const
 /**
  * Remove a (key,value) pair from a message.
  *
- * It is not an error to remove a non-existant (key,value) pair
+ * It is not an error to remove a non-existant (key,value) pair.  If
+ * *value* is NULL, remove all properties with the given key.
  *
  * @returns
  * - NOTMUCH_STATUS_ILLEGAL_ARGUMENT: *key* may not contain an '=' character.
- * - NOTMUCH_STATUS_NULL_POINTER: Neither *key* nor *value* may be NULL.
+ * - NOTMUCH_STATUS_NULL_POINTER: *key* may not be NULL.
  * - NOTMUCH_STATUS_SUCCESS: No error occured.
  */
 notmuch_status_t
-- 
2.8.1

  reply	other threads:[~2016-07-08 10:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-13  1:05 message properties patches, v1.0 David Bremner
2016-06-13  1:05 ` [PATCH 1/8] lib: read "property" terms from messages David Bremner
2016-06-13  1:05 ` [PATCH 2/8] lib: private string map (associative array) API David Bremner
2016-06-13  8:10   ` Tomi Ollila
2016-06-13 13:02     ` David Bremner
2016-06-13 15:18       ` Bijan Chokoufe Nejad
2016-06-13  1:05 ` [PATCH 3/8] lib: basic message-property API David Bremner
2016-07-08  4:36   ` Daniel Kahn Gillmor [this message]
2016-07-16 10:32     ` [PATCH] RFC: all deleting all properties with a given key David Bremner
2016-07-17 23:33       ` Daniel Kahn Gillmor
2016-06-13  1:05 ` [PATCH 4/8] lib: extend private string map API with iterators David Bremner
2016-06-13  1:05 ` [PATCH 5/8] lib: iterator API for message properties David Bremner
2016-06-13  1:05 ` [PATCH 6/8] CLI: refactor dumping of tags David Bremner
2016-06-13  1:05 ` [PATCH 7/8] CLI: add properties to dump output David Bremner
2016-06-13  1:05 ` [PATCH 8/8] cli: optionally restore message properties from dump file David Bremner
2016-07-08  9:15   ` [PATCH] add has: query prefix to search for specific properties Daniel Kahn Gillmor
2016-07-17  0:39     ` David Bremner
2016-07-17 10:38       ` David Bremner
2016-07-17 23:44       ` Daniel Kahn Gillmor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467952610-27015-1-git-send-email-dkg@fifthhorseman.net \
    --to=dkg@fifthhorseman.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).