[PATCH 1/2] lib/message: Add function to get maildir flags.

classic Classic list List threaded Threaded
6 messages Options
Stefan Schmidt-2 Stefan Schmidt-2
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/2] lib/message: Add function to get maildir flags.

With notmuch_message_get_flags() we gain the information if the message was
flagged as read, draft, trashed, etc. Handy for big mail spooles that were used
with another mailer.

Signed-off-by: Stefan Schmidt <[hidden email]>
---
 lib/message.cc |   26 ++++++++++++++++++++++++++
 lib/notmuch.h  |   10 ++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 069cedb..9bec61e 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -35,6 +35,7 @@ struct _notmuch_message {
     char *thread_id;
     char *in_reply_to;
     char *filename;
+    char *flags;
     notmuch_message_file_t *message_file;
     notmuch_message_list_t *replies;
 
@@ -114,6 +115,7 @@ _notmuch_message_create (const void *talloc_owner,
     message->thread_id = NULL;
     message->in_reply_to = NULL;
     message->filename = NULL;
+    message->flags = NULL;
     message->message_file = NULL;
 
     message->replies = _notmuch_message_list_create (message);
@@ -438,6 +440,30 @@ notmuch_message_get_filename (notmuch_message_t *message)
     return message->filename;
 }
 
+const char *
+notmuch_message_get_flags (notmuch_message_t *message)
+{
+    std::string filename_str, flags;
+    size_t position;
+    const char *db_path;
+
+    if (message->flags)
+ return message->flags;
+
+    filename_str = message->doc.get_data ();
+    db_path = notmuch_database_get_path (message->notmuch);
+
+    if (filename_str[0] != '/')
+ filename_str.insert (0, db_path);
+
+    /* Flags are everything behind ":" */
+    position = filename_str.find (":");
+    flags = filename_str.substr (position + 3); /* We don't want :2, */
+    message->flags = talloc_strdup (message, flags.c_str ());
+
+    return message->flags;
+}
+
 time_t
 notmuch_message_get_date (notmuch_message_t *message)
 {
diff --git a/lib/notmuch.h b/lib/notmuch.h
index a61cd02..1da5dfd 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -694,6 +694,16 @@ notmuch_message_get_replies (notmuch_message_t *message);
 const char *
 notmuch_message_get_filename (notmuch_message_t *message);
 
+/* Get the maildir flags for the email corresponding to 'message'.
+ *
+ * The returned flags will be a string of ascii format flags.
+ *
+ * The returned string belongs to the message so should not be
+ * modified or freed by the caller (nor should it be referenced after
+ * the message is destroyed). */
+const char *
+notmuch_message_get_flags (notmuch_message_t *message);
+
 /* Get the date of 'message' as a time_t value.
  *
  * For the original textual representation of the Date header from the
--
1.6.5.3


Stefan Schmidt-2 Stefan Schmidt-2
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/2] notmuch-new: Tag mails not as unread when the seen flag in the maildir is set.

With the new notmuch_message_get_flags() function we can get the information if
a message was already flagged as seen in maildir by another mailer or tool. This
gives a more realistic picture instead of flagging all as unread.

Signed-off-by: Stefan Schmidt <[hidden email]>
---
 Makefile      |    2 +-
 notmuch-new.c |   16 +++++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 3fedcf1..dfcfc70 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 # Default FLAGS, (can be overridden by user such as "make CFLAGS=-O2")
 WARN_FLAGS=-Wall -Wextra -Wmissing-declarations -Wwrite-strings -Wswitch-enum
-CFLAGS=-O2
+CFLAGS=-O0 -ggdb3
 
 # Additional flags that we will append to whatever the user set.
 # These aren't intended for the user to manipulate.
diff --git a/notmuch-new.c b/notmuch-new.c
index bc35b4e..ef4429d 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -41,8 +41,22 @@ handle_sigint (unused (int sig))
 static void
 tag_inbox_and_unread (notmuch_message_t *message)
 {
-    notmuch_message_add_tag (message, "inbox");
+    char *buf;
+    int i;
+
+    buf = notmuch_message_get_flags (message);
+    for (i = 0; i < strlen (buf); i++) {
+        /* If the S flag is set the message can be tagged as read */
+        if (buf[i] == 'S') {
+            notmuch_message_add_tag (message, "read");
+            goto inbox;
+        }
+    }
+
     notmuch_message_add_tag (message, "unread");
+
+inbox:
+    notmuch_message_add_tag (message, "inbox");
 }
 
 static void
