unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] notmuch-new: Parse some maildir flags for labels
@ 2010-03-18  2:59 Emil Sit
  2010-03-22 21:49 ` Michal Sojka
  0 siblings, 1 reply; 3+ messages in thread
From: Emil Sit @ 2010-03-18  2:59 UTC (permalink / raw
  To: notmuch

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@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

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

end of thread, other threads:[~2010-03-23  8:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-18  2:59 [PATCH] notmuch-new: Parse some maildir flags for labels Emil Sit
2010-03-22 21:49 ` Michal Sojka
2010-03-23  8:53   ` 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).