1 Return-Path: <dkg@fifthhorseman.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id 221AA6DE091F
\r
6 for <notmuch@notmuchmail.org>; Sat, 2 Apr 2016 07:16:19 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.244 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.244] autolearn=disabled
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id wRtNIK7n5KyE for <notmuch@notmuchmail.org>;
\r
16 Sat, 2 Apr 2016 07:16:11 -0700 (PDT)
\r
17 Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])
\r
18 by arlo.cworth.org (Postfix) with ESMTP id C47E16DE02DB
\r
19 for <notmuch@notmuchmail.org>; Sat, 2 Apr 2016 07:15:55 -0700 (PDT)
\r
20 Received: from fifthhorseman.net (dhcp-a244.meeting.ietf.org [31.133.162.68])
\r
21 by che.mayfirst.org (Postfix) with ESMTPSA id 6847DF997
\r
22 for <notmuch@notmuchmail.org>; Sat, 2 Apr 2016 10:15:54 -0400 (EDT)
\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)
\r
24 id B6F8920CD0; Sat, 2 Apr 2016 11:15:41 -0300 (BRT)
\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>
\r
27 Subject: [PATCH v2 6/7] On deletion,
\r
28 replace with ghost when other active messages in thread
\r
29 Date: Sat, 2 Apr 2016 11:15:40 -0300
\r
30 Message-Id: <1459606541-23889-6-git-send-email-dkg@fifthhorseman.net>
\r
31 X-Mailer: git-send-email 2.8.0.rc3
\r
32 In-Reply-To: <1459606541-23889-1-git-send-email-dkg@fifthhorseman.net>
\r
33 References: <1459445693-3900-1-git-send-email-dkg@fifthhorseman.net>
\r
34 <1459606541-23889-1-git-send-email-dkg@fifthhorseman.net>
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.20
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Sat, 02 Apr 2016 14:16:19 -0000
\r
49 There is no need to add a ghost message upon deletion if there are no
\r
50 other active messages in the thread.
\r
52 Also, if the message being deleted was a ghost already, we can just go
\r
53 ahead and delete it.
\r
55 lib/message.cc | 58 ++++++++++++++++++++++++++++++++++++++++++----------------
\r
56 1 file changed, 42 insertions(+), 16 deletions(-)
\r
58 diff --git a/lib/message.cc b/lib/message.cc
\r
59 index fab70fd..f715e39 100644
\r
60 --- a/lib/message.cc
\r
61 +++ b/lib/message.cc
\r
62 @@ -1044,11 +1044,14 @@ _notmuch_message_delete (notmuch_message_t *message)
\r
64 notmuch_status_t status;
\r
65 Xapian::WritableDatabase *db;
\r
66 - const char *mid, *tid;
\r
67 + const char *mid, *tid, *query_string;
\r
68 notmuch_message_t *ghost;
\r
69 notmuch_private_status_t private_status;
\r
70 notmuch_database_t *notmuch;
\r
72 + notmuch_query_t *query;
\r
73 + unsigned int count = 0;
\r
74 + notmuch_bool_t is_ghost;
\r
76 mid = notmuch_message_get_message_id (message);
\r
77 tid = notmuch_message_get_thread_id (message);
\r
78 notmuch = message->notmuch;
\r
79 @@ -1059,21 +1062,44 @@ _notmuch_message_delete (notmuch_message_t *message)
\r
81 db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
\r
82 db->delete_document (message->doc_id);
\r
84 - /* and reintroduce a ghost in its place */
\r
85 - ghost = _notmuch_message_create_for_message_id (notmuch, mid, &private_status);
\r
86 - if (private_status == NOTMUCH_PRIVATE_STATUS_SUCCESS) {
\r
87 - /* this is deeply weird, and we should not have gotten into
\r
88 - this state. is there a better error message to return
\r
90 - return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
91 - } else if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
\r
92 - private_status = _notmuch_message_initialize_ghost (ghost, tid);
\r
93 - if (! private_status)
\r
94 - _notmuch_message_sync (ghost);
\r
96 + /* if this was a ghost to begin with, we are done */
\r
97 + private_status = _notmuch_message_has_term_st (message, "type", "ghost", &is_ghost);
\r
98 + if (private_status)
\r
99 + return COERCE_STATUS (private_status,
\r
100 + "Error trying to determine whether message was a ghost");
\r
102 + return NOTMUCH_STATUS_SUCCESS;
\r
104 + query_string = talloc_asprintf (message, "thread:%s", tid);
\r
105 + query = notmuch_query_create (notmuch, query_string);
\r
106 + if (query == NULL)
\r
107 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
108 + status = notmuch_query_count_messages_st (query, &count);
\r
110 + notmuch_query_destroy (query);
\r
113 - notmuch_message_destroy (ghost);
\r
114 - return COERCE_STATUS (private_status, "Error converting to ghost message");
\r
117 + /* reintroduce a ghost in its place because there are still
\r
118 + * other active messages in this thread: */
\r
119 + ghost = _notmuch_message_create_for_message_id (notmuch, mid, &private_status);
\r
120 + if (private_status == NOTMUCH_PRIVATE_STATUS_SUCCESS) {
\r
121 + /* this is deeply weird, and we should not have gotten
\r
122 + into this state. is there a better error message to
\r
124 + status = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
125 + } else if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
\r
126 + private_status = _notmuch_message_initialize_ghost (ghost, tid);
\r
127 + if (! private_status)
\r
128 + _notmuch_message_sync (ghost);
\r
130 + notmuch_message_destroy (ghost);
\r
131 + status = COERCE_STATUS (private_status, "Error converting to ghost message");
\r
133 + notmuch_query_destroy (query);
\r
137 /* Transform a blank message into a ghost message. The caller must
\r