[notmuch] [PATCH] notmuch new: support for filename pattern filtering

2010-01-17 Thread Bart Massey
Together with the new support for message deletion (thank
you!) this patch lets me use notmuch in parallel with MH
pretty successfully.

Bart

>From 9418781ad8f1efed5e0866d351ce9d5baf584500 Mon Sep 17 00:00:00 2001
From: Bart Massey 
Date: Sun, 17 Jan 2010 17:00:47 -0800
Subject: [PATCH] notmuch new: support for filename pattern filtering

In most maildir formats, only filenames consisting only of
digits should be candidate emails.  We add a new option
"filename_pattern" in the "database" section of the config
file that takes a regexp to filter candidate filenames
against.  By setting this string to "^[0-9]+$" only files
that match this pattern will even be considered.  This will
inhibit bogus "Notice: non-mail" messages, and may also
noticeably improve the efficiency of the tool if, for
example, large mbox files are left lying around in the
maildir.

Signed-off-by: Bart Massey 
---
 notmuch-client.h |7 +++
 notmuch-config.c |   46 --
 notmuch-new.c|   35 +++
 3 files changed, 82 insertions(+), 6 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 77766de..191988c 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -146,6 +146,13 @@ notmuch_config_set_database_path (notmuch_config_t *config,
   const char *database_path);
 
 const char *
+notmuch_config_get_filename_regex (notmuch_config_t *config);
+
+void
+notmuch_config_set_filename_regex (notmuch_config_t *config,
+  const char *filename_regex);
+
+const char *
 notmuch_config_get_user_name (notmuch_config_t *config);
 
 void
diff --git a/notmuch-config.c b/notmuch-config.c
index 95430db..edfb4a6 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -31,11 +31,21 @@ static const char toplevel_config_comment[] =
 static const char database_config_comment[] =
 " Database configuration\n"
 "\n"
-" The only value supported here is 'path' which should be the top-level\n"
+" The value 'path' should be the top-level\n"
 " directory where your mail currently exists and to where mail will be\n"
 " delivered in the future. Files should be individual email messages.\n"
 " Notmuch will store its database within a sub-directory of the path\n"
-" configured here named \".notmuch\".\n";
+" configured here named \".notmuch\".\n"
+"\n"
+" The optional value 'filename_pattern' should be a POSIX"
+" regular expression\n"
+" matching only those filenames that will be checked for email\n"
+" messages.  The match is against the last component of the pathname\n"
+" only.  Anchors may be used, and probably should be.\n"
+" Typically, this is used to match only\n"
+" files whose name is a number in standard maildir format.  The\n"
+" default pattern matches anything.\n" ;
+
 
 static const char user_config_comment[] =
 " User configuration\n"
@@ -58,6 +68,7 @@ struct _notmuch_config {
 GKeyFile *key_file;
 
 char *database_path;
+char *filename_regex;
 char *user_name;
 char *user_primary_email;
 char **user_other_email;
@@ -151,6 +162,8 @@ get_username_from_passwd_file (void *ctx)
  *
  *	database_path:		$HOME/mail
  *
+ *	filename_pattern:	.*
+ *
  *	user_name:		From /etc/passwd
  *
  *	user_primary_mail: 	$EMAIL variable if set, otherwise
@@ -195,6 +208,7 @@ notmuch_config_open (void *ctx,
 config->key_file = g_key_file_new ();
 
 config->database_path = NULL;
+config->filename_regex = NULL;
 config->user_name = NULL;
 config->user_primary_email = NULL;
 config->user_other_email = NULL;
@@ -354,6 +368,34 @@ notmuch_config_set_database_path (notmuch_config_t *config,
 }
 
 const char *
+notmuch_config_get_filename_regex (notmuch_config_t *config)
+{
+char *regex;
+
+if (config->filename_regex == NULL) {
+	regex = g_key_file_get_string (config->key_file,
+  "database", "filename_pattern", NULL);
+	if (regex) {
+	config->filename_regex = talloc_strdup (config, regex);
+	free (regex);
+	}
+}
+
+return config->filename_regex;
+}
+
+void
+notmuch_config_set_filename_regex (notmuch_config_t *config,
+   const char *filename_regex)
+{
+g_key_file_set_string (config->key_file,
+			   "database", "filename_pattern", filename_regex);
+
+talloc_free (config->filename_regex);
+config->filename_regex = NULL;
+}
+
+const char *
 notmuch_config_get_user_name (notmuch_config_t *config)
 {
 char *name;
diff --git a/notmuch-new.c b/notmuch-new.c
index b740ee2..ab7ef9e 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -21,6 +21,8 @@
 #include "notmuch-client.h"
 
 #include 
+#include 
+#include 
 
 typedef struct _filename_node {
 char *filename;
@@ -207,6 +209,7 @@ _entries_resemble_maildir (struct dirent **entries, int count)
 static notmuch_status_t
 add_files_recursive (notmuch_database_t *notmuch,
 		 const char *path,
+		 const regex_t *maybe_regex,
 		 add_files_state_t *state)

[notmuch] [PATCH] notmuch new: support for filename pattern filtering

2010-01-17 Thread Bart Massey
Together with the new support for message deletion (thank
you!) this patch lets me use notmuch in parallel with MH
pretty successfully.

Bart

-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: text/x-csrc
Size: 8109 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20100117/0e6477a7/attachment.c>


[notmuch] inbox/unread tags for new messages [was: Re: Thoughts on notmuch and Lua]

2010-01-17 Thread Jameson Rollins
On Sat, Jan 16, 2010 at 06:33:17PM -0800, Carl Worth wrote:
> I have thousands of messages that I have read with sup and notmuch. The
> filenames have never changed since the mail was originally delivered by
> maildrop. So these messages are all in "new" directories, do not have
> the 'S' flag in the filename, and do not have an "unread" tag.
> 
> So the database and the filesystem are currently inconsistent and
> neither of the above state changes will trigger for any of these
> messages.
> 
> Things "work" fine for me now because I'm treating the database state as
> authoritative and ignoring the names of the files. Your proposal is to
> treat the filenames as authoritative, so will require an additional
> step, (to copy the current state from the database to the file names),
> besides what you've outlineed above.

I guess my take on this is that notmuch is a mail processing program
with nominal support for maildir, and should therefore be following
the maildir specification.  I wouldn't say this necessarily means that
the filesystem is "authoritative", just that the specification is
being followed.  I could also see notmuch punting on that and just
offering something that indexes messages stored in individual,
uniquely named files.

I can definitely see, though, that switching to fully following the
maildir spec would require a bit more work and a transition.  My
personal opinion is that notmuch should follow the maildir
specification.  It would definitely facilitate interoperability with
other MTAs and MUAs that do properly follow the maildir specification.

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20100117/17fa7f2f/attachment.pgp>