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 EACBC431FC4 for ; Sun, 20 Dec 2009 12:27:41 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 f3tleb56Fog4 for ; Sun, 20 Dec 2009 12:27:40 -0800 (PST) Received: from jameswestby.net (jameswestby.net [89.145.97.141]) by olra.theworths.org (Postfix) with ESMTP id A78D5431FBF for ; Sun, 20 Dec 2009 12:27:40 -0800 (PST) Received: from cpc4-aztw22-2-0-cust59.aztw.cable.virginmedia.com ([94.169.116.60] helo=flash) by jameswestby.net with esmtpa (Exim 4.69) (envelope-from ) id 1NMSNP-0000aG-22; Sun, 20 Dec 2009 20:27:39 +0000 Received: by flash (Postfix, from userid 1000) id 4BC046E546A; Sun, 20 Dec 2009 20:27:33 +0000 (GMT) From: James Westby To: notmuch@notmuchmail.org Date: Sun, 20 Dec 2009 20:27:32 +0000 Message-Id: <1261340852-20183-1-git-send-email-jw+debian@jameswestby.net> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <871virzzjy.fsf@yoom.home.cworth.org> References: <871virzzjy.fsf@yoom.home.cworth.org> Subject: [notmuch] [PATCH] Store documents for message-ids we haven't seen X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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, 20 Dec 2009 20:27:42 -0000 When scanning the maildir there can be earlier messages in the thread that we haven't seen, either due to mail delays, or because they weren't sent. This can break the threading. Therefore we store stub documents for every message id we see, so that we can link them in to the threads. If we see the message later then we will replace the document with the full information. --- Here's the third part of the patch, that actually stores the stubs and links the threads. It's fairly simple, though we may want to store a little more in the stubs. One case that isn't handled is when we don't find the thread id of the parent, but then find the message itself. I believe this case shouldn't happen, but you never know. lib/database.cc | 25 +++++++++++++++++++++++++ lib/message.cc | 9 +-------- lib/notmuch-private.h | 10 ++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 64f29b9..6ee8068 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -782,8 +782,33 @@ _notmuch_database_link_message_to_parents (notmuch_database_t *notmuch, parent_message_id); if (parent_thread_id == NULL) { + notmuch_private_status_t private_status; + notmuch_message_t *new_parent_message; + thread_id_t parent_thread_id_t; + + // We have yet to see the referenced message, generate a thread id + // for it if needed and store a dummy message for the parent. If we + // find the mail later we will replace the dummy. _notmuch_message_add_term (message, "reference", parent_message_id); + if (*thread_id == NULL) { + thread_id_generate (&parent_thread_id_t); + *thread_id = parent_thread_id_t.str; + } + new_parent_message = _notmuch_message_create_for_message_id (notmuch, + parent_message_id, &private_status); + if (private_status) { + if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) { + // expected + _notmuch_message_add_term (new_parent_message, "thread", *thread_id); + _notmuch_message_sync (new_parent_message); + } else { + ret = COERCE_STATUS (private_status, + "Cannot create parent message"); + goto DONE; + } + } + _notmuch_message_add_term (message, "thread", *thread_id); } else { if (*thread_id == NULL) { *thread_id = talloc_strdup (message, parent_thread_id); diff --git a/lib/message.cc b/lib/message.cc index 7129d59..dff02c4 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -42,13 +42,6 @@ struct _notmuch_message { Xapian::Document doc; }; -/* "128 bits of thread-id ought to be enough for anybody" */ -#define NOTMUCH_THREAD_ID_BITS 128 -#define NOTMUCH_THREAD_ID_DIGITS (NOTMUCH_THREAD_ID_BITS / 4) -typedef struct _thread_id { - char str[NOTMUCH_THREAD_ID_DIGITS + 1]; -} thread_id_t; - /* We end up having to call the destructor explicitly because we had * to use "placement new" in order to initialize C++ objects within a * block that we allocated with talloc. So C++ is making talloc @@ -551,7 +544,7 @@ _notmuch_message_set_date (notmuch_message_t *message, Xapian::sortable_serialise (time_value)); } -static void +void thread_id_generate (thread_id_t *thread_id) { static int seeded = 0; diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index cf65fd9..cf75b4a 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -141,6 +141,13 @@ typedef enum _notmuch_private_status { : \ (notmuch_status_t) private_status) +/* "128 bits of thread-id ought to be enough for anybody" */ +#define NOTMUCH_THREAD_ID_BITS 128 +#define NOTMUCH_THREAD_ID_DIGITS (NOTMUCH_THREAD_ID_BITS / 4) +typedef struct _thread_id { + char str[NOTMUCH_THREAD_ID_DIGITS + 1]; +} thread_id_t; + /* database.cc */ /* Lookup a prefix value by name. @@ -347,6 +354,9 @@ void _notmuch_message_add_reply (notmuch_message_t *message, notmuch_message_node_t *reply); +void +thread_id_generate (thread_id_t *thread_id); + /* sha1.c */ char * -- 1.6.3.3