--- /dev/null
+Return-Path: <stebalien@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 arlo.cworth.org (Postfix) with ESMTP id BF51A6DE1343\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Nov 2015 13:04:45 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.681\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.681 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001,\r
+ T_FREEMAIL_FORGED_FROMDOMAIN=0.01,\r
+ T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] 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 6sxUEwiSP0kr for <notmuch@notmuchmail.org>;\r
+ Sat, 7 Nov 2015 13:04:43 -0800 (PST)\r
+Received: from mail-vk0-f43.google.com (mail-vk0-f43.google.com\r
+ [209.85.213.43])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 50E416DE1006\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Nov 2015 13:04:43 -0800 (PST)\r
+Received: by vkfw189 with SMTP id w189so35685790vkf.2\r
+ for <notmuch@notmuchmail.org>; Sat, 07 Nov 2015 13:04:42 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=sender:from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=XV38gCwswr3Z1qNgGfbC4k+fxluRzPJLD3DfyH7mRIw=;\r
+ b=XJTxmSgg0uCOlFszvI2l6Ga5IIgO2L5Hb4mLs/4oz/Qd9QzwSCAgP0dgr85ge23o+D\r
+ Uh38VIBLjapkGx2DV+zQK9x9ImF9isQhUkYos4SOtU4Jk8jJ+i17kUOfNYlAKV/LBETg\r
+ 4Sb9U3m4jNsdH7xjXI+My6ppXA2bXcquusXrEw8cOAKW4SUP8EQzIvo207jIQPV8KJRq\r
+ JCkk2r8wojxVCxZmMW221uWT7a4IZ3yA6v8oJLP7CAReit7QrvO07cYYrxtvVqgRp7Iw\r
+ IjhbfOx9bw4zo8zaLP7VCzwgsLQtHzMxbd+gVAwB1+5Zdye842xnUiOskEcefkonKirv\r
+ sXBA==\r
+X-Received: by 10.31.160.5 with SMTP id j5mr22470137vke.107.1446930282057;\r
+ Sat, 07 Nov 2015 13:04:42 -0800 (PST)\r
+Received: from localhost ([50.247.245.235])\r
+ by smtp.gmail.com with ESMTPSA id k7sm5632937vki.8.2015.11.07.13.04.41\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 07 Nov 2015 13:04:41 -0800 (PST)\r
+Sender: Steven <stebalien@gmail.com>\r
+From: Steven Allen <steven@stebalien.com>\r
+To: notmuch@notmuchmail.org\r
+Cc: Steven Allen <steven@stebalien.com>\r
+Subject: [PATCH] Add a method to reparent threads to the database.\r
+Date: Sat, 7 Nov 2015 16:04:29 -0500\r
+Message-Id: <1446930269-4865-1-git-send-email-steven@stebalien.com>\r
+X-Mailer: git-send-email 2.6.2\r
+In-Reply-To: <1446408428-7703-1-git-send-email-steven@stebalien.com>\r
+References: <1446408428-7703-1-git-send-email-steven@stebalien.com>\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, 07 Nov 2015 21:04:45 -0000\r
+\r
+This allows threads yielded from a query to outlive the query.\r
+---\r
+ lib/notmuch.h | 11 +++++++++++\r
+ lib/thread.cc | 6 ++++++\r
+ 2 files changed, 17 insertions(+)\r
+\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 310a8b8..9a2869b 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -1188,6 +1188,17 @@ notmuch_tags_t *\r
+ notmuch_thread_get_tags (notmuch_thread_t *thread);\r
+ \r
+ /**\r
++ * Reparent a notmuch_thread_t object onto the database.\r
++ *\r
++ * Calling this function allows a notmuch_thread_t object to outlive its\r
++ * query. The query will automatically be reclaimed when the database is\r
++ * destroyed but if you want to free its memory before then, you should call\r
++ * notmuch_thread_destroy.\r
++ */\r
++void\r
++notmuch_thread_own (notmuch_thread_t *thread);\r
++\r
++/**\r
+ * Destroy a notmuch_thread_t object.\r
+ */\r
+ void\r
+diff --git a/lib/thread.cc b/lib/thread.cc\r
+index 0c937d7..06fa155 100644\r
+--- a/lib/thread.cc\r
++++ b/lib/thread.cc\r
+@@ -623,3 +623,9 @@ notmuch_thread_destroy (notmuch_thread_t *thread)\r
+ {\r
+ talloc_free (thread);\r
+ }\r
++\r
++void\r
++notmuch_thread_own (notmuch_thread_t *thread)\r
++{\r
++ talloc_steal (thread->notmuch, thread);\r
++}\r
+-- \r
+2.6.2\r
+\r