From 58b12fa3016835d8af103f07505a0e4ef617047c Mon Sep 17 00:00:00 2001 From: Todd Date: Fri, 23 Jan 2015 17:43:38 +1800 Subject: [PATCH] [PATCH v4 3/5] Add indexing for the mimetype term --- 04/37b3890ddebe32d79360754226e0258325f934 | 138 ++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 04/37b3890ddebe32d79360754226e0258325f934 diff --git a/04/37b3890ddebe32d79360754226e0258325f934 b/04/37b3890ddebe32d79360754226e0258325f934 new file mode 100644 index 000000000..182b51514 --- /dev/null +++ b/04/37b3890ddebe32d79360754226e0258325f934 @@ -0,0 +1,138 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id AC8EF431FD5 + for ; Thu, 22 Jan 2015 15:44:28 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: 2.438 +X-Spam-Level: ** +X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 9nP200UGzqAJ for ; + Thu, 22 Jan 2015 15:44:24 -0800 (PST) +Received: from s75.web-hosting.com (s75.web-hosting.com [198.187.31.9]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 14F0F431FC9 + for ; Thu, 22 Jan 2015 15:44:24 -0800 (PST) +Received: from user-69-73-37-128.knology.net ([69.73.37.128]:32799 + helo=localhost.localdomain) + by server75.web-hosting.com with esmtpsa (UNKNOWN:AES128-SHA256:128) + (Exim 4.82) (envelope-from ) + id 1YERQF-0036iE-6O; Thu, 22 Jan 2015 18:44:23 -0500 +From: Todd +To: notmuch@notmuchmail.org +Subject: [PATCH v4 3/5] Add indexing for the mimetype term +Date: Thu, 22 Jan 2015 17:43:38 -0600 +Message-Id: <1421970220-9019-4-git-send-email-todd@electricoding.com> +X-Mailer: git-send-email 1.9.1 +In-Reply-To: <1421970220-9019-1-git-send-email-todd@electricoding.com> +References: <1421970220-9019-1-git-send-email-todd@electricoding.com> +In-Reply-To: <1420849787-4401-1-git-send-email-todd@electricoding.com> +References: <1420849787-4401-1-git-send-email-todd@electricoding.com> +X-AntiAbuse: This header was added to track abuse, + please include it with any abuse report +X-AntiAbuse: Primary Hostname - server75.web-hosting.com +X-AntiAbuse: Original Domain - notmuchmail.org +X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] +X-AntiAbuse: Sender Address Domain - electricoding.com +X-Get-Message-Sender-Via: server75.web-hosting.com: authenticated_id: + todd@electricoding.com +X-Source: +X-Source-Args: +X-Source-Dir: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Thu, 22 Jan 2015 23:44:29 -0000 + +This adds the indexing support for the "mimetype:" term and removes +the broken test flag. The indexing is probablistic in Xapian terms, +which gives a better experience to end users. Standard content-types +of the form "foo/bar" are automatically interpreted as phrases in +Xapian due to the embedded slash. + +Assume, separate messages with application/pdf and application/x-pdf +are indexed, then: + +- mimetype:application/x-pdf will find only the application/x-pdf +- mimetype:application/pdf will find only the application/pdf +- mimetype:pdf will find both of the messages +--- + lib/database.cc | 1 + + lib/index.cc | 10 ++++++++++ + test/T190-multipart.sh | 3 --- + 3 files changed, 11 insertions(+), 3 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 0d2c417..3974e2e 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -254,6 +254,7 @@ static prefix_t PROBABILISTIC_PREFIX[]= { + { "from", "XFROM" }, + { "to", "XTO" }, + { "attachment", "XATTACHMENT" }, ++ { "mimetype", "XMIMETYPE"}, + { "subject", "XSUBJECT"}, + }; + +diff --git a/lib/index.cc b/lib/index.cc +index 1a2e63d..c88ed8d 100644 +--- a/lib/index.cc ++++ b/lib/index.cc +@@ -318,6 +318,16 @@ _index_mime_part (notmuch_message_t *message, + return; + } + ++ GMimeContentType *content_type = g_mime_object_get_content_type(part); ++ if (content_type) { ++ char *mime_string = g_mime_content_type_to_string(content_type); ++ if (mime_string) ++ { ++ _notmuch_message_gen_terms (message, "mimetype", mime_string); ++ g_free(mime_string); ++ } ++ } ++ + if (GMIME_IS_MULTIPART (part)) { + GMimeMultipart *multipart = GMIME_MULTIPART (part); + int i; +diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh +index a97dc28..ad8d29e 100755 +--- a/test/T190-multipart.sh ++++ b/test/T190-multipart.sh +@@ -752,17 +752,14 @@ notmuch show --format=json --include-html id:htmlmessage > OUTPUT + test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED.withhtml)" + + test_begin_subtest "indexes mime-type #1" +-test_subtest_known_broken + output=$(notmuch search mimetype:application/unique_identifier | notmuch_search_sanitize) + test_expect_equal "$output" "thread:XXX 2014-01-12 [1/1] Todd; odd content types (inbox unread)" + + test_begin_subtest "indexes mime-type #2" +-test_subtest_known_broken + output=$(notmuch search mimetype:text/some_other_identifier | notmuch_search_sanitize) + test_expect_equal "$output" "thread:XXX 2014-01-12 [1/1] Todd; odd content types (inbox unread)" + + test_begin_subtest "indexes mime-type #3" +-test_subtest_known_broken + output=$(notmuch search from:todd and mimetype:multipart/alternative | notmuch_search_sanitize) + test_expect_equal "$output" "thread:XXX 2014-01-12 [1/1] Todd; odd content types (inbox unread)" + +-- +1.9.1 + -- 2.26.2