1 Return-Path: <sojkam1@fel.cvut.cz>
\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 79D44431FD5
\r
6 for <notmuch@notmuchmail.org>; Thu, 28 Jan 2010 07:25:47 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.176 tagged_above=-999 required=5 tests=[AWL=0.423,
\r
12 BAYES_00=-2.599] autolearn=ham
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id woab4JcFKE6X for <notmuch@notmuchmail.org>;
\r
16 Thu, 28 Jan 2010 07:25:46 -0800 (PST)
\r
17 Received: from mout.perfora.net (mout.perfora.net [74.208.4.194])
\r
18 by olra.theworths.org (Postfix) with ESMTP id B5999431FDE
\r
19 for <notmuch@notmuchmail.org>; Thu, 28 Jan 2010 07:25:44 -0800 (PST)
\r
20 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
21 by mx.perfora.net (node=mxus2) with ESMTP (Nemesis)
\r
22 id 0MFun8-1NXkYB3MGM-00Ex7G for notmuch@notmuchmail.org;
\r
23 Thu, 28 Jan 2010 10:25:38 -0500
\r
24 Received: from localhost (unknown [192.168.200.4])
\r
25 by max.feld.cvut.cz (Postfix) with ESMTP id 50E2219F33A0;
\r
26 Thu, 28 Jan 2010 16:25:36 +0100 (CET)
\r
27 X-Virus-Scanned: IMAP AMAVIS
\r
28 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
29 by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,
\r
31 with ESMTP id KfaG+Qz8PfD1; Thu, 28 Jan 2010 16:25:32 +0100 (CET)
\r
32 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
33 by max.feld.cvut.cz (Postfix) with ESMTP id 166EA19F338C;
\r
34 Thu, 28 Jan 2010 16:25:32 +0100 (CET)
\r
35 Received: from localhost.localdomain (k335-30.felk.cvut.cz [147.32.86.30])
\r
36 (Authenticated sender: sojkam1)
\r
37 by imap.feld.cvut.cz (Postfix) with ESMTPSA id 105A5FA004;
\r
38 Thu, 28 Jan 2010 16:25:32 +0100 (CET)
\r
39 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
40 To: notmuch@notmuchmail.org
\r
41 Date: Thu, 28 Jan 2010 16:25:17 +0100
\r
42 Message-Id: <1264692317-9175-2-git-send-email-sojkam1@fel.cvut.cz>
\r
43 X-Mailer: git-send-email 1.6.6
\r
44 In-Reply-To: <201001281624.01577.sojkam1@fel.cvut.cz>
\r
45 References: <201001281624.01577.sojkam1@fel.cvut.cz>
\r
47 Content-Type: text/plain; charset=UTF-8
\r
48 Content-Transfer-Encoding: 8bit
\r
49 Subject: [notmuch] [PATCH 2/2] Preserve folder information when indexing
\r
50 X-BeenThere: notmuch@notmuchmail.org
\r
51 X-Mailman-Version: 2.1.13
\r
53 List-Id: "Use and development of the notmuch mail system."
\r
54 <notmuch.notmuchmail.org>
\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
56 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
58 List-Post: <mailto:notmuch@notmuchmail.org>
\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
61 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
62 X-List-Received-Date: Thu, 28 Jan 2010 15:25:47 -0000
\r
64 This patch was originally sent by Andreas Klöckner. This is a slightly
\r
65 reworked version (only coding style changes) which was manually rebased
\r
66 to the current HEAD.
\r
68 There are still things to fix (see the previous Carl's email)
\r
69 - Redundant trailing directory name traversal
\r
70 - Supporting hierarchical folders
\r
72 lib/database.cc | 13 +++++++++----
\r
74 notmuch-new.c | 38 +++++++++++++++++++++++++++++++++++++-
\r
75 3 files changed, 47 insertions(+), 5 deletions(-)
\r
77 diff --git a/lib/database.cc b/lib/database.cc
\r
78 index cce7847..5f2f35d 100644
\r
79 --- a/lib/database.cc
\r
80 +++ b/lib/database.cc
\r
81 @@ -84,9 +84,9 @@ typedef struct {
\r
82 * MESSAGE_ID: The unique ID of the mail mess (see "id" above)
\r
84 * In addition, terms from the content of the message are added with
\r
85 - * "from", "to", "attachment", and "subject" prefixes for use by the
\r
86 - * user in searching. But the database doesn't really care itself
\r
87 - * about any of these.
\r
88 + * "from", "to", "attachment", "subject" and "folder" prefixes for use
\r
89 + * by the user in searching. But the database doesn't really care
\r
90 + * itself about any of these.
\r
92 * The data portion of a mail document is empty.
\r
94 @@ -154,7 +154,8 @@ prefix_t PROBABILISTIC_PREFIX[]= {
\r
95 { "from", "XFROM" },
\r
97 { "attachment", "XATTACHMENT" },
\r
98 - { "subject", "XSUBJECT"}
\r
99 + { "subject", "XSUBJECT"},
\r
100 + { "folder", "XFOLDER"}
\r
104 @@ -1317,6 +1318,7 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
\r
106 notmuch_database_add_message (notmuch_database_t *notmuch,
\r
107 const char *filename,
\r
108 + const char *folder_name,
\r
109 notmuch_message_t **message_ret)
\r
111 notmuch_message_file_t *message_file;
\r
112 @@ -1432,6 +1434,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
113 date = notmuch_message_file_get_header (message_file, "date");
\r
114 _notmuch_message_set_date (message, date);
\r
116 + if (folder_name != NULL)
\r
117 + _notmuch_message_gen_terms (message, "folder", folder_name);
\r
119 _notmuch_message_index_file (message, filename);
\r
121 ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
122 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
123 index 15c9db4..3a5ab78 100644
\r
124 --- a/lib/notmuch.h
\r
125 +++ b/lib/notmuch.h
\r
126 @@ -263,6 +263,7 @@ notmuch_database_get_directory (notmuch_database_t *database,
\r
128 notmuch_database_add_message (notmuch_database_t *database,
\r
129 const char *filename,
\r
130 + const char *folder_name,
\r
131 notmuch_message_t **message);
\r
133 /* Remove a message from the given notmuch database.
\r
134 diff --git a/notmuch-new.c b/notmuch-new.c
\r
135 index f25c71f..b7c65db 100644
\r
136 --- a/notmuch-new.c
\r
137 +++ b/notmuch-new.c
\r
139 #include "notmuch-client.h"
\r
141 #include <unistd.h>
\r
144 typedef struct _filename_node {
\r
146 @@ -169,6 +170,35 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
151 +_get_folder_base_name(const char *path)
\r
153 + gchar *full_folder_name = NULL;
\r
154 + gchar *folder_base_name = NULL;
\r
156 + /* Find name of "folder" containing the email. */
\r
157 + full_folder_name = g_strdup(path);
\r
159 + folder_base_name = g_path_get_basename(full_folder_name);
\r
161 + if (strcmp(folder_base_name, "cur") == 0
\r
162 + || strcmp(folder_base_name, "new") == 0) {
\r
163 + gchar *parent_name = g_path_get_dirname(full_folder_name);
\r
164 + g_free(full_folder_name);
\r
165 + full_folder_name = parent_name;
\r
170 + g_free(full_folder_name);
\r
172 + if (strcmp(folder_base_name, ".") == 0) {
\r
173 + g_free(folder_base_name);
\r
174 + folder_base_name = NULL;
\r
176 + return folder_base_name;
\r
179 /* Examine 'path' recursively as follows:
\r
181 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
182 @@ -222,6 +252,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
183 notmuch_filenames_t *db_subdirs = NULL;
\r
185 notmuch_bool_t is_maildir, new_directory;
\r
186 + char *folder_base_name = NULL;
\r
188 if (stat (path, &st)) {
\r
189 fprintf (stderr, "Error reading directory %s: %s\n",
\r
190 @@ -407,7 +438,10 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
194 - status = notmuch_database_add_message (notmuch, next, &message);
\r
195 + folder_base_name = _get_folder_base_name(path);
\r
196 + status = notmuch_database_add_message (notmuch, next,
\r
197 + folder_base_name,
\r
201 case NOTMUCH_STATUS_SUCCESS:
\r
202 @@ -499,6 +533,8 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
203 notmuch_filenames_destroy (db_files);
\r
205 notmuch_directory_destroy (directory);
\r
206 + if (folder_base_name)
\r
207 + g_free(folder_base_name);
\r