[PATCH v4 3/5] Add indexing for the mimetype term
authorTodd <todd@electricoding.com>
Thu, 22 Jan 2015 23:43:38 +0000 (17:43 +1800)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:47:44 +0000 (14:47 -0700)
04/37b3890ddebe32d79360754226e0258325f934 [new file with mode: 0644]

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