From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id BB6A66DE10A7 for ; Sat, 2 Mar 2019 07:42:02 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.009 X-Spam-Level: X-Spam-Status: No, score=-0.009 tagged_above=-999 required=5 tests=[AWL=-0.008, SPF_PASS=-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 2CpxJrcU5lXU for ; Sat, 2 Mar 2019 07:41:57 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 0DBD86DE1066 for ; Sat, 2 Mar 2019 07:41:46 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.89) (envelope-from ) id 1h06lm-0004Jo-1B; Sat, 02 Mar 2019 10:41:46 -0500 Received: (nullmailer pid 25733 invoked by uid 1000); Sat, 02 Mar 2019 15:41:37 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 6/7] lib/database: index user headers. Date: Sat, 2 Mar 2019 11:41:32 -0400 Message-Id: <20190302154133.25642-7-david@tethera.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190302154133.25642-1-david@tethera.net> References: <20190302154133.25642-1-david@tethera.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 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: Sat, 02 Mar 2019 15:42:02 -0000 There is a O(log(#user headers)) penalty for the second lookup of the prefix name. --- lib/database.cc | 6 ++++++ lib/index.cc | 28 ++++++++++++++++++++++++++++ lib/notmuch-private.h | 5 +++++ test/T730-user-header.sh | 17 +++++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/lib/database.cc b/lib/database.cc index 19aff0e8..2219a76a 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -308,6 +308,12 @@ _setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch) notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix); } +notmuch_string_map_iterator_t * +_notmuch_database_user_headers (notmuch_database_t *notmuch) +{ + return _notmuch_string_map_iterator_create (notmuch->user_header, "", false); +} + const char * _user_prefix (void *ctx, const char* name) { diff --git a/lib/index.cc b/lib/index.cc index efd9da4c..ef3369fd 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -595,6 +595,32 @@ _index_encrypted_mime_part (notmuch_message_t *message, } +static notmuch_status_t +_notmuch_message_index_user_headers (notmuch_message_t *message, GMimeMessage *mime_message) +{ + + notmuch_database_t *notmuch = notmuch_message_get_database (message); + notmuch_string_map_iterator_t *iter = _notmuch_database_user_headers (notmuch); + + for (; _notmuch_string_map_iterator_valid (iter); + _notmuch_string_map_iterator_move_to_next (iter)) { + + const char *prefix_name = _notmuch_string_map_iterator_key (iter); + + const char *header_name = _notmuch_string_map_iterator_value (iter); + + const char *header = g_mime_object_get_header (GMIME_OBJECT (mime_message), header_name); + if (header) + _notmuch_message_gen_terms (message, prefix_name, header); + } + + if (iter) + _notmuch_string_map_iterator_destroy (iter); + return NOTMUCH_STATUS_SUCCESS; + +} + + notmuch_status_t _notmuch_message_index_file (notmuch_message_t *message, notmuch_indexopts_t *indexopts, @@ -625,6 +651,8 @@ _notmuch_message_index_file (notmuch_message_t *message, subject = g_mime_message_get_subject (mime_message); _notmuch_message_gen_terms (message, "subject", subject); + status = _notmuch_message_index_user_headers (message, mime_message); + _index_mime_part (message, indexopts, g_mime_message_get_mime_part (mime_message)); return NOTMUCH_STATUS_SUCCESS; diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index cf08411e..e46df9a8 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -652,6 +652,11 @@ _notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator); void _notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator); +/* Create an iterator for user headers. Destroy with + * _notmuch_string_map_iterator_destroy. Actually in database.cc*/ +notmuch_string_map_iterator_t * +_notmuch_database_user_headers (notmuch_database_t *notmuch); + /* tags.c */ notmuch_tags_t * diff --git a/test/T730-user-header.sh b/test/T730-user-header.sh index 1531f1d6..c08985b9 100755 --- a/test/T730-user-header.sh +++ b/test/T730-user-header.sh @@ -56,4 +56,21 @@ Query((Tmail AND (XUlist:notmuchmail@1 PHRASE 2 XUlist:org@2))) EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "index user header" +notmuch config set index.header.list "List-Id" +notmuch reindex '*' +notmuch search --output=files list:notmuch | notmuch_search_files_sanitize | sort > OUTPUT +cat < EXPECTED +MAIL_DIR/bar/baz/05:2, +MAIL_DIR/bar/baz/23:2, +MAIL_DIR/bar/baz/24:2, +MAIL_DIR/bar/cur/20:2, +MAIL_DIR/bar/new/21:2, +MAIL_DIR/bar/new/22:2, +MAIL_DIR/foo/cur/08:2, +MAIL_DIR/foo/new/03:2, +MAIL_DIR/new/04:2, +EOF +test_expect_equal_file EXPECTED OUTPUT + test_done -- 2.20.1