--- /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 967AF6DE0AC2\r
+ for <notmuch@notmuchmail.org>; Sun, 1 Nov 2015 12:07:21 -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 rTsOnTnQh8xA for <notmuch@notmuchmail.org>;\r
+ Sun, 1 Nov 2015 12:07:19 -0800 (PST)\r
+Received: from mail-qg0-f42.google.com (mail-qg0-f42.google.com\r
+ [209.85.192.42])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 192FD6DE0A9A\r
+ for <notmuch@notmuchmail.org>; Sun, 1 Nov 2015 12:07:19 -0800 (PST)\r
+Received: by qgeo38 with SMTP id o38so102660784qge.0\r
+ for <notmuch@notmuchmail.org>; Sun, 01 Nov 2015 12:07:17 -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;\r
+ bh=+IAkOe57Zmn0FWAMdKVUkWgelWIKDRw8+6Dn8ePS3Ns=;\r
+ b=vBYH3h0HNeBqVkAZEkF4o7i75IhmZiWB9o3nUQ018anMZsBYH0Rle/VBdVy/LSPU+j\r
+ c8MRZuVgTOVZVDnKYYd76pLte5jqa5hysSnfq0MwiILl91rp2Opb/E+HSumwpBl2lerj\r
+ hFuJMJQaBGteH0AFR7EXCkaSLSVWVQoskIRxtO6eG6fh+NPXGsnJN9qqf5ioIZeawv9h\r
+ lfmaXonw7uDUPROl7DQz6qFoHMo9ZLBlDgRaYrcekxRHtJA+gYJOK/B7AzoXCfhe1bqN\r
+ 4hd8nQBfEedY2QSrB/o8aUk9LFBi1mrnE9/feQRJrZ1NSNYEEaYm3wBILHya9ZSrWpJ/\r
+ +8ww==\r
+X-Received: by 10.140.44.33 with SMTP id f30mr24737950qga.30.1446408436914;\r
+ Sun, 01 Nov 2015 12:07:16 -0800 (PST)\r
+Received: from localhost (c-24-218-80-235.hsd1.ma.comcast.net.\r
+ [24.218.80.235]) by smtp.gmail.com with ESMTPSA id\r
+ 108sm786068qgz.17.2015.11.01.12.07.16 (version=TLSv1.2\r
+ cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Nov 2015 12:07:16\r
+ -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 method to reparent of message to the database.\r
+Date: Sun, 1 Nov 2015 15:07:08 -0500\r
+Message-Id: <1446408428-7703-1-git-send-email-steven@stebalien.com>\r
+X-Mailer: git-send-email 2.6.2\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: Sun, 01 Nov 2015 20:07:21 -0000\r
+\r
+Currently, a message is owned by its iterator (messages object) and,\r
+ultimately, its query. This unfortunately makes encapsulating query\r
+logic difficult because there is no way to return a message after\r
+disposing of the query used to find the message (other than looking it\r
+up again in the database by id).\r
+\r
+This patch adds a function `notmuch_message_own` that reparents a\r
+message onto the database making it the user's job to destroy it.\r
+---\r
+ lib/message.cc | 6 ++++++\r
+ lib/notmuch.h | 12 ++++++++++++\r
+ 2 files changed, 18 insertions(+)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 26b5e76..014363f 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -1657,6 +1657,12 @@ notmuch_message_thaw (notmuch_message_t *message)\r
+ }\r
+ \r
+ void\r
++notmuch_message_own (notmuch_message_t *message)\r
++{\r
++ talloc_steal(message->notmuch, message);\r
++}\r
++\r
++void\r
+ notmuch_message_destroy (notmuch_message_t *message)\r
+ {\r
+ talloc_free (message);\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 310a8b8..c80d7aa 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -1629,6 +1629,18 @@ notmuch_message_freeze (notmuch_message_t *message);\r
+ notmuch_status_t\r
+ notmuch_message_thaw (notmuch_message_t *message);\r
+ \r
++\r
++/**\r
++ * Reparent a notmuch_message_t object onto the database.\r
++ *\r
++ * Calling this function allows a notmuch_message_t object to outlive its\r
++ * query. The message 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_message_destroy.\r
++ */\r
++void\r
++notmuch_message_own (notmuch_message_t *message);\r
++\r
+ /**\r
+ * Destroy a notmuch_message_t object.\r
+ *\r
+-- \r
+2.6.2\r
+\r