[notmuch] [PATCH] notmuch-new: Parse some maildir flags for labels

Emil Sit sit at emilsit.net
Wed Mar 17 19:59:07 PDT 2010


Instead of blanket applying tag:inbox and tag:unread to
all messages, when parsing a Maildir file, attempt to
parse the flags encoded in the filename to determine whether
to mark something as unread (and inbox).  Also, parse user
flagged messages and trash messages.

Signed-off-by: Emil Sit <sit at emilsit.net>
---
I confess that I'm not actively following the mailing list or actively using
notmuch to read mail (the vim client seems not to work well for me on Ubuntu
Hardy and not a huge emacs fan and don't have emacs23; still using mutt/mairix)
so I apologize if something like this has been discussed/rejected before.  I've
been playing with this patch locally and it definitely helped with the initial
import.  It's a nice complement to notmuchsync.

Hope someone finds it useful.

 notmuch-new.c |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 44b50aa..f937e85 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -94,10 +94,34 @@ _filename_list_add (_filename_list_t *list,
 }
 
 static void
-tag_inbox_and_unread (notmuch_message_t *message)
+tag_maildir_message (const char *filename, notmuch_message_t *message)
 {
-    notmuch_message_add_tag (message, "inbox");
-    notmuch_message_add_tag (message, "unread");
+    notmuch_bool_t is_read = FALSE;
+
+    const char *p = strrchr (filename, ':');
+    if (p != NULL && strncmp(p + 1, "2,", 2) == 0) {
+        /* This appears to be a valid Maildir filename.
+         * Interpret some basic semantics */
+        while (*p) {
+            switch (*p) {
+                case 'S': /* seen */
+                    is_read = TRUE;
+                    break;
+                case 'T': /* trashed */
+                    notmuch_message_add_tag (message, "trash");
+                    break;
+                case 'F': /* flagged */
+                    notmuch_message_add_tag (message, "flagged");
+                    break;
+            }
+            p++;
+        }
+    }
+
+    if (!is_read) {
+        notmuch_message_add_tag (message, "inbox");
+        notmuch_message_add_tag (message, "unread");
+    }
 }
 
 static void
@@ -412,7 +436,7 @@ add_files_recursive (notmuch_database_t *notmuch,
 	/* success */
 	case NOTMUCH_STATUS_SUCCESS:
 	    state->added_messages++;
-	    tag_inbox_and_unread (message);
+	    tag_maildir_message (next, message);
 	    break;
 	/* Non-fatal issues (go on to next file) */
 	case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
-- 
1.6.3.3



More information about the notmuch mailing list