unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Michal Sojka <sojkam1@fel.cvut.cz>
To: notmuch@notmuchmail.org
Subject: [PATCHv2] Preserve folder information when indexing
Date: Tue,  2 Feb 2010 16:01:08 +0100	[thread overview]
Message-ID: <1265122868-12133-1-git-send-email-sojkam1@fel.cvut.cz> (raw)
In-Reply-To: <201001291049.21048.sojkam1@fel.cvut.cz>

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)

  reply	other threads:[~2010-02-02 15:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-14 19:21 [patch] store folder information Andreas Klöckner
2009-12-15 12:16 ` Ruben Pollan
2009-12-15 19:57   ` Marten Veldthuis
2009-12-15 21:22 ` Carl Worth
2010-01-27 15:55 ` micah anderson
2010-01-28 15:24   ` Michal Sojka
2010-01-28 15:25     ` [PATCH 1/2] Skip German "aw:" prefix in subjects Michal Sojka
2010-01-28 15:25     ` [PATCH 2/2] Preserve folder information when indexing Michal Sojka
2010-01-28 17:13       ` micah anderson
2010-01-29  9:49         ` Michal Sojka
2010-02-02 15:01           ` Michal Sojka [this message]
2010-02-02 16:20             ` [PATCHv2] " Jameson Rollins
2010-02-02 16:52               ` Jameson Rollins
2010-02-02 17:48               ` Arvid Picciani
2010-02-02 18:22                 ` Jameson Rollins
2010-02-02 18:42                   ` Arvid Picciani
2010-02-02 21:31                   ` micah anderson
2010-02-02 22:25                     ` Michal Sojka
2010-02-02 22:36                       ` Jameson Rollins
2010-02-03  9:58                       ` Sebastian Spaeth
2010-02-02 20:43                 ` Michal Sojka
2010-02-03  7:56                 ` Sebastian Spaeth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1265122868-12133-1-git-send-email-sojkam1@fel.cvut.cz \
    --to=sojkam1@fel.cvut.cz \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).