unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] lib/message: Add function to get maildir flags.
       [not found] <yes>
@ 2009-11-22  0:11 ` Stefan Schmidt
  2009-11-22  0:11   ` [PATCH 2/2] notmuch-new: Tag mails not as unread when the seen flag in the maildir is set Stefan Schmidt
  2009-11-22  0:28   ` [PATCH 1/2] lib/message: Add function to get maildir flags Keith Packard
  2009-11-26  8:17 ` [PATCH] Makefile: Enable backslash escapes for echo Stefan Schmidt
  1 sibling, 2 replies; 10+ messages in thread
From: Stefan Schmidt @ 2009-11-22  0:11 UTC (permalink / raw)
  To: notmuch

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 <stefan@datenfreihafen.org>
---
 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

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

* [PATCH 2/2] notmuch-new: Tag mails not as unread when the seen flag in the maildir is set.
  2009-11-22  0:11 ` [PATCH 1/2] lib/message: Add function to get maildir flags Stefan Schmidt
@ 2009-11-22  0:11   ` Stefan Schmidt
  2009-11-22  0:28   ` [PATCH 1/2] lib/message: Add function to get maildir flags Keith Packard
  1 sibling, 0 replies; 10+ messages in thread
From: Stefan Schmidt @ 2009-11-22  0:11 UTC (permalink / raw)
  To: notmuch

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 <stefan@datenfreihafen.org>
---
 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

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

* Re: [PATCH 1/2] lib/message: Add function to get maildir flags.
  2009-11-22  0:11 ` [PATCH 1/2] lib/message: Add function to get maildir flags Stefan Schmidt
  2009-11-22  0:11   ` [PATCH 2/2] notmuch-new: Tag mails not as unread when the seen flag in the maildir is set Stefan Schmidt
@ 2009-11-22  0:28   ` Keith Packard
  2009-11-22 18:33     ` Stefan Schmidt
  1 sibling, 1 reply; 10+ messages in thread
From: Keith Packard @ 2009-11-22  0:28 UTC (permalink / raw)
  To: Stefan Schmidt, notmuch

[-- Attachment #1: Type: text/plain, Size: 703 bytes --]

On Sun, 22 Nov 2009 01:11:00 +0100, Stefan Schmidt <stefan@datenfreihafen.org> 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'.

-- 
keith.packard@intel.com

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH 1/2] lib/message: Add function to get maildir flags.
  2009-11-22  0:28   ` [PATCH 1/2] lib/message: Add function to get maildir flags Keith Packard
@ 2009-11-22 18:33     ` Stefan Schmidt
  2009-11-22 18:55       ` Michiel Buddingh'
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Schmidt @ 2009-11-22 18:33 UTC (permalink / raw)
  To: Keith Packard; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 1027 bytes --]

Hello.

On Sat, 2009-11-21 at 16:28, Keith Packard wrote:
> On Sun, 22 Nov 2009 01:11:00 +0100, Stefan Schmidt <stefan@datenfreihafen.org> 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

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

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

* Re: [PATCH 1/2] lib/message: Add function to get maildir flags.
  2009-11-22 18:33     ` Stefan Schmidt
@ 2009-11-22 18:55       ` Michiel Buddingh'
  2009-11-22 19:52         ` Stefan Schmidt
  0 siblings, 1 reply; 10+ messages in thread
From: Michiel Buddingh' @ 2009-11-22 18:55 UTC (permalink / raw)
  To: notmuch, stefan, keithp

Stefan Schmidt <stefan@datenfreihafen.org> 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

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

* Re: [PATCH 1/2] lib/message: Add function to get maildir flags.
  2009-11-22 18:55       ` Michiel Buddingh'
@ 2009-11-22 19:52         ` Stefan Schmidt
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Schmidt @ 2009-11-22 19:52 UTC (permalink / raw)
  To: Michiel Buddingh'; +Cc: notmuch

Hello.

On Sun, 2009-11-22 at 19:55, Michiel Buddingh' wrote:
> Stefan Schmidt <stefan@datenfreihafen.org> 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

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

* [PATCH] Makefile: Enable backslash escapes for echo.
       [not found] <yes>
  2009-11-22  0:11 ` [PATCH 1/2] lib/message: Add function to get maildir flags Stefan Schmidt
@ 2009-11-26  8:17 ` Stefan Schmidt
  2009-11-26  8:43   ` Ingmar Vanhassel
  2009-11-26 11:05   ` Jan Janak
  1 sibling, 2 replies; 10+ messages in thread
From: Stefan Schmidt @ 2009-11-26  8:17 UTC (permalink / raw)
  To: notmuch

This fixes a visual glitch during a silent compile.
Before:
Use "make V=1" to see the verbose compile lines.\n  CC  debugger.o
  CC    gmime-filter-reply.o

After:
Use "make V=1" to see the verbose compile lines.
  CC    debugger.o
  CC    gmime-filter-reply.o

Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>
---
 Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 2cd1b1b..2d19a6e 100644
--- a/Makefile
+++ b/Makefile
@@ -41,7 +41,7 @@ include Makefile.config
 # user how to enable verbose compiles.
 ifeq ($(V),)
 quiet_DOC := "Use \"$(MAKE) V=1\" to see the verbose compile lines.\n"
-quiet = @echo $(quiet_DOC)$(eval quiet_DOC:=)"  $1	$@"; $($1)
+quiet = @echo -e $(quiet_DOC)$(eval quiet_DOC:=)"  $1	$@"; $($1)
 endif
 # The user has explicitly enabled quiet compilation.
 ifeq ($(V),0)
-- 
1.6.5.3

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

* Re: [PATCH] Makefile: Enable backslash escapes for echo.
  2009-11-26  8:17 ` [PATCH] Makefile: Enable backslash escapes for echo Stefan Schmidt
