From: David Bremner Date: Mon, 30 May 2016 11:49:55 +0000 (+2100) Subject: [RFC2 Patch 1/5] lib: read "property" terms from messages. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2d1ae7ee2311c97ced185cb61668d9faf76e7e48;p=notmuch-archives.git [RFC2 Patch 1/5] lib: read "property" terms from messages. --- diff --git a/c0/765d861b80014dd0dbf6110fa2afe925984771 b/c0/765d861b80014dd0dbf6110fa2afe925984771 new file mode 100644 index 000000000..da3f9ef39 --- /dev/null +++ b/c0/765d861b80014dd0dbf6110fa2afe925984771 @@ -0,0 +1,158 @@ +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 0D1886DE02D9 + for ; Mon, 30 May 2016 04:50:29 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.012 +X-Spam-Level: +X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5 + tests=[AWL=-0.001, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] + 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 IdL_KacHErf7 for ; + Mon, 30 May 2016 04:50:20 -0700 (PDT) +Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) + by arlo.cworth.org (Postfix) with ESMTPS id CFDBF6DE028C + for ; Mon, 30 May 2016 04:50:11 -0700 (PDT) +Received: from remotemail by fethera.tethera.net with local (Exim 4.84) + (envelope-from ) + id 1b7Lhp-0000PA-0U; Mon, 30 May 2016 07:50:01 -0400 +Received: (nullmailer pid 14848 invoked by uid 1000); + Mon, 30 May 2016 11:50:06 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [RFC2 Patch 1/5] lib: read "property" terms from messages. +Date: Mon, 30 May 2016 08:49:55 -0300 +Message-Id: <1464608999-14774-2-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.8.1 +In-Reply-To: <1464608999-14774-1-git-send-email-david@tethera.net> +References: <1463927339-5441-1-git-send-email-david@tethera.net> + <1464608999-14774-1-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: Mon, 30 May 2016 11:50:29 -0000 + +This is a first step towards providing an API to attach +arbitrary (key,value) pairs to messages and retrieve all of the values +for a given key. +--- + lib/database.cc | 1 + + lib/message.cc | 29 ++++++++++++++++++++++++++++- + lib/notmuch-private.h | 3 +++ + 3 files changed, 32 insertions(+), 1 deletion(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 9630000..7750f50 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -237,6 +237,7 @@ static prefix_t BOOLEAN_PREFIX_INTERNAL[] = { + { "directory", "XDIRECTORY" }, + { "file-direntry", "XFDIRENTRY" }, + { "directory-direntry", "XDDIRENTRY" }, ++ { "property", "XPROPERTY" }, + }; + + static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = { +diff --git a/lib/message.cc b/lib/message.cc +index 6839305..47946a3 100644 +--- a/lib/message.cc ++++ b/lib/message.cc +@@ -37,6 +37,8 @@ struct visible _notmuch_message { + notmuch_string_list_t *filename_list; + char *author; + notmuch_message_file_t *message_file; ++ notmuch_string_list_t *property_term_list; ++ notmuch_string_map_t *property_map; + notmuch_message_list_t *replies; + unsigned long flags; + /* For flags that are initialized on-demand, lazy_flags indicates +@@ -116,6 +118,8 @@ _notmuch_message_create_for_document (const void *talloc_owner, + message->filename_list = NULL; + message->message_file = NULL; + message->author = NULL; ++ message->property_term_list = NULL; ++ message->property_map = NULL; + + message->replies = _notmuch_message_list_create (message); + if (unlikely (message->replies == NULL)) { +@@ -314,6 +318,7 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message) + *id_prefix = _find_prefix ("id"), + *type_prefix = _find_prefix ("type"), + *filename_prefix = _find_prefix ("file-direntry"), ++ *property_prefix = _find_prefix ("property"), + *replyto_prefix = _find_prefix ("replyto"); + + /* We do this all in a single pass because Xapian decompresses the +@@ -369,11 +374,21 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message) + _notmuch_database_get_terms_with_prefix (message, i, end, + filename_prefix); + ++ ++ /* Get property terms. Mimic the setup with filenames above */ ++ assert (strcmp (filename_prefix, property_prefix) < 0); ++ if (!message->property_map && !message->property_term_list) ++ message->property_term_list = ++ _notmuch_database_get_terms_with_prefix (message, i, end, ++ property_prefix); ++ + /* Get reply to */ +- assert (strcmp (filename_prefix, replyto_prefix) < 0); ++ assert (strcmp (property_prefix, replyto_prefix) < 0); + if (!message->in_reply_to) + message->in_reply_to = + _notmuch_message_get_term (message, i, end, replyto_prefix); ++ ++ + /* It's perfectly valid for a message to have no In-Reply-To + * header. For these cases, we return an empty string. */ + if (!message->in_reply_to) +@@ -405,6 +420,18 @@ _notmuch_message_invalidate_metadata (notmuch_message_t *message, + message->filename_term_list = message->filename_list = NULL; + } + ++ if (strcmp ("property", prefix_name) == 0) { ++ ++ if (message->property_term_list) ++ talloc_free (message->property_term_list); ++ message->property_term_list = NULL; ++ ++ if (message->property_map) ++ talloc_free (message->property_map); ++ ++ message->property_map = NULL; ++ } ++ + if (strcmp ("replyto", prefix_name) == 0) { + talloc_free (message->in_reply_to); + message->in_reply_to = NULL; +diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h +index 9280797..6f9af91 100644 +--- a/lib/notmuch-private.h ++++ b/lib/notmuch-private.h +@@ -537,6 +537,9 @@ _notmuch_string_list_append (notmuch_string_list_t *list, + void + _notmuch_string_list_sort (notmuch_string_list_t *list); + ++/* string-map.c */ ++typedef struct _notmuch_string_map notmuch_string_map_t; ++ + /* tags.c */ + + notmuch_tags_t * +-- +2.8.1 +