[balsa] mailbox: Make cache-message a class method



commit 6b8d818c989e73f515727e684a96daaebee89fb9
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Mar 6 18:29:36 2020 -0500

    mailbox: Make cache-message a class method
    
    * libbalsa/mailbox.c (libbalsa_mailbox_class_init),
      (lbm_cache_message), (libbalsa_mailbox_get_message),
      (libbalsa_mailbox_real_cache_message),
      (libbalsa_mailbox_cache_message):
    * libbalsa/mailbox.h:
    * libbalsa/mailbox_local.c (libbalsa_mailbox_local_class_init),
      (lbm_local_cache_message), (libbalsa_mailbox_local_cache_message):
    * libbalsa/mailbox_local.h:
    * libbalsa/mailbox_mbox.c (parse_mailbox):

 ChangeLog                | 14 ++++++++++++++
 libbalsa/mailbox.c       | 22 ++++++++++++++--------
 libbalsa/mailbox.h       |  3 +++
 libbalsa/mailbox_local.c | 40 +++++++++++++++++++++-------------------
 libbalsa/mailbox_local.h |  3 ---
 libbalsa/mailbox_mbox.c  |  5 ++---
 6 files changed, 54 insertions(+), 33 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2468b65fb..ccfb3c6ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2020-03-06  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       mailbox: Make cache-message a class method
+
+       * libbalsa/mailbox.c (libbalsa_mailbox_class_init),
+       (lbm_cache_message), (libbalsa_mailbox_get_message),
+       (libbalsa_mailbox_real_cache_message),
+       (libbalsa_mailbox_cache_message):
+       * libbalsa/mailbox.h:
+       * libbalsa/mailbox_local.c (libbalsa_mailbox_local_class_init),
+       (lbm_local_cache_message), (libbalsa_mailbox_local_cache_message):
+       * libbalsa/mailbox_local.h:
+       * libbalsa/mailbox_mbox.c (parse_mailbox):
+
 2020-03-06  Peter Bloomfield  <pbloomfield bellsouth net>
 
        mailbox: Guard against out-of-bounds access to a GPtrArray
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index ac7abe092..fbc90d000 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -61,6 +61,9 @@ static gboolean libbalsa_mailbox_real_close_backend (LibBalsaMailbox *
                                                      mailbox);
 static void libbalsa_mailbox_real_lock_store(LibBalsaMailbox * mailbox,
                                              gboolean lock);
+static void libbalsa_mailbox_real_cache_message(LibBalsaMailbox * mailbox,
+                                                guint msgno,
+                                                LibBalsaMessage * message);
 
 /* SIGNALS MEANINGS :
    - CHANGED: notification signal sent by the mailbox to allow the
@@ -256,6 +259,7 @@ libbalsa_mailbox_class_init(LibBalsaMailboxClass * klass)
     klass->duplicate_msgnos = NULL;
     klass->lock_store  = libbalsa_mailbox_real_lock_store;
     klass->test_can_reach = NULL;
+    klass->cache_message = libbalsa_mailbox_real_cache_message;
 }
 
 static void
@@ -2006,7 +2010,7 @@ lbm_cache_message(LibBalsaMailbox * mailbox, guint msgno,
     gboolean need_sort;
 
     /* Do we need to cache the message info? */
-    if (priv->view == NULL || priv->view->position < 0)
+    if (priv->mindex == NULL || priv->view == NULL || priv->view->position < 0)
         return;
 
     if (priv->mindex->len < msgno)
@@ -2058,7 +2062,7 @@ libbalsa_mailbox_get_message(LibBalsaMailbox * mailbox, guint msgno)
 
     message = LIBBALSA_MAILBOX_GET_CLASS(mailbox)->get_message(mailbox,
                                                                msgno);
-    if (message && priv->mindex)
+    if (message != NULL)
         /* Cache the message info, if we do not already have it. */
         lbm_cache_message(mailbox, msgno, message);
 
@@ -4676,20 +4680,22 @@ libbalsa_mailbox_unlock_store(LibBalsaMailbox * mailbox)
         LIBBALSA_MAILBOX_GET_CLASS(mailbox)->lock_store(mailbox, FALSE);
 }
 
+static void
+libbalsa_mailbox_real_cache_message(LibBalsaMailbox * mailbox, guint msgno,
+                                    LibBalsaMessage * message)
+{
+    lbm_cache_message(mailbox, msgno, message);
+}
+
 void
 libbalsa_mailbox_cache_message(LibBalsaMailbox * mailbox, guint msgno,
                                LibBalsaMessage * message)
 {
-    LibBalsaMailboxPrivate *priv = libbalsa_mailbox_get_instance_private(mailbox);
-
     g_return_if_fail(LIBBALSA_IS_MAILBOX(mailbox));
-
-    if (!priv->mindex)
-        return;
     g_return_if_fail(msgno > 0);
     g_return_if_fail(LIBBALSA_IS_MESSAGE(message));
 
-    lbm_cache_message(mailbox, msgno, message);
+    LIBBALSA_MAILBOX_GET_CLASS(mailbox)->cache_message(mailbox, msgno, message);
 }
 
 static void
diff --git a/libbalsa/mailbox.h b/libbalsa/mailbox.h
index 42d90e13f..18bb6b3a4 100644
--- a/libbalsa/mailbox.h
+++ b/libbalsa/mailbox.h
@@ -258,6 +258,9 @@ struct _LibBalsaMailboxClass {
     void (*test_can_reach) (LibBalsaMailbox          * mailbox,
                             LibBalsaCanReachCallback * cb,
                             gpointer                   cb_data);
+    void (*cache_message) (LibBalsaMailbox *mailbox,
+                           guint            msgno,
+                           LibBalsaMessage *message);
 };
 
 LibBalsaMailbox *libbalsa_mailbox_new_from_config(const gchar *prefix,
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 508790f8c..9793750af 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -119,10 +119,13 @@ static gboolean libbalsa_mailbox_local_msgno_has_flags(LibBalsaMailbox *
 static void libbalsa_mailbox_local_test_can_reach(LibBalsaMailbox          * mailbox,
                                                   LibBalsaCanReachCallback * cb,
                                                   gpointer                   cb_data);
-static void lbm_local_cache_message(LibBalsaMailboxLocal * local,
-                                    guint                  msgno,
-                                    LibBalsaMessage      * message);
+static gboolean lbm_local_cache_message(LibBalsaMailboxLocal * local,
+                                        guint                  msgno,
+                                        LibBalsaMessage      * message);
 static gboolean lbml_set_threading_idle_cb(LibBalsaMailboxLocal *local);
+static void libbalsa_mailbox_local_cache_message(LibBalsaMailbox * mailbox,
+                                                 guint             msgno,
+                                                 LibBalsaMessage * message);
 
 /* LibBalsaMailboxLocal class method: */
 static void lbm_local_real_remove_files(LibBalsaMailboxLocal * local);
@@ -177,6 +180,9 @@ libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass * klass)
         libbalsa_mailbox_local_duplicate_msgnos;
     libbalsa_mailbox_class->test_can_reach =
         libbalsa_mailbox_local_test_can_reach;
+    libbalsa_mailbox_class->cache_message =
+        libbalsa_mailbox_local_cache_message;
+
     klass->check_files  = NULL;
     klass->set_path     = NULL;
     klass->remove_files = lbm_local_real_remove_files;
@@ -988,16 +994,12 @@ libbalsa_mailbox_local_message_match(LibBalsaMailbox * mailbox,
 
 /*
  * libbalsa_mailbox_local_cache_message
- * private 
- * PS: called by mail_progress_notify_cb:
- * loads incrementally new messages, if any.
- *  Mailbox lock MUST BE HELD before calling this function.
  *
  *  Caches the message-id, references, and sender,
  *  and passes the message to libbalsa_mailbox_cache_message for caching
  *  other info.
  */
-static void
+static gboolean
 lbm_local_cache_message(LibBalsaMailboxLocal * local,
                         guint msgno,
                         LibBalsaMessage * message)
@@ -1010,13 +1012,13 @@ lbm_local_cache_message(LibBalsaMailboxLocal * local,
     /* If we are not preparing the mailbox for viewing, there is nothing
      * to do. */
     if (priv->threading_info == NULL)
-        return;
+        return FALSE;
 
     if (priv->threading_info->len < msgno)
         g_ptr_array_set_size(priv->threading_info, msgno);
 
     if (g_ptr_array_index(priv->threading_info, msgno - 1) != NULL)
-        return;
+        return FALSE;
 
     info = g_new(LibBalsaMailboxLocalInfo, 1);
     info->message_id = g_strdup(libbalsa_message_get_message_id(message));
@@ -1038,19 +1040,19 @@ lbm_local_cache_message(LibBalsaMailboxLocal * local,
             g_idle_add((GSourceFunc) lbml_set_threading_idle_cb, local);
     }
 
-    libbalsa_mailbox_cache_message(LIBBALSA_MAILBOX(local), msgno,
-                                   message);
+    return TRUE;
 }
 
-void
-libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal * local,
-                                     guint msgno,
+static void
+libbalsa_mailbox_local_cache_message(LibBalsaMailbox * mailbox,
+                                     guint             msgno,
                                      LibBalsaMessage * message)
 {
-    g_return_if_fail(LIBBALSA_IS_MAILBOX_LOCAL(local));
-
-    if (message != NULL)
-        lbm_local_cache_message(local, msgno, message);
+    if (message != NULL &&
+        lbm_local_cache_message(LIBBALSA_MAILBOX_LOCAL(mailbox), msgno, message)) {
+        LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->
+            cache_message(mailbox, msgno, message);
+    }
 }
 
 static gboolean
diff --git a/libbalsa/mailbox_local.h b/libbalsa/mailbox_local.h
index d7e6d1c97..562227a38 100644
--- a/libbalsa/mailbox_local.h
+++ b/libbalsa/mailbox_local.h
@@ -73,9 +73,6 @@ gint libbalsa_mailbox_local_set_path(LibBalsaMailboxLocal * mailbox,
 
 void libbalsa_mailbox_local_load_messages(LibBalsaMailbox * mailbox,
                                          guint last_msgno);
-void libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal * local,
-                                          guint msgno,
-                                          LibBalsaMessage * message);
 void libbalsa_mailbox_local_msgno_removed(LibBalsaMailbox * mailbox,
                                          guint msgno);
 void libbalsa_mailbox_local_remove_files(LibBalsaMailboxLocal *mailbox);
diff --git a/libbalsa/mailbox_mbox.c b/libbalsa/mailbox_mbox.c
index 40f4df4e1..bbf3597c3 100644
--- a/libbalsa/mailbox_mbox.c
+++ b/libbalsa/mailbox_mbox.c
@@ -132,7 +132,7 @@ libbalsa_mailbox_mbox_class_init(LibBalsaMailboxMboxClass * klass)
     libbalsa_mailbox_class->lock_store = libbalsa_mailbox_mbox_lock_store;
 
     libbalsa_mailbox_local_class->check_files  = lbm_mbox_check_files;
-    libbalsa_mailbox_local_class->remove_files = 
+    libbalsa_mailbox_local_class->remove_files =
        libbalsa_mailbox_mbox_remove_files;
 
     libbalsa_mailbox_local_class->get_info = lbm_mbox_get_info;
@@ -430,7 +430,6 @@ static LibBalsaMessage *lbm_mbox_message_new(GMimeMessage * mime_message,
 static void
 parse_mailbox(LibBalsaMailboxMbox * mbox)
 {
-    LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mbox);
     GMimeParser *gmime_parser;
     struct message_info msg_info;
     struct message_info * msg_info_p = &msg_info;
@@ -515,7 +514,7 @@ parse_mailbox(LibBalsaMailboxMbox * mbox)
         * holding the lock. */
         offset = g_mime_stream_tell(mbox->gmime_stream);
         libbalsa_mime_stream_shared_unlock(mbox->gmime_stream);
-        libbalsa_mailbox_local_cache_message(local, msgno, msg);
+        libbalsa_mailbox_cache_message(LIBBALSA_MAILBOX(mbox), msgno, msg);
         libbalsa_mime_stream_shared_lock(mbox->gmime_stream);
         g_mime_stream_seek(mbox->gmime_stream, offset, GMIME_STREAM_SEEK_SET);
 


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