@ 2009-11-26  8:43   ` Ingmar Vanhassel
  2009-11-26 11:05   ` Jan Janak
  1 sibling, 0 replies; 10+ messages in thread
From: Ingmar Vanhassel @ 2009-11-26  8:43 UTC (permalink / raw)
  To: notmuch

Excerpts from Stefan Schmidt's message of Thu Nov 26 09:17:15 +0100 2009:
> This fixes a visual glitch during a silent compile.
> Before:
> Use "make V=1" to see the verbose compile lines.\n  CC  debugger.o
>   CC    gmime-filter-reply.o
> 
> After:
> Use "make V=1" to see the verbose compile lines.
>   CC    debugger.o
>   CC    gmime-filter-reply.o
> 
> Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>

Looks right, works here with bash, dash & zsh, so:

Reviewed-by: Ingmar Vanhassel <ingmar@exherbo.org>

Thanks!

> ---
>  Makefile |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 2cd1b1b..2d19a6e 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -41,7 +41,7 @@ include Makefile.config
>  # user how to enable verbose compiles.
>  ifeq ($(V),)
>  quiet_DOC := "Use \"$(MAKE) V=1\" to see the verbose compile lines.\n"
> -quiet = @echo $(quiet_DOC)$(eval quiet_DOC:=)"  $1    $@"; $($1)
> +quiet = @echo -e $(quiet_DOC)$(eval quiet_DOC:=)"  $1    $@"; $($1)
>  endif
>  # The user has explicitly enabled quiet compilation.
>  ifeq ($(V),0)
-- 
Exherbo KDE, X.org maintainer

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

* Re: [PATCH] Makefile: Enable backslash escapes for echo.
  2009-11-26  8:17 ` [PATCH] Makefile: Enable backslash escapes for echo Stefan Schmidt
  2009-11-26  8:43   ` Ingmar Vanhassel
@ 2009-11-26 11:05   ` Jan Janak
  2009-11-26 11:41     ` Karl Wiberg
  1 sibling, 1 reply; 10+ messages in thread
From: Jan Janak @ 2009-11-26 11:05 UTC (permalink / raw)
  To: Stefan Schmidt; +Cc: notmuch

Hi Stefan,

On 26-11 09:17, Stefan Schmidt wrote:
> This fixes a visual glitch during a silent compile.
> Before:
> Use "make V=1" to see the verbose compile lines.\n  CC  debugger.o
>   CC    gmime-filter-reply.o
> 
> After:
> Use "make V=1" to see the verbose compile lines.
>   CC    debugger.o
>   CC    gmime-filter-reply.o
> 
> Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>
> ---
>  Makefile |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 2cd1b1b..2d19a6e 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -41,7 +41,7 @@ include Makefile.config
>  # user how to enable verbose compiles.
>  ifeq ($(V),)
>  quiet_DOC := "Use \"$(MAKE) V=1\" to see the verbose compile lines.\n"
> -quiet = @echo $(quiet_DOC)$(eval quiet_DOC:=)"  $1	$@"; $($1)
> +quiet = @echo -e $(quiet_DOC)$(eval quiet_DOC:=)"  $1	$@"; $($1)
>  endif
>  # The user has explicitly enabled quiet compilation.
>  ifeq ($(V),0)

I sent exactly the same patch a couple of days ago and it was rejected because
it does not work everywhere, see:

http://notmuchmail.org/pipermail/notmuch/2009/000370.html

  -- Jan

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

* Re: [PATCH] Makefile: Enable backslash escapes for echo.
  2009-11-26 11:05   ` Jan Janak
@ 2009-11-26 11:41     ` Karl Wiberg
  0 siblings, 0 replies; 10+ messages in thread
From: Karl Wiberg @ 2009-11-26 11:41 UTC (permalink / raw)
  To: Jan Janak; +Cc: notmuch

On Thu, Nov 26, 2009 at 12:05 PM, Jan Janak <jan@ryngle.com> wrote:

> I sent exactly the same patch a couple of days ago and it was
> rejected because it does not work everywhere, see:
>
> http://notmuchmail.org/pipermail/notmuch/2009/000370.html

And as I said in that thread, I believe you should use printf instead.
(http://www.in-ulm.de/~mascheck/various/echo+printf/ seems like a good
reference in this matter.)

-- 
Karl Wiberg, kha@treskal.com
   subrabbit.wordpress.com
   www.treskal.com/kalle

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

end of thread, other threads:[~2009-11-26 11:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <yes>
2009-11-22  0:11 ` [PATCH 1/2] lib/message: Add function to get maildir flags Stefan Schmidt
2009-11-22  0:11   ` [PATCH 2/2] notmuch-new: Tag mails not as unread when the seen flag in the maildir is set Stefan Schmidt
2009-11-22  0:28   ` [PATCH 1/2] lib/message: Add function to get maildir flags Keith Packard
2009-11-22 18:33     ` Stefan Schmidt
2009-11-22 18:55       ` Michiel Buddingh'
2009-11-22 19:52         ` Stefan Schmidt
2009-11-26  8:17 ` [PATCH] Makefile: Enable backslash escapes for echo Stefan Schmidt
2009-11-26  8:43   ` Ingmar Vanhassel
2009-11-26 11:05   ` Jan Janak
2009-11-26 11:41     ` Karl Wiberg

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).