Re: [PATCH] remove message archiving from show-advance-and-archive
[notmuch-archives.git] / 0d / 172346bfcee87011fafbdac16797180c9a5e97
1 Return-Path: <james@jameswestby.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 olra.theworths.org (Postfix) with ESMTP id EACBC431FC4\r
6         for <notmuch@notmuchmail.org>; Sun, 20 Dec 2009 12:27:41 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id f3tleb56Fog4 for <notmuch@notmuchmail.org>;\r
11         Sun, 20 Dec 2009 12:27:40 -0800 (PST)\r
12 Received: from jameswestby.net (jameswestby.net [89.145.97.141])\r
13         by olra.theworths.org (Postfix) with ESMTP id A78D5431FBF\r
14         for <notmuch@notmuchmail.org>; Sun, 20 Dec 2009 12:27:40 -0800 (PST)\r
15 Received: from cpc4-aztw22-2-0-cust59.aztw.cable.virginmedia.com\r
16         ([94.169.116.60] helo=flash)\r
17         by jameswestby.net with esmtpa (Exim 4.69)\r
18         (envelope-from <james@jameswestby.net>)\r
19         id 1NMSNP-0000aG-22; Sun, 20 Dec 2009 20:27:39 +0000\r
20 Received: by flash (Postfix, from userid 1000)\r
21         id 4BC046E546A; Sun, 20 Dec 2009 20:27:33 +0000 (GMT)\r
22 From: James Westby <jw+debian@jameswestby.net>\r
23 To: notmuch@notmuchmail.org\r
24 Date: Sun, 20 Dec 2009 20:27:32 +0000\r
25 Message-Id: <1261340852-20183-1-git-send-email-jw+debian@jameswestby.net>\r
26 X-Mailer: git-send-email 1.6.3.3\r
27 In-Reply-To: <871virzzjy.fsf@yoom.home.cworth.org>\r
28 References: <871virzzjy.fsf@yoom.home.cworth.org>\r
29 Subject: [notmuch] [PATCH] Store documents for message-ids we haven't seen\r
30 X-BeenThere: notmuch@notmuchmail.org\r
31 X-Mailman-Version: 2.1.12\r
32 Precedence: list\r
33 List-Id: "Use and development of the notmuch mail system."\r
34         <notmuch.notmuchmail.org>\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
36         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
38 List-Post: <mailto:notmuch@notmuchmail.org>\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
42 X-List-Received-Date: Sun, 20 Dec 2009 20:27:42 -0000\r
43 \r
44 When scanning the maildir there can be earlier messages\r
45 in the thread that we haven't seen, either due to mail\r
46 delays, or because they weren't sent. This can break the\r
47 threading.\r
48 \r
49 Therefore we store stub documents for every message id\r
50 we see, so that we can link them in to the threads. If\r
51 we see the message later then we will replace the document\r
52 with the full information.\r
53 ---\r
54 \r
55   Here's the third part of the patch, that actually stores\r
56   the stubs and links the threads. It's fairly simple,\r
57   though we may want to store a little more in the stubs.\r
58 \r
59   One case that isn't handled is when we don't find the thread\r
60   id of the parent, but then find the message itself. I believe\r
61   this case shouldn't happen, but you never know.\r
62 \r
63  lib/database.cc       |   25 +++++++++++++++++++++++++\r
64  lib/message.cc        |    9 +--------\r
65  lib/notmuch-private.h |   10 ++++++++++\r
66  3 files changed, 36 insertions(+), 8 deletions(-)\r
67 \r
68 diff --git a/lib/database.cc b/lib/database.cc\r
69 index 64f29b9..6ee8068 100644\r
70 --- a/lib/database.cc\r
71 +++ b/lib/database.cc\r
72 @@ -782,8 +782,33 @@ _notmuch_database_link_message_to_parents (notmuch_database_t *notmuch,\r
73                                                              parent_message_id);\r
74  \r
75         if (parent_thread_id == NULL) {\r
76 +           notmuch_private_status_t private_status;\r
77 +           notmuch_message_t *new_parent_message;\r
78 +           thread_id_t parent_thread_id_t;\r
79 +\r
80 +           // We have yet to see the referenced message, generate a thread id\r
81 +           // for it if needed and store a dummy message for the parent. If we\r
82 +           // find the mail later we will replace the dummy.\r
83             _notmuch_message_add_term (message, "reference",\r
84                                        parent_message_id);\r
85 +           if (*thread_id == NULL) {\r
86 +               thread_id_generate (&parent_thread_id_t);\r
87 +               *thread_id = parent_thread_id_t.str;\r
88 +           }\r
89 +           new_parent_message = _notmuch_message_create_for_message_id (notmuch,\r
90 +                                           parent_message_id, &private_status);\r
91 +               if (private_status) {\r
92 +                   if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {\r
93 +                       // expected\r
94 +                       _notmuch_message_add_term (new_parent_message, "thread", *thread_id);\r
95 +                       _notmuch_message_sync (new_parent_message);\r
96 +                   } else {\r
97 +                       ret = COERCE_STATUS (private_status,\r
98 +                                "Cannot create parent message");\r
99 +                       goto DONE;\r
100 +                   }\r
101 +               }\r
102 +           _notmuch_message_add_term (message, "thread", *thread_id);\r
103         } else {\r
104             if (*thread_id == NULL) {\r
105                 *thread_id = talloc_strdup (message, parent_thread_id);\r
106 diff --git a/lib/message.cc b/lib/message.cc\r
107 index 7129d59..dff02c4 100644\r
108 --- a/lib/message.cc\r
109 +++ b/lib/message.cc\r
110 @@ -42,13 +42,6 @@ struct _notmuch_message {\r
111      Xapian::Document doc;\r
112  };\r
113  \r
114 -/* "128 bits of thread-id ought to be enough for anybody" */\r
115 -#define NOTMUCH_THREAD_ID_BITS  128\r
116 -#define NOTMUCH_THREAD_ID_DIGITS (NOTMUCH_THREAD_ID_BITS / 4)\r
117 -typedef struct _thread_id {\r
118 -    char str[NOTMUCH_THREAD_ID_DIGITS + 1];\r
119 -} thread_id_t;\r
120 -\r
121  /* We end up having to call the destructor explicitly because we had\r
122   * to use "placement new" in order to initialize C++ objects within a\r
123   * block that we allocated with talloc. So C++ is making talloc\r
124 @@ -551,7 +544,7 @@ _notmuch_message_set_date (notmuch_message_t *message,\r
125                             Xapian::sortable_serialise (time_value));\r
126  }\r
127  \r
128 -static void\r
129 +void\r
130  thread_id_generate (thread_id_t *thread_id)\r
131  {\r
132      static int seeded = 0;\r
133 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
134 index cf65fd9..cf75b4a 100644\r
135 --- a/lib/notmuch-private.h\r
136 +++ b/lib/notmuch-private.h\r
137 @@ -141,6 +141,13 @@ typedef enum _notmuch_private_status {\r
138       :                                                                 \\r
139       (notmuch_status_t) private_status)\r
140  \r
141 +/* "128 bits of thread-id ought to be enough for anybody" */\r
142 +#define NOTMUCH_THREAD_ID_BITS  128\r
143 +#define NOTMUCH_THREAD_ID_DIGITS (NOTMUCH_THREAD_ID_BITS / 4)\r
144 +typedef struct _thread_id {\r
145 +    char str[NOTMUCH_THREAD_ID_DIGITS + 1];\r
146 +} thread_id_t;\r
147 +\r
148  /* database.cc */\r
149  \r
150  /* Lookup a prefix value by name.\r
151 @@ -347,6 +354,9 @@ void\r
152  _notmuch_message_add_reply (notmuch_message_t *message,\r
153                             notmuch_message_node_t *reply);\r
154  \r
155 +void\r
156 +thread_id_generate (thread_id_t *thread_id);\r
157 +\r
158  /* sha1.c */\r
159  \r
160  char *\r
161 -- \r
162 1.6.3.3\r
163 \r