move Context.{v2r,vcount}
authorRichard Russon <rich@flatcap.org>
Sat, 8 Sep 2018 12:37:27 +0000 (13:37 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 9 Sep 2018 15:12:32 +0000 (16:12 +0100)
15 files changed:
context.h
copy.c
curs_main.c
imap/imap.c
mailbox.h
mbox/mbox.c
menu.c
mutt_thread.c
mx.c
nntp/nntp.c
pager.c
pattern.c
sidebar.c
sort.c
status.c

index 2e28ecad83fd1926a2e7bef7f2036f849df1cc16..6bd49b9f7029963aaa1e5e7c4a3adcf9c24c727a 100644 (file)
--- a/context.h
+++ b/context.h
@@ -40,8 +40,6 @@ struct Context
   struct Header *last_tag;  /**< last tagged msg. used to link threads */
   struct MuttThread *tree;  /**< top of thread tree */
   struct Hash *thread_hash; /**< hash table for threading */
-  int *v2r;                 /**< mapping from virtual to real msgno */
-  int vcount;               /**< the number of virtual messages */
   int tagged;               /**< how many messages are tagged? */
   int new;                  /**< how many new messages? */
   int deleted;              /**< how many deleted messages */
diff --git a/copy.c b/copy.c
index 519a7cabf2395540cbd511db7a413a0a864adb59..ccba4575c78572dc74e5c2f492ec7c106c90d88f 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -657,7 +657,7 @@ int mutt_copy_message_fp(FILE *fpout, FILE *fpin, struct Header *hdr, int flags,
         /* update the total size of the mailbox to reflect this deletion */
         Context->mailbox->size -= body->length - new_length;
         /* if the message is visible, update the visible size of the mailbox as well.  */
-        if (Context->v2r[hdr->msgno] != -1)
+        if (Context->mailbox->v2r[hdr->msgno] != -1)
           Context->vsize -= body->length - new_length;
 
         body->length = new_length;
index cc4d58f7267990095f4f2882a5f6fac0d6473644..04d82977a9f28c9821720be2c956c7d81369fd55 100644 (file)
@@ -129,7 +129,7 @@ static const char *NoVisible = N_("No visible messages");
   }
 
 #define CHECK_VISIBLE                                                          \
-  if (Context && menu->current >= Context->vcount)                             \
+  if (Context && menu->current >= Context->mailbox->vcount)                    \
   {                                                                            \
     mutt_flushinp();                                                           \
     mutt_error(_(NoVisible));                                                  \
@@ -161,7 +161,7 @@ static const char *NoVisible = N_("No visible messages");
     break;                                                                     \
   }
 
-#define CURHDR Context->mailbox->hdrs[Context->v2r[menu->current]]
+#define CURHDR Context->mailbox->hdrs[Context->mailbox->v2r[menu->current]]
 #define UNREAD(h) mutt_thread_contains_unread(Context, h)
 #define FLAGGED(h) mutt_thread_contains_flagged(Context, h)
 
@@ -197,7 +197,7 @@ static void collapse_all(struct Menu *menu, int toggle)
   else
     final = CURHDR->virtual;
 
-  base = Context->mailbox->hdrs[Context->v2r[final]];
+  base = Context->mailbox->hdrs[Context->mailbox->v2r[final]];
 
   /* Iterate all threads, perform collapse/uncollapse as needed */
   top = Context->tree;
@@ -220,9 +220,9 @@ static void collapse_all(struct Menu *menu, int toggle)
 
   /* Restore the cursor */
   mutt_set_virtual(Context);
-  for (int j = 0; j < Context->vcount; j++)
+  for (int j = 0; j < Context->mailbox->vcount; j++)
   {
-    if (Context->mailbox->hdrs[Context->v2r[j]]->index == base->index)
+    if (Context->mailbox->hdrs[Context->mailbox->v2r[j]]->index == base->index)
     {
       menu->current = j;
       break;
@@ -240,8 +240,8 @@ static void collapse_all(struct Menu *menu, int toggle)
  */
 static int ci_next_undeleted(int msgno)
 {
-  for (int i = msgno + 1; i < Context->vcount; i++)
-    if (!Context->mailbox->hdrs[Context->v2r[i]]->deleted)
+  for (int i = msgno + 1; i < Context->mailbox->vcount; i++)
+    if (!Context->mailbox->hdrs[Context->mailbox->v2r[i]]->deleted)
       return i;
   return -1;
 }
@@ -255,7 +255,7 @@ static int ci_next_undeleted(int msgno)
 static int ci_previous_undeleted(int msgno)
 {
   for (int i = msgno - 1; i >= 0; i--)
-    if (!Context->mailbox->hdrs[Context->v2r[i]]->deleted)
+    if (!Context->mailbox->hdrs[Context->mailbox->v2r[i]]->deleted)
       return i;
   return -1;
 }
@@ -273,12 +273,12 @@ static int ci_first_message(void)
     return 0;
 
   int old = -1;
-  for (int i = 0; i < Context->vcount; i++)
+  for (int i = 0; i < Context->mailbox->vcount; i++)
   {
-    if (!Context->mailbox->hdrs[Context->v2r[i]]->read &&
-        !Context->mailbox->hdrs[Context->v2r[i]]->deleted)
+    if (!Context->mailbox->hdrs[Context->mailbox->v2r[i]]->read &&
+        !Context->mailbox->hdrs[Context->mailbox->v2r[i]]->deleted)
     {
-      if (!Context->mailbox->hdrs[Context->v2r[i]]->old)
+      if (!Context->mailbox->hdrs[Context->mailbox->v2r[i]]->old)
         return i;
       else if (old == -1)
         old = i;
@@ -298,7 +298,7 @@ static int ci_first_message(void)
   }
   else
   {
-    return Context->vcount ? Context->vcount - 1 : 0;
+    return Context->mailbox->vcount ? Context->mailbox->vcount - 1 : 0;
   }
 
   return 0;
@@ -349,9 +349,9 @@ static void resort_index(struct Menu *menu)
   mutt_sort_headers(Context, false);
   /* Restore the current message */
 
-  for (int i = 0; i < Context->vcount; i++)
+  for (int i = 0; i < Context->mailbox->vcount; i++)
   {
-    if (Context->mailbox->hdrs[Context->v2r[i]] == current)
+    if (Context->mailbox->hdrs[Context->mailbox->v2r[i]] == current)
     {
       menu->current = i;
       break;
@@ -464,18 +464,18 @@ static void update_index_unthreaded(struct Context *ctx, int check, int oldcount
     {
       if (!i)
       {
-        ctx->vcount = 0;
+        ctx->mailbox->vcount = 0;
         ctx->vsize = 0;
       }
 
       if (mutt_pattern_exec(ctx->limit_pattern, MUTT_MATCH_FULL_ADDRESS, ctx,
                             ctx->mailbox->hdrs[i], NULL))
       {
-        assert(ctx->vcount < ctx->mailbox->msg_count);
-        ctx->mailbox->hdrs[i]->virtual = ctx->vcount;
-        ctx->v2r[ctx->vcount] = i;
+        assert(ctx->mailbox->vcount < ctx->mailbox->msg_count);
+        ctx->mailbox->hdrs[i]->virtual = ctx->mailbox->vcount;
+        ctx->mailbox->v2r[ctx->mailbox->vcount] = i;
         ctx->mailbox->hdrs[i]->limited = true;
-        ctx->vcount++;
+        ctx->mailbox->vcount++;
         struct Body *b = ctx->mailbox->hdrs[i]->content;
         ctx->vsize += b->length + b->offset - b->hdr_offset + padding;
       }
@@ -502,7 +502,7 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun
   /* take note of the current message */
   if (oldcount)
   {
-    if (menu->current < ctx->vcount)
+    if (menu->current < ctx->mailbox->vcount)
       menu->oldcurrent = index_hint;
     else
       oldcount = 0; /* invalid message number! */
@@ -517,9 +517,9 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun
   if (oldcount)
   {
     /* restore the current message to the message it was pointing to */
-    for (int i = 0; i < ctx->vcount; i++)
+    for (int i = 0; i < ctx->mailbox->vcount; i++)
     {
-      if (ctx->mailbox->hdrs[ctx->v2r[i]]->index == menu->oldcurrent)
+      if (ctx->mailbox->hdrs[ctx->mailbox->v2r[i]]->index == menu->oldcurrent)
       {
         menu->current = i;
         break;
@@ -652,7 +652,7 @@ void index_make_entry(char *buf, size_t buflen, struct Menu *menu, int num)
   if (!Context || !menu || (num < 0) || (num >= Context->mailbox->hdrmax))
     return;
 
-  struct Header *h = Context->mailbox->hdrs[Context->v2r[num]];
+  struct Header *h = Context->mailbox->hdrs[Context->mailbox->v2r[num]];
   if (!h)
     return;
 
@@ -671,12 +671,12 @@ void index_make_entry(char *buf, size_t buflen, struct Menu *menu, int num)
       if (reverse)
       {
         if (menu->top + menu->pagelen > menu->max)
-          edgemsgno = Context->v2r[menu->max - 1];
+          edgemsgno = Context->mailbox->v2r[menu->max - 1];
         else
-          edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
+          edgemsgno = Context->mailbox->v2r[menu->top + menu->pagelen - 1];
       }
       else
-        edgemsgno = Context->v2r[menu->top];
+        edgemsgno = Context->mailbox->v2r[menu->top];
 
       for (tmp = h->thread->parent; tmp; tmp = tmp->parent)
       {
@@ -727,7 +727,7 @@ int index_color(int index_no)
   if (!Context || (index_no < 0))
     return 0;
 
-  struct Header *h = Context->mailbox->hdrs[Context->v2r[index_no]];
+  struct Header *h = Context->mailbox->hdrs[Context->mailbox->v2r[index_no]];
 
   if (h && h->pair)
     return h->pair;
@@ -920,7 +920,7 @@ static void index_menu_redraw(struct Menu *menu)
   }
 #endif
 
-  if (Context && Context->mailbox->hdrs && !(menu->current >= Context->vcount))
+  if (Context && Context->mailbox->hdrs && !(menu->current >= Context->mailbox->vcount))
   {
     menu_check_recenter(menu);
 
@@ -1023,7 +1023,7 @@ int mutt_index_menu(void)
     if (OptNeedResort && Context && Context->mailbox->msg_count && menu->current >= 0)
       resort_index(menu);
 
-    menu->max = Context ? Context->vcount : 0;
+    menu->max = Context ? Context->mailbox->vcount : 0;
     oldcount = Context ? Context->mailbox->msg_count : 0;
 
     if (OptRedrawTree && Context && Context->mailbox->msg_count && (Sort & SORT_MASK) == SORT_THREADS)
@@ -1044,10 +1044,10 @@ int mutt_index_menu(void)
        * modified underneath us.)
        */
 
-      index_hint =
-          (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ?
-              CURHDR->index :
-              0;
+      index_hint = (Context->mailbox->vcount && menu->current >= 0 &&
+                    menu->current < Context->mailbox->vcount) ?
+                       CURHDR->index :
+                       0;
 
       check = mx_mbox_check(Context, &index_hint);
       if (check < 0)
@@ -1101,7 +1101,7 @@ int mutt_index_menu(void)
         Context->mailbox->quiet = q;
 
         menu->redraw = REDRAW_FULL;
-        menu->max = Context->vcount;
+        menu->max = Context->mailbox->vcount;
 
         OptSearchInvalid = true;
       }
@@ -1605,10 +1605,10 @@ int mutt_index_menu(void)
       case OP_TOGGLE_READ:
 
         CHECK_IN_MAILBOX;
-        menu->oldcurrent =
-            (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ?
-                CURHDR->index :
-                -1;
+        menu->oldcurrent = (Context->mailbox->vcount && menu->current >= 0 &&
+                            menu->current < Context->mailbox->vcount) ?
+                               CURHDR->index :
+                               -1;
         if (op == OP_TOGGLE_READ)
         {
           char buf2[LONG_STRING];
@@ -1639,9 +1639,9 @@ int mutt_index_menu(void)
           {
             /* try to find what used to be the current message */
             menu->current = -1;
-            for (i = 0; i < Context->vcount; i++)
+            for (i = 0; i < Context->mailbox->vcount; i++)
             {
-              if (Context->mailbox->hdrs[Context->v2r[i]]->index == menu->oldcurrent)
+              if (Context->mailbox->hdrs[Context->mailbox->v2r[i]]->index == menu->oldcurrent)
               {
                 menu->current = i;
                 break;
@@ -1751,7 +1751,7 @@ int mutt_index_menu(void)
                                        Context->last_tag);
 
           menu->redraw |= REDRAW_STATUS;
-          if (Resolve && menu->current < Context->vcount - 1)
+          if (Resolve && menu->current < Context->mailbox->vcount - 1)
           {
             menu->current++;
             menu->redraw |= REDRAW_MOTION_RESYNCH;
@@ -1842,13 +1842,13 @@ int mutt_index_menu(void)
         CHECK_MSGCOUNT;
         CHECK_READONLY;
         {
-          int ovc = Context->vcount;
+          int ovc = Context->mailbox->vcount;
           int oc = Context->mailbox->msg_count;
           int check;
           struct Header *newhdr = NULL;
 
           /* don't attempt to move the cursor if there are no visible messages in the current limit */
-          if (menu->current < Context->vcount)
+          if (menu->current < Context->mailbox->vcount)
           {
             /* threads may be reordered, so figure out what header the cursor
              * should be on. #3092 */
@@ -1858,17 +1858,17 @@ int mutt_index_menu(void)
             if (newidx < 0)
               newidx = ci_previous_undeleted(menu->current);
             if (newidx >= 0)
-              newhdr = Context->mailbox->hdrs[Context->v2r[newidx]];
+              newhdr = Context->mailbox->hdrs[Context->mailbox->v2r[newidx]];
           }
 
           check = mx_mbox_sync(Context, &index_hint);
           if (check == 0)
           {
-            if (newhdr && Context->vcount != ovc)
+            if (newhdr && Context->mailbox->vcount != ovc)
             {
-              for (j = 0; j < Context->vcount; j++)
+              for (j = 0; j < Context->mailbox->vcount; j++)
               {
-                if (Context->mailbox->hdrs[Context->v2r[j]] == newhdr)
+                if (Context->mailbox->hdrs[Context->mailbox->v2r[j]] == newhdr)
                 {
                   menu->current = j;
                   break;
@@ -1882,7 +1882,7 @@ int mutt_index_menu(void)
 
           /* do a sanity check even if mx_mbox_sync failed.  */
 
-          if (menu->current < 0 || menu->current >= Context->vcount)
+          if (menu->current < 0 || menu->current >= Context->mailbox->vcount)
             menu->current = ci_first_message();
         }
 
@@ -2284,7 +2284,7 @@ int mutt_index_menu(void)
         {
           mutt_check_traditional_pgp(tag ? NULL : CURHDR, &menu->redraw);
         }
-        int hint = Context->mailbox->hdrs[Context->v2r[menu->current]]->index;
+        int hint = Context->mailbox->hdrs[Context->mailbox->v2r[menu->current]]->index;
 
         /* If we are returning to the pager via an index menu redirection, we
          * need to reset the menu->menu.  Otherwise mutt_menu_pop_current() will
@@ -2428,7 +2428,7 @@ int mutt_index_menu(void)
 
         CHECK_MSGCOUNT;
         CHECK_VISIBLE;
-        if (menu->current >= Context->vcount - 1)
+        if (menu->current >= Context->mailbox->vcount - 1)
         {
           if (menu->menu == MENU_MAIN)
             mutt_error(_("You are on the last message"));
@@ -2454,7 +2454,7 @@ int mutt_index_menu(void)
 
         CHECK_MSGCOUNT;
         CHECK_VISIBLE;
-        if (menu->current >= Context->vcount - 1)
+        if (menu->current >= Context->mailbox->vcount - 1)
         {
           if (menu->menu == MENU_MAIN)
             mutt_error(_("You are on the last message"));
@@ -2568,12 +2568,12 @@ int mutt_index_menu(void)
         const int saved_current = menu->current;
         i = menu->current;
         menu->current = -1;
-        for (j = 0; j != Context->vcount; j++)
+        for (j = 0; j != Context->mailbox->vcount; j++)
         {
           if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_NEXT_NEW_THEN_UNREAD)
           {
             i++;
-            if (i > Context->vcount - 1)
+            if (i > Context->mailbox->vcount - 1)
             {
               i = 0;
             }
@@ -2583,11 +2583,11 @@ int mutt_index_menu(void)
             i--;
             if (i < 0)
             {
-              i = Context->vcount - 1;
+              i = Context->mailbox->vcount - 1;
             }
           }
 
-          struct Header *h = Context->mailbox->hdrs[Context->v2r[i]];
+          struct Header *h = Context->mailbox->hdrs[Context->mailbox->v2r[i]];
           if (h->collapsed && (Sort & SORT_MASK) == SORT_THREADS)
           {
             if (UNREAD(h) && first_unread == -1)
@@ -2910,7 +2910,7 @@ int mutt_index_menu(void)
 
       case OP_CREATE_ALIAS:
 
-        mutt_alias_create(Context && Context->vcount ? CURHDR->env : NULL, NULL);
+        mutt_alias_create(Context && Context->mailbox->vcount ? CURHDR->env : NULL, NULL);
         menu->redraw |= REDRAW_CURRENT;
         break;
 
@@ -3398,7 +3398,7 @@ int mutt_index_menu(void)
         {
           mutt_set_flag(Context, CURHDR, MUTT_DELETE, 0);
           mutt_set_flag(Context, CURHDR, MUTT_PURGE, 0);
-          if (Resolve && menu->current < Context->vcount - 1)
+          if (Resolve && menu->current < Context->mailbox->vcount - 1)
           {
             menu->current++;
             menu->redraw |= REDRAW_MOTION_RESYNCH;
index ec5d5cf14e7bfd26a8704b227d76b546175bfcf0..cc0a43a0943480068275217028ac862ecede2592 100644 (file)
@@ -2220,7 +2220,7 @@ static int imap_mbox_open(struct Context *ctx)
 
   ctx->mailbox->hdrmax = count;
   ctx->mailbox->hdrs = mutt_mem_calloc(count, sizeof(struct Header *));
-  ctx->v2r = mutt_mem_calloc(count, sizeof(int));
+  ctx->mailbox->v2r = mutt_mem_calloc(count, sizeof(int));
   ctx->mailbox->msg_count = 0;
 
   if (count && (imap_read_headers(idata, 1, count, true) < 0))
index f8c10a37a9ad547180629675585afca8fdb1106f..334caaf948414e8abfe33d4df8373c5af9e3329a 100644 (file)
--- a/mailbox.h
+++ b/mailbox.h
@@ -88,6 +88,8 @@ struct Mailbox
 
   struct Header **hdrs;
   int hdrmax;               /**< number of pointers in hdrs */
+  int *v2r;                 /**< mapping from virtual to real msgno */
+  int vcount;               /**< the number of virtual messages */
 
   bool notified;             /**< user has been notified */
   enum MailboxType magic;    /**< mailbox type */
index 4d2226f8bea34a3efe86dd2214e8ccf1a57c3f6e..cf0df20c6b93f2947b84eac90a156eb5d560c6d6 100644 (file)
@@ -800,7 +800,7 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint)
   mutt_hash_destroy(&ctx->mailbox->subj_hash);
   mutt_hash_destroy(&ctx->mailbox->label_hash);
   mutt_clear_threads(ctx);
-  FREE(&ctx->v2r);
+  FREE(&ctx->mailbox->v2r);
   if (ctx->mailbox->readonly)
   {
     for (i = 0; i < ctx->mailbox->msg_count; i++)
@@ -817,7 +817,7 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint)
 
   ctx->mailbox->hdrmax = 0; /* force allocation of new headers */
   ctx->mailbox->msg_count = 0;
-  ctx->vcount = 0;
+  ctx->mailbox->vcount = 0;
   ctx->vsize = 0;
   ctx->tagged = 0;
   ctx->deleted = 0;
diff --git a/menu.c b/menu.c
index 4c41d5ec32ddf118ef496a2644d09f6e326116d7..daedc23beab75279598fb733fc42a0c8cbc522af 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -79,7 +79,7 @@ static int get_color(int index, unsigned char *s)
 {
   struct ColorLineHead *color = NULL;
   struct ColorLine *np = NULL;
-  struct Header *hdr = Context->mailbox->hdrs[Context->v2r[index]];
+  struct Header *hdr = Context->mailbox->hdrs[Context->mailbox->v2r[index]];
   int type = *s;
 
   switch (type)
index 2f3f8f7e856c74c2ec20a7b28fccfe975db0f40e..8def2f0bc82c172f7a48ab1c96fb209252523539 100644 (file)
@@ -1154,7 +1154,7 @@ void mutt_set_virtual(struct Context *ctx)
 {
   struct Header *cur = NULL;
 
-  ctx->vcount = 0;
+  ctx->mailbox->vcount = 0;
   ctx->vsize = 0;
   int padding = mx_msg_padding_size(ctx);
 
@@ -1163,9 +1163,9 @@ void mutt_set_virtual(struct Context *ctx)
     cur = ctx->mailbox->hdrs[i];
     if (cur->virtual >= 0)
     {
-      cur->virtual = ctx->vcount;
-      ctx->v2r[ctx->vcount] = i;
-      ctx->vcount++;
+      cur->virtual = ctx->mailbox->vcount;
+      ctx->mailbox->v2r[ctx->mailbox->vcount] = i;
+      ctx->mailbox->vcount++;
       ctx->vsize += cur->content->length + cur->content->offset -
                     cur->content->hdr_offset + padding;
       cur->num_hidden = mutt_get_hidden(ctx, cur);
diff --git a/mx.c b/mx.c
index 69fa1265e84ccff9f95e54bb8eaacd6ba10bf241..ccc93fac442693f5bbf336b1cc26a891b90aa488 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -363,7 +363,7 @@ void mx_fastclose_mailbox(struct Context *ctx)
   for (int i = 0; i < ctx->mailbox->msg_count; i++)
     mutt_header_free(&ctx->mailbox->hdrs[i]);
   FREE(&ctx->mailbox->hdrs);
-  FREE(&ctx->v2r);
+  FREE(&ctx->mailbox->v2r);
   FREE(&ctx->pattern);
   if (ctx->limit_pattern)
     mutt_pattern_free(&ctx->limit_pattern);
@@ -781,7 +781,7 @@ void mx_update_tables(struct Context *ctx, bool committing)
   int i, j, padding;
 
   /* update memory to reflect the new state of the mailbox */
-  ctx->vcount = 0;
+  ctx->mailbox->vcount = 0;
   ctx->vsize = 0;
   ctx->tagged = 0;
   ctx->deleted = 0;
@@ -805,8 +805,8 @@ void mx_update_tables(struct Context *ctx, bool committing)
       ctx->mailbox->hdrs[j]->msgno = j;
       if (ctx->mailbox->hdrs[j]->virtual != -1)
       {
-        ctx->v2r[ctx->vcount] = j;
-        ctx->mailbox->hdrs[j]->virtual = ctx->vcount++;
+        ctx->mailbox->v2r[ctx->mailbox->vcount] = j;
+        ctx->mailbox->hdrs[j]->virtual = ctx->mailbox->vcount++;
         struct Body *b = ctx->mailbox->hdrs[j]->content;
         ctx->vsize += b->length + b->offset - b->hdr_offset + padding;
       }
@@ -1166,18 +1166,18 @@ void mx_alloc_memory(struct Context *ctx)
   {
     mutt_mem_realloc(&ctx->mailbox->hdrs,
                      sizeof(struct Header *) * (ctx->mailbox->hdrmax += 25));
-    mutt_mem_realloc(&ctx->v2r, sizeof(int) * ctx->mailbox->hdrmax);
+    mutt_mem_realloc(&ctx->mailbox->v2r, sizeof(int) * ctx->mailbox->hdrmax);
   }
   else
   {
     ctx->mailbox->hdrs =
         mutt_mem_calloc((ctx->mailbox->hdrmax += 25), sizeof(struct Header *));
-    ctx->v2r = mutt_mem_calloc(ctx->mailbox->hdrmax, sizeof(int));
+    ctx->mailbox->v2r = mutt_mem_calloc(ctx->mailbox->hdrmax, sizeof(int));
   }
   for (int i = ctx->mailbox->msg_count; i < ctx->mailbox->hdrmax; i++)
   {
     ctx->mailbox->hdrs[i] = NULL;
-    ctx->v2r[i] = -1;
+    ctx->mailbox->v2r[i] = -1;
   }
 }
 
@@ -1205,8 +1205,8 @@ void mx_update_context(struct Context *ctx, int new_messages)
 
     if (!ctx->pattern)
     {
-      ctx->v2r[ctx->vcount] = msgno;
-      h->virtual = ctx->vcount++;
+      ctx->mailbox->v2r[ctx->mailbox->vcount] = msgno;
+      h->virtual = ctx->mailbox->vcount++;
     }
     else
       h->virtual = -1;
index 6e8a28cfbffa6d69442216ce415b590125e64afb..1d6898785b7443d9d664a60333e239877166b2a9 100644 (file)
@@ -2080,7 +2080,7 @@ static int check_mailbox(struct Context *ctx)
       mutt_hash_destroy(&ctx->mailbox->id_hash);
     mutt_clear_threads(ctx);
 
-    ctx->vcount = 0;
+    ctx->mailbox->vcount = 0;
     ctx->deleted = 0;
     ctx->new = 0;
     ctx->mailbox->msg_unread = 0;
diff --git a/pager.c b/pager.c
index 4df8f4e0600e2d2fb27ebdd5ee572fdb7afeb451..3cfaea161fb4d91d7755cbf9ce3980bd35e0d1ca 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1904,8 +1904,8 @@ static void pager_menu_redraw(struct Menu *pager_menu)
     move(0, 0);
     clrtobot();
 
-    if (IsHeader(rd->extra) && Context && ((Context->vcount + 1) < PagerIndexLines))
-      rd->indexlen = Context->vcount + 1;
+    if (IsHeader(rd->extra) && Context && ((Context->mailbox->vcount + 1) < PagerIndexLines))
+      rd->indexlen = Context->mailbox->vcount + 1;
     else
       rd->indexlen = PagerIndexLines;
 
@@ -1989,7 +1989,7 @@ static void pager_menu_redraw(struct Menu *pager_menu)
         rd->index = mutt_menu_new(MENU_MAIN);
         rd->index->make_entry = index_make_entry;
         rd->index->color = index_color;
-        rd->index->max = Context ? Context->vcount : 0;
+        rd->index->max = Context ? Context->mailbox->vcount : 0;
         rd->index->current = rd->extra->hdr->virtual;
         rd->index->indexwin = rd->index_window;
         rd->index->statuswin = rd->index_status_window;
@@ -2376,22 +2376,25 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e
              * rd.index->current might be invalid */
             rd.index->current =
                 MIN(rd.index->current, (Context->mailbox->msg_count - 1));
-            index_hint = Context->mailbox->hdrs[Context->v2r[rd.index->current]]->index;
+            index_hint =
+                Context->mailbox->hdrs[Context->mailbox->v2r[rd.index->current]]->index;
 
             bool q = Context->mailbox->quiet;
             Context->mailbox->quiet = true;
             update_index(rd.index, Context, check, oldcount, index_hint);
             Context->mailbox->quiet = q;
 
-            rd.index->max = Context->vcount;
+            rd.index->max = Context->mailbox->vcount;
 
             /* If these header pointers don't match, then our email may have
              * been deleted.  Make the pointer safe, then leave the pager.
              * This have a unpleasant behaviour to close the pager even the
              * deleted message is not the opened one, but at least it's safe. */
-            if (extra->hdr != Context->mailbox->hdrs[Context->v2r[rd.index->current]])
+            if (extra->hdr !=
+                Context->mailbox->hdrs[Context->mailbox->v2r[rd.index->current]])
             {
-              extra->hdr = Context->mailbox->hdrs[Context->v2r[rd.index->current]];
+              extra->hdr =
+                  Context->mailbox->hdrs[Context->mailbox->v2r[rd.index->current]];
               break;
             }
           }
index fe4576be5d05b23d7945a4583237238d0bf88cd7..28992d7798ca7506ede309261a5613189071c655 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -85,7 +85,7 @@ bool ThoroughSearch; ///< Config: Decode headers and messages before searching t
 #define KILO 1024
 #define MEGA 1048576
 #define HMSG(h) (((h)->msgno) + 1)
-#define CTX_MSGNO(c) (HMSG((c)->mailbox->hdrs[(c)->v2r[(c)->menu->current]]))
+#define CTX_MSGNO(c) (HMSG((c)->mailbox->hdrs[(c)->mailbox->v2r[(c)->menu->current]]))
 
 #define MUTT_MAXRANGE -1
 
@@ -2181,7 +2181,7 @@ bool mutt_limit_current_thread(struct Header *h)
   if (!me)
     return false;
 
-  Context->vcount = 0;
+  Context->mailbox->vcount = 0;
   Context->vsize = 0;
   Context->collapsed = false;
 
@@ -2196,10 +2196,10 @@ bool mutt_limit_current_thread(struct Header *h)
     {
       struct Body *body = Context->mailbox->hdrs[i]->content;
 
-      Context->mailbox->hdrs[i]->virtual = Context->vcount;
+      Context->mailbox->hdrs[i]->virtual = Context->mailbox->vcount;
       Context->mailbox->hdrs[i]->limited = true;
-      Context->v2r[Context->vcount] = i;
-      Context->vcount++;
+      Context->mailbox->v2r[Context->mailbox->vcount] = i;
+      Context->mailbox->vcount++;
       Context->vsize += (body->length + body->offset - body->hdr_offset);
     }
   }
@@ -2248,11 +2248,12 @@ int mutt_pattern_func(int op, char *prompt)
 
   mutt_progress_init(&progress, _("Executing command on matching messages..."),
                      MUTT_PROGRESS_MSG, ReadInc,
-                     (op == MUTT_LIMIT) ? Context->mailbox->msg_count : Context->vcount);
+                     (op == MUTT_LIMIT) ? Context->mailbox->msg_count :
+                                          Context->mailbox->vcount);
 
   if (op == MUTT_LIMIT)
   {
-    Context->vcount = 0;
+    Context->mailbox->vcount = 0;
     Context->vsize = 0;
     Context->collapsed = false;
     padding = mx_msg_padding_size(Context);
@@ -2268,10 +2269,10 @@ int mutt_pattern_func(int op, char *prompt)
       if (mutt_pattern_exec(pat, MUTT_MATCH_FULL_ADDRESS, Context,
                             Context->mailbox->hdrs[i], NULL))
       {
-        Context->mailbox->hdrs[i]->virtual = Context->vcount;
+        Context->mailbox->hdrs[i]->virtual = Context->mailbox->vcount;
         Context->mailbox->hdrs[i]->limited = true;
-        Context->v2r[Context->vcount] = i;
-        Context->vcount++;
+        Context->mailbox->v2r[Context->mailbox->vcount] = i;
+        Context->mailbox->vcount++;
         struct Body *b = Context->mailbox->hdrs[i]->content;
         Context->vsize += b->length + b->offset - b->hdr_offset + padding;
       }
@@ -2279,24 +2280,25 @@ int mutt_pattern_func(int op, char *prompt)
   }
   else
   {
-    for (int i = 0; i < Context->vcount; i++)
+    for (int i = 0; i < Context->mailbox->vcount; i++)
     {
       mutt_progress_update(&progress, i, -1);
       if (mutt_pattern_exec(pat, MUTT_MATCH_FULL_ADDRESS, Context,
-                            Context->mailbox->hdrs[Context->v2r[i]], NULL))
+                            Context->mailbox->hdrs[Context->mailbox->v2r[i]], NULL))
       {
         switch (op)
         {
           case MUTT_UNDELETE:
-            mutt_set_flag(Context, Context->mailbox->hdrs[Context->v2r[i]], MUTT_PURGE, 0);
+            mutt_set_flag(Context, Context->mailbox->hdrs[Context->mailbox->v2r[i]],
+                          MUTT_PURGE, 0);
           /* fallthrough */
           case MUTT_DELETE:
-            mutt_set_flag(Context, Context->mailbox->hdrs[Context->v2r[i]],
+            mutt_set_flag(Context, Context->mailbox->hdrs[Context->mailbox->v2r[i]],
                           MUTT_DELETE, (op == MUTT_DELETE));
             break;
           case MUTT_TAG:
           case MUTT_UNTAG:
-            mutt_set_flag(Context, Context->mailbox->hdrs[Context->v2r[i]],
+            mutt_set_flag(Context, Context->mailbox->hdrs[Context->mailbox->v2r[i]],
                           MUTT_TAG, (op == MUTT_TAG));
             break;
         }
@@ -2313,7 +2315,7 @@ int mutt_pattern_func(int op, char *prompt)
     if (Context->limit_pattern)
       mutt_pattern_free(&Context->limit_pattern);
 
-    if (Context->mailbox->msg_count && !Context->vcount)
+    if (Context->mailbox->msg_count && !Context->mailbox->vcount)
       mutt_error(_("No messages matched criteria"));
 
     /* record new limit pattern, unless match all */
@@ -2413,13 +2415,13 @@ int mutt_search_command(int cur, int op)
     incr = -incr;
 
   mutt_progress_init(&progress, _("Searching..."), MUTT_PROGRESS_MSG, ReadInc,
-                     Context->vcount);
+                     Context->mailbox->vcount);
 
-  for (int i = cur + incr, j = 0; j != Context->vcount; j++)
+  for (int i = cur + incr, j = 0; j != Context->mailbox->vcount; j++)
   {
     const char *msg = NULL;
     mutt_progress_update(&progress, j, -1);
-    if (i > Context->vcount - 1)
+    if (i > Context->mailbox->vcount - 1)
     {
       i = 0;
       if (WrapSearch)
@@ -2432,7 +2434,7 @@ int mutt_search_command(int cur, int op)
     }
     else if (i < 0)
     {
-      i = Context->vcount - 1;
+      i = Context->mailbox->vcount - 1;
       if (WrapSearch)
         msg = _("Search wrapped to bottom");
       else
@@ -2442,7 +2444,7 @@ int mutt_search_command(int cur, int op)
       }
     }
 
-    struct Header *h = Context->mailbox->hdrs[Context->v2r[i]];
+    struct Header *h = Context->mailbox->hdrs[Context->mailbox->v2r[i]];
     if (h->searched)
     {
       /* if we've already evaluated this message, use the cached value */
index 3d09d38dabbfa88cfbc2bec9e0991de195a98bcd..bea3afdca91d241d352c860018ab38198e5ece1d 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -173,9 +173,9 @@ static const char *sidebar_format_str(char *buf, size_t buflen, size_t col, int
       if (!optional)
       {
         snprintf(fmt, sizeof(fmt), "%%%sd", prec);
-        snprintf(buf, buflen, fmt, c ? Context->vcount : m->msg_count);
+        snprintf(buf, buflen, fmt, c ? Context->mailbox->vcount : m->msg_count);
       }
-      else if ((c && Context->vcount == m->msg_count) || !c)
+      else if ((c && Context->mailbox->vcount == m->msg_count) || !c)
         optional = 0;
       break;
 
diff --git a/sort.c b/sort.c
index fb8d9eff6895ba11a289aac86123ac1a7573c3b3..32220423353ede88d667f14f3a3e95d14ff51f9a 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -366,7 +366,7 @@ void mutt_sort_headers(struct Context *ctx, bool init)
      * deleted all the messages.  the virtual message numbers are not updated
      * in that routine, so we must make sure to zero the vcount member.
      */
-    ctx->vcount = 0;
+    ctx->mailbox->vcount = 0;
     ctx->vsize = 0;
     mutt_clear_threads(ctx);
     return; /* nothing to do! */
@@ -417,15 +417,15 @@ void mutt_sort_headers(struct Context *ctx, bool init)
           sizeof(struct Header *), sortfunc);
 
   /* adjust the virtual message numbers */
-  ctx->vcount = 0;
+  ctx->mailbox->vcount = 0;
   for (int i = 0; i < ctx->mailbox->msg_count; i++)
   {
     struct Header *cur = ctx->mailbox->hdrs[i];
     if (cur->virtual != -1 || (cur->collapsed && (!ctx->pattern || cur->limited)))
     {
-      cur->virtual = ctx->vcount;
-      ctx->v2r[ctx->vcount] = i;
-      ctx->vcount++;
+      cur->virtual = ctx->mailbox->vcount;
+      ctx->mailbox->v2r[ctx->mailbox->vcount] = i;
+      ctx->mailbox->vcount++;
     }
     cur->msgno = i;
   }
index 2d293234f9d063be0cce6c7859b6016e34a51fd9..6b057f919a0ecba9c8b776b8ab9779d79cbc319d 100644 (file)
--- a/status.c
+++ b/status.c
@@ -201,7 +201,7 @@ static const char *status_format_str(char *buf, size_t buflen, size_t col, int c
       if (!optional)
       {
         snprintf(fmt, sizeof(fmt), "%%%sd", prec);
-        snprintf(buf, buflen, fmt, Context ? Context->vcount : 0);
+        snprintf(buf, buflen, fmt, Context ? Context->mailbox->vcount : 0);
       }
       else if (!Context || !Context->pattern)
         optional = 0;