From a52f04f1f91a6a71c5a0366dbc7fc37dd5d5d2c4 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 2 Nov 2015 15:07:08 +1900 Subject: [PATCH] [PATCH] Add method to reparent of message to the database. --- 98/0a38f9df077eff44bf924f12d7f4a4b3003d0d | 119 ++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 98/0a38f9df077eff44bf924f12d7f4a4b3003d0d diff --git a/98/0a38f9df077eff44bf924f12d7f4a4b3003d0d b/98/0a38f9df077eff44bf924f12d7f4a4b3003d0d new file mode 100644 index 000000000..facef015b --- /dev/null +++ b/98/0a38f9df077eff44bf924f12d7f4a4b3003d0d @@ -0,0 +1,119 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 967AF6DE0AC2 + for ; Sun, 1 Nov 2015 12:07:21 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.681 +X-Spam-Level: +X-Spam-Status: No, score=-0.681 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, + RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, + T_FREEMAIL_FORGED_FROMDOMAIN=0.01, + T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id rTsOnTnQh8xA for ; + Sun, 1 Nov 2015 12:07:19 -0800 (PST) +Received: from mail-qg0-f42.google.com (mail-qg0-f42.google.com + [209.85.192.42]) + by arlo.cworth.org (Postfix) with ESMTPS id 192FD6DE0A9A + for ; Sun, 1 Nov 2015 12:07:19 -0800 (PST) +Received: by qgeo38 with SMTP id o38so102660784qge.0 + for ; Sun, 01 Nov 2015 12:07:17 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=sender:from:to:cc:subject:date:message-id; + bh=+IAkOe57Zmn0FWAMdKVUkWgelWIKDRw8+6Dn8ePS3Ns=; + b=vBYH3h0HNeBqVkAZEkF4o7i75IhmZiWB9o3nUQ018anMZsBYH0Rle/VBdVy/LSPU+j + c8MRZuVgTOVZVDnKYYd76pLte5jqa5hysSnfq0MwiILl91rp2Opb/E+HSumwpBl2lerj + hFuJMJQaBGteH0AFR7EXCkaSLSVWVQoskIRxtO6eG6fh+NPXGsnJN9qqf5ioIZeawv9h + lfmaXonw7uDUPROl7DQz6qFoHMo9ZLBlDgRaYrcekxRHtJA+gYJOK/B7AzoXCfhe1bqN + 4hd8nQBfEedY2QSrB/o8aUk9LFBi1mrnE9/feQRJrZ1NSNYEEaYm3wBILHya9ZSrWpJ/ + +8ww== +X-Received: by 10.140.44.33 with SMTP id f30mr24737950qga.30.1446408436914; + Sun, 01 Nov 2015 12:07:16 -0800 (PST) +Received: from localhost (c-24-218-80-235.hsd1.ma.comcast.net. + [24.218.80.235]) by smtp.gmail.com with ESMTPSA id + 108sm786068qgz.17.2015.11.01.12.07.16 (version=TLSv1.2 + cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Nov 2015 12:07:16 + -0800 (PST) +Sender: Steven +From: Steven Allen +To: notmuch@notmuchmail.org +Cc: Steven Allen +Subject: [PATCH] Add method to reparent of message to the database. +Date: Sun, 1 Nov 2015 15:07:08 -0500 +Message-Id: <1446408428-7703-1-git-send-email-steven@stebalien.com> +X-Mailer: git-send-email 2.6.2 +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 01 Nov 2015 20:07:21 -0000 + +Currently, a message is owned by its iterator (messages object) and, +ultimately, its query. This unfortunately makes encapsulating query +logic difficult because there is no way to return a message after +disposing of the query used to find the message (other than looking it +up again in the database by id). + +This patch adds a function `notmuch_message_own` that reparents a +message onto the database making it the user's job to destroy it. +--- + lib/message.cc | 6 ++++++ + lib/notmuch.h | 12 ++++++++++++ + 2 files changed, 18 insertions(+) + +diff --git a/lib/message.cc b/lib/message.cc +index 26b5e76..014363f 100644 +--- a/lib/message.cc ++++ b/lib/message.cc +@@ -1657,6 +1657,12 @@ notmuch_message_thaw (notmuch_message_t *message) + } + + void ++notmuch_message_own (notmuch_message_t *message) ++{ ++ talloc_steal(message->notmuch, message); ++} ++ ++void + notmuch_message_destroy (notmuch_message_t *message) + { + talloc_free (message); +diff --git a/lib/notmuch.h b/lib/notmuch.h +index 310a8b8..c80d7aa 100644 +--- a/lib/notmuch.h ++++ b/lib/notmuch.h +@@ -1629,6 +1629,18 @@ notmuch_message_freeze (notmuch_message_t *message); + notmuch_status_t + notmuch_message_thaw (notmuch_message_t *message); + ++ ++/** ++ * Reparent a notmuch_message_t object onto the database. ++ * ++ * Calling this function allows a notmuch_message_t object to outlive its ++ * query. The message will automatically be reclaimed when the database is ++ * destroyed but if you want to free its memory before then, you should call ++ * notmuch_message_destroy. ++ */ ++void ++notmuch_message_own (notmuch_message_t *message); ++ + /** + * Destroy a notmuch_message_t object. + * +-- +2.6.2 + -- 2.26.2