--
1.6.5.3


Keith Packard Keith Packard
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] lib/message: Add function to get maildir flags.

In reply to this post by Stefan Schmidt-2
On Sun, 22 Nov 2009 01:11:00 +0100, Stefan Schmidt <[hidden email]> wrote:

> +const char *
> +notmuch_message_get_flags (notmuch_message_t *message)

This function should interpret the flags that it finds and return a
suitable set of notmuch tags. I'd suggest that 'unread' messages get
both 'unread' and 'inbox' tags, as Maildir doesn't distinguish between
'don't show this to be by default again please' and 'I've read this
message'. It seems best to hide the maildir-specific details inside the
library instead of exposing them.

Also, we have only the 'unread' tag; we don't have a 'read' tag, which
would simply be the inverse of 'unread'.

--
[hidden email]

attachment0 (189 bytes) Download Attachment
Stefan Schmidt-2 Stefan Schmidt-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] lib/message: Add function to get maildir flags.

Hello.

On Sat, 2009-11-21 at 16:28, Keith Packard wrote:

> On Sun, 22 Nov 2009 01:11:00 +0100, Stefan Schmidt <[hidden email]> wrote:
>
> > +const char *
> > +notmuch_message_get_flags (notmuch_message_t *message)
>
> This function should interpret the flags that it finds and return a
> suitable set of notmuch tags. I'd suggest that 'unread' messages get
> both 'unread' and 'inbox' tags, as Maildir doesn't distinguish between
> 'don't show this to be by default again please' and 'I've read this
> message'. It seems best to hide the maildir-specific details inside the
> library instead of exposing them.
Thanks for the review. On a second thought the interface was really a bit ugly.
:)

I'm just back to my box and going through the outstanding mails shows me that
Michiel Buddingh has a more complete patch on the
convert-maildir-flags-into-tags issue which Carl has tagged for review. Will
wait what comes out of it and if anything is left for me to. :)

regards
Stefan Schmidt

signature.asc (250 bytes) Download Attachment
Michiel Buddingh' Michiel Buddingh'
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] lib/message: Add function to get maildir flags.

Stefan Schmidt <[hidden email]> wrote:

> > This function should interpret the flags that it finds and return a
> > suitable set of notmuch tags. I'd suggest that 'unread' messages get
> > both 'unread' and 'inbox' tags, as Maildir doesn't distinguish between
> > 'don't show this to be by default again please' and 'I've read this
> > message'. It seems best to hide the maildir-specific details inside the
> > library instead of exposing them.
>
> Thanks for the review. On a second thought the interface was really a bit ugly.
> :)
>
> I'm just back to my box and going through the outstanding mails shows me that
> Michiel Buddingh has a more complete patch on the
> convert-maildir-flags-into-tags issue which Carl has tagged for review. Will
> wait what comes out of it and if anything is left for me to. :)

Apologies.  In my haste to cover up my appalling and incorrect first patch, I
neglected to review the archives to see if someone had already done this. Sorry
for stealing your thunder.

Michiel

Stefan Schmidt-2 Stefan Schmidt-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] lib/message: Add function to get maildir flags.

Hello.

On Sun, 2009-11-22 at 19:55, Michiel Buddingh' wrote:

> Stefan Schmidt <[hidden email]> wrote:
> > > This function should interpret the flags that it finds and return a
> > > suitable set of notmuch tags. I'd suggest that 'unread' messages get
> > > both 'unread' and 'inbox' tags, as Maildir doesn't distinguish between
> > > 'don't show this to be by default again please' and 'I've read this
> > > message'. It seems best to hide the maildir-specific details inside the
> > > library instead of exposing them.
> >
> > Thanks for the review. On a second thought the interface was really a bit ugly.
> > :)
> >
> > I'm just back to my box and going through the outstanding mails shows me that
> > Michiel Buddingh has a more complete patch on the
> > convert-maildir-flags-into-tags issue which Carl has tagged for review. Will
> > wait what comes out of it and if anything is left for me to. :)
>
> Apologies.  In my haste to cover up my appalling and incorrect first patch, I
> neglected to review the archives to see if someone had already done this. Sorry
> for stealing your thunder.

No need to be sorry. I'm interestecd in having this itch scratched, but don't
care who is doing it. :)

Just go ahead and get it in after Carl's review.

regards
Stefan Schmidt