--- /dev/null
+Return-Path: <wael.nasreddine@gmail.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 1C010431FCF\r
+ for <notmuch@notmuchmail.org>; Sat, 10 May 2014 14:40:24 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.099\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.099 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001] 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 6uasiR7Id1Ok for <notmuch@notmuchmail.org>;\r
+ Sat, 10 May 2014 14:40:19 -0700 (PDT)\r
+Received: from mail-pd0-f174.google.com (mail-pd0-f174.google.com\r
+ [209.85.192.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 37E0A431FC0\r
+ for <notmuch@notmuchmail.org>; Sat, 10 May 2014 14:40:19 -0700 (PDT)\r
+Received: by mail-pd0-f174.google.com with SMTP id w10so5011919pde.5\r
+ for <notmuch@notmuchmail.org>; Sat, 10 May 2014 14:40:18 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=XgR3UYfdC5orUhYJGVI+HbeUu+9Am7ujymxme465g4M=;\r
+ b=jd8JGIXEP9uNgg7grerq0+HX07Ofi7aFj5aj1+p1JrQsEiBpNaamsBubZEyrmA23oV\r
+ VD5eADQuUavIgSeE60K+gPSUyowwzeIFK8u2wj4wOPsTGDztSks0KrdbRxzW8O1Jbyly\r
+ kGYeymh3ipmCm7LvQfAY556V61GNAf2gu+Mm9S3bRJOJAYkG3zjAuwcX/vgjD73DmcQU\r
+ my2HQp5Zqsau1yOQCB88PIYdytNhIMy/kwRF0gwV9xKaft/OWRmKHiWftrF3Vc+ay0h2\r
+ zFgWmsywUY49ZlORfSf0qwN2FduMkqKmSykj22FMTWfimz9/Aqd5nRg6KnrxuhzINY3y\r
+ wkoA==\r
+X-Received: by 10.66.148.70 with SMTP id tq6mr37060602pab.56.1399758018358;\r
+ Sat, 10 May 2014 14:40:18 -0700 (PDT)\r
+Received: from localhost ([2620:0:1000:2e00:dc94:fbf5:1606:3c5b])\r
+ by mx.google.com with ESMTPSA id\r
+ zv3sm26772175pab.20.2014.05.10.14.40.17 for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sat, 10 May 2014 14:40:17 -0700 (PDT)\r
+From: "Wael M. Nasreddine" <wael.nasreddine@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] ruby: Add wrapper for notmuch_query_count_threads\r
+Date: Sat, 10 May 2014 14:40:11 -0700\r
+Message-Id: <1399758011-26217-2-git-send-email-wael.nasreddine@gmail.com>\r
+X-Mailer: git-send-email 1.9.1.423.g4596e3a\r
+In-Reply-To: <1399758011-26217-1-git-send-email-wael.nasreddine@gmail.com>\r
+References: <1399758011-26217-1-git-send-email-wael.nasreddine@gmail.com>\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: Sat, 10 May 2014 21:40:24 -0000\r
+\r
+---\r
+ bindings/ruby/defs.h | 3 +++\r
+ bindings/ruby/init.c | 1 +\r
+ bindings/ruby/query.c | 19 +++++++++++++++++++\r
+ 3 files changed, 23 insertions(+)\r
+\r
+diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h\r
+index 5b44585..f4901a0 100644\r
+--- a/bindings/ruby/defs.h\r
++++ b/bindings/ruby/defs.h\r
+@@ -231,6 +231,9 @@ notmuch_rb_query_search_messages (VALUE self);\r
+ VALUE\r
+ notmuch_rb_query_count_messages (VALUE self);\r
+ \r
++VALUE\r
++notmuch_rb_query_count_threads (VALUE self);\r
++\r
+ /* threads.c */\r
+ VALUE\r
+ notmuch_rb_threads_destroy (VALUE self);\r
+diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c\r
+index 663271d..ab3f22d 100644\r
+--- a/bindings/ruby/init.c\r
++++ b/bindings/ruby/init.c\r
+@@ -271,6 +271,7 @@ Init_notmuch (void)\r
+ rb_define_method (notmuch_rb_cQuery, "search_threads", notmuch_rb_query_search_threads, 0); /* in query.c */\r
+ rb_define_method (notmuch_rb_cQuery, "search_messages", notmuch_rb_query_search_messages, 0); /* in query.c */\r
+ rb_define_method (notmuch_rb_cQuery, "count_messages", notmuch_rb_query_count_messages, 0); /* in query.c */\r
++ rb_define_method (notmuch_rb_cQuery, "count_threads", notmuch_rb_query_count_threads, 0); /* in query.c */\r
+ \r
+ /*\r
+ * Document-class: Notmuch::Threads\r
+diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c\r
+index 1658ede..a7dacba 100644\r
+--- a/bindings/ruby/query.c\r
++++ b/bindings/ruby/query.c\r
+@@ -182,3 +182,22 @@ notmuch_rb_query_count_messages (VALUE self)\r
+ */\r
+ return UINT2NUM(notmuch_query_count_messages(query));\r
+ }\r
++\r
++/*\r
++ * call-seq: QUERY.count_threads => Fixnum\r
++ *\r
++ * Return an estimate of the number of threads matching a search\r
++ */\r
++VALUE\r
++notmuch_rb_query_count_threads (VALUE self)\r
++{\r
++ notmuch_query_t *query;\r
++\r
++ Data_Get_Notmuch_Query (self, query);\r
++\r
++ /* Xapian exceptions are not handled properly.\r
++ * (function may return 0 after printing a message)\r
++ * Thus there is nothing we can do here...\r
++ */\r
++ return UINT2NUM(notmuch_query_count_threads(query));\r
++}\r
+-- \r
+1.9.1.423.g4596e3a\r
+\r