--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 C7C7A431FBF\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 20:57:24 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 wTEjIsKdfJZv for <notmuch@notmuchmail.org>;\r
+ Sat, 24 Nov 2012 20:57:20 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+ [18.9.25.15])\r
+ by olra.theworths.org (Postfix) with ESMTP id 726D6431FBD\r
+ for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 20:57:19 -0800 (PST)\r
+X-AuditID: 1209190f-b7f636d00000095b-63-50b1a52e591f\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id DC.2B.02395.E25A1B05; Sat, 24 Nov 2012 23:57:18 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id qAP4vG10000523; \r
+ Sat, 24 Nov 2012 23:57:16 -0500\r
+Received: from drake.dyndns.org\r
+ (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [209.6.116.242]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qAP4vEGI000085\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Sat, 24 Nov 2012 23:57:16 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1TcUHJ-0003Zs-VB; Sat, 24 Nov 2012 23:57:13 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/6] lib: Add an iterator over all messages in a thread\r
+Date: Sat, 24 Nov 2012 23:57:05 -0500\r
+Message-Id: <1353819427-13182-5-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1353819427-13182-1-git-send-email-amdragon@mit.edu>\r
+References: <1353819427-13182-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrOIsWRmVeSWpSXmKPExsUixCmqrKu3dGOAwfdrrBar5/JYXL85k9mB\r
+ yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgynh64iZLwTuBirvnTzA3MD7n7WLk5JAQMJFo\r
+ XtXHBGGLSVy4t54NxBYS2Mco8faUHYS9gVFiTZdbFyMXkP2ISeL09m5miMRcRonXe+pAbDYB\r
+ DYlt+5czgtgiAtISO+/OZgWxmQUcJT7vXwQ0lINDWMBd4s1lPxCTRUBV4vgisCm8Ag4SE25f\r
+ ZIY4QVGi+9kEsGpOoM7GvXIQixwkbv2bxDyBkX8BI8MqRtmU3Crd3MTMnOLUZN3i5MS8vNQi\r
+ XRO93MwSvdSU0k2M4PCR5N/B+O2g0iFGAQ5GJR7eG4kbA4RYE8uKK3MPMUpyMCmJ8mYuAgrx\r
+ JeWnVGYkFmfEF5XmpBYfYpTgYFYS4bVWBcrxpiRWVqUW5cOkpDlYlMR5r6bc9BcSSE8sSc1O\r
+ TS1ILYLJynBwKEnwBi0BahQsSk1PrUjLzClBSDNxcIIM5wEaLgpSw1tckJhbnJkOkT/FqCgl\r
+ zmsOkhAASWSU5sH1wuL7FaM40CvCvA4gVTzA1ADX/QpoMBPQ4Kez14EMLklESEk1MHrPXqzM\r
+ xWijevHLJNVcfYmJyx4Flx7SSumLiO5d/p5tk6Deia2+e58/5bjJNOe8wpTIC7MNL+llnutZ\r
+ fHiN9TdeliDm7S5OL39ouGYz7XS7NVnxzD/tT7au9YKRes0+Xg+etslnzJ0rrK/7w9p/u0/M\r
+ W6vkg2m3nmgqHk8NzDvz6Qrb1Kj2K0osxRmJhlrMRcWJAGvN5J/KAgAA\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: Sun, 25 Nov 2012 04:57:25 -0000\r
+\r
+Previously, getting the list of all messages in a thread required\r
+recursively traversing the thread's message hierarchy, which was both\r
+difficult and resulted in messages being out of order. This adds a\r
+public function to retrieve an iterator over all of the messages in a\r
+thread in oldest-first order.\r
+---\r
+ lib/notmuch.h | 13 +++++++------\r
+ lib/thread.cc | 6 ++++++\r
+ 2 files changed, 13 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 3633bed..3739336 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -719,20 +719,21 @@ int\r
+ notmuch_thread_get_total_messages (notmuch_thread_t *thread);\r
+ \r
+ /* Get a notmuch_messages_t iterator for the top-level messages in\r
+- * 'thread'.\r
++ * 'thread' in oldest-first order.\r
+ *\r
+ * This iterator will not necessarily iterate over all of the messages\r
+ * in the thread. It will only iterate over the messages in the thread\r
+ * which are not replies to other messages in the thread.\r
+- *\r
+- * To iterate over all messages in the thread, the caller will need to\r
+- * iterate over the result of notmuch_message_get_replies for each\r
+- * top-level message (and do that recursively for the resulting\r
+- * messages, etc.).\r
+ */\r
+ notmuch_messages_t *\r
+ notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread);\r
+ \r
++/* Get a notmuch_thread_t iterator for all messages in 'thread' in\r
++ * oldest-first order.\r
++ */\r
++notmuch_messages_t *\r
++notmuch_thread_get_messages (notmuch_thread_t *thread);\r
++\r
+ /* Get the number of messages in 'thread' that matched the search.\r
+ *\r
+ * This count includes only the messages in this thread that were\r
+diff --git a/lib/thread.cc b/lib/thread.cc\r
+index 45a7d1d..c126aac 100644\r
+--- a/lib/thread.cc\r
++++ b/lib/thread.cc\r
+@@ -508,6 +508,12 @@ notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread)\r
+ return _notmuch_messages_create (thread->toplevel_list);\r
+ }\r
+ \r
++notmuch_messages_t *\r
++notmuch_thread_get_messages (notmuch_thread_t *thread)\r
++{\r
++ return _notmuch_messages_create (thread->message_list);\r
++}\r
++\r
+ const char *\r
+ notmuch_thread_get_thread_id (notmuch_thread_t *thread)\r
+ {\r
+-- \r
+1.7.10.4\r
+\r