When adding new messages, if they have the 'S' (seen) flag, do not add
them to the 'unread' tag.
---
 lib/message.cc |   25 +++++++++++++++++++++++++
 lib/notmuch.h  |    5 +++++
 notmuch-new.c  |    3 ++-
 3 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index f0e905b..61c9cc3 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -516,6 +516,31 @@ notmuch_message_set_flag (notmuch_message_t *message,
        message->flags &= ~(1 << flag);
 }
 
+notmuch_bool_t
+notmuch_message_md_flag (notmuch_message_t *message,
+                        const char flag)
+{
+    const char *filename;
+    const char *p;
+
+    filename = notmuch_message_get_filename (message);
+
+    p = strstr (filename, ":2,");
+    if (p == NULL) {
+        /* Not a valid maildir filename */
+        return FALSE;
+    }
+
+    for (p += 3; *p != '\0'; p++) {
+        if (*p == flag) {
+            return TRUE;
+        }
+    }
+
+    return FALSE;
+}
+
+
 time_t
 notmuch_message_get_date (notmuch_message_t *message)
 {
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 15c9db4..db9e917 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -753,6 +753,11 @@ void
 notmuch_message_set_flag (notmuch_message_t *message,
                          notmuch_message_flag_t flag, notmuch_bool_t value);
 
+/* See if a given maildir flag is set, based on the message's filename. */
+notmuch_bool_t
+notmuch_message_md_flag (notmuch_message_t *message,
+                        const char flag);
+
 /* Get the date of 'message' as a time_t value.
  *
  * For the original textual representation of the Date header from the
diff --git a/notmuch-new.c b/notmuch-new.c
index b740ee2..6d62f3f 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -97,7 +97,8 @@ static void
 tag_inbox_and_unread (notmuch_message_t *message)
 {
     notmuch_message_add_tag (message, "inbox");
-    notmuch_message_add_tag (message, "unread");
+    if (! notmuch_message_md_flag(message, 'S'))
+        notmuch_message_add_tag (message, "unread");
 }
 
 static void
-- 
1.7.0

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to