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 24613431FC4 for ; Tue, 2 Feb 2010 07:01:14 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.959 X-Spam-Level: X-Spam-Status: No, score=-0.959 tagged_above=-999 required=5 tests=[AWL=-0.960, BAYES_50=0.001] autolearn=ham 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 6XPr0jM+WH9T for ; Tue, 2 Feb 2010 07:01:13 -0800 (PST) Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) by olra.theworths.org (Postfix) with ESMTP id D1C35431FC0 for ; Tue, 2 Feb 2010 07:01:12 -0800 (PST) Received: from localhost (unknown [192.168.200.4]) by max.feld.cvut.cz (Postfix) with ESMTP id 3BA3219F3331 for ; Tue, 2 Feb 2010 16:01:11 +0100 (CET) X-Virus-Scanned: IMAP AMAVIS Received: from max.feld.cvut.cz ([192.168.200.1]) by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new, port 10044) with ESMTP id KfMAfBLv1ay5 for ; Tue, 2 Feb 2010 16:01:11 +0100 (CET) Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34]) by max.feld.cvut.cz (Postfix) with ESMTP id 1408B19F332E for ; Tue, 2 Feb 2010 16:01:11 +0100 (CET) Received: from localhost.localdomain (k335-30.felk.cvut.cz [147.32.86.30]) (Authenticated sender: sojkam1) by imap.feld.cvut.cz (Postfix) with ESMTPSA id 0B87215C052 for ; Tue, 2 Feb 2010 16:01:10 +0100 (CET) From: Michal Sojka To: notmuch@notmuchmail.org Date: Tue, 2 Feb 2010 16:01:08 +0100 Message-Id: <1265122868-12133-1-git-send-email-sojkam1@fel.cvut.cz> X-Mailer: git-send-email 1.6.6 In-Reply-To: <201001291049.21048.sojkam1@fel.cvut.cz> References: <201001291049.21048.sojkam1@fel.cvut.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [notmuch] [PATCHv2] Preserve folder information when indexing 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: Tue, 02 Feb 2010 15:01:14 -0000 Stores the folder (directory name) of the message in the database as a term with folder prefix. This patch was originally sent by Andreas Klöckner. The differences from the original patch are: - Folder name is taken from strings generated during travesal. It no longer uses glib nor it allocates additional memory to determine the base name. The same approach as in id:87fx8bygi7.fsf@linux.vnet.ibm.com was used. - Removed unrelated change which was submitted separately as id:1264691584-8290-2-git-send-email-sojkam1@fel.cvut.cz - Changed the comment describing database schema. TODO (see the previous Carl's email): - Support hierarchical folders --- lib/database.cc | 17 ++++++++++++----- lib/notmuch.h | 1 + notmuch-new.c | 9 ++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index cce7847..ba2aa16 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -83,10 +83,10 @@ typedef struct { * * MESSAGE_ID: The unique ID of the mail mess (see "id" above) * - * In addition, terms from the content of the message are added with - * "from", "to", "attachment", and "subject" prefixes for use by the - * user in searching. But the database doesn't really care itself - * about any of these. + * In addition, terms from the content and path of the message are + * added with "from", "to", "attachment", "subject" and "folder" + * prefixes for use by the user in searching. But the database doesn't + * really care itself about any of these. * * The data portion of a mail document is empty. * @@ -154,7 +154,10 @@ prefix_t PROBABILISTIC_PREFIX[]= { { "from", "XFROM" }, { "to", "XTO" }, { "attachment", "XATTACHMENT" }, - { "subject", "XSUBJECT"} + { "subject", "XSUBJECT"}, + { "folder", "XFOLDER"} + // FIXME: Is folder realy a candidate for probabilistic prefix or + // it should be a boolean prefix instead? }; int @@ -1317,6 +1320,7 @@ _notmuch_database_link_message (notmuch_database_t *notmuch, notmuch_status_t notmuch_database_add_message (notmuch_database_t *notmuch, const char *filename, + const char *folder_name, notmuch_message_t **message_ret) { notmuch_message_file_t *message_file; @@ -1432,6 +1436,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch, date = notmuch_message_file_get_header (message_file, "date"); _notmuch_message_set_date (message, date); + if (folder_name != NULL) + _notmuch_message_gen_terms (message, "folder", folder_name); + _notmuch_message_index_file (message, filename); } else { ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID; diff --git a/lib/notmuch.h b/lib/notmuch.h index 15c9db4..3a5ab78 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -263,6 +263,7 @@ notmuch_database_get_directory (notmuch_database_t *database, notmuch_status_t notmuch_database_add_message (notmuch_database_t *database, const char *filename, + const char *folder_name, notmuch_message_t **message); /* Remove a message from the given notmuch database. diff --git a/notmuch-new.c b/notmuch-new.c index f25c71f..afd4e3d 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -207,6 +207,7 @@ _entries_resemble_maildir (struct dirent **entries, int count) static notmuch_status_t add_files_recursive (notmuch_database_t *notmuch, const char *path, + const char *folder, add_files_state_t *state) { DIR *dir = NULL; @@ -302,7 +303,9 @@ add_files_recursive (notmuch_database_t *notmuch, } next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); - status = add_files_recursive (notmuch, next, state); + status = add_files_recursive (notmuch, next, + is_maildir ? folder : entry->d_name, + state); if (status && ret == NOTMUCH_STATUS_SUCCESS) ret = status; talloc_free (next); @@ -407,7 +410,7 @@ add_files_recursive (notmuch_database_t *notmuch, fflush (stdout); } - status = notmuch_database_add_message (notmuch, next, &message); + status = notmuch_database_add_message (notmuch, next, folder, &message); switch (status) { /* success */ case NOTMUCH_STATUS_SUCCESS: @@ -546,7 +549,7 @@ add_files (notmuch_database_t *notmuch, return NOTMUCH_STATUS_FILE_ERROR; } - status = add_files_recursive (notmuch, path, state); + status = add_files_recursive (notmuch, path, basename(path), state); if (timer_is_active) { /* Now stop the timer. */ -- tg: (a2d919e..) t/Preserve-folder-information-when-indexing (depends on: master)