From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [RFC2 Patch 1/5] lib: read "property" terms from messages.
Date: Mon, 30 May 2016 08:49:55 -0300 [thread overview]
Message-ID: <1464608999-14774-2-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1464608999-14774-1-git-send-email-david@tethera.net>
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
next prev parent reply other threads:[~2016-05-30 11:50 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-22 14:28 RFC: message property API David Bremner
2016-05-22 14:28 ` [RFC patch 1/2] lib: refactor _notmuch_message_has_term David Bremner
2016-05-22 14:28 ` [RFC patch 2/2] RFC message-property API David Bremner
2016-05-30 11:49 ` message properties, round 2 David Bremner
2016-05-30 11:49 ` David Bremner [this message]
2016-05-30 11:49 ` [RFC2 Patch 2/5] lib: private string map (associative array) API David Bremner
2016-05-30 11:49 ` [RFC2 Patch 3/5] lib: basic message-property API David Bremner
2016-05-30 11:49 ` [RFC2 Patch 4/5] lib: extend private string map API with iterators David Bremner
2016-05-30 11:49 ` [RFC2 Patch 5/5] lib: iterator API for message properties David Bremner
2016-06-01 1:12 ` David Bremner
2016-06-01 1:52 ` Daniel Kahn Gillmor
2016-06-01 5:04 ` Tomi Ollila
2016-06-01 10:04 ` David Bremner
2016-06-01 14:13 ` Daniel Kahn Gillmor
2016-06-01 23:29 ` David Bremner
2016-06-02 17:33 ` Daniel Kahn Gillmor
2016-06-03 12:54 ` David Bremner
2016-06-03 14:38 ` Daniel Kahn Gillmor
2016-06-03 23:12 ` David Bremner
2016-06-04 16:23 ` Daniel Kahn Gillmor
2016-06-05 10:24 ` [PATCH] doc: document notmuch-dump header line David Bremner
2016-06-05 22:23 ` David Bremner
2016-06-06 6:38 ` Tomi Ollila
2016-06-07 10:55 ` David Bremner
2016-06-01 4:38 ` [RFC2 Patch 5/5] lib: iterator API for message properties Tomi Ollila
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=1464608999-14774-2-git-send-email-david@tethera.net \
--to=david@tethera.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).