--- /dev/null
+Return-Path: <dkg@fifthhorseman.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 2B7166DE028C\r
+ for <notmuch@notmuchmail.org>; Fri, 8 Apr 2016 18:02:47 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id GiAuDJqU5Egu for <notmuch@notmuchmail.org>;\r
+ Fri, 8 Apr 2016 18:02:38 -0700 (PDT)\r
+Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
+ by arlo.cworth.org (Postfix) with ESMTP id C284E6DE0173\r
+ for <notmuch@notmuchmail.org>; Fri, 8 Apr 2016 18:02:38 -0700 (PDT)\r
+Received: from fifthhorseman.net (unknown [201.140.212.132])\r
+ by che.mayfirst.org (Postfix) with ESMTPSA id 916A910081\r
+ for <notmuch@notmuchmail.org>; Fri, 8 Apr 2016 21:02:36 -0400 (EDT)\r
+Received: by fifthhorseman.net (Postfix, from userid 1000)\r
+ id 02D73200A4; Fri, 8 Apr 2016 22:02:35 -0300 (ART)\r
+From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH v3 4/7] Add internal functions to search for alternate doc\r
+ types\r
+Date: Fri, 8 Apr 2016 22:02:31 -0300\r
+Message-Id: <1460163754-22994-4-git-send-email-dkg@fifthhorseman.net>\r
+X-Mailer: git-send-email 2.8.0.rc3\r
+In-Reply-To: <1460163754-22994-1-git-send-email-dkg@fifthhorseman.net>\r
+References: <1459445693-3900-1-git-send-email-dkg@fifthhorseman.net>\r
+ <1460163754-22994-1-git-send-email-dkg@fifthhorseman.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 09 Apr 2016 01:02:47 -0000\r
+\r
+Publicly we are only exposing the non-ghost documents (of "type"\r
+"mail"). But internally we might want to inspect the ghost messages\r
+as well.\r
+\r
+This changeset adds two new private interfaces to queries to recover\r
+information about alternate document types.\r
+---\r
+ lib/notmuch-private.h | 11 +++++++++++\r
+ lib/query.cc | 18 ++++++++++++++++--\r
+ 2 files changed, 27 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index 5dd4770..d95bf31 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -477,6 +477,17 @@ void\r
+ _notmuch_doc_id_set_remove (notmuch_doc_id_set_t *doc_ids,\r
+ unsigned int doc_id);\r
+ \r
++/* querying xapian documents by type (e.g. "mail" or "ghost"): */\r
++notmuch_status_t\r
++_notmuch_query_search_documents (notmuch_query_t *query,\r
++ const char *type,\r
++ notmuch_messages_t **out);\r
++\r
++notmuch_status_t\r
++_notmuch_query_count_documents (notmuch_query_t *query,\r
++ const char *type,\r
++ unsigned *count_out);\r
++\r
+ /* message.cc */\r
+ \r
+ void\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index e627bfc..77a7926 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -187,6 +187,14 @@ notmuch_status_t\r
+ notmuch_query_search_messages_st (notmuch_query_t *query,\r
+ notmuch_messages_t **out)\r
+ {\r
++ return _notmuch_query_search_documents (query, "mail", out);\r
++}\r
++\r
++notmuch_status_t\r
++_notmuch_query_search_documents (notmuch_query_t *query,\r
++ const char *type,\r
++ notmuch_messages_t **out)\r
++{\r
+ notmuch_database_t *notmuch = query->notmuch;\r
+ const char *query_string = query->query_string;\r
+ notmuch_mset_messages_t *messages;\r
+@@ -208,7 +216,7 @@ notmuch_query_search_messages_st (notmuch_query_t *query,\r
+ Xapian::Enquire enquire (*notmuch->xapian_db);\r
+ Xapian::Query mail_query (talloc_asprintf (query, "%s%s",\r
+ _find_prefix ("type"),\r
+- "mail"));\r
++ type));\r
+ Xapian::Query string_query, final_query, exclude_query;\r
+ Xapian::MSet mset;\r
+ Xapian::MSetIterator iterator;\r
+@@ -554,6 +562,12 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+ notmuch_status_t\r
+ notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
+ {\r
++ return _notmuch_query_count_documents (query, "mail", count_out);\r
++}\r
++\r
++notmuch_status_t\r
++_notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsigned *count_out)\r
++{\r
+ notmuch_database_t *notmuch = query->notmuch;\r
+ const char *query_string = query->query_string;\r
+ Xapian::doccount count = 0;\r
+@@ -562,7 +576,7 @@ notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
+ Xapian::Enquire enquire (*notmuch->xapian_db);\r
+ Xapian::Query mail_query (talloc_asprintf (query, "%s%s",\r
+ _find_prefix ("type"),\r
+- "mail"));\r
++ type));\r
+ Xapian::Query string_query, final_query, exclude_query;\r
+ Xapian::MSet mset;\r
+ unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
+-- \r
+2.8.0.rc3\r
+\r