[balsa/gtk3] Fix miscounting of unread messages



commit ee5a299e05d130faa26570941c26c7978a298aba
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Apr 15 18:26:24 2013 -0400

    Fix miscounting of unread messages
    
        * libbalsa/mailbox_local.h: new member
        gboolean _LibBalsaMailboxLocalMessageInfo::loaded.
        * libbalsa/mailbox_local.c (libbalsa_mailbox_local_load_message),
        (lbm_local_restore_tree): use it to indicate when we are
        changing flags on a message that has not yet been counted.
        * libbalsa/mailbox_mbox.c (parse_mailbox), (lbm_mbox_restore):
        initialize it to FALSE.

 ChangeLog                | 12 ++++++++++++
 libbalsa/mailbox_local.c | 29 ++++++++++++++++++++++-------
 libbalsa/mailbox_local.h |  1 +
 libbalsa/mailbox_mbox.c  |  2 ++
 4 files changed, 37 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index dbd1ad4..3dfac90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2013-04-15  Peter Bloomfield
+
+       Fix miscounting of unread messages
+
+       * libbalsa/mailbox_local.h: new member
+       gboolean _LibBalsaMailboxLocalMessageInfo::loaded.
+       * libbalsa/mailbox_local.c (libbalsa_mailbox_local_load_message),
+       (lbm_local_restore_tree): use it to indicate when we are
+       changing flags on a message that has not yet been counted.
+       * libbalsa/mailbox_mbox.c (parse_mailbox), (lbm_mbox_restore):
+       initialize it to FALSE.
+
 2013-04-12  Peter Bloomfield
 
        * src/balsa-mime-widget-message.c (bm_header_widget_realized):
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 8223381..34f4087 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -318,6 +318,8 @@ libbalsa_mailbox_local_load_message(LibBalsaMailboxLocal * local,
     LibBalsaMailbox *mbx = LIBBALSA_MAILBOX(local);
     gboolean match;
 
+    msg_info->loaded = TRUE;
+
     if ((msg_info->flags & LIBBALSA_MESSAGE_FLAG_NEW)
         && !(msg_info->flags & LIBBALSA_MESSAGE_FLAG_DELETED)) {
         mbx->unread_messages++;
@@ -574,6 +576,8 @@ lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
     GNode *parent, *sibling;
     LibBalsaMailboxLocalTreeInfo *info;
     guint8 *seen;
+    LibBalsaMailboxLocalMessageInfo *(*get_info) (LibBalsaMailboxLocal *,
+                                                  guint);
 
     filename = lbm_local_get_cache_filename(local);
     name = mailbox->name ? g_strdup(mailbox->name) :
@@ -625,7 +629,9 @@ lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
     seen = g_new0(guint8, *total);
     parent = mailbox->msg_tree;
     sibling = NULL;
+    get_info = LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->get_info;
     while (++info < (LibBalsaMailboxLocalTreeInfo *) (contents + length)) {
+        LibBalsaMailboxLocalMessageInfo *msg_info;
         if (info->msgno == 0 || info->msgno > *total
             || seen[info->msgno - 1]) {
             libbalsa_information(LIBBALSA_INFORMATION_DEBUG,
@@ -665,6 +671,10 @@ lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
         }
         libbalsa_mailbox_msgno_inserted(mailbox, info->msgno,
                                         parent, &sibling);
+
+        msg_info = get_info(local, info->msgno);
+        msg_info->loaded = TRUE;
+
         if (libbalsa_mailbox_msgno_has_flags(mailbox, info->msgno,
                                              LIBBALSA_MESSAGE_FLAG_NEW,
                                              LIBBALSA_MESSAGE_FLAG_DELETED))
@@ -2220,7 +2230,6 @@ libbalsa_mailbox_local_messages_change_flags(LibBalsaMailbox * mailbox,
         guint msgno = g_array_index(msgnos, guint, i);
         LibBalsaMailboxLocalMessageInfo *msg_info;
         LibBalsaMessageFlag old_flags;
-        gboolean was_unread_undeleted, is_unread_undeleted;
 
         if (!(msgno > 0
               && msgno <= libbalsa_mailbox_total_messages(mailbox))) {
@@ -2242,12 +2251,18 @@ libbalsa_mailbox_local_messages_change_flags(LibBalsaMailbox * mailbox,
 
         libbalsa_mailbox_index_set_flags(mailbox, msgno, msg_info->flags);
 
-        was_unread_undeleted = (old_flags & LIBBALSA_MESSAGE_FLAG_NEW)
-            && !(old_flags & LIBBALSA_MESSAGE_FLAG_DELETED);
-        is_unread_undeleted = (msg_info->flags & LIBBALSA_MESSAGE_FLAG_NEW)
-            && !(msg_info->flags & LIBBALSA_MESSAGE_FLAG_DELETED);
-        mailbox->unread_messages +=
-            is_unread_undeleted - was_unread_undeleted;
+        if (msg_info->loaded) {
+            gboolean was_unread_undeleted, is_unread_undeleted;
+
+            was_unread_undeleted =
+                (old_flags & LIBBALSA_MESSAGE_FLAG_NEW)
+                && !(old_flags & LIBBALSA_MESSAGE_FLAG_DELETED);
+            is_unread_undeleted =
+                (msg_info->flags & LIBBALSA_MESSAGE_FLAG_NEW)
+                && !(msg_info->flags & LIBBALSA_MESSAGE_FLAG_DELETED);
+            mailbox->unread_messages +=
+                is_unread_undeleted - was_unread_undeleted;
+        }
     }
     libbalsa_unlock_mailbox(mailbox);
 
diff --git a/libbalsa/mailbox_local.h b/libbalsa/mailbox_local.h
index e8d881d..8a6721f 100644
--- a/libbalsa/mailbox_local.h
+++ b/libbalsa/mailbox_local.h
@@ -56,6 +56,7 @@ typedef struct _LibBalsaMailboxLocalPool LibBalsaMailboxLocalPool;
 struct _LibBalsaMailboxLocalMessageInfo {
     LibBalsaMessageFlag flags;          /* May have pseudo-flags */
     LibBalsaMessage *message;
+    gboolean loaded;
 };
 typedef struct _LibBalsaMailboxLocalMessageInfo LibBalsaMailboxLocalMessageInfo;
 
diff --git a/libbalsa/mailbox_mbox.c b/libbalsa/mailbox_mbox.c
index 78ff608..f1e21f7 100644
--- a/libbalsa/mailbox_mbox.c
+++ b/libbalsa/mailbox_mbox.c
@@ -490,6 +490,7 @@ parse_mailbox(LibBalsaMailboxMbox * mbox)
 
     libbalsa_mailbox_local_set_threading_info(local);
     msg_info.local_info.message = NULL;
+    msg_info.local_info.loaded  = FALSE;
     while (!g_mime_parser_eos(gmime_parser)) {
        GMimeMessage *mime_message;
         LibBalsaMessage *msg;
@@ -625,6 +626,7 @@ lbm_mbox_restore(LibBalsaMailboxMbox * mbox)
     end = 0;
     do {
         msg_info->local_info.message = NULL;
+        msg_info->local_info.loaded  = FALSE;
         if (msg_info->start != end)
             /* Error: this message doesn't start at the end of the
              * previous one. */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]