From 0e2b831623551f582783dd1c489545a6fb276884 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 24 Oct 2014 08:30:36 +2000 Subject: [PATCH] [PATCH v3 4/9] lib: Internal support for querying and creating ghost messages --- 35/13253d195736cc53c91e586764503dab48d1f1 | 249 ++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 35/13253d195736cc53c91e586764503dab48d1f1 diff --git a/35/13253d195736cc53c91e586764503dab48d1f1 b/35/13253d195736cc53c91e586764503dab48d1f1 new file mode 100644 index 000000000..f17d2d2b3 --- /dev/null +++ b/35/13253d195736cc53c91e586764503dab48d1f1 @@ -0,0 +1,249 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 1F440431FD4 + for ; Thu, 23 Oct 2014 05:31:13 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id JhhI9C9AN1ks for ; + Thu, 23 Oct 2014 05:31:07 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu + [18.9.25.14]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 568E5431FDF + for ; Thu, 23 Oct 2014 05:30:56 -0700 (PDT) +X-AuditID: 1209190e-f79d46d000003643-84-5448f4ffc8d3 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id FB.79.13891.005F8445; Thu, 23 Oct 2014 08:30:56 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s9NCUrD3030512; + Thu, 23 Oct 2014 08:30:53 -0400 +Received: from drake.dyndns.org + (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [216.15.114.40]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s9NCUmIb008961 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Thu, 23 Oct 2014 08:30:51 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.84) + (envelope-from ) + id 1XhHXP-0007bq-AA; Thu, 23 Oct 2014 08:30:43 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v3 4/9] lib: Internal support for querying and creating ghost + messages +Date: Thu, 23 Oct 2014 08:30:36 -0400 +Message-Id: <1414067441-29054-5-git-send-email-aclements@csail.mit.edu> +X-Mailer: git-send-email 2.1.0 +In-Reply-To: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu> +References: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixG6nrsvw1SPE4PVvFovVc3ksrt+cyezA + 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZXRtlCyYZljR/uwKUwPjY/UuRk4OCQETiStr + 57BB2GISF+6tB7OFBGYzSeydotfFyAVkb2SU2H58OyOEc4dJYt60A2wQzhJGiXer37KCtLAJ + 6EusWDsJzBYRkJbYeXc2mM0s4Cjxef8isLHCAmESczfOYAKxWQRUJZ68X8MCYvMKuEvMnvSI + GeIMOYkNu/8zgticAh4Se3bcgTrJXWL784OsExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtL + LdI11svNLNFLTSndxAgKI05Jvh2MXw8qHWIU4GBU4uGtSPYIEWJNLCuuzD3EKMnBpCTKG/MA + KMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmEN/4CUI43JbGyKrUoHyYlzcGiJM676QdfiJBAemJJ + anZqakFqEUxWhoNDSYKX8QtQo2BRanpqRVpmTglCmomDE2Q4D9BwEZAa3uKCxNzizHSI/ClG + RSlx3uTPQAkBkERGaR5cLyzOXzGKA70izKsG0s4DTBFw3a+ABjOBXL0BbHBJIkJKqoGxtGL5 + q02XEqw/W3D83pF9RkV/dnPr1U+MP/qqnL49rZHa9fe/RqPUkfWXvmvVSTlV7FrBv3qxSYZC + /4HvVRO8F5/9kzhrje7OyYX+h3c3+5kHbXgWnmqWsDblej7zmt7iNZzsh2Jyrib+Fdlk7h02 + yWzDrkkcgYc+tv87fsvg4o+mSEGVulQ7JZbijERDLeai4kQAueIBCc4CAAA= +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Thu, 23 Oct 2014 12:31:13 -0000 + +From: Austin Clements + +This updates the message abstraction to support ghost messages: it +adds a message flag that distinguishes regular messages from ghost +messages, and an internal function for initializing a newly created +(blank) message as a ghost message. +--- + lib/message.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++++++-- + lib/notmuch-private.h | 4 ++++ + lib/notmuch.h | 9 ++++++++- + 3 files changed, 62 insertions(+), 3 deletions(-) + +diff --git a/lib/message.cc b/lib/message.cc +index 55d2ff6..a7a13cc 100644 +--- a/lib/message.cc ++++ b/lib/message.cc +@@ -39,6 +39,9 @@ struct visible _notmuch_message { + notmuch_message_file_t *message_file; + notmuch_message_list_t *replies; + unsigned long flags; ++ /* For flags that are initialized on-demand, lazy_flags indicates ++ * if each flag has been initialized. */ ++ unsigned long lazy_flags; + + Xapian::Document doc; + Xapian::termcount termpos; +@@ -99,6 +102,7 @@ _notmuch_message_create_for_document (const void *talloc_owner, + + message->frozen = 0; + message->flags = 0; ++ message->lazy_flags = 0; + + /* Each of these will be lazily created as needed. */ + message->message_id = NULL; +@@ -192,7 +196,7 @@ _notmuch_message_create (const void *talloc_owner, + * + * There is already a document with message ID 'message_id' in the + * database. The returned message can be used to query/modify the +- * document. ++ * document. The message may be a ghost message. + * + * NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND: + * +@@ -305,6 +309,7 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message) + const char *thread_prefix = _find_prefix ("thread"), + *tag_prefix = _find_prefix ("tag"), + *id_prefix = _find_prefix ("id"), ++ *type_prefix = _find_prefix ("type"), + *filename_prefix = _find_prefix ("file-direntry"), + *replyto_prefix = _find_prefix ("replyto"); + +@@ -337,10 +342,25 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message) + message->message_id = + _notmuch_message_get_term (message, i, end, id_prefix); + ++ /* Get document type */ ++ assert (strcmp (id_prefix, type_prefix) < 0); ++ if (! NOTMUCH_TEST_BIT (message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST)) { ++ i.skip_to (type_prefix); ++ /* "T" is the prefix "type" fields. See ++ * BOOLEAN_PREFIX_INTERNAL. */ ++ if (*i == "Tmail") ++ NOTMUCH_CLEAR_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST); ++ else if (*i == "Tghost") ++ NOTMUCH_SET_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST); ++ else ++ INTERNAL_ERROR ("Message without type term"); ++ NOTMUCH_SET_BIT (&message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST); ++ } ++ + /* Get filename list. Here we get only the terms. We lazily + * expand them to full file names when needed in + * _notmuch_message_ensure_filename_list. */ +- assert (strcmp (id_prefix, filename_prefix) < 0); ++ assert (strcmp (type_prefix, filename_prefix) < 0); + if (!message->filename_term_list && !message->filename_list) + message->filename_term_list = + _notmuch_database_get_terms_with_prefix (message, i, end, +@@ -371,6 +391,11 @@ _notmuch_message_invalidate_metadata (notmuch_message_t *message, + message->tag_list = NULL; + } + ++ if (strcmp ("type", prefix_name) == 0) { ++ NOTMUCH_CLEAR_BIT (&message->flags, NOTMUCH_MESSAGE_FLAG_GHOST); ++ NOTMUCH_CLEAR_BIT (&message->lazy_flags, NOTMUCH_MESSAGE_FLAG_GHOST); ++ } ++ + if (strcmp ("file-direntry", prefix_name) == 0) { + talloc_free (message->filename_term_list); + talloc_free (message->filename_list); +@@ -869,6 +894,10 @@ notmuch_bool_t + notmuch_message_get_flag (notmuch_message_t *message, + notmuch_message_flag_t flag) + { ++ if (flag == NOTMUCH_MESSAGE_FLAG_GHOST && ++ ! NOTMUCH_TEST_BIT (message->lazy_flags, flag)) ++ _notmuch_message_ensure_metadata (message); ++ + return NOTMUCH_TEST_BIT (message->flags, flag); + } + +@@ -880,6 +909,7 @@ notmuch_message_set_flag (notmuch_message_t *message, + NOTMUCH_SET_BIT (&message->flags, flag); + else + NOTMUCH_CLEAR_BIT (&message->flags, flag); ++ NOTMUCH_SET_BIT (&message->lazy_flags, flag); + } + + time_t +@@ -989,6 +1019,24 @@ _notmuch_message_delete (notmuch_message_t *message) + return NOTMUCH_STATUS_SUCCESS; + } + ++/* Transform a blank message into a ghost message. The caller must ++ * _notmuch_message_sync the message. */ ++notmuch_private_status_t ++_notmuch_message_initialize_ghost (notmuch_message_t *message, ++ const char *thread_id) ++{ ++ notmuch_private_status_t status; ++ ++ status = _notmuch_message_add_term (message, "type", "ghost"); ++ if (status) ++ return status; ++ status = _notmuch_message_add_term (message, "thread", thread_id); ++ if (status) ++ return status; ++ ++ return NOTMUCH_PRIVATE_STATUS_SUCCESS; ++} ++ + /* Ensure that 'message' is not holding any file object open. Future + * calls to various functions will still automatically open the + * message file as needed. +diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h +index 7250291..2f43c1d 100644 +--- a/lib/notmuch-private.h ++++ b/lib/notmuch-private.h +@@ -308,6 +308,10 @@ _notmuch_message_sync (notmuch_message_t *message); + notmuch_status_t + _notmuch_message_delete (notmuch_message_t *message); + ++notmuch_private_status_t ++_notmuch_message_initialize_ghost (notmuch_message_t *message, ++ const char *thread_id); ++ + void + _notmuch_message_close (notmuch_message_t *message); + +diff --git a/lib/notmuch.h b/lib/notmuch.h +index dae0416..92594b9 100644 +--- a/lib/notmuch.h ++++ b/lib/notmuch.h +@@ -1221,7 +1221,14 @@ notmuch_message_get_filenames (notmuch_message_t *message); + */ + typedef enum _notmuch_message_flag { + NOTMUCH_MESSAGE_FLAG_MATCH, +- NOTMUCH_MESSAGE_FLAG_EXCLUDED ++ NOTMUCH_MESSAGE_FLAG_EXCLUDED, ++ ++ /* This message is a "ghost message", meaning it has no filenames ++ * or content, but we know it exists because it was referenced by ++ * some other message. A ghost message has only a message ID and ++ * thread ID. ++ */ ++ NOTMUCH_MESSAGE_FLAG_GHOST, + } notmuch_message_flag_t; + + /** +-- +2.1.0 + -- 2.26.2