]> granicus.if.org Git - neomutt/commitdiff
maildir: use mbox_check_stats()
authorAustin Ray <austin@austinray.io>
Fri, 7 Dec 2018 00:41:07 +0000 (00:41 +0000)
committerAustin Ray <austin@austinray.io>
Fri, 7 Dec 2018 00:42:02 +0000 (00:42 +0000)
mailbox.c
maildir/lib.h
maildir/maildir.c
maildir/mh.c
maildir/shared.c

index 64668861ba0c20fbaa1d2acd819fb8d2cb3c30e7..6343f12b55cb175385643610e9faa0210ff86897 100644 (file)
--- a/mailbox.c
+++ b/mailbox.c
@@ -171,21 +171,14 @@ static void mailbox_check(struct Mailbox *m, struct stat *ctx_sb, bool check_sta
   {
     switch (m->magic)
     {
-      case MUTT_MAILDIR:
-        if (maildir_check(m, check_stats) > 0)
-          MailboxCount++;
-        break;
-
-      case MUTT_MH:
-        if (mh_mailbox(m, check_stats))
-          MailboxCount++;
-        break;
       case MUTT_IMAP:
         if (!m->has_new)
           break;
         /* fallthrough */
       case MUTT_MBOX:
       case MUTT_MMDF:
+      case MUTT_MAILDIR:
+      case MUTT_MH:
       case MUTT_NOTMUCH:
         if (mx_mbox_check_stats(m, 0))
           MailboxCount++;
index 17ada5e7e967dee24e20f8055dcfa7adf560f363..cb180a2dbb9260a51f5d6ded30f88761f5e3613e 100644 (file)
@@ -58,7 +58,6 @@ extern struct MxOps mx_maildir_ops;
 extern struct MxOps mx_mh_ops;
 
 int           maildir_check_empty      (const char *path);
-int           maildir_check            (struct Mailbox *m, bool check_stats);
 void          maildir_gen_flags        (char *dest, size_t destlen, struct Email *e);
 FILE *        maildir_open_find_message(const char *folder, const char *msg, char **newname);
 void          maildir_parse_flags      (struct Email *e, const char *path);
@@ -66,7 +65,6 @@ struct Email *maildir_parse_message    (enum MailboxType magic, const char *fnam
 struct Email *maildir_parse_stream     (enum MailboxType magic, FILE *f, const char *fname, bool is_old, struct Email *e);
 bool          maildir_update_flags     (struct Mailbox *m, struct Email *o, struct Email *n);
 int           mh_check_empty           (const char *path);
-bool          mh_mailbox               (struct Mailbox *m, bool check_stats);
 #ifdef USE_HCACHE
 int           mh_sync_mailbox_message  (struct Mailbox *m, int msgno, header_cache_t *hc);
 #else
index 53cdba349944b91245986f1c6c4a458a832843c3..204b16da2c42174b14bed97885f2d1bee10d2da7 100644 (file)
@@ -543,6 +543,31 @@ int maildir_mbox_check(struct Context *ctx, int *index_hint)
   return 0;
 }
 
+/**
+ * maildir_mbox_check_stats - Implements MxOps::mbox_check_stats
+ */
+static int maildir_mbox_check_stats(struct Mailbox *m, int flags)
+{
+  if (!m)
+    return -1;
+
+  bool check_stats = true;
+  bool check_new = true;
+
+  m->msg_count = 0;
+  m->msg_unread = 0;
+  m->msg_flagged = 0;
+  m->msg_new = 0;
+
+  maildir_check_dir(m, "new", check_new, check_stats);
+
+  check_new = !m->has_new && MaildirCheckCur;
+  if (check_new || check_stats)
+    maildir_check_dir(m, "cur", check_new, check_stats);
+
+  return 0;
+}
+
 /**
  * maildir_msg_open - Implements MxOps::msg_open()
  */
@@ -671,6 +696,7 @@ struct MxOps mx_maildir_ops = {
   .mbox_open        = maildir_mbox_open,
   .mbox_open_append = maildir_mbox_open_append,
   .mbox_check       = maildir_mbox_check,
+  .mbox_check_stats = maildir_mbox_check_stats,
   .mbox_sync        = mh_mbox_sync,
   .mbox_close       = mh_mbox_close,
   .msg_open         = maildir_msg_open,
index 4fa77503d31ed94f51b1f24f42380834c27f7a2d..2974f58630e38973c15ac85e9ec5303f1ec283c3 100644 (file)
@@ -416,12 +416,9 @@ bool mh_valid_message(const char *s)
 }
 
 /**
- * mh_mailbox - Check for new mail for a mh mailbox
- * @param m           Mailbox to check
- * @param check_stats Also count total, new, and flagged messages
- * @retval true if the mailbox has new mail
+ * mh_mbox_check_stats - Implements MxOps::check_stats
  */
-bool mh_mailbox(struct Mailbox *m, bool check_stats)
+static int mh_mbox_check_stats(struct Mailbox *m, int flags)
 {
   struct MhSequences mhs = { 0 };
   bool check_new = true;
@@ -437,27 +434,23 @@ bool mh_mailbox(struct Mailbox *m, bool check_stats)
     check_new = false;
   }
 
-  if (!(check_new || check_stats))
-    return rc;
+  if (!check_new)
+    return 0;
 
   if (mh_read_sequences(&mhs, m->path) < 0)
     return false;
 
-  if (check_stats)
-  {
-    m->msg_count = 0;
-    m->msg_unread = 0;
-    m->msg_flagged = 0;
-  }
+  m->msg_count = 0;
+  m->msg_unread = 0;
+  m->msg_flagged = 0;
 
   for (int i = mhs.max; i > 0; i--)
   {
-    if (check_stats && (mhs_check(&mhs, i) & MH_SEQ_FLAGGED))
+    if ((mhs_check(&mhs, i) & MH_SEQ_FLAGGED))
       m->msg_flagged++;
     if (mhs_check(&mhs, i) & MH_SEQ_UNSEEN)
     {
-      if (check_stats)
-        m->msg_unread++;
+      m->msg_unread++;
       if (check_new)
       {
         /* if the first unseen message we encounter was in the m during the
@@ -471,27 +464,23 @@ bool mh_mailbox(struct Mailbox *m, bool check_stats)
          * checking for new mail after the first unseen message.
          * Whether it resulted in "new mail" or not. */
         check_new = false;
-        if (!check_stats)
-          break;
       }
     }
   }
+
   mhs_free_sequences(&mhs);
 
-  if (check_stats)
+  dirp = opendir(m->path);
+  if (dirp)
   {
-    dirp = opendir(m->path);
-    if (dirp)
+    while ((de = readdir(dirp)))
     {
-      while ((de = readdir(dirp)))
-      {
-        if (*de->d_name == '.')
-          continue;
-        if (mh_valid_message(de->d_name))
-          m->msg_count++;
-      }
-      closedir(dirp);
+      if (*de->d_name == '.')
+        continue;
+      if (mh_valid_message(de->d_name))
+        m->msg_count++;
     }
+    closedir(dirp);
   }
 
   return rc;
@@ -819,6 +808,7 @@ struct MxOps mx_mh_ops = {
   .mbox_open        = mh_mbox_open,
   .mbox_open_append = mh_mbox_open_append,
   .mbox_check       = mh_mbox_check,
+  .mbox_check_stats = mh_mbox_check_stats,
   .mbox_sync        = mh_mbox_sync,
   .mbox_close       = mh_mbox_close,
   .msg_open         = mh_msg_open,
index 9b59960e8d8a667de5d8c95a82d2410bdda8bd7a..de7e7e1fee71d92f4b495eec0c5f74f9ffa97a59 100644 (file)
@@ -1864,32 +1864,3 @@ int mh_msg_close(struct Mailbox *m, struct Message *msg)
 {
   return mutt_file_fclose(&msg->fp);
 }
-
-/**
- * maildir_check - Check for new mail in a maildir mailbox
- * @param m           Mailbox to check
- * @param check_stats if true, also count total, new, and flagged messages
- * @retval 1 if the mailbox has new mail
- */
-int maildir_check(struct Mailbox *m, bool check_stats)
-{
-  int rc = 1;
-  bool check_new = true;
-
-  if (check_stats)
-  {
-    m->msg_count = 0;
-    m->msg_unread = 0;
-    m->msg_flagged = 0;
-    m->msg_new = 0;
-  }
-
-  rc = maildir_check_dir(m, "new", check_new, check_stats);
-
-  check_new = !rc && MaildirCheckCur;
-  if (check_new || check_stats)
-    if (maildir_check_dir(m, "cur", check_new, check_stats))
-      rc = 1;
-
-  return rc;
-}