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

* Re: [PATCH] notmuch-new: Parse some maildir flags for labels
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Sojka @ 2010-03-22 21:49 UTC (permalink / raw)
  To: Emil Sit, notmuch

On Thu, 18 Mar 2010, Emil Sit wrote:
> 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.

Hi,

if I remember, there has been at least three different patches for this,
so you are the fourth :-) You're right that it helps a lot with initial
import. To promote my work a little bit, I use bidirectional
synchronization between maildir flags and notmuch tags, which I sent in
id:1268926780-20045-4-git-send-email-sojkam1@fel.cvut.cz. I use IMAP
clients from time to time and this helps me a lot because the IMAP
server has almost never outdated status.

Bye
Michal

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

* Re: [PATCH] notmuch-new: Parse some maildir flags for labels
  2010-03-22 21:49 ` Michal Sojka
@ 2010-03-23  8:53   ` Sebastian Spaeth
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Spaeth @ 2010-03-23  8:53 UTC (permalink / raw)
  To: Michal Sojka, Emil Sit, notmuch

> if I remember, there has been at least three different patches for this,
> so you are the fourth :-) You're right that it helps a lot with initial
> import. To promote my work a little bit, I use bidirectional
> synchronization between maildir flags and notmuch tags, which I sent in
> id:1268926780-20045-4-git-send-email-sojkam1@fel.cvut.cz. I use IMAP
> clients from time to time and this helps me a lot because the IMAP
> server has almost never outdated status.

And it shows the need for such a patch :-). It doesn't hurt people who
stop using IMAP flags, and it helps those who still can't use notmuch
locally all the time...

So +1 from me to get one of the patches into mainline.

Sebastian

^ permalink raw reply	[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).