[notmuch] [PATCHv2] Preserve folder information when indexing
Michal Sojka
sojkam1 at fel.cvut.cz
Tue Feb 2 07:01:08 PST 2010
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 at linux.vnet.ibm.com was used.
- Removed unrelated change which was submitted separately as
id:1264691584-8290-2-git-send-email-sojkam1 at 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)
More information about the notmuch
mailing list