Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / 7b / 06e39b629532d7081b70e85030a05c336101bb
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 695456DE0360\r
6  for <notmuch@notmuchmail.org>; Sat,  2 Apr 2016 07:16:11 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.314\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.314 tagged_above=-999 required=5\r
12  tests=[AWL=-0.314] 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 mWQiHFtSQ_J5 for <notmuch@notmuchmail.org>;\r
16  Sat,  2 Apr 2016 07:16:03 -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 25C5B6DE02D9\r
19  for <notmuch@notmuchmail.org>; Sat,  2 Apr 2016 07:15:48 -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 D20DCF99C\r
22  for <notmuch@notmuchmail.org>; Sat,  2 Apr 2016 10:15:46 -0400 (EDT)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id A9EBC20898; 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 3/7] fix thread breakage via ghost-on-removal\r
28 Date: Sat,  2 Apr 2016 11:15:37 -0300\r
29 Message-Id: <1459606541-23889-3-git-send-email-dkg@fifthhorseman.net>\r
30 X-Mailer: git-send-email 2.8.0.rc3\r
31 In-Reply-To: <1459606541-23889-1-git-send-email-dkg@fifthhorseman.net>\r
32 References: <1459445693-3900-1-git-send-email-dkg@fifthhorseman.net>\r
33  <1459606541-23889-1-git-send-email-dkg@fifthhorseman.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.20\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38  <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
40  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Sat, 02 Apr 2016 14:16:11 -0000\r
47 \r
48 ghost-on-removal the solution to T590-thread-breakage.sh that just\r
49 adds a ghost message after removing each message.\r
50 \r
51 It leaks information about whether we've ever seen a given message id,\r
52 but it's a fairly simple implementation.\r
53 \r
54 Note that _resolve_message_id_to_thread_id also introduces new\r
55 message_ids to the database, so i think just searching for a given\r
56 message ID may introduce the same metadata leakage.\r
57 \r
58 This differs from v1 of this changeset in that we implement the change\r
59 in _notmuch_message_delete, a more "internal" function.\r
60 ---\r
61  lib/database.cc |  2 +-\r
62  lib/message.cc  | 29 ++++++++++++++++++++++++++---\r
63  2 files changed, 27 insertions(+), 4 deletions(-)\r
64 \r
65 diff --git a/lib/database.cc b/lib/database.cc\r
66 index 3b342f1..d5733c9 100644\r
67 --- a/lib/database.cc\r
68 +++ b/lib/database.cc\r
69 @@ -2557,7 +2557,7 @@ notmuch_database_remove_message (notmuch_database_t *notmuch,\r
70  \r
71      if (status == NOTMUCH_STATUS_SUCCESS && message) {\r
72             status = _notmuch_message_remove_filename (message, filename);\r
73 -           if (status == NOTMUCH_STATUS_SUCCESS)\r
74 +           if (status == NOTMUCH_STATUS_SUCCESS) \r
75                 _notmuch_message_delete (message);\r
76             else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)\r
77                 _notmuch_message_sync (message);\r
78 diff --git a/lib/message.cc b/lib/message.cc\r
79 index 8d72ea2..e414e9c 100644\r
80 --- a/lib/message.cc\r
81 +++ b/lib/message.cc\r
82 @@ -1037,20 +1037,43 @@ _notmuch_message_sync (notmuch_message_t *message)\r
83      message->modified = FALSE;\r
84  }\r
85  \r
86 -/* Delete a message document from the database. */\r
87 +/* Delete a message document from the database, leaving a ghost\r
88 + * message in its place */\r
89  notmuch_status_t\r
90  _notmuch_message_delete (notmuch_message_t *message)\r
91  {\r
92      notmuch_status_t status;\r
93      Xapian::WritableDatabase *db;\r
94 +    const char *mid, *tid;\r
95 +    notmuch_message_t *ghost;\r
96 +    notmuch_private_status_t private_status;\r
97 +    notmuch_database_t *notmuch;\r
98 +           \r
99 +    mid = notmuch_message_get_message_id (message);\r
100 +    tid = notmuch_message_get_thread_id (message);\r
101 +    notmuch = message->notmuch;\r
102  \r
103      status = _notmuch_database_ensure_writable (message->notmuch);\r
104      if (status)\r
105         return status;\r
106  \r
107 -    db = static_cast <Xapian::WritableDatabase *> (message->notmuch->xapian_db);\r
108 +    db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);\r
109      db->delete_document (message->doc_id);\r
110 -    return NOTMUCH_STATUS_SUCCESS;\r
111 +           \r
112 +    /* and reintroduce a ghost in its place */\r
113 +    ghost = _notmuch_message_create_for_message_id (notmuch, mid, &private_status);\r
114 +    if (private_status == NOTMUCH_PRIVATE_STATUS_SUCCESS) {\r
115 +       /* this is deeply weird, and we should not have gotten into\r
116 +          this state.  is there a better error message to return\r
117 +          here? */\r
118 +       return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;\r
119 +    } else if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {\r
120 +       private_status = _notmuch_message_initialize_ghost (ghost, tid);\r
121 +       if (! private_status)\r
122 +           _notmuch_message_sync (ghost);\r
123 +    }\r
124 +    notmuch_message_destroy (ghost);\r
125 +    return COERCE_STATUS (private_status, "Error converting to ghost message");\r
126  }\r
127  \r
128  /* Transform a blank message into a ghost message.  The caller must\r
129 -- \r
130 2.8.0.rc3\r
131 \r