unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [patch] store folder information
@ 2009-12-14 19:21 Andreas Klöckner
  2009-12-15 12:16 ` Ruben Pollan
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Andreas Klöckner @ 2009-12-14 19:21 UTC (permalink / raw)
  To: notmuch


[-- Attachment #1.1: Type: Text/Plain, Size: 223 bytes --]

Hi there,

I've patched notmuch to retain information on which folder emails are stored 
in. This makes the transition from a folders-and-procmail model somewhat 
easier. The resulting changes are attached.

Andreas

[-- Attachment #1.2: 0001-Preseve-folder-information-when-indexing.patch --]
[-- Type: text/x-patch, Size: 5052 bytes --]

From 179af7f436d8c21bad90e7eb88fc17c56f83c26c Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Mon, 14 Dec 2009 14:16:20 -0500
Subject: [PATCH] Preseve folder information when indexing.

---
 lib/database.cc |   14 +++++++++-----
 lib/index.cc    |    2 ++
 lib/notmuch.h   |    1 +
 notmuch-new.c   |   35 ++++++++++++++++++++++++++++++++++-
 4 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index b6c4d07..e6b4272 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -70,10 +70,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.
+ * In addition, terms from the content 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.
  *
  * Timestamp document
  * ------------------
@@ -124,7 +123,8 @@ prefix_t PROBABILISTIC_PREFIX[]= {
     { "from", "XFROM" },
     { "to", "XTO" },
     { "attachment", "XATTACHMENT" },
-    { "subject", "XSUBJECT"}
+    { "subject", "XSUBJECT"},
+    { "folder", "XFOLDER"}
 };
 
 int
@@ -889,6 +889,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;
@@ -1006,6 +1007,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 
 	_notmuch_message_index_file (message, filename);
 
+        if (folder_name != NULL)
+            _notmuch_message_gen_terms (message, "folder", folder_name);
+
 	_notmuch_message_sync (message);
     } catch (const Xapian::Error &error) {
 	fprintf (stderr, "A Xapian exception occurred adding message: %s.\n",
diff --git a/lib/index.cc b/lib/index.cc
index 125fa6c..55f3fbc 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -116,6 +116,8 @@ skip_re_in_subject (const char *subject)
 	    s++;
 	if (strncasecmp (s, "re:", 3) == 0)
 	    s += 3;
+        else if (strncasecmp (s, "aw:", 3) == 0)
+	    s += 3;
 	else
 	    break;
     }
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 60834fb..5d3b3c6 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -265,6 +265,7 @@ notmuch_database_get_timestamp (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);
 
 /* Find a message with the given message_id.
diff --git a/notmuch-new.c b/notmuch-new.c
index 9d20616..bc8adc8 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -21,6 +21,7 @@
 #include "notmuch-client.h"
 
 #include <unistd.h>
+#include <glib.h>
 
 static volatile sig_atomic_t do_add_files_print_progress = 0;
 
@@ -144,6 +145,34 @@ add_files_recursive (notmuch_database_t *notmuch,
     struct dirent **namelist = NULL;
     int num_entries;
 
+    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;
+    }
+
     /* If we're told to, we bail out on encountering a read-only
      * directory, (with this being a clear clue from the user to
      * Notmuch that new mail won't be arriving there and we need not
@@ -235,7 +264,9 @@ 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_base_name, 
+                                                       &message);
 		switch (status) {
 		    /* success */
 		    case NOTMUCH_STATUS_SUCCESS:
@@ -301,6 +332,8 @@ add_files_recursive (notmuch_database_t *notmuch,
 	closedir (dir);
     if (namelist)
 	free (namelist);
+    if (folder_base_name)
+        g_free(folder_base_name);
 
     return ret;
 }
-- 
1.6.5


[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2010-02-03  9:58 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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           ` [PATCHv2] " Michal Sojka
2010-02-02 16:20             ` 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

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).