From e0565fb7c303acebc0761111b06d63cf7166781b Mon Sep 17 00:00:00 2001
From: Julius Plenz <plenz@cis.fu-berlin.de>
Date: Wed, 30 Nov 2011 14:25:31 +0100
Subject: [PATCH 18/19] Fix Buffy/Sidebar and mail_check_recent issues


Signed-off-by: Julius Plenz <plenz@cis.fu-berlin.de>
---
 buffy.c |   17 ++++++-----------
 mx.c    |    3 ++-
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/buffy.c b/buffy.c
index fa76a49..e58d4f1 100644
--- a/buffy.c
+++ b/buffy.c
@@ -301,11 +301,6 @@ static int buffy_maildir_hasnew (BUFFY* mailbox)
 
   snprintf (path, sizeof (path), "%s/new", mailbox->path);
 
-  if (option(OPTSIDEBAR) && mailbox->msg_unread > 0) {
-      mailbox->new = 1;
-      return 1;
-  }
-
   /* when $mail_check_recent is set, if the new/ directory hasn't been modified since
    * the user last exited the mailbox, then we know there is no recent mail.
    */
@@ -315,6 +310,11 @@ static int buffy_maildir_hasnew (BUFFY* mailbox)
       return 0;
   }
 
+  if (option(OPTSIDEBAR) && mailbox->msg_unread > 0) {
+      mailbox->new = 1;
+      return 1;
+  }
+
   if ((dirp = opendir (path)) == NULL)
   {
     mailbox->magic = 0;
@@ -426,7 +426,7 @@ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
   else
     statcheck = sb->st_mtime > sb->st_atime
       || (mailbox->newly_created && sb->st_ctime == sb->st_mtime && sb->st_ctime == sb->st_atime);
-  if (statcheck)
+  if ((!option(OPTSIDEBAR) && statcheck) || (option(OPTSIDEBAR) && mailbox->msg_unread > 0))
   {
     if (!option(OPTMAILCHECKRECENT) || sb->st_mtime > mailbox->last_visited)
     {
@@ -443,11 +443,6 @@ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
       (sb->st_ctime != sb->st_mtime || sb->st_ctime != sb->st_atime))
     mailbox->newly_created = 0;
 
-  if (option(OPTSIDEBAR) && mailbox->msg_unread > 0) {
-      mailbox->new = 1;
-      rc = 1;
-  }
-
   return rc;
 }
 
diff --git a/mx.c b/mx.c
index 24ffe2e..6903559 100644
--- a/mx.c
+++ b/mx.c
@@ -722,7 +722,8 @@ void mx_fastclose_mailbox (CONTEXT *ctx)
 
   /* never announce that a mailbox we've just left has new mail. #3290
    * XXX: really belongs in mx_close_mailbox, but this is a nice hook point */
-  mutt_buffy_setnotified(ctx->path);
+  if(!ctx->peekonly)
+    mutt_buffy_setnotified(ctx->path);
 
   if (ctx->mx_close)
     ctx->mx_close (ctx);
-- 
1.7.7.3


