From: David Bremner Date: Wed, 3 Aug 2016 00:30:20 +0000 (+0900) Subject: v2 of message properties patches X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1be9f05428e9520b78c3fbbbd6d3ec425fe1d5ae;p=notmuch-archives.git v2 of message properties patches --- diff --git a/7a/fb9fd63227aefb7dbd3e44908b2631bcaf8dbf b/7a/fb9fd63227aefb7dbd3e44908b2631bcaf8dbf new file mode 100644 index 000000000..c27918087 --- /dev/null +++ b/7a/fb9fd63227aefb7dbd3e44908b2631bcaf8dbf @@ -0,0 +1,277 @@ +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 92CF16DE00BD + for ; Tue, 2 Aug 2016 17:30:46 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.005 +X-Spam-Level: +X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 + tests=[AWL=-0.006, HEADER_FROM_DIFFERENT_DOMAINS=0.001] + 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 wB3Uu-mMOK0J for ; + Tue, 2 Aug 2016 17:30:37 -0700 (PDT) +Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) + by arlo.cworth.org (Postfix) with ESMTPS id 3C9186DE00B8 + for ; Tue, 2 Aug 2016 17:30:36 -0700 (PDT) +Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) + (envelope-from ) id 1bUk5F-0005kk-2L + for notmuch@notmuchmail.org; Tue, 02 Aug 2016 20:30:53 -0400 +Received: (nullmailer pid 12776 invoked by uid 1000); + Wed, 03 Aug 2016 00:30:32 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: v2 of message properties patches +Date: Wed, 3 Aug 2016 09:30:20 +0900 +Message-Id: <1470184228-12517-1-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.8.1 +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: Wed, 03 Aug 2016 00:30:46 -0000 + +This includes a bunch of whitespace cleanup (enough that the interdiff +is a bit boring/noisy) and +id:1468665174-11929-1-git-send-email-david@tethera.net, as well as +being rebased on master. + +Here is said boring interdiff + +diff --git a/lib/message-property.cc b/lib/message-property.cc +index 4fa6cac..0b13cac 100644 +--- a/lib/message-property.cc ++++ b/lib/message-property.cc +@@ -86,16 +86,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 f6bad67..e03a05d 100644 +--- a/lib/notmuch.h ++++ b/lib/notmuch.h +@@ -1711,6 +1711,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. +@@ -1718,7 +1721,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); + + /** + * Opaque message property iterator +diff --git a/notmuch-dump.c b/notmuch-dump.c +index ec82660..e7965ce 100644 +--- a/notmuch-dump.c ++++ b/notmuch-dump.c +@@ -80,11 +80,11 @@ print_dump_header (gzFile output, int output_format, int include) + sep = ","; + } + if (include & DUMP_INCLUDE_PROPERTIES) { +- gzprintf (output, "%sproperties",sep); ++ gzprintf (output, "%sproperties", sep); + sep = ","; + } + if (include & DUMP_INCLUDE_TAGS) { +- gzprintf (output, "%sproperties",sep); ++ gzprintf (output, "%sproperties", sep); + } + gzputs (output, "\n"); + } +@@ -106,38 +106,38 @@ dump_properties_message (void *ctx, + return 0; + } + +- for (list = notmuch_message_get_properties (message, "", FALSE); +- notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) { +- const char *key, *val; +- +- if (first) { +- if (hex_encode (ctx, message_id, buffer_p, size_p) != HEX_SUCCESS) { +- fprintf (stderr, "Error: failed to hex-encode message-id %s\n", message_id); +- return 1; +- } +- gzprintf (output, "#= %s", *buffer_p); +- first = FALSE; +- } +- +- key = notmuch_message_properties_key (list); +- val = notmuch_message_properties_value (list); +- +- if (hex_encode (ctx, key, buffer_p, size_p) != HEX_SUCCESS) { +- fprintf (stderr, "Error: failed to hex-encode key %s\n", key); +- return 1; +- } +- gzprintf (output, " %s", *buffer_p); +- +- if (hex_encode (ctx, val, buffer_p, size_p) != HEX_SUCCESS) { +- fprintf (stderr, "Error: failed to hex-encode value %s\n", val); +- return 1; +- } +- gzprintf (output, "=%s", *buffer_p); +-} +- notmuch_message_properties_destroy (list); ++ for (list = notmuch_message_get_properties (message, "", FALSE); ++ notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) { ++ const char *key, *val; ++ ++ if (first) { ++ if (hex_encode (ctx, message_id, buffer_p, size_p) != HEX_SUCCESS) { ++ fprintf (stderr, "Error: failed to hex-encode message-id %s\n", message_id); ++ return 1; ++ } ++ gzprintf (output, "#= %s", *buffer_p); ++ first = FALSE; ++ } ++ ++ key = notmuch_message_properties_key (list); ++ val = notmuch_message_properties_value (list); ++ ++ if (hex_encode (ctx, key, buffer_p, size_p) != HEX_SUCCESS) { ++ fprintf (stderr, "Error: failed to hex-encode key %s\n", key); ++ return 1; ++ } ++ gzprintf (output, " %s", *buffer_p); ++ ++ if (hex_encode (ctx, val, buffer_p, size_p) != HEX_SUCCESS) { ++ fprintf (stderr, "Error: failed to hex-encode value %s\n", val); ++ return 1; ++ } ++ gzprintf (output, "=%s", *buffer_p); ++ } ++ notmuch_message_properties_destroy (list); + +- if (!first) +- gzprintf (output, "\n", *buffer_p); ++ if (! first) ++ gzprintf (output, "\n", *buffer_p); + + return 0; + } +diff --git a/notmuch-restore.c b/notmuch-restore.c +index d2ada61..4b3690f 100644 +--- a/notmuch-restore.c ++++ b/notmuch-restore.c +@@ -69,7 +69,7 @@ process_properties_line (notmuch_database_t *notmuch, const char* line) + const char *delim = " \t\n"; + int ret = EXIT_FAILURE; + +- void *local = talloc_new(NULL); ++ void *local = talloc_new (NULL); + + id_p = strtok_len_c (line, delim, &id_len); + id = talloc_strndup (local, id_p, id_len); +@@ -97,7 +97,7 @@ process_properties_line (notmuch_database_t *notmuch, const char* line) + } + + key = talloc_strndup (local, tok, off); +- value = talloc_strndup (local, tok+off+1, tok_len - off - 1); ++ value = talloc_strndup (local, tok + off + 1, tok_len - off - 1); + + if (hex_decode_inplace (key) != HEX_SUCCESS) { + fprintf (stderr, "hex decoding failure on key %s\n", key); +@@ -111,13 +111,13 @@ process_properties_line (notmuch_database_t *notmuch, const char* line) + + if (print_status_database ("notmuch restore", notmuch, + notmuch_message_add_property (message, key, value))) +- goto DONE; ++ goto DONE; + + } + + ret = EXIT_SUCCESS; + +- DONE: ++ DONE: + talloc_free (local); + return ret; + } +@@ -341,7 +341,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) + goto DONE; + } + if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] == '=') { +- ret = process_properties_line(notmuch, line+2); ++ ret = process_properties_line (notmuch, line + 2); + if (ret) + goto DONE; + } +@@ -380,7 +380,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) + line_ctx = talloc_new (config); + + if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] == '=') { +- ret = process_properties_line(notmuch, line+2); ++ ret = process_properties_line (notmuch, line + 2); + if (ret) + goto DONE; + } +@@ -423,7 +423,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) + break; + + } while (! (ret = gz_getline (line_ctx, &line, &line_len, input))); +- ++ + + /* EOF is normal loop termination condition, UTIL_SUCCESS is + * impossible here */ +@@ -435,14 +435,14 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) + ret = EXIT_FAILURE; + } + +- /* currently this should not be after DONE: since we don't ++ /* currently this should not be after DONE: since we don't + * know if the xregcomp was reached + */ + + if (input_format == DUMP_FORMAT_SUP) + regfree (®ex); + +- DONE: ++ DONE: + if (line_ctx != NULL) + talloc_free (line_ctx); + + +