1 Return-Path: <micah@riseup.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 54CEE4196F2
\r
6 for <notmuch@notmuchmail.org>; Wed, 14 Apr 2010 08:38:02 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.599 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001]
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id TnQ2SGKKTgJJ for <notmuch@notmuchmail.org>;
\r
17 Wed, 14 Apr 2010 08:38:00 -0700 (PDT)
\r
18 Received: from mx1.riseup.net (mx1.riseup.net [204.13.164.18])
\r
19 by olra.theworths.org (Postfix) with ESMTP id B6B52431FC1
\r
20 for <notmuch@notmuchmail.org>; Wed, 14 Apr 2010 08:38:00 -0700 (PDT)
\r
21 Received: from [127.0.0.1] (localhost [127.0.0.1])
\r
22 (Authenticated sender: micah@mx1.riseup.net)
\r
23 with ESMTPSA id D23B825ED32
\r
24 Received: by algae (Postfix, from userid 1000)
\r
25 id AC9156184A; Wed, 14 Apr 2010 11:37:57 -0400 (EDT)
\r
26 From: Micah Anderson <micah@riseup.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [PATCH 1/1] Stores the folder (directory name) of the message in the
\r
29 database as a term with folder prefix.
\r
30 Date: Wed, 14 Apr 2010 11:37:37 -0400
\r
31 Message-Id: <1271259457-662-1-git-send-email-micah@riseup.net>
\r
32 X-Mailer: git-send-email 1.7.0.4
\r
34 Content-Type: text/plain; charset=UTF-8
\r
35 Content-Transfer-Encoding: 8bit
\r
36 X-Virus-Scanned: clamav-milter 0.95.3 at mx1
\r
37 X-Virus-Status: Clean
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Wed, 14 Apr 2010 15:38:02 -0000
\r
52 This patch was originally sent by Andreas Klöckner in:
\r
53 id:200912141421.52561.lists@informa.tiker.net. It was then
\r
54 subsequently updated by Michal Sojka in:
\r
55 id:1264692317-9175-2-git-send-email-sojkam1@fel.cvut.cz and then
\r
56 further improved again by Michal Sojka in:
\r
57 id:1265122868-12133-1-git-send-email-sojkam1@fel.cvut.cz
\r
59 This is a rebase of the latest patch off of the current git HEAD.
\r
61 . The differences from the original patch are:
\r
62 - Rebased off of current git HEAD
\r
63 - Folder name is taken from strings generated during travesal. It no
\r
64 longer uses glib nor it allocates additional memory to determine the
\r
65 base name. The same approach as in
\r
66 id:87fx8bygi7.fsf@linux.vnet.ibm.com was used.
\r
67 - Removed unrelated change which was submitted separately as
\r
68 id:1264691584-8290-2-git-send-email-sojkam1@fel.cvut.cz
\r
69 - Changed the comment describing database schema.
\r
71 TODO (see Carl's email: id:87zl5k0w6s.fsf@yoom.home.cworth.org):
\r
73 - Support hierarchical folders: this patch is only storing the final
\r
74 directory component. This should be hooked in differently with
\r
75 filename storage so the whole filename is indexed as text to
\r
76 provide arbitrary search phrases such as "folder:'foo/bar/baz'"
\r
78 lib/database.cc | 13 +++++++++----
\r
80 notmuch-new.c | 39 +++++++++++++++++++++++++++++++++++++--
\r
81 3 files changed, 47 insertions(+), 6 deletions(-)
\r
83 diff --git a/lib/database.cc b/lib/database.cc
\r
84 index c91e97c..6364623 100644
\r
85 --- a/lib/database.cc
\r
86 +++ b/lib/database.cc
\r
87 @@ -84,9 +84,9 @@ typedef struct {
\r
88 * MESSAGE_ID: The unique ID of the mail mess (see "id" above)
\r
90 * In addition, terms from the content of the message are added with
\r
91 - * "from", "to", "attachment", and "subject" prefixes for use by the
\r
92 - * user in searching. But the database doesn't really care itself
\r
93 - * about any of these.
\r
94 + * "from", "to", "attachment", "subject" and "folder" prefixes for use
\r
95 + * by the user in searching. But the database doesn't really care
\r
96 + * itself about any of these.
\r
98 * The data portion of a mail document is empty.
\r
100 @@ -155,7 +155,8 @@ prefix_t PROBABILISTIC_PREFIX[]= {
\r
101 { "from", "XFROM" },
\r
103 { "attachment", "XATTACHMENT" },
\r
104 - { "subject", "XSUBJECT"}
\r
105 + { "subject", "XSUBJECT"},
\r
106 + { "folder", "XFOLDER"}
\r
110 @@ -1362,6 +1363,7 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
\r
112 notmuch_database_add_message (notmuch_database_t *notmuch,
\r
113 const char *filename,
\r
114 + const char *folder_name,
\r
115 notmuch_message_t **message_ret)
\r
117 notmuch_message_file_t *message_file;
\r
118 @@ -1477,6 +1479,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
119 date = notmuch_message_file_get_header (message_file, "date");
\r
120 _notmuch_message_set_date (message, date);
\r
122 + if (folder_name != NULL)
\r
123 + _notmuch_message_gen_terms (message, "folder", folder_name);
\r
125 _notmuch_message_index_file (message, filename);
\r
127 ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
128 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
129 index 88da078..ce81565 100644
\r
130 --- a/lib/notmuch.h
\r
131 +++ b/lib/notmuch.h
\r
132 @@ -264,6 +264,7 @@ notmuch_database_get_directory (notmuch_database_t *database,
\r
134 notmuch_database_add_message (notmuch_database_t *database,
\r
135 const char *filename,
\r
136 + const char *folder_name,
\r
137 notmuch_message_t **message);
\r
139 /* Remove a message from the given notmuch database.
\r
140 diff --git a/notmuch-new.c b/notmuch-new.c
\r
141 index 44b50aa..6ad3c09 100644
\r
142 --- a/notmuch-new.c
\r
143 +++ b/notmuch-new.c
\r
145 #include "notmuch-client.h"
\r
147 #include <unistd.h>
\r
150 typedef struct _filename_node {
\r
152 @@ -169,6 +170,35 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
157 +_get_folder_base_name(const char *path)
\r
159 + gchar *full_folder_name = NULL;
\r
160 + gchar *folder_base_name = NULL;
\r
162 + /* Find name of "folder" containing the email. */
\r
163 + full_folder_name = g_strdup(path);
\r
165 + folder_base_name = g_path_get_basename(full_folder_name);
\r
167 + if (strcmp(folder_base_name, "cur") == 0
\r
168 + || strcmp(folder_base_name, "new") == 0) {
\r
169 + gchar *parent_name = g_path_get_dirname(full_folder_name);
\r
170 + g_free(full_folder_name);
\r
171 + full_folder_name = parent_name;
\r
176 + g_free(full_folder_name);
\r
178 + if (strcmp(folder_base_name, ".") == 0) {
\r
179 + g_free(folder_base_name);
\r
180 + folder_base_name = NULL;
\r
182 + return folder_base_name;
\r
185 /* Examine 'path' recursively as follows:
\r
187 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
188 @@ -222,6 +252,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
189 notmuch_filenames_t *db_subdirs = NULL;
\r
191 notmuch_bool_t is_maildir, new_directory;
\r
192 + char *folder_base_name = NULL;
\r
194 if (stat (path, &st)) {
\r
195 fprintf (stderr, "Error reading directory %s: %s\n",
\r
196 @@ -407,7 +438,10 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
200 - status = notmuch_database_add_message (notmuch, next, &message);
\r
201 + folder_base_name = _get_folder_base_name(path);
\r
202 + status = notmuch_database_add_message (notmuch, next,
\r
203 + folder_base_name,
\r
207 case NOTMUCH_STATUS_SUCCESS:
\r
208 @@ -499,7 +533,8 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
209 notmuch_filenames_destroy (db_files);
\r
211 notmuch_directory_destroy (directory);
\r
213 + if (folder_base_name)
\r
214 + g_free(folder_base_name);
\r