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 79D44431FD5 for ; Thu, 28 Jan 2010 07:25:47 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.176 X-Spam-Level: X-Spam-Status: No, score=-2.176 tagged_above=-999 required=5 tests=[AWL=0.423, BAYES_00=-2.599] 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 woab4JcFKE6X for ; Thu, 28 Jan 2010 07:25:46 -0800 (PST) Received: from mout.perfora.net (mout.perfora.net [74.208.4.194]) by olra.theworths.org (Postfix) with ESMTP id B5999431FDE for ; Thu, 28 Jan 2010 07:25:44 -0800 (PST) Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) by mx.perfora.net (node=mxus2) with ESMTP (Nemesis) id 0MFun8-1NXkYB3MGM-00Ex7G for notmuch@notmuchmail.org; Thu, 28 Jan 2010 10:25:38 -0500 Received: from localhost (unknown [192.168.200.4]) by max.feld.cvut.cz (Postfix) with ESMTP id 50E2219F33A0; Thu, 28 Jan 2010 16:25:36 +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 KfaG+Qz8PfD1; Thu, 28 Jan 2010 16:25:32 +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 166EA19F338C; Thu, 28 Jan 2010 16:25:32 +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 105A5FA004; Thu, 28 Jan 2010 16:25:32 +0100 (CET) From: Michal Sojka To: notmuch@notmuchmail.org Date: Thu, 28 Jan 2010 16:25:17 +0100 Message-Id: <1264692317-9175-2-git-send-email-sojkam1@fel.cvut.cz> X-Mailer: git-send-email 1.6.6 In-Reply-To: <201001281624.01577.sojkam1@fel.cvut.cz> References: <201001281624.01577.sojkam1@fel.cvut.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [notmuch] [PATCH 2/2] 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: Thu, 28 Jan 2010 15:25:47 -0000 This patch was originally sent by Andreas Klöckner. This is a slightly reworked version (only coding style changes) which was manually rebased to the current HEAD. There are still things to fix (see the previous Carl's email) - Redundant trailing directory name traversal - Supporting hierarchical folders --- lib/database.cc | 13 +++++++++---- lib/notmuch.h | 1 + notmuch-new.c | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index cce7847..5f2f35d 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -84,9 +84,9 @@ 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. + * "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,8 @@ prefix_t PROBABILISTIC_PREFIX[]= { { "from", "XFROM" }, { "to", "XTO" }, { "attachment", "XATTACHMENT" }, - { "subject", "XSUBJECT"} + { "subject", "XSUBJECT"}, + { "folder", "XFOLDER"} }; int @@ -1317,6 +1318,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 +1434,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..b7c65db 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -21,6 +21,7 @@ #include "notmuch-client.h" #include +#include typedef struct _filename_node { char *filename; @@ -169,6 +170,35 @@ _entries_resemble_maildir (struct dirent **entries, int count) return 0; } +static char* +_get_folder_base_name(const char *path) +{ + gchar *full_folder_name = NULL; + gchar *folder_base_name = NULL; + + /* Find name of "folder" containing the email. */ + full_folder_name = g_strdup(path); + while (1) { + folder_base_name = g_path_get_basename(full_folder_name); + + if (strcmp(folder_base_name, "cur") == 0 + || strcmp(folder_base_name, "new") == 0) { + gchar *parent_name = g_path_get_dirname(full_folder_name); + g_free(full_folder_name); + full_folder_name = parent_name; + } else + break; + } + + g_free(full_folder_name); + + if (strcmp(folder_base_name, ".") == 0) { + g_free(folder_base_name); + folder_base_name = NULL; + } + return folder_base_name; +} + /* Examine 'path' recursively as follows: * * o Ask the filesystem for the mtime of 'path' (fs_mtime) @@ -222,6 +252,7 @@ add_files_recursive (notmuch_database_t *notmuch, notmuch_filenames_t *db_subdirs = NULL; struct stat st; notmuch_bool_t is_maildir, new_directory; + char *folder_base_name = NULL; if (stat (path, &st)) { fprintf (stderr, "Error reading directory %s: %s\n", @@ -407,7 +438,10 @@ add_files_recursive (notmuch_database_t *notmuch, fflush (stdout); } - status = notmuch_database_add_message (notmuch, next, &message); + folder_base_name = _get_folder_base_name(path); + status = notmuch_database_add_message (notmuch, next, + folder_base_name, + &message); switch (status) { /* success */ case NOTMUCH_STATUS_SUCCESS: @@ -499,6 +533,8 @@ add_files_recursive (notmuch_database_t *notmuch, notmuch_filenames_destroy (db_files); if (directory) notmuch_directory_destroy (directory); + if (folder_base_name) + g_free(folder_base_name); return ret; } -- 1.6.6