From 772b406571d26cde8ef70115385b56203df5d550 Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Fri, 8 Jul 2016 06:36:50 +0200 Subject: [PATCH] [PATCH] n_m_remove_property(msg, key, NULL) should removes all properties with key --- 1b/2a04ac80c5e7a7f612641b775335e3636c435b | 130 ++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 1b/2a04ac80c5e7a7f612641b775335e3636c435b diff --git a/1b/2a04ac80c5e7a7f612641b775335e3636c435b b/1b/2a04ac80c5e7a7f612641b775335e3636c435b new file mode 100644 index 000000000..39dfc21f5 --- /dev/null +++ b/1b/2a04ac80c5e7a7f612641b775335e3636c435b @@ -0,0 +1,130 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 6BBE16DE092F + for ; Fri, 8 Jul 2016 03:13:24 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.538 +X-Spam-Level: +X-Spam-Status: No, score=0.538 tagged_above=-999 required=5 tests=[AWL=-0.538, + DATE_IN_PAST_03_06=1.076] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id ePRrZ0gv-n_5 for ; + Fri, 8 Jul 2016 03:13:16 -0700 (PDT) +Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) + by arlo.cworth.org (Postfix) with ESMTP id 0FB1C6DE015B + for ; Fri, 8 Jul 2016 03:13:07 -0700 (PDT) +Received: from fifthhorseman.net (unknown [88.128.80.54]) + by che.mayfirst.org (Postfix) with ESMTPSA id 94D94F993 + for ; Fri, 8 Jul 2016 06:13:03 -0400 (EDT) +Received: by fifthhorseman.net (Postfix, from userid 1000) + id CF6DB20887; Fri, 8 Jul 2016 00:36:50 -0400 (EDT) +From: Daniel Kahn Gillmor +To: Notmuch Mail +Subject: [PATCH] n_m_remove_property(msg, key, + NULL) should removes all properties with key +Date: Fri, 8 Jul 2016 06:36:50 +0200 +Message-Id: <1467952610-27015-1-git-send-email-dkg@fifthhorseman.net> +X-Mailer: git-send-email 2.8.1 +In-Reply-To: <1465779955-5539-4-git-send-email-david@tethera.net> +References: <1465779955-5539-4-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 08 Jul 2016 10:13:24 -0000 + +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 + -- 2.26.2