]> granicus.if.org Git - neomutt/commitdiff
mbox_check: factor out Context
authorRichard Russon <rich@flatcap.org>
Mon, 24 Dec 2018 11:57:57 +0000 (11:57 +0000)
committerRichard Russon <rich@flatcap.org>
Sat, 5 Jan 2019 14:44:35 +0000 (14:44 +0000)
14 files changed:
compress.c
imap/imap.c
index.c
maildir/maildir.c
maildir/maildir_private.h
maildir/mh.c
maildir/shared.c
mbox/mbox.c
mx.c
mx.h
nntp/nntp.c
notmuch/mutt_notmuch.c
pager.c
pop/pop.c

index c1f9af83b61aadfe147a992a7cb9d5aa4b3a107d..638f0e3f06a697dc02319e5eed3f9a9d05b613f1 100644 (file)
@@ -590,7 +590,7 @@ cmoa_fail1:
 
 /**
  * comp_mbox_check - Implements MxOps::mbox_check()
- * @param ctx        Mailbox
+ * @param m          Mailbox
  * @param index_hint Currently selected mailbox
  * @retval 0              Mailbox OK
  * @retval #MUTT_REOPENED The mailbox was closed and reopened
@@ -603,12 +603,11 @@ cmoa_fail1:
  *
  * The return codes are picked to match mx_mbox_check().
  */
-static int comp_mbox_check(struct Context *ctx, int *index_hint)
+static int comp_mbox_check(struct Mailbox *m, int *index_hint)
 {
-  if (!ctx || !ctx->mailbox || !ctx->mailbox->compress_info)
+  if (!m || !m->compress_info)
     return -1;
 
-  struct Mailbox *m = ctx->mailbox;
   struct CompressInfo *ci = m->compress_info;
 
   const struct MxOps *ops = ci->child_ops;
@@ -631,7 +630,7 @@ static int comp_mbox_check(struct Context *ctx, int *index_hint)
   if (rc == 0)
     return -1;
 
-  return ops->mbox_check(ctx, index_hint);
+  return ops->mbox_check(m, index_hint);
 }
 
 /**
@@ -664,7 +663,7 @@ static int comp_mbox_sync(struct Context *ctx, int *index_hint)
     return -1;
   }
 
-  int rc = comp_mbox_check(ctx, index_hint);
+  int rc = comp_mbox_check(m, index_hint);
   if (rc != 0)
     goto sync_cleanup;
 
index 28f10e8922441b9521d6b1d725d9ba303ddd8856..18001e2a3a6d5be4eaa6e76b7998c61fd964bb86 100644 (file)
@@ -2194,18 +2194,16 @@ static int imap_mbox_open_append(struct Mailbox *m, int flags)
 
 /**
  * imap_mbox_check - Implements MxOps::mbox_check()
- * @param ctx        Mailbox
+ * @param m          Mailbox
  * @param index_hint Remember our place in the index
  * @retval >0 Success, e.g. #MUTT_REOPENED
  * @retval -1 Failure
  */
-static int imap_mbox_check(struct Context *ctx, int *index_hint)
+static int imap_mbox_check(struct Mailbox *m, int *index_hint)
 {
-  if (!ctx || !ctx->mailbox)
+  if (!m)
     return -1;
 
-  struct Mailbox *m = ctx->mailbox;
-
   imap_allow_reopen(m);
   int rc = imap_check_mailbox(m, false);
   /* NOTE - ctx might have been changed at this point. In particular,
diff --git a/index.c b/index.c
index 5f9b0eef923527987df494d2ec692a41a7c1c929..9b2beb8a551a4155e8a17d782a01b2c4583ccd54 100644 (file)
--- a/index.c
+++ b/index.c
@@ -1061,7 +1061,7 @@ int mutt_index_menu(void)
                        CUR_EMAIL->index :
                        0;
 
-      check = mx_mbox_check(Context, &index_hint);
+      check = mx_mbox_check(Context->mailbox, &index_hint);
       if (check < 0)
       {
         if (!Context->mailbox || Context->mailbox->path[0] == '\0')
index 5a63e8d01f4089ab6c8734d9eff5229636d9eecb..49823acb18e2898dbb066e5c268fc570da9ad19d 100644 (file)
@@ -360,13 +360,11 @@ static int maildir_mbox_open_append(struct Mailbox *m, int flags)
  * already knew about.  We don't treat either subdirectory differently, as mail
  * could be copied directly into the cur directory from another agent.
  */
-int maildir_mbox_check(struct Context *ctx, int *index_hint)
+int maildir_mbox_check(struct Mailbox *m, int *index_hint)
 {
-  if (!ctx || !ctx->mailbox)
+  if (!m)
     return -1;
 
-  struct Mailbox *m = ctx->mailbox;
-
   struct stat st_new;         /* status of the "new" subdirectory */
   struct stat st_cur;         /* status of the "cur" subdirectory */
   int changed = 0;            /* bitmask representing which subdirectories
@@ -472,7 +470,7 @@ int maildir_mbox_check(struct Context *ctx, int *index_hint)
        * the flags we just detected.
        */
       if (!m->emails[i]->changed)
-        if (maildir_update_flags(ctx->mailbox, m->emails[i], p->email))
+        if (maildir_update_flags(m, m->emails[i], p->email))
           flags_changed = true;
 
       if (m->emails[i]->deleted == m->emails[i]->trash)
index b4f6818badf8d948b7268121b42495126fe399d8..d304f1d3c85c965f16f9ae84e4b801ae53efbf3b 100644 (file)
@@ -74,11 +74,11 @@ struct MhSequences
 /* MXAPI shared functions */
 int             maildir_ac_add     (struct Account *a, struct Mailbox *m);
 struct Account *maildir_ac_find    (struct Account *a, const char *path);
-int             maildir_mbox_check (struct Context *ctx, int *index_hint);
+int             maildir_mbox_check (struct Mailbox *m, int *index_hint);
 int             maildir_path_canon (char *buf, size_t buflen);
 int             maildir_path_parent(char *buf, size_t buflen);
 int             maildir_path_pretty(char *buf, size_t buflen, const char *folder);
-int             mh_mbox_check      (struct Context *ctx, int *index_hint);
+int             mh_mbox_check      (struct Mailbox *m, int *index_hint);
 int             mh_mbox_close      (struct Mailbox *m);
 int             mh_mbox_sync       (struct Context *ctx, int *index_hint);
 int             mh_msg_close       (struct Mailbox *m, struct Message *msg);
index 5d93776fbbd9d9b0708f771790a571dfdba8f1c5..0ba59f97056a8c5119b0bd13f59e4616610cde76 100644 (file)
@@ -589,13 +589,11 @@ static int mh_mbox_open_append(struct Mailbox *m, int flags)
  *
  * Don't change this code unless you _really_ understand what happens.
  */
-int mh_mbox_check(struct Context *ctx, int *index_hint)
+int mh_mbox_check(struct Mailbox *m, int *index_hint)
 {
-  if (!ctx || !ctx->mailbox)
+  if (!m)
     return -1;
 
-  struct Mailbox *m = ctx->mailbox;
-
   char buf[PATH_MAX];
   struct stat st, st_cur;
   bool modified = false, occult = false, flags_changed = false;
@@ -690,7 +688,7 @@ int mh_mbox_check(struct Context *ctx, int *index_hint)
       m->emails[i]->active = true;
       /* found the right message */
       if (!m->emails[i]->changed)
-        if (maildir_update_flags(ctx->mailbox, m->emails[i], p->email))
+        if (maildir_update_flags(m, m->emails[i], p->email))
           flags_changed = true;
 
       mutt_email_free(&p->email);
index 767196c0c566c5d66bf0f462014e753c495f2059..e042a6bb9678ff0a4d0c160c980c12cf05a5758b 100644 (file)
@@ -1772,9 +1772,9 @@ int mh_mbox_sync(struct Context *ctx, int *index_hint)
   struct Progress progress;
 
   if (m->magic == MUTT_MH)
-    i = mh_mbox_check(ctx, index_hint);
+    i = mh_mbox_check(m, index_hint);
   else
-    i = maildir_mbox_check(ctx, index_hint);
+    i = maildir_mbox_check(m, index_hint);
 
   if (i != 0)
     return i;
index 99e121b197a0f2195689641f06d778f7bf173319..7946955ec3d43eddd0ff6cb8f96ffde45ff234c4 100644 (file)
@@ -992,7 +992,7 @@ static int mbox_mbox_open_append(struct Mailbox *m, int flags)
 
 /**
  * mbox_mbox_check - Implements MxOps::mbox_check()
- * @param[in]  ctx        Mailbox
+ * @param[in]  m          Mailbox
  * @param[out] index_hint Keep track of current index selection
  * @retval #MUTT_REOPENED  Mailbox has been reopened
  * @retval #MUTT_NEW_MAIL  New mail has arrived
@@ -1000,13 +1000,11 @@ static int mbox_mbox_open_append(struct Mailbox *m, int flags)
  * @retval 0               No change
  * @retval -1              Error
  */
-static int mbox_mbox_check(struct Context *ctx, int *index_hint)
+static int mbox_mbox_check(struct Mailbox *m, int *index_hint)
 {
-  if (!ctx || !ctx->mailbox)
+  if (!m)
     return -1;
 
-  struct Mailbox *m = ctx->mailbox;
-
   struct MboxAccountData *adata = mbox_adata_get(m);
   if (!adata)
     return -1;
@@ -1187,7 +1185,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint)
   }
 
   /* Check to make sure that the file hasn't changed on disk */
-  i = mbox_mbox_check(ctx, index_hint);
+  i = mbox_mbox_check(m, index_hint);
   if ((i == MUTT_NEW_MAIL) || (i == MUTT_REOPENED))
   {
     /* new mail arrived, or mailbox reopened */
diff --git a/mx.c b/mx.c
index 522a2b5990fa65b0f62af52c7ea65d532f4b93bd..563717faf0f8e706e8d53f3c48489caddbb001ce 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -1137,23 +1137,20 @@ struct Message *mx_msg_open_new(struct Mailbox *m, struct Email *e, int flags)
 
 /**
  * mx_mbox_check - Check for new mail - Wrapper for MxOps::mbox_check()
- * @param ctx        Mailbox
+ * @param m          Mailbox
  * @param index_hint Current email
  * @retval >0 Success, e.g. #MUTT_NEW_MAIL
  * @retval  0 Success, no change
  * @retval -1 Failure
  */
-int mx_mbox_check(struct Context *ctx, int *index_hint)
+int mx_mbox_check(struct Mailbox *m, int *index_hint)
 {
-  if (!ctx || !ctx->mailbox || !ctx->mailbox->mx_ops)
+  if (!m || !m->mx_ops)
     return -1;
 
-  struct Mailbox *m = ctx->mailbox;
-  int rc = m->mx_ops->mbox_check(ctx, index_hint);
+  int rc = m->mx_ops->mbox_check(m, index_hint);
   if (rc == MUTT_NEW_MAIL || rc == MUTT_REOPENED)
-  {
-    mx_update_context(ctx);
-  }
+    mutt_mailbox_changed(m, MBN_INVALID);
 
   return rc;
 }
diff --git a/mx.h b/mx.h
index a9a860722f354d56ac173ac16a5f5dbcf34f9141..5796bf7b7d7604856dbbdebfc3c48dbabb25abe8 100644 (file)
--- a/mx.h
+++ b/mx.h
@@ -136,12 +136,12 @@ struct MxOps
   int (*mbox_open_append)(struct Mailbox *m, int flags);
   /**
    * mbox_check - Check for new mail
-   * @param ctx Mailbox
+   * @param m          Mailbox
    * @param index_hint Remember our place in the index
    * @retval >0 Success, e.g. #MUTT_REOPENED
    * @retval -1 Error
    */
-  int (*mbox_check)      (struct Context *ctx, int *index_hint);
+  int (*mbox_check)      (struct Mailbox *m, int *index_hint);
   /**
    * mbox_check_stats - Check the mailbox statistics
    * @param m     Mailbox to check
@@ -260,7 +260,7 @@ struct MxOps
 };
 
 /* Wrappers for the Mailbox API, see MxOps */
-int             mx_mbox_check      (struct Context *ctx, int *index_hint);
+int             mx_mbox_check      (struct Mailbox *m, int *index_hint);
 int             mx_mbox_check_stats(struct Mailbox *m, int flags);
 int             mx_mbox_close      (struct Context **pctx, int *index_hint);
 struct Context *mx_mbox_open       (struct Mailbox *m, const char *path, int flags);
index 8220ef5f31b33b69f8bbeaaebc568a1af284575f..09be2b3a761343164d7a792357af7397d0956fc8 100644 (file)
@@ -2579,20 +2579,18 @@ static int nntp_mbox_open(struct Mailbox *m)
 
 /**
  * nntp_mbox_check - Implements MxOps::mbox_check()
- * @param ctx        Mailbox
+ * @param m          Mailbox
  * @param index_hint Current message (UNUSED)
  * @retval #MUTT_REOPENED Articles have been renumbered or removed from server
  * @retval #MUTT_NEW_MAIL New articles found
  * @retval  0             No change
  * @retval -1             Lost connection
  */
-static int nntp_mbox_check(struct Context *ctx, int *index_hint)
+static int nntp_mbox_check(struct Mailbox *m, int *index_hint)
 {
-  if (!ctx || !ctx->mailbox)
+  if (!m)
     return -1;
 
-  struct Mailbox *m = ctx->mailbox;
-
   int ret = check_mailbox(m);
   if (ret == 0)
   {
index 8a051d1979ae7505cdb4c9ec7c53c29f8f35967d..bea00dec8c4418d1eeba421aaf0857bd432798e6 100644 (file)
@@ -2166,7 +2166,7 @@ static int nm_mbox_open(struct Mailbox *m)
 
 /**
  * nm_mbox_check - Implements MxOps::mbox_check()
- * @param ctx         Mailbox
+ * @param m           Mailbox
  * @param index_hint  Remember our place in the index
  * @retval -1 Error
  * @retval  0 Success
@@ -2174,13 +2174,11 @@ static int nm_mbox_open(struct Mailbox *m)
  * @retval #MUTT_REOPENED Mailbox closed and reopened
  * @retval #MUTT_FLAGS    Flags have changed
  */
-static int nm_mbox_check(struct Context *ctx, int *index_hint)
+static int nm_mbox_check(struct Mailbox *m, int *index_hint)
 {
-  if (!ctx || !ctx->mailbox)
+  if (!m)
     return -1;
 
-  struct Mailbox *m = ctx->mailbox;
-
   struct NmMboxData *mdata = nm_mdata_get(m);
   time_t mtime = 0;
   if (!mdata || (nm_db_get_mtime(m, &mtime) != 0))
@@ -2258,7 +2256,7 @@ static int nm_mbox_check(struct Context *ctx, int *index_hint)
        */
       struct Email tmp = { 0 };
       maildir_parse_flags(&tmp, new);
-      maildir_update_flags(ctx->mailbox, e, &tmp);
+      maildir_update_flags(m, e, &tmp);
     }
 
     if (update_email_tags(e, msg) == 0)
diff --git a/pager.c b/pager.c
index b00cae411d6d672ba508c7f4ce3dd4cc3f4412fd..61f621dd2d3ac987583e6f2486ac951ac7a85fe5 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -2355,7 +2355,7 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e
     {
       oldcount = Context->mailbox->msg_count;
       /* check for new mail */
-      check = mx_mbox_check(Context, &index_hint);
+      check = mx_mbox_check(Context->mailbox, &index_hint);
       if (check < 0)
       {
         if (!Context->mailbox || Context->mailbox->path[0] == '\0')
index cdd0cd8812badadbabc5a4023a4b6498c3f05a4d..92d494e500a32928a43900e0ebfc50edb77521f1 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -890,13 +890,11 @@ static int pop_mbox_open(struct Mailbox *m)
 /**
  * pop_mbox_check - Implements MxOps::mbox_check()
  */
-static int pop_mbox_check(struct Context *ctx, int *index_hint)
+static int pop_mbox_check(struct Mailbox *m, int *index_hint)
 {
-  if (!ctx || !ctx->mailbox)
+  if (!m)
     return -1;
 
-  struct Mailbox *m = ctx->mailbox;
-
   struct PopAccountData *adata = pop_get_adata(m);
 
   if ((adata->check_time + PopCheckinterval) > time(NULL))