From: Richard Russon Date: Wed, 5 Sep 2018 15:55:32 +0000 (+0100) Subject: move Context.{hdrs,hdrmax} X-Git-Tag: 2019-10-25~657^2~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8afc1e79097dad1da51adda6f27dc031f1106dee;p=neomutt move Context.{hdrs,hdrmax} --- diff --git a/color.c b/color.c index ed141a1bf..14004a3d9 100644 --- a/color.c +++ b/color.c @@ -657,7 +657,7 @@ static int parse_uncolor(struct Buffer *buf, struct Buffer *s, unsigned long dat mutt_menu_set_redraw_full(MENU_MAIN); /* force re-caching of index colors */ for (int i = 0; Context && i < Context->mailbox->msg_count; i++) - Context->hdrs[i]->pair = 0; + Context->mailbox->hdrs[i]->pair = 0; } return 0; } @@ -800,7 +800,7 @@ static int add_pattern(struct ColorLineHead *top, const char *s, bool sensitive, if (is_index) { for (int i = 0; Context && i < Context->mailbox->msg_count; i++) - Context->hdrs[i]->pair = 0; + Context->mailbox->hdrs[i]->pair = 0; } return 0; diff --git a/commands.c b/commands.c index 8c07f25ca..6c3db34fd 100644 --- a/commands.c +++ b/commands.c @@ -304,10 +304,10 @@ void ci_bounce_message(struct Header *h) msgcount = 0; // count the precise number of messages. for (rc = 0; rc < Context->mailbox->msg_count; rc++) { - if (message_is_tagged(Context, rc) && !Context->hdrs[rc]->env->from) + if (message_is_tagged(Context, rc) && !Context->mailbox->hdrs[rc]->env->from) { msgcount++; - if (!Context->hdrs[rc]->env->from) + if (!Context->mailbox->hdrs[rc]->env->from) { mutt_error(_("Warning: message contains no From: header")); break; @@ -484,10 +484,10 @@ static int pipe_message(struct Header *h, char *cmd, bool decode, bool print, if (!message_is_tagged(Context, i)) continue; - mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGE_HOOK); - mutt_parse_mime_message(Context, Context->hdrs[i]); - if (Context->hdrs[i]->security & ENCRYPT && - !crypt_valid_passphrase(Context->hdrs[i]->security)) + mutt_message_hook(Context, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); + mutt_parse_mime_message(Context, Context->mailbox->hdrs[i]); + if (Context->mailbox->hdrs[i]->security & ENCRYPT && + !crypt_valid_passphrase(Context->mailbox->hdrs[i]->security)) { return 1; } @@ -501,7 +501,7 @@ static int pipe_message(struct Header *h, char *cmd, bool decode, bool print, if (!message_is_tagged(Context, i)) continue; - mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGE_HOOK); + mutt_message_hook(Context, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); mutt_endwin(); thepid = mutt_create_filter(cmd, &fpout, NULL, NULL); if (thepid < 0) @@ -510,7 +510,7 @@ static int pipe_message(struct Header *h, char *cmd, bool decode, bool print, return 1; } OptKeepQuiet = true; - pipe_msg(Context->hdrs[i], fpout, decode, print); + pipe_msg(Context->mailbox->hdrs[i], fpout, decode, print); /* add the message separator */ if (sep) fputs(sep, fpout); @@ -535,8 +535,8 @@ static int pipe_message(struct Header *h, char *cmd, bool decode, bool print, if (!message_is_tagged(Context, i)) continue; - mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGE_HOOK); - pipe_msg(Context->hdrs[i], fpout, decode, print); + mutt_message_hook(Context, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); + pipe_msg(Context->mailbox->hdrs[i], fpout, decode, print); /* add the message separator */ if (sep) fputs(sep, fpout); @@ -915,7 +915,7 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt) { if (message_is_tagged(Context, i)) { - h = Context->hdrs[i]; + h = Context->mailbox->hdrs[i]; break; } } @@ -1033,14 +1033,14 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt) if (!message_is_tagged(Context, i)) continue; - mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGE_HOOK); - rc = mutt_save_message_ctx(Context->hdrs[i], delete, decode, decrypt, savectx); + mutt_message_hook(Context, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); + rc = mutt_save_message_ctx(Context->mailbox->hdrs[i], delete, decode, decrypt, savectx); if (rc != 0) break; #ifdef USE_COMPRESSED if (cm) { - struct Header *h2 = Context->hdrs[i]; + struct Header *h2 = Context->mailbox->hdrs[i]; cm->msg_count++; if (!h2->read) cm->msg_unread++; @@ -1226,9 +1226,10 @@ bool mutt_check_traditional_pgp(struct Header *h, int *redraw) { for (int i = 0; i < Context->mailbox->msg_count; i++) { - if (message_is_tagged(Context, i) && !(Context->hdrs[i]->security & PGP_TRADITIONAL_CHECKED)) + if (message_is_tagged(Context, i) && + !(Context->mailbox->hdrs[i]->security & PGP_TRADITIONAL_CHECKED)) { - rc = check_traditional_pgp(Context->hdrs[i], redraw) || rc; + rc = check_traditional_pgp(Context->mailbox->hdrs[i], redraw) || rc; } } } diff --git a/compose.c b/compose.c index c991c8c03..3029106f8 100644 --- a/compose.c +++ b/compose.c @@ -1494,7 +1494,8 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen, continue; new = mutt_mem_calloc(1, sizeof(struct AttachPtr)); - new->content = mutt_make_message_attach(Context, Context->hdrs[i], true); + new->content = + mutt_make_message_attach(Context, Context->mailbox->hdrs[i], true); if (new->content) update_idx(menu, actx, new); else diff --git a/context.h b/context.h index 8a3299ed3..842f659ba 100644 --- a/context.h +++ b/context.h @@ -65,7 +65,6 @@ struct Context off_t vsize; char *pattern; /**< limit pattern string */ struct Pattern *limit_pattern; /**< compiled limit pattern */ - struct Header **hdrs; struct Header *last_tag; /**< last tagged msg. used to link threads */ struct MuttThread *tree; /**< top of thread tree */ struct Hash *id_hash; /**< hash table by msg id */ @@ -73,7 +72,6 @@ struct Context struct Hash *thread_hash; /**< hash table for threading */ struct Hash *label_hash; /**< hash table for x-labels */ int *v2r; /**< mapping from virtual to real msgno */ - int hdrmax; /**< number of pointers in hdrs */ int vcount; /**< the number of virtual messages */ int tagged; /**< how many messages are tagged? */ int new; /**< how many new messages? */ diff --git a/curs_lib.c b/curs_lib.c index 3fe2ae0f9..631209c93 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -1220,10 +1220,10 @@ int mutt_strwidth(const char *s) */ bool message_is_visible(struct Context *ctx, int index) { - if (!ctx || !ctx->hdrs || (index >= ctx->mailbox->msg_count)) + if (!ctx || !ctx->mailbox->hdrs || (index >= ctx->mailbox->msg_count)) return false; - return !ctx->pattern || ctx->hdrs[index]->limited; + return !ctx->pattern || ctx->mailbox->hdrs[index]->limited; } /** @@ -1236,5 +1236,5 @@ bool message_is_visible(struct Context *ctx, int index) */ bool message_is_tagged(struct Context *ctx, int index) { - return message_is_visible(ctx, index) && ctx->hdrs[index]->tagged; + return message_is_visible(ctx, index) && ctx->mailbox->hdrs[index]->tagged; } diff --git a/curs_main.c b/curs_main.c index d76df9069..56a7459f4 100644 --- a/curs_main.c +++ b/curs_main.c @@ -161,7 +161,7 @@ static const char *NoVisible = N_("No visible messages"); break; \ } -#define CURHDR Context->hdrs[Context->v2r[menu->current]] +#define CURHDR Context->mailbox->hdrs[Context->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->hdrs[Context->v2r[final]]; + base = Context->mailbox->hdrs[Context->v2r[final]]; /* Iterate all threads, perform collapse/uncollapse as needed */ top = Context->tree; @@ -222,7 +222,7 @@ static void collapse_all(struct Menu *menu, int toggle) mutt_set_virtual(Context); for (int j = 0; j < Context->vcount; j++) { - if (Context->hdrs[Context->v2r[j]]->index == base->index) + if (Context->mailbox->hdrs[Context->v2r[j]]->index == base->index) { menu->current = j; break; @@ -241,7 +241,7 @@ 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->hdrs[Context->v2r[i]]->deleted) + if (!Context->mailbox->hdrs[Context->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->hdrs[Context->v2r[i]]->deleted) + if (!Context->mailbox->hdrs[Context->v2r[i]]->deleted) return i; return -1; } @@ -275,9 +275,10 @@ static int ci_first_message(void) int old = -1; for (int i = 0; i < Context->vcount; i++) { - if (!Context->hdrs[Context->v2r[i]]->read && !Context->hdrs[Context->v2r[i]]->deleted) + if (!Context->mailbox->hdrs[Context->v2r[i]]->read && + !Context->mailbox->hdrs[Context->v2r[i]]->deleted) { - if (!Context->hdrs[Context->v2r[i]]->old) + if (!Context->mailbox->hdrs[Context->v2r[i]]->old) return i; else if (old == -1) old = i; @@ -350,7 +351,7 @@ static void resort_index(struct Menu *menu) for (int i = 0; i < Context->vcount; i++) { - if (Context->hdrs[Context->v2r[i]] == current) + if (Context->mailbox->hdrs[Context->v2r[i]] == current) { menu->current = i; break; @@ -381,7 +382,7 @@ static void update_index_threaded(struct Context *ctx, int check, int oldcount) { save_new = mutt_mem_malloc(sizeof(struct Header *) * (ctx->mailbox->msg_count - oldcount)); for (int i = oldcount; i < ctx->mailbox->msg_count; i++) - save_new[i - oldcount] = ctx->hdrs[i]; + save_new[i - oldcount] = ctx->mailbox->hdrs[i]; } /* Sort first to thread the new messages, because some patterns @@ -399,7 +400,7 @@ static void update_index_threaded(struct Context *ctx, int check, int oldcount) if ((check != MUTT_REOPENED) && oldcount) h = save_new[i - oldcount]; else - h = ctx->hdrs[i]; + h = ctx->mailbox->hdrs[i]; if (mutt_pattern_exec(ctx->limit_pattern, MUTT_MATCH_FULL_ADDRESS, ctx, h, NULL)) { @@ -468,14 +469,14 @@ static void update_index_unthreaded(struct Context *ctx, int check, int oldcount } if (mutt_pattern_exec(ctx->limit_pattern, MUTT_MATCH_FULL_ADDRESS, ctx, - ctx->hdrs[i], NULL)) + ctx->mailbox->hdrs[i], NULL)) { assert(ctx->vcount < ctx->mailbox->msg_count); - ctx->hdrs[i]->virtual = ctx->vcount; + ctx->mailbox->hdrs[i]->virtual = ctx->vcount; ctx->v2r[ctx->vcount] = i; - ctx->hdrs[i]->limited = true; + ctx->mailbox->hdrs[i]->limited = true; ctx->vcount++; - struct Body *b = ctx->hdrs[i]->content; + struct Body *b = ctx->mailbox->hdrs[i]->content; ctx->vsize += b->length + b->offset - b->hdr_offset + padding; } } @@ -518,7 +519,7 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun /* restore the current message to the message it was pointing to */ for (int i = 0; i < ctx->vcount; i++) { - if (ctx->hdrs[ctx->v2r[i]]->index == menu->oldcurrent) + if (ctx->mailbox->hdrs[ctx->v2r[i]]->index == menu->oldcurrent) { menu->current = i; break; @@ -648,10 +649,10 @@ static int main_change_folder(struct Menu *menu, int op, char *buf, */ void index_make_entry(char *buf, size_t buflen, struct Menu *menu, int num) { - if (!Context || !menu || (num < 0) || (num >= Context->hdrmax)) + if (!Context || !menu || (num < 0) || (num >= Context->mailbox->hdrmax)) return; - struct Header *h = Context->hdrs[Context->v2r[num]]; + struct Header *h = Context->mailbox->hdrs[Context->v2r[num]]; if (!h) return; @@ -726,7 +727,7 @@ int index_color(int index_no) if (!Context || (index_no < 0)) return 0; - struct Header *h = Context->hdrs[Context->v2r[index_no]]; + struct Header *h = Context->mailbox->hdrs[Context->v2r[index_no]]; if (h && h->pair) return h->pair; @@ -919,7 +920,7 @@ static void index_menu_redraw(struct Menu *menu) } #endif - if (Context && Context->hdrs && !(menu->current >= Context->vcount)) + if (Context && Context->mailbox->hdrs && !(menu->current >= Context->vcount)) { menu_check_recenter(menu); @@ -1072,7 +1073,7 @@ int mutt_index_menu(void) { for (i = oldcount; i < Context->mailbox->msg_count; i++) { - if (!Context->hdrs[i]->read) + if (!Context->mailbox->hdrs[i]->read) { mutt_message(_("New mail in this mailbox")); if (BeepNew) @@ -1358,7 +1359,7 @@ int mutt_index_menu(void) rc2 = nntp_check_msgid(Context, buf); if (rc2 == 0) { - hdr = Context->hdrs[Context->mailbox->msg_count - 1]; + hdr = Context->mailbox->hdrs[Context->mailbox->msg_count - 1]; mutt_sort_headers(Context, false); menu->current = hdr->virtual; menu->redraw = REDRAW_FULL; @@ -1447,9 +1448,9 @@ int mutt_index_menu(void) { for (int k = 0; k < Context->mailbox->msg_count; k++) { - if (Context->hdrs[k]->index == oldindex) + if (Context->mailbox->hdrs[k]->index == oldindex) { - menu->current = Context->hdrs[k]->virtual; + menu->current = Context->mailbox->hdrs[k]->virtual; /* as an added courtesy, recenter the menu * with the current entry at the middle of the screen */ menu_check_recenter(menu); @@ -1494,7 +1495,7 @@ int mutt_index_menu(void) mutt_error(_("That message is not visible")); else { - struct Header *hdr = Context->hdrs[i - 1]; + struct Header *hdr = Context->mailbox->hdrs[i - 1]; if (mutt_messages_in_thread(Context, hdr, 1) != 1) { @@ -1623,7 +1624,7 @@ int mutt_index_menu(void) menu->current = -1; for (i = 0; i < Context->vcount; i++) { - if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) + if (Context->mailbox->hdrs[Context->v2r[i]]->index == menu->oldcurrent) { menu->current = i; break; @@ -1719,7 +1720,7 @@ int mutt_index_menu(void) { for (j = 0; j < Context->mailbox->msg_count; j++) if (message_is_visible(Context, j)) - mutt_set_flag(Context, Context->hdrs[j], MUTT_TAG, 0); + mutt_set_flag(Context, Context->mailbox->hdrs[j], MUTT_TAG, 0); menu->redraw |= REDRAW_STATUS | REDRAW_INDEX; } else @@ -1840,7 +1841,7 @@ int mutt_index_menu(void) if (newidx < 0) newidx = ci_previous_undeleted(menu->current); if (newidx >= 0) - newhdr = Context->hdrs[Context->v2r[newidx]]; + newhdr = Context->mailbox->hdrs[Context->v2r[newidx]]; } check = mx_mbox_sync(Context, &index_hint); @@ -1850,7 +1851,7 @@ int mutt_index_menu(void) { for (j = 0; j < Context->vcount; j++) { - if (Context->hdrs[Context->v2r[j]] == newhdr) + if (Context->mailbox->hdrs[Context->v2r[j]] == newhdr) { menu->current = j; break; @@ -1891,7 +1892,7 @@ int mutt_index_menu(void) { if (message_is_tagged(Context, j)) { - Context->hdrs[j]->quasi_deleted = true; + Context->mailbox->hdrs[j]->quasi_deleted = true; Context->changed = true; } } @@ -1990,15 +1991,16 @@ int mutt_index_menu(void) if (!Context->quiet) mutt_progress_update(&progress, ++px, -1); - mx_tags_commit(Context, Context->hdrs[j], buf); + mx_tags_commit(Context, Context->mailbox->hdrs[j], buf); if (op == OP_MAIN_MODIFY_TAGS_THEN_HIDE) { bool still_queried = false; #ifdef USE_NOTMUCH if (Context->mailbox->magic == MUTT_NOTMUCH) - still_queried = nm_message_is_still_queried(Context, Context->hdrs[j]); + still_queried = + nm_message_is_still_queried(Context, Context->mailbox->hdrs[j]); #endif - Context->hdrs[j]->quasi_deleted = !still_queried; + Context->mailbox->hdrs[j]->quasi_deleted = !still_queried; Context->changed = true; } } @@ -2265,7 +2267,7 @@ int mutt_index_menu(void) { mutt_check_traditional_pgp(tag ? NULL : CURHDR, &menu->redraw); } - int hint = Context->hdrs[Context->v2r[menu->current]]->index; + int hint = Context->mailbox->hdrs[Context->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 @@ -2568,7 +2570,7 @@ int mutt_index_menu(void) } } - struct Header *h = Context->hdrs[Context->v2r[i]]; + struct Header *h = Context->mailbox->hdrs[Context->v2r[i]]; if (h->collapsed && (Sort & SORT_MASK) == SORT_THREADS) { if (UNREAD(h) && first_unread == -1) @@ -2661,8 +2663,8 @@ int mutt_index_menu(void) { if (message_is_tagged(Context, j)) { - mutt_set_flag(Context, Context->hdrs[j], MUTT_FLAG, - !Context->hdrs[j]->flagged); + mutt_set_flag(Context, Context->mailbox->hdrs[j], MUTT_FLAG, + !Context->mailbox->hdrs[j]->flagged); } } @@ -2703,10 +2705,10 @@ int mutt_index_menu(void) if (!message_is_tagged(Context, j)) continue; - if (Context->hdrs[j]->read || Context->hdrs[j]->old) - mutt_set_flag(Context, Context->hdrs[j], MUTT_NEW, 1); + if (Context->mailbox->hdrs[j]->read || Context->mailbox->hdrs[j]->old) + mutt_set_flag(Context, Context->mailbox->hdrs[j], MUTT_NEW, 1); else - mutt_set_flag(Context, Context->hdrs[j], MUTT_READ, 1); + mutt_set_flag(Context, Context->mailbox->hdrs[j], MUTT_READ, 1); } menu->redraw |= REDRAW_STATUS | REDRAW_INDEX; } @@ -3277,7 +3279,7 @@ int mutt_index_menu(void) for (j = 0; j < Context->mailbox->msg_count; j++) { if (message_is_tagged(Context, j)) - mutt_resend_message(NULL, Context, Context->hdrs[j]); + mutt_resend_message(NULL, Context, Context->mailbox->hdrs[j]); } } else @@ -3533,7 +3535,7 @@ bool mutt_reply_listener(const struct ConfigSet *cs, struct HashElem *he, for (int i = 0; i < Context->mailbox->msg_count; i++) { - struct Envelope *e = Context->hdrs[i]->env; + struct Envelope *e = Context->mailbox->hdrs[i]->env; if (!e || !e->subject) continue; diff --git a/edit.c b/edit.c index edc2006fd..aaa5b1880 100644 --- a/edit.c +++ b/edit.c @@ -219,7 +219,8 @@ static char **be_include_messages(char *msg, char **buf, int *bufmax, if (Attribution) { setlocale(LC_TIME, NONULL(AttributionLocale)); - mutt_make_string(tmp, sizeof(tmp) - 1, Attribution, Context, Context->hdrs[n]); + mutt_make_string(tmp, sizeof(tmp) - 1, Attribution, Context, + Context->mailbox->hdrs[n]); setlocale(LC_TIME, ""); strcat(tmp, "\n"); } @@ -228,14 +229,14 @@ static char **be_include_messages(char *msg, char **buf, int *bufmax, mutt_mem_realloc(&buf, sizeof(char *) * (*bufmax += 25)); buf[(*buflen)++] = mutt_str_strdup(tmp); - bytes = Context->hdrs[n]->content->length; + bytes = Context->mailbox->hdrs[n]->content->length; if (inc_hdrs) { - offset = Context->hdrs[n]->offset; - bytes += Context->hdrs[n]->content->offset - offset; + offset = Context->mailbox->hdrs[n]->offset; + bytes += Context->mailbox->hdrs[n]->content->offset - offset; } else - offset = Context->hdrs[n]->content->offset; + offset = Context->mailbox->hdrs[n]->content->offset; buf = be_snarf_data(Context->fp, buf, bufmax, buflen, offset, bytes, pfx); if (*bufmax == *buflen) diff --git a/editmsg.c b/editmsg.c index e9e0fdf87..eb40bae1c 100644 --- a/editmsg.c +++ b/editmsg.c @@ -280,7 +280,7 @@ int edit_or_view_message(bool edit, struct Context *ctx, struct Header *hdr) if (!message_is_tagged(ctx, i)) continue; - if (edit_or_view_one_message(edit, ctx, ctx->hdrs[i]) == -1) + if (edit_or_view_one_message(edit, ctx, ctx->mailbox->hdrs[i]) == -1) return -1; } diff --git a/flags.c b/flags.c index 49384be37..16173a3ec 100644 --- a/flags.c +++ b/flags.c @@ -356,7 +356,7 @@ void mutt_tag_set_flag(int flag, int bf) { for (int i = 0; i < Context->mailbox->msg_count; i++) if (message_is_tagged(Context, i)) - mutt_set_flag(Context, Context->hdrs[i], flag, bf); + mutt_set_flag(Context, Context->mailbox->hdrs[i], flag, bf); } /** diff --git a/imap/imap.c b/imap/imap.c index 13a2fb2ed..106a7037b 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -184,7 +184,7 @@ static int make_msg_set(struct ImapData *idata, struct Buffer *buf, int flag, unsigned int setstart = 0; /* start of current message range */ int n; bool started = false; - struct Header **hdrs = idata->ctx->hdrs; + struct Header **hdrs = idata->ctx->mailbox->hdrs; for (n = *pos; n < idata->ctx->mailbox->msg_count && buf->dptr - buf->data < IMAP_MAX_CMDLEN; n++) @@ -846,7 +846,7 @@ void imap_expunge_mailbox(struct ImapData *idata) for (int i = 0; i < idata->ctx->mailbox->msg_count; i++) { - h = idata->ctx->hdrs[i]; + h = idata->ctx->mailbox->hdrs[i]; if (h->index == INT_MAX) { @@ -1202,13 +1202,14 @@ int imap_exec_msgset(struct ImapData *idata, const char *pre, const char *post, oldsort = Sort; if (Sort != SORT_ORDER) { - hdrs = idata->ctx->hdrs; - idata->ctx->hdrs = + hdrs = idata->ctx->mailbox->hdrs; + idata->ctx->mailbox->hdrs = mutt_mem_malloc(idata->ctx->mailbox->msg_count * sizeof(struct Header *)); - memcpy(idata->ctx->hdrs, hdrs, idata->ctx->mailbox->msg_count * sizeof(struct Header *)); + memcpy(idata->ctx->mailbox->hdrs, hdrs, + idata->ctx->mailbox->msg_count * sizeof(struct Header *)); Sort = SORT_ORDER; - qsort(idata->ctx->hdrs, idata->ctx->mailbox->msg_count, + qsort(idata->ctx->mailbox->hdrs, idata->ctx->mailbox->msg_count, sizeof(struct Header *), mutt_get_sort_func(SORT_ORDER)); } @@ -1238,8 +1239,8 @@ out: if (oldsort != Sort) { Sort = oldsort; - FREE(&idata->ctx->hdrs); - idata->ctx->hdrs = hdrs; + FREE(&idata->ctx->mailbox->hdrs); + idata->ctx->mailbox->hdrs = hdrs; } return rc; @@ -1687,7 +1688,7 @@ int imap_search(struct Context *ctx, const struct Pattern *pat) struct Buffer buf; struct ImapData *idata = ctx->mailbox->data; for (int i = 0; i < ctx->mailbox->msg_count; i++) - ctx->hdrs[i]->matched = false; + ctx->mailbox->hdrs[i]->matched = false; if (do_search(pat, 1) == 0) return 0; @@ -1917,10 +1918,10 @@ int imap_fast_trash(struct Context *ctx, char *dest) sync_cmd = mutt_buffer_new(); for (int i = 0; i < ctx->mailbox->msg_count; i++) { - if (ctx->hdrs[i]->active && ctx->hdrs[i]->changed && - ctx->hdrs[i]->deleted && !ctx->hdrs[i]->purge) + if (ctx->mailbox->hdrs[i]->active && ctx->mailbox->hdrs[i]->changed && + ctx->mailbox->hdrs[i]->deleted && !ctx->mailbox->hdrs[i]->purge) { - rc = imap_sync_message_for_copy(idata, ctx->hdrs[i], sync_cmd, &err_continue); + rc = imap_sync_message_for_copy(idata, ctx->mailbox->hdrs[i], sync_cmd, &err_continue); if (rc < 0) { mutt_debug(1, "could not sync\n"); @@ -2215,8 +2216,8 @@ static int imap_mbox_open(struct Context *ctx) ctx->readonly = true; } - ctx->hdrmax = count; - ctx->hdrs = mutt_mem_calloc(count, sizeof(struct Header *)); + ctx->mailbox->hdrmax = count; + ctx->mailbox->hdrs = mutt_mem_calloc(count, sizeof(struct Header *)); ctx->v2r = mutt_mem_calloc(count, sizeof(int)); ctx->mailbox->msg_count = 0; @@ -2342,8 +2343,8 @@ static int imap_mbox_close(struct Context *ctx) for (int i = 0; i < ctx->mailbox->msg_count; i++) { /* mailbox may not have fully loaded */ - if (ctx->hdrs[i] && ctx->hdrs[i]->data) - imap_free_header_data((struct ImapHeaderData **) &(ctx->hdrs[i]->data)); + if (ctx->mailbox->hdrs[i] && ctx->mailbox->hdrs[i]->data) + imap_free_header_data((struct ImapHeaderData **) &(ctx->mailbox->hdrs[i]->data)); } return 0; @@ -2433,8 +2434,8 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) /* mark these messages as unchanged so second pass ignores them. Done * here so BOGUS UW-IMAP 4.7 SILENT FLAGS updates are ignored. */ for (int i = 0; i < ctx->mailbox->msg_count; i++) - if (ctx->hdrs[i]->deleted && ctx->hdrs[i]->changed) - ctx->hdrs[i]->active = false; + if (ctx->mailbox->hdrs[i]->deleted && ctx->mailbox->hdrs[i]->changed) + ctx->mailbox->hdrs[i]->active = false; mutt_message(ngettext("Marking %d message deleted...", "Marking %d messages deleted...", rc), rc); @@ -2448,7 +2449,7 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) /* save messages with real (non-flag) changes */ for (int i = 0; i < ctx->mailbox->msg_count; i++) { - h = ctx->hdrs[i]; + h = ctx->mailbox->hdrs[i]; if (h->deleted) { @@ -2492,12 +2493,13 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) oldsort = Sort; if (Sort != SORT_ORDER) { - hdrs = ctx->hdrs; - ctx->hdrs = mutt_mem_malloc(ctx->mailbox->msg_count * sizeof(struct Header *)); - memcpy(ctx->hdrs, hdrs, ctx->mailbox->msg_count * sizeof(struct Header *)); + hdrs = ctx->mailbox->hdrs; + ctx->mailbox->hdrs = + mutt_mem_malloc(ctx->mailbox->msg_count * sizeof(struct Header *)); + memcpy(ctx->mailbox->hdrs, hdrs, ctx->mailbox->msg_count * sizeof(struct Header *)); Sort = SORT_ORDER; - qsort(ctx->hdrs, ctx->mailbox->msg_count, sizeof(struct Header *), + qsort(ctx->mailbox->hdrs, ctx->mailbox->msg_count, sizeof(struct Header *), mutt_get_sort_func(SORT_ORDER)); } @@ -2514,8 +2516,8 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) if (oldsort != Sort) { Sort = oldsort; - FREE(&ctx->hdrs); - ctx->hdrs = hdrs; + FREE(&ctx->mailbox->hdrs); + ctx->mailbox->hdrs = hdrs; } /* Flush the queued flags if any were changed in sync_helper. */ @@ -2545,12 +2547,12 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) * there is no need to mutate the hcache after flag-only changes. */ for (int i = 0; i < ctx->mailbox->msg_count; i++) { - HEADER_DATA(ctx->hdrs[i])->deleted = ctx->hdrs[i]->deleted; - HEADER_DATA(ctx->hdrs[i])->flagged = ctx->hdrs[i]->flagged; - HEADER_DATA(ctx->hdrs[i])->old = ctx->hdrs[i]->old; - HEADER_DATA(ctx->hdrs[i])->read = ctx->hdrs[i]->read; - HEADER_DATA(ctx->hdrs[i])->replied = ctx->hdrs[i]->replied; - ctx->hdrs[i]->changed = false; + HEADER_DATA(ctx->mailbox->hdrs[i])->deleted = ctx->mailbox->hdrs[i]->deleted; + HEADER_DATA(ctx->mailbox->hdrs[i])->flagged = ctx->mailbox->hdrs[i]->flagged; + HEADER_DATA(ctx->mailbox->hdrs[i])->old = ctx->mailbox->hdrs[i]->old; + HEADER_DATA(ctx->mailbox->hdrs[i])->read = ctx->mailbox->hdrs[i]->read; + HEADER_DATA(ctx->mailbox->hdrs[i])->replied = ctx->mailbox->hdrs[i]->replied; + ctx->mailbox->hdrs[i]->changed = false; } ctx->changed = false; diff --git a/imap/message.c b/imap/message.c index df8420dc4..cd72a1f86 100644 --- a/imap/message.c +++ b/imap/message.c @@ -718,47 +718,48 @@ static int read_headers_normal_eval_cache(struct ImapData *idata, continue; } - ctx->hdrs[idx] = imap_hcache_get(idata, h.data->uid); - if (ctx->hdrs[idx]) + ctx->mailbox->hdrs[idx] = imap_hcache_get(idata, h.data->uid); + if (ctx->mailbox->hdrs[idx]) { idata->max_msn = MAX(idata->max_msn, h.data->msn); - idata->msn_index[h.data->msn - 1] = ctx->hdrs[idx]; - mutt_hash_int_insert(idata->uid_hash, h.data->uid, ctx->hdrs[idx]); + idata->msn_index[h.data->msn - 1] = ctx->mailbox->hdrs[idx]; + mutt_hash_int_insert(idata->uid_hash, h.data->uid, ctx->mailbox->hdrs[idx]); - ctx->hdrs[idx]->index = idx; + ctx->mailbox->hdrs[idx]->index = idx; /* messages which have not been expunged are ACTIVE (borrowed from mh * folders) */ - ctx->hdrs[idx]->active = true; - ctx->hdrs[idx]->changed = false; + ctx->mailbox->hdrs[idx]->active = true; + ctx->mailbox->hdrs[idx]->changed = false; if (!eval_condstore) { - ctx->hdrs[idx]->read = h.data->read; - ctx->hdrs[idx]->old = h.data->old; - ctx->hdrs[idx]->deleted = h.data->deleted; - ctx->hdrs[idx]->flagged = h.data->flagged; - ctx->hdrs[idx]->replied = h.data->replied; + ctx->mailbox->hdrs[idx]->read = h.data->read; + ctx->mailbox->hdrs[idx]->old = h.data->old; + ctx->mailbox->hdrs[idx]->deleted = h.data->deleted; + ctx->mailbox->hdrs[idx]->flagged = h.data->flagged; + ctx->mailbox->hdrs[idx]->replied = h.data->replied; } else { - h.data->read = ctx->hdrs[idx]->read; - h.data->old = ctx->hdrs[idx]->old; - h.data->deleted = ctx->hdrs[idx]->deleted; - h.data->flagged = ctx->hdrs[idx]->flagged; - h.data->replied = ctx->hdrs[idx]->replied; + h.data->read = ctx->mailbox->hdrs[idx]->read; + h.data->old = ctx->mailbox->hdrs[idx]->old; + h.data->deleted = ctx->mailbox->hdrs[idx]->deleted; + h.data->flagged = ctx->mailbox->hdrs[idx]->flagged; + h.data->replied = ctx->mailbox->hdrs[idx]->replied; } /* ctx->hdrs[msgno]->received is restored from mutt_hcache_restore */ - ctx->hdrs[idx]->data = h.data; - STAILQ_INIT(&ctx->hdrs[idx]->tags); - driver_tags_replace(&ctx->hdrs[idx]->tags, mutt_str_strdup(h.data->flags_remote)); + ctx->mailbox->hdrs[idx]->data = h.data; + STAILQ_INIT(&ctx->mailbox->hdrs[idx]->tags); + driver_tags_replace(&ctx->mailbox->hdrs[idx]->tags, + mutt_str_strdup(h.data->flags_remote)); ctx->mailbox->msg_count++; - ctx->size += ctx->hdrs[idx]->content->length; + ctx->size += ctx->mailbox->hdrs[idx]->content->length; /* If this is the first time we are fetching, we need to * store the current state of flags back into the header cache */ if (!eval_condstore && store_flag_updates) - imap_hcache_put(idata, ctx->hdrs[idx]); + imap_hcache_put(idata, ctx->mailbox->hdrs[idx]); h.data = NULL; idx++; @@ -812,7 +813,7 @@ static int read_headers_qresync_eval_cache(struct ImapData *idata, char *uid_seq idata->max_msn = MAX(idata->max_msn, msn); idata->msn_index[msn - 1] = h; - if (ctx->mailbox->msg_count >= ctx->hdrmax) + if (ctx->mailbox->msg_count >= ctx->mailbox->hdrmax) mx_alloc_memory(ctx); struct ImapHeaderData *ihd = mutt_mem_calloc(1, sizeof(struct ImapHeaderData)); @@ -832,7 +833,7 @@ static int read_headers_qresync_eval_cache(struct ImapData *idata, char *uid_seq mutt_hash_int_insert(idata->uid_hash, uid, h); ctx->size += h->content->length; - ctx->hdrs[ctx->mailbox->msg_count++] = h; + ctx->mailbox->hdrs[ctx->mailbox->msg_count++] = h; msn++; } @@ -1054,26 +1055,27 @@ static int read_headers_fetch_new(struct ImapData *idata, unsigned int msn_begin continue; } - ctx->hdrs[idx] = mutt_header_new(); + ctx->mailbox->hdrs[idx] = mutt_header_new(); idata->max_msn = MAX(idata->max_msn, h.data->msn); - idata->msn_index[h.data->msn - 1] = ctx->hdrs[idx]; - mutt_hash_int_insert(idata->uid_hash, h.data->uid, ctx->hdrs[idx]); + idata->msn_index[h.data->msn - 1] = ctx->mailbox->hdrs[idx]; + mutt_hash_int_insert(idata->uid_hash, h.data->uid, ctx->mailbox->hdrs[idx]); - ctx->hdrs[idx]->index = idx; + ctx->mailbox->hdrs[idx]->index = idx; /* messages which have not been expunged are ACTIVE (borrowed from mh * folders) */ - ctx->hdrs[idx]->active = true; - ctx->hdrs[idx]->changed = false; - ctx->hdrs[idx]->read = h.data->read; - ctx->hdrs[idx]->old = h.data->old; - ctx->hdrs[idx]->deleted = h.data->deleted; - ctx->hdrs[idx]->flagged = h.data->flagged; - ctx->hdrs[idx]->replied = h.data->replied; - ctx->hdrs[idx]->received = h.received; - ctx->hdrs[idx]->data = (void *) (h.data); - STAILQ_INIT(&ctx->hdrs[idx]->tags); - driver_tags_replace(&ctx->hdrs[idx]->tags, mutt_str_strdup(h.data->flags_remote)); + ctx->mailbox->hdrs[idx]->active = true; + ctx->mailbox->hdrs[idx]->changed = false; + ctx->mailbox->hdrs[idx]->read = h.data->read; + ctx->mailbox->hdrs[idx]->old = h.data->old; + ctx->mailbox->hdrs[idx]->deleted = h.data->deleted; + ctx->mailbox->hdrs[idx]->flagged = h.data->flagged; + ctx->mailbox->hdrs[idx]->replied = h.data->replied; + ctx->mailbox->hdrs[idx]->received = h.received; + ctx->mailbox->hdrs[idx]->data = (void *) (h.data); + STAILQ_INIT(&ctx->mailbox->hdrs[idx]->tags); + driver_tags_replace(&ctx->mailbox->hdrs[idx]->tags, + mutt_str_strdup(h.data->flags_remote)); if (*maxuid < h.data->uid) *maxuid = h.data->uid; @@ -1081,13 +1083,14 @@ static int read_headers_fetch_new(struct ImapData *idata, unsigned int msn_begin rewind(fp); /* NOTE: if Date: header is missing, mutt_rfc822_read_header depends * on h.received being set */ - ctx->hdrs[idx]->env = mutt_rfc822_read_header(fp, ctx->hdrs[idx], false, false); + ctx->mailbox->hdrs[idx]->env = + mutt_rfc822_read_header(fp, ctx->mailbox->hdrs[idx], false, false); /* content built as a side-effect of mutt_rfc822_read_header */ - ctx->hdrs[idx]->content->length = h.content_length; + ctx->mailbox->hdrs[idx]->content->length = h.content_length; ctx->size += h.content_length; #ifdef USE_HCACHE - imap_hcache_put(idata, ctx->hdrs[idx]); + imap_hcache_put(idata, ctx->mailbox->hdrs[idx]); #endif /* USE_HCACHE */ ctx->mailbox->msg_count++; @@ -1114,7 +1117,7 @@ static int read_headers_fetch_new(struct ImapData *idata, unsigned int msn_begin fetch_msn_end = idata->max_msn; msn_begin = idata->max_msn + 1; msn_end = idata->new_mail_count; - while (msn_end > ctx->hdrmax) + while (msn_end > ctx->mailbox->hdrmax) mx_alloc_memory(ctx); alloc_msn_index(idata, msn_end); idata->reopen &= ~IMAP_NEWMAIL_PENDING; @@ -1169,7 +1172,7 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, struct Context *ctx = idata->ctx; /* make sure context has room to hold the mailbox */ - while (msn_end > ctx->hdrmax) + while (msn_end > ctx->mailbox->hdrmax) mx_alloc_memory(ctx); alloc_msn_index(idata, msn_end); imap_alloc_uid_hash(idata, msn_end); @@ -1351,7 +1354,7 @@ int imap_msg_open(struct Context *ctx, struct Message *msg, int msgno) int output_progress; struct ImapData *idata = ctx->mailbox->data; - struct Header *h = ctx->hdrs[msgno]; + struct Header *h = ctx->mailbox->hdrs[msgno]; msg->fp = msg_cache_get(idata, h); if (msg->fp) @@ -1781,15 +1784,16 @@ int imap_copy_messages(struct Context *ctx, struct Header *h, char *dest, bool d if (!message_is_tagged(ctx, i)) continue; - if (ctx->hdrs[i]->attach_del) + if (ctx->mailbox->hdrs[i]->attach_del) { mutt_debug(3, "#2 Message contains attachments to be deleted\n"); return 1; } - if (ctx->hdrs[i]->active && ctx->hdrs[i]->changed) + if (ctx->mailbox->hdrs[i]->active && ctx->mailbox->hdrs[i]->changed) { - rc = imap_sync_message_for_copy(idata, ctx->hdrs[i], &sync_cmd, &err_continue); + rc = imap_sync_message_for_copy(idata, ctx->mailbox->hdrs[i], + &sync_cmd, &err_continue); if (rc < 0) { mutt_debug(1, "#1 could not sync\n"); @@ -1879,10 +1883,10 @@ int imap_copy_messages(struct Context *ctx, struct Header *h, char *dest, bool d if (!message_is_tagged(ctx, i)) continue; - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_DELETE, 1); - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_PURGE, 1); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_DELETE, 1); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_PURGE, 1); if (DeleteUntag) - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_TAG, 0); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_TAG, 0); } } else diff --git a/init.c b/init.c index c638c5b8a..485099d42 100644 --- a/init.c +++ b/init.c @@ -133,7 +133,7 @@ static void alternates_clean(void) return; for (int i = 0; i < Context->mailbox->msg_count; i++) - Context->hdrs[i]->recip_valid = false; + Context->mailbox->hdrs[i]->recip_valid = false; } /** @@ -145,7 +145,7 @@ static void attachments_clean(void) return; for (int i = 0; i < Context->mailbox->msg_count; i++) - Context->hdrs[i]->attach_valid = false; + Context->mailbox->hdrs[i]->attach_valid = false; } /** @@ -205,7 +205,7 @@ static void clear_subject_mods(void) return; for (int i = 0; i < Context->mailbox->msg_count; i++) - FREE(&Context->hdrs[i]->env->disp_subj); + FREE(&Context->mailbox->hdrs[i]->env->disp_subj); } #ifdef USE_NOTMUCH diff --git a/mailbox.h b/mailbox.h index 8da21d3e7..b1ae3d7f8 100644 --- a/mailbox.h +++ b/mailbox.h @@ -64,6 +64,9 @@ struct Mailbox int msg_unread; /**< number of unread messages */ int msg_flagged; /**< number of flagged messages */ + struct Header **hdrs; + int hdrmax; /**< number of pointers in hdrs */ + bool notified; /**< user has been notified */ enum MailboxType magic; /**< mailbox type */ bool newly_created; /**< mbox or mmdf just popped into existence */ diff --git a/maildir/mh.c b/maildir/mh.c index 446b3106d..1ae06e010 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -589,29 +589,29 @@ static void mh_update_sequences(struct Context *ctx) /* now, update our unseen, flagged, and replied sequences */ for (l = 0; l < ctx->mailbox->msg_count; l++) { - if (ctx->hdrs[l]->deleted) + if (ctx->mailbox->hdrs[l]->deleted) continue; - p = strrchr(ctx->hdrs[l]->path, '/'); + p = strrchr(ctx->mailbox->hdrs[l]->path, '/'); if (p) p++; else - p = ctx->hdrs[l]->path; + p = ctx->mailbox->hdrs[l]->path; if (mutt_str_atoi(p, &i) < 0) continue; - if (!ctx->hdrs[l]->read) + if (!ctx->mailbox->hdrs[l]->read) { mhs_set(&mhs, i, MH_SEQ_UNSEEN); unseen++; } - if (ctx->hdrs[l]->flagged) + if (ctx->mailbox->hdrs[l]->flagged) { mhs_set(&mhs, i, MH_SEQ_FLAGGED); flagged++; } - if (ctx->hdrs[l]->replied) + if (ctx->mailbox->hdrs[l]->replied) { mhs_set(&mhs, i, MH_SEQ_REPLIED); replied++; @@ -1040,11 +1040,11 @@ static bool maildir_add_to_context(struct Context *ctx, struct Maildir *md) mutt_debug(2, "Adding header structure. Flags: %s%s%s%s%s\n", md->h->flagged ? "f" : "", md->h->deleted ? "D" : "", md->h->replied ? "r" : "", md->h->old ? "O" : "", md->h->read ? "R" : ""); - if (ctx->mailbox->msg_count == ctx->hdrmax) + if (ctx->mailbox->msg_count == ctx->mailbox->hdrmax) mx_alloc_memory(ctx); - ctx->hdrs[ctx->mailbox->msg_count] = md->h; - ctx->hdrs[ctx->mailbox->msg_count]->index = ctx->mailbox->msg_count; + ctx->mailbox->hdrs[ctx->mailbox->msg_count] = md->h; + ctx->mailbox->hdrs[ctx->mailbox->msg_count]->index = ctx->mailbox->msg_count; ctx->size += md->h->content->length + md->h->content->offset - md->h->content->hdr_offset; @@ -1669,7 +1669,7 @@ void maildir_flags(char *dest, size_t destlen, struct Header *hdr) static int maildir_mh_open_message(struct Context *ctx, struct Message *msg, int msgno, int is_maildir) { - struct Header *cur = ctx->hdrs[msgno]; + struct Header *cur = ctx->mailbox->hdrs[msgno]; char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", ctx->mailbox->path, cur->path); @@ -2004,7 +2004,7 @@ static int mh_msg_commit(struct Context *ctx, struct Message *msg) */ static int mh_rewrite_message(struct Context *ctx, int msgno) { - struct Header *h = ctx->hdrs[msgno]; + struct Header *h = ctx->mailbox->hdrs[msgno]; bool restore = true; long old_body_offset = h->content->offset; @@ -2082,7 +2082,7 @@ static int mh_rewrite_message(struct Context *ctx, int msgno) */ static int mh_sync_message(struct Context *ctx, int msgno) { - struct Header *h = ctx->hdrs[msgno]; + struct Header *h = ctx->mailbox->hdrs[msgno]; if (h->attach_del || h->xlabel_changed || (h->env && (h->env->refs_changed || h->env->irt_changed))) @@ -2103,7 +2103,7 @@ static int mh_sync_message(struct Context *ctx, int msgno) */ static int maildir_sync_message(struct Context *ctx, int msgno) { - struct Header *h = ctx->hdrs[msgno]; + struct Header *h = ctx->mailbox->hdrs[msgno]; if (h->attach_del || h->xlabel_changed || (h->env && (h->env->refs_changed || h->env->irt_changed))) @@ -2176,7 +2176,7 @@ int mh_sync_mailbox_message(struct Context *ctx, int msgno, header_cache_t *hc) int mh_sync_mailbox_message(struct Context *ctx, int msgno) #endif { - struct Header *h = ctx->hdrs[msgno]; + struct Header *h = ctx->mailbox->hdrs[msgno]; if (h->deleted && (ctx->mailbox->magic != MUTT_MAILDIR || !MaildirTrash)) { @@ -2293,11 +2293,11 @@ static void maildir_update_tables(struct Context *ctx, int *index_hint) const int old_count = ctx->mailbox->msg_count; for (int i = 0, j = 0; i < old_count; i++) { - if (ctx->hdrs[i]->active && index_hint && *index_hint == i) + if (ctx->mailbox->hdrs[i]->active && index_hint && *index_hint == i) *index_hint = j; - if (ctx->hdrs[i]->active) - ctx->hdrs[i]->index = j++; + if (ctx->mailbox->hdrs[i]->active) + ctx->mailbox->hdrs[i]->index = j++; } mx_update_tables(ctx, false); @@ -2394,36 +2394,36 @@ static int maildir_mbox_check(struct Context *ctx, int *index_hint) /* check for modifications and adjust flags */ for (int i = 0; i < ctx->mailbox->msg_count; i++) { - ctx->hdrs[i]->active = false; - maildir_canon_filename(ctx->hdrs[i]->path, buf, sizeof(buf)); + ctx->mailbox->hdrs[i]->active = false; + maildir_canon_filename(ctx->mailbox->hdrs[i]->path, buf, sizeof(buf)); p = mutt_hash_find(fnames, buf); if (p && p->h) { /* message already exists, merge flags */ - ctx->hdrs[i]->active = true; + ctx->mailbox->hdrs[i]->active = true; /* check to see if the message has moved to a different * subdirectory. If so, update the associated filename. */ - if (mutt_str_strcmp(ctx->hdrs[i]->path, p->h->path) != 0) - mutt_str_replace(&ctx->hdrs[i]->path, p->h->path); + if (mutt_str_strcmp(ctx->mailbox->hdrs[i]->path, p->h->path) != 0) + mutt_str_replace(&ctx->mailbox->hdrs[i]->path, p->h->path); /* if the user hasn't modified the flags on this message, update * the flags we just detected. */ - if (!ctx->hdrs[i]->changed) - if (maildir_update_flags(ctx, ctx->hdrs[i], p->h)) + if (!ctx->mailbox->hdrs[i]->changed) + if (maildir_update_flags(ctx, ctx->mailbox->hdrs[i], p->h)) flags_changed = true; - if (ctx->hdrs[i]->deleted == ctx->hdrs[i]->trash) + if (ctx->mailbox->hdrs[i]->deleted == ctx->mailbox->hdrs[i]->trash) { - if (ctx->hdrs[i]->deleted != p->h->deleted) + if (ctx->mailbox->hdrs[i]->deleted != p->h->deleted) { - ctx->hdrs[i]->deleted = p->h->deleted; + ctx->mailbox->hdrs[i]->deleted = p->h->deleted; flags_changed = true; } } - ctx->hdrs[i]->trash = p->h->trash; + ctx->mailbox->hdrs[i]->trash = p->h->trash; /* this is a duplicate of an existing header, so remove it */ mutt_header_free(&p->h); @@ -2432,8 +2432,8 @@ static int maildir_mbox_check(struct Context *ctx, int *index_hint) * Check to see if we have enough information to know if the * message has disappeared out from underneath us. */ - else if (((changed & 1) && (strncmp(ctx->hdrs[i]->path, "new/", 4) == 0)) || - ((changed & 2) && (strncmp(ctx->hdrs[i]->path, "cur/", 4) == 0))) + else if (((changed & 1) && (strncmp(ctx->mailbox->hdrs[i]->path, "new/", 4) == 0)) || + ((changed & 2) && (strncmp(ctx->mailbox->hdrs[i]->path, "cur/", 4) == 0))) { /* This message disappeared, so we need to simulate a "reopen" * event. We know it disappeared because we just scanned the @@ -2447,7 +2447,7 @@ static int maildir_mbox_check(struct Context *ctx, int *index_hint) * modified, so we assume that it is still present and * unchanged. */ - ctx->hdrs[i]->active = true; + ctx->mailbox->hdrs[i]->active = true; } } @@ -2571,15 +2571,15 @@ static int mh_mbox_check(struct Context *ctx, int *index_hint) for (i = 0; i < ctx->mailbox->msg_count; i++) { - ctx->hdrs[i]->active = false; + ctx->mailbox->hdrs[i]->active = false; - p = mutt_hash_find(fnames, ctx->hdrs[i]->path); - if (p && p->h && mutt_header_cmp_strict(ctx->hdrs[i], p->h)) + p = mutt_hash_find(fnames, ctx->mailbox->hdrs[i]->path); + if (p && p->h && mutt_header_cmp_strict(ctx->mailbox->hdrs[i], p->h)) { - ctx->hdrs[i]->active = true; + ctx->mailbox->hdrs[i]->active = true; /* found the right message */ - if (!ctx->hdrs[i]->changed) - if (maildir_update_flags(ctx, ctx->hdrs[i], p->h)) + if (!ctx->mailbox->hdrs[i]->changed) + if (maildir_update_flags(ctx, ctx->mailbox->hdrs[i], p->h)) flags_changed = true; mutt_header_free(&p->h); @@ -2672,8 +2672,8 @@ static int mh_mbox_sync(struct Context *ctx, int *index_hint) { for (i = 0, j = 0; i < ctx->mailbox->msg_count; i++) { - if (!ctx->hdrs[i]->deleted || (ctx->mailbox->magic == MUTT_MAILDIR && MaildirTrash)) - ctx->hdrs[i]->index = j++; + if (!ctx->mailbox->hdrs[i]->deleted || (ctx->mailbox->magic == MUTT_MAILDIR && MaildirTrash)) + ctx->mailbox->hdrs[i]->index = j++; } } diff --git a/mbox/mbox.c b/mbox/mbox.c index 44b9a0c01..50e097b9c 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -160,10 +160,10 @@ static int mmdf_parse_mailbox(struct Context *ctx) if (!ctx->quiet) mutt_progress_update(&progress, count, (int) (loc / (ctx->size / 100 + 1))); - if (ctx->mailbox->msg_count == ctx->hdrmax) + if (ctx->mailbox->msg_count == ctx->mailbox->hdrmax) mx_alloc_memory(ctx); hdr = mutt_header_new(); - ctx->hdrs[ctx->mailbox->msg_count] = hdr; + ctx->mailbox->hdrs[ctx->mailbox->msg_count] = hdr; hdr->offset = loc; hdr->index = ctx->mailbox->msg_count; @@ -312,7 +312,7 @@ static int mbox_parse_mailbox(struct Context *ctx) /* Save the Content-Length of the previous message */ if (count > 0) { - struct Header *h = ctx->hdrs[ctx->mailbox->msg_count - 1]; + struct Header *h = ctx->mailbox->hdrs[ctx->mailbox->msg_count - 1]; if (h->content->length < 0) { h->content->length = loc - h->content->offset - 1; @@ -331,11 +331,11 @@ static int mbox_parse_mailbox(struct Context *ctx) (int) (ftello(ctx->fp) / (ctx->size / 100 + 1))); } - if (ctx->mailbox->msg_count == ctx->hdrmax) + if (ctx->mailbox->msg_count == ctx->mailbox->hdrmax) mx_alloc_memory(ctx); - ctx->hdrs[ctx->mailbox->msg_count] = mutt_header_new(); - curhdr = ctx->hdrs[ctx->mailbox->msg_count]; + ctx->mailbox->hdrs[ctx->mailbox->msg_count] = mutt_header_new(); + curhdr = ctx->mailbox->hdrs[ctx->mailbox->msg_count]; curhdr->received = t - mutt_date_local_tz(t); curhdr->offset = loc; curhdr->index = ctx->mailbox->msg_count; @@ -437,7 +437,7 @@ static int mbox_parse_mailbox(struct Context *ctx) */ if (count > 0) { - struct Header *h = ctx->hdrs[ctx->mailbox->msg_count - 1]; + struct Header *h = ctx->mailbox->hdrs[ctx->mailbox->msg_count - 1]; if (h->content->length < 0) { h->content->length = ftello(ctx->fp) - h->content->offset - 1; @@ -672,18 +672,18 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint) if (ctx->readonly) { for (i = 0; i < ctx->mailbox->msg_count; i++) - mutt_header_free(&(ctx->hdrs[i])); /* nothing to do! */ - FREE(&ctx->hdrs); + mutt_header_free(&(ctx->mailbox->hdrs[i])); /* nothing to do! */ + FREE(&ctx->mailbox->hdrs); } else { /* save the old headers */ old_msgcount = ctx->mailbox->msg_count; - old_hdrs = ctx->hdrs; - ctx->hdrs = NULL; + old_hdrs = ctx->mailbox->hdrs; + ctx->mailbox->hdrs = NULL; } - ctx->hdrmax = 0; /* force allocation of new headers */ + ctx->mailbox->hdrmax = 0; /* force allocation of new headers */ ctx->mailbox->msg_count = 0; ctx->vcount = 0; ctx->vsize = 0; @@ -748,7 +748,7 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint) { if (!old_hdrs[j]) continue; - if (cmp_headers(ctx->hdrs[i], old_hdrs[j])) + if (cmp_headers(ctx->mailbox->hdrs[i], old_hdrs[j])) { found = true; break; @@ -760,7 +760,7 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint) { if (!old_hdrs[j]) continue; - if (cmp_headers(ctx->hdrs[i], old_hdrs[j])) + if (cmp_headers(ctx->mailbox->hdrs[i], old_hdrs[j])) { found = true; break; @@ -780,14 +780,14 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint) * otherwise, the header may have been modified externally, * and we don't want to lose _those_ changes */ - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_FLAG, old_hdrs[j]->flagged); - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_REPLIED, old_hdrs[j]->replied); - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_OLD, old_hdrs[j]->old); - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_READ, old_hdrs[j]->read); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_FLAG, old_hdrs[j]->flagged); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_REPLIED, old_hdrs[j]->replied); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_OLD, old_hdrs[j]->old); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_READ, old_hdrs[j]->read); } - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_DELETE, old_hdrs[j]->deleted); - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_PURGE, old_hdrs[j]->purge); - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_TAG, old_hdrs[j]->tagged); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_DELETE, old_hdrs[j]->deleted); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_PURGE, old_hdrs[j]->purge); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_TAG, old_hdrs[j]->tagged); /* we don't need this header any more */ mutt_header_free(&(old_hdrs[j])); @@ -937,7 +937,8 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint) static bool mbox_has_new(struct Context *ctx) { for (int i = 0; i < ctx->mailbox->msg_count; i++) - if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read && !ctx->hdrs[i]->old) + if (!ctx->mailbox->hdrs[i]->deleted && !ctx->mailbox->hdrs[i]->read && + !ctx->mailbox->hdrs[i]->old) return true; return false; } @@ -1057,8 +1058,8 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint) /* find the first deleted/changed message. we save a lot of time by only * rewriting the mailbox from the point where it has actually changed. */ - for (i = 0; (i < ctx->mailbox->msg_count) && !ctx->hdrs[i]->deleted && - !ctx->hdrs[i]->changed && !ctx->hdrs[i]->attach_del; + for (i = 0; (i < ctx->mailbox->msg_count) && !ctx->mailbox->hdrs[i]->deleted && + !ctx->mailbox->hdrs[i]->changed && !ctx->mailbox->hdrs[i]->attach_del; i++) { } @@ -1078,7 +1079,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint) /* save the index of the first changed/deleted message */ first = i; /* where to start overwriting */ - offset = ctx->hdrs[i]->offset; + offset = ctx->mailbox->hdrs[i]->offset; /* the offset stored in the header does not include the MMDF_SEP, so make * sure we seek to the correct location @@ -1106,12 +1107,12 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint) */ old_offset[i - first].valid = true; - old_offset[i - first].hdr = ctx->hdrs[i]->offset; - old_offset[i - first].body = ctx->hdrs[i]->content->offset; - old_offset[i - first].lines = ctx->hdrs[i]->lines; - old_offset[i - first].length = ctx->hdrs[i]->content->length; + old_offset[i - first].hdr = ctx->mailbox->hdrs[i]->offset; + old_offset[i - first].body = ctx->mailbox->hdrs[i]->content->offset; + old_offset[i - first].lines = ctx->mailbox->hdrs[i]->lines; + old_offset[i - first].length = ctx->mailbox->hdrs[i]->content->length; - if (!ctx->hdrs[i]->deleted) + if (!ctx->mailbox->hdrs[i]->deleted) { j++; @@ -1131,7 +1132,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint) */ new_offset[i - first].hdr = ftello(fp) + offset; - if (mutt_copy_message_ctx(fp, ctx, ctx->hdrs[i], MUTT_CM_UPDATE, + if (mutt_copy_message_ctx(fp, ctx, ctx->mailbox->hdrs[i], MUTT_CM_UPDATE, CH_FROM | CH_UPDATE | CH_UPDATE_LEN) != 0) { mutt_perror(tempfile); @@ -1145,8 +1146,9 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint) * we just flush the in memory cache so that the message will be reparsed * if the user accesses it later. */ - new_offset[i - first].body = ftello(fp) - ctx->hdrs[i]->content->length + offset; - mutt_body_free(&ctx->hdrs[i]->content->parts); + new_offset[i - first].body = + ftello(fp) - ctx->mailbox->hdrs[i]->content->length + offset; + mutt_body_free(&ctx->mailbox->hdrs[i]->content->parts); switch (ctx->mailbox->magic) { @@ -1282,12 +1284,12 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint) /* update the offsets of the rewritten messages */ for (i = first, j = first; i < ctx->mailbox->msg_count; i++) { - if (!ctx->hdrs[i]->deleted) + if (!ctx->mailbox->hdrs[i]->deleted) { - ctx->hdrs[i]->offset = new_offset[i - first].hdr; - ctx->hdrs[i]->content->hdr_offset = new_offset[i - first].hdr; - ctx->hdrs[i]->content->offset = new_offset[i - first].body; - ctx->hdrs[i]->index = j++; + ctx->mailbox->hdrs[i]->offset = new_offset[i - first].hdr; + ctx->mailbox->hdrs[i]->content->hdr_offset = new_offset[i - first].hdr; + ctx->mailbox->hdrs[i]->content->offset = new_offset[i - first].body; + ctx->mailbox->hdrs[i]->index = j++; } } FREE(&new_offset); @@ -1313,11 +1315,11 @@ bail: /* Come here in case of disaster */ { for (i = first; (i < ctx->mailbox->msg_count) && old_offset[i - first].valid; i++) { - ctx->hdrs[i]->offset = old_offset[i - first].hdr; - ctx->hdrs[i]->content->hdr_offset = old_offset[i - first].hdr; - ctx->hdrs[i]->content->offset = old_offset[i - first].body; - ctx->hdrs[i]->lines = old_offset[i - first].lines; - ctx->hdrs[i]->content->length = old_offset[i - first].length; + ctx->mailbox->hdrs[i]->offset = old_offset[i - first].hdr; + ctx->mailbox->hdrs[i]->content->hdr_offset = old_offset[i - first].hdr; + ctx->mailbox->hdrs[i]->content->offset = old_offset[i - first].body; + ctx->mailbox->hdrs[i]->lines = old_offset[i - first].lines; + ctx->mailbox->hdrs[i]->content->length = old_offset[i - first].length; } } diff --git a/menu.c b/menu.c index 0db926086..4c41d5ec3 100644 --- a/menu.c +++ b/menu.c @@ -36,6 +36,7 @@ #include "curs_lib.h" #include "globals.h" #include "keymap.h" +#include "mailbox.h" #include "mutt_curses.h" #include "mutt_logging.h" #include "mutt_window.h" @@ -78,7 +79,7 @@ static int get_color(int index, unsigned char *s) { struct ColorLineHead *color = NULL; struct ColorLine *np = NULL; - struct Header *hdr = Context->hdrs[Context->v2r[index]]; + struct Header *hdr = Context->mailbox->hdrs[Context->v2r[index]]; int type = *s; switch (type) diff --git a/mutt_header.c b/mutt_header.c index af3c31093..1bb5e857e 100644 --- a/mutt_header.c +++ b/mutt_header.c @@ -156,7 +156,7 @@ int mutt_label_message(struct Header *hdr) if (!message_is_tagged(Context, i)) continue; - struct Header *h = Context->hdrs[i]; + struct Header *h = Context->mailbox->hdrs[i]; if (label_message(Context, h, new)) { changed++; diff --git a/mutt_thread.c b/mutt_thread.c index 103ce0660..f324d3934 100644 --- a/mutt_thread.c +++ b/mutt_thread.c @@ -119,7 +119,7 @@ static void linearize_tree(struct Context *ctx) { struct MuttThread *tree = ctx->tree; struct Header **array = - ctx->hdrs + ((Sort & SORT_REVERSE) ? ctx->mailbox->msg_count - 1 : 0); + ctx->mailbox->hdrs + ((Sort & SORT_REVERSE) ? ctx->mailbox->msg_count - 1 : 0); while (tree) { @@ -495,7 +495,7 @@ static struct Hash *make_subj_hash(struct Context *ctx) for (int i = 0; i < ctx->mailbox->msg_count; i++) { - struct Header *hdr = ctx->hdrs[i]; + struct Header *hdr = ctx->mailbox->hdrs[i]; if (hdr->env->real_subj) mutt_hash_insert(hash, hdr->env->real_subj, hdr); } @@ -579,10 +579,10 @@ void mutt_clear_threads(struct Context *ctx) for (int i = 0; i < ctx->mailbox->msg_count; i++) { /* mailbox may have been only partially read */ - if (ctx->hdrs[i]) + if (ctx->mailbox->hdrs[i]) { - ctx->hdrs[i]->thread = NULL; - ctx->hdrs[i]->threaded = false; + ctx->mailbox->hdrs[i]->thread = NULL; + ctx->mailbox->hdrs[i]->threaded = false; } } ctx->tree = NULL; @@ -766,7 +766,7 @@ static void check_subjects(struct Context *ctx, bool init) struct MuttThread *tmp = NULL; for (int i = 0; i < ctx->mailbox->msg_count; i++) { - cur = ctx->hdrs[i]; + cur = ctx->mailbox->hdrs[i]; if (cur->thread->check_subject) cur->thread->check_subject = false; else if (!init) @@ -840,7 +840,7 @@ void mutt_sort_threads(struct Context *ctx, bool init) * MuttThread, make a new one for it. */ for (i = 0; i < ctx->mailbox->msg_count; i++) { - cur = ctx->hdrs[i]; + cur = ctx->mailbox->hdrs[i]; if (!cur->thread) { @@ -932,7 +932,7 @@ void mutt_sort_threads(struct Context *ctx, bool init) /* thread by references */ for (i = 0; i < ctx->mailbox->msg_count; i++) { - cur = ctx->hdrs[i]; + cur = ctx->mailbox->hdrs[i]; if (cur->threaded) continue; cur->threaded = true; @@ -1160,7 +1160,7 @@ void mutt_set_virtual(struct Context *ctx) for (int i = 0; i < ctx->mailbox->msg_count; i++) { - cur = ctx->hdrs[i]; + cur = ctx->mailbox->hdrs[i]; if (cur->virtual >= 0) { cur->virtual = ctx->vcount; @@ -1400,7 +1400,7 @@ struct Hash *mutt_make_id_hash(struct Context *ctx) for (int i = 0; i < ctx->mailbox->msg_count; i++) { - struct Header *hdr = ctx->hdrs[i]; + struct Header *hdr = ctx->mailbox->hdrs[i]; if (hdr->env->message_id) mutt_hash_insert(hash, hdr->env->message_id, hdr); } @@ -1446,7 +1446,7 @@ int mutt_link_threads(struct Header *cur, struct Header *last, struct Context *c { for (int i = 0; i < ctx->mailbox->msg_count; i++) if (message_is_tagged(ctx, i)) - changed |= link_threads(cur, ctx->hdrs[i], ctx); + changed |= link_threads(cur, ctx->mailbox->hdrs[i], ctx); } else changed = link_threads(cur, last, ctx); diff --git a/mx.c b/mx.c index 7e5d8cece..25eb92304 100644 --- a/mx.c +++ b/mx.c @@ -380,8 +380,8 @@ void mx_fastclose_mailbox(struct Context *ctx) mutt_hash_destroy(&ctx->label_hash); mutt_clear_threads(ctx); for (int i = 0; i < ctx->mailbox->msg_count; i++) - mutt_header_free(&ctx->hdrs[i]); - FREE(&ctx->hdrs); + mutt_header_free(&ctx->mailbox->hdrs[i]); + FREE(&ctx->mailbox->hdrs); FREE(&ctx->v2r); FREE(&ctx->pattern); if (ctx->limit_pattern) @@ -437,7 +437,7 @@ static int trash_append(struct Context *ctx) int first_del = -1; for (i = 0; i < ctx->mailbox->msg_count; i++) { - if (ctx->hdrs[i]->deleted && (!ctx->hdrs[i]->purge)) + if (ctx->mailbox->hdrs[i]->deleted && (!ctx->mailbox->hdrs[i]->purge)) { if (first_del < 0) first_del = i; @@ -484,9 +484,9 @@ static int trash_append(struct Context *ctx) /* continue from initial scan above */ for (i = first_del; i < ctx->mailbox->msg_count; i++) { - if (ctx->hdrs[i]->deleted && (!ctx->hdrs[i]->purge)) + if (ctx->mailbox->hdrs[i]->deleted && (!ctx->mailbox->hdrs[i]->purge)) { - if (mutt_append_message(ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1) + if (mutt_append_message(ctx_trash, ctx, ctx->mailbox->hdrs[i], 0, 0) == -1) { mx_mbox_close(&ctx_trash, NULL); return -1; @@ -554,7 +554,8 @@ int mx_mbox_close(struct Context **pctx, int *index_hint) for (i = 0; i < ctx->mailbox->msg_count; i++) { - if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->read && !(ctx->hdrs[i]->flagged && KeepFlagged)) + if (!ctx->mailbox->hdrs[i]->deleted && ctx->mailbox->hdrs[i]->read && + !(ctx->mailbox->hdrs[i]->flagged && KeepFlagged)) { read_msgs++; } @@ -618,8 +619,9 @@ int mx_mbox_close(struct Context **pctx, int *index_hint) { for (i = 0; i < ctx->mailbox->msg_count; i++) { - if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->old && !ctx->hdrs[i]->read) - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_OLD, 1); + if (!ctx->mailbox->hdrs[i]->deleted && !ctx->mailbox->hdrs[i]->old && + !ctx->mailbox->hdrs[i]->read) + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_OLD, 1); } } @@ -637,14 +639,14 @@ int mx_mbox_close(struct Context **pctx, int *index_hint) /* tag messages for moving, and clear old tags, if any */ for (i = 0; i < ctx->mailbox->msg_count; i++) { - if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted && - !(ctx->hdrs[i]->flagged && KeepFlagged)) + if (ctx->mailbox->hdrs[i]->read && !ctx->mailbox->hdrs[i]->deleted && + !(ctx->mailbox->hdrs[i]->flagged && KeepFlagged)) { - ctx->hdrs[i]->tagged = true; + ctx->mailbox->hdrs[i]->tagged = true; } else { - ctx->hdrs[i]->tagged = false; + ctx->mailbox->hdrs[i]->tagged = false; } } @@ -670,13 +672,13 @@ int mx_mbox_close(struct Context **pctx, int *index_hint) for (i = 0; i < ctx->mailbox->msg_count; i++) { - if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted && - !(ctx->hdrs[i]->flagged && KeepFlagged)) + if (ctx->mailbox->hdrs[i]->read && !ctx->mailbox->hdrs[i]->deleted && + !(ctx->mailbox->hdrs[i]->flagged && KeepFlagged)) { - if (mutt_append_message(f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0) + if (mutt_append_message(f, ctx, ctx->mailbox->hdrs[i], 0, CH_UPDATE_LEN) == 0) { - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_DELETE, 1); - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_PURGE, 1); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_DELETE, 1); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_PURGE, 1); } else { @@ -729,8 +731,8 @@ int mx_mbox_close(struct Context **pctx, int *index_hint) { for (i = 0; i < ctx->mailbox->msg_count; i++) { - ctx->hdrs[i]->deleted = false; - ctx->hdrs[i]->purge = false; + ctx->mailbox->hdrs[i]->deleted = false; + ctx->mailbox->hdrs[i]->purge = false; } ctx->deleted = 0; } @@ -772,9 +774,9 @@ int mx_mbox_close(struct Context **pctx, int *index_hint) for (i = 0; i < ctx->mailbox->msg_count; i++) { - if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read) + if (ctx->mailbox->hdrs[i]->deleted && !ctx->mailbox->hdrs[i]->read) ctx->mailbox->msg_unread--; - if (ctx->hdrs[i]->deleted && ctx->hdrs[i]->flagged) + if (ctx->mailbox->hdrs[i]->deleted && ctx->mailbox->hdrs[i]->flagged) ctx->mailbox->msg_flagged--; } ctx->mailbox->msg_count -= ctx->deleted; @@ -810,44 +812,44 @@ void mx_update_tables(struct Context *ctx, bool committing) padding = mx_msg_padding_size(ctx); for (i = 0, j = 0; i < ctx->mailbox->msg_count; i++) { - if (!ctx->hdrs[i]->quasi_deleted && - ((committing && (!ctx->hdrs[i]->deleted || + if (!ctx->mailbox->hdrs[i]->quasi_deleted && + ((committing && (!ctx->mailbox->hdrs[i]->deleted || (ctx->mailbox->magic == MUTT_MAILDIR && MaildirTrash))) || - (!committing && ctx->hdrs[i]->active))) + (!committing && ctx->mailbox->hdrs[i]->active))) { if (i != j) { - ctx->hdrs[j] = ctx->hdrs[i]; - ctx->hdrs[i] = NULL; + ctx->mailbox->hdrs[j] = ctx->mailbox->hdrs[i]; + ctx->mailbox->hdrs[i] = NULL; } - ctx->hdrs[j]->msgno = j; - if (ctx->hdrs[j]->virtual != -1) + ctx->mailbox->hdrs[j]->msgno = j; + if (ctx->mailbox->hdrs[j]->virtual != -1) { ctx->v2r[ctx->vcount] = j; - ctx->hdrs[j]->virtual = ctx->vcount++; - struct Body *b = ctx->hdrs[j]->content; + ctx->mailbox->hdrs[j]->virtual = ctx->vcount++; + struct Body *b = ctx->mailbox->hdrs[j]->content; ctx->vsize += b->length + b->offset - b->hdr_offset + padding; } if (committing) - ctx->hdrs[j]->changed = false; - else if (ctx->hdrs[j]->changed) + ctx->mailbox->hdrs[j]->changed = false; + else if (ctx->mailbox->hdrs[j]->changed) ctx->changed = true; if (!committing || (ctx->mailbox->magic == MUTT_MAILDIR && MaildirTrash)) { - if (ctx->hdrs[j]->deleted) + if (ctx->mailbox->hdrs[j]->deleted) ctx->deleted++; } - if (ctx->hdrs[j]->tagged) + if (ctx->mailbox->hdrs[j]->tagged) ctx->tagged++; - if (ctx->hdrs[j]->flagged) + if (ctx->mailbox->hdrs[j]->flagged) ctx->mailbox->msg_flagged++; - if (!ctx->hdrs[j]->read) + if (!ctx->mailbox->hdrs[j]->read) { ctx->mailbox->msg_unread++; - if (!ctx->hdrs[j]->old) + if (!ctx->mailbox->hdrs[j]->old) ctx->new ++; } @@ -857,23 +859,26 @@ void mx_update_tables(struct Context *ctx, bool committing) { if (ctx->mailbox->magic == MUTT_MH || ctx->mailbox->magic == MUTT_MAILDIR) { - ctx->size -= (ctx->hdrs[i]->content->length + ctx->hdrs[i]->content->offset - - ctx->hdrs[i]->content->hdr_offset); + ctx->size -= (ctx->mailbox->hdrs[i]->content->length + + ctx->mailbox->hdrs[i]->content->offset - + ctx->mailbox->hdrs[i]->content->hdr_offset); } /* remove message from the hash tables */ - if (ctx->subj_hash && ctx->hdrs[i]->env->real_subj) - mutt_hash_delete(ctx->subj_hash, ctx->hdrs[i]->env->real_subj, ctx->hdrs[i]); - if (ctx->id_hash && ctx->hdrs[i]->env->message_id) - mutt_hash_delete(ctx->id_hash, ctx->hdrs[i]->env->message_id, ctx->hdrs[i]); - mutt_label_hash_remove(ctx, ctx->hdrs[i]); + if (ctx->subj_hash && ctx->mailbox->hdrs[i]->env->real_subj) + mutt_hash_delete(ctx->subj_hash, ctx->mailbox->hdrs[i]->env->real_subj, + ctx->mailbox->hdrs[i]); + if (ctx->id_hash && ctx->mailbox->hdrs[i]->env->message_id) + mutt_hash_delete(ctx->id_hash, ctx->mailbox->hdrs[i]->env->message_id, + ctx->mailbox->hdrs[i]); + mutt_label_hash_remove(ctx, ctx->mailbox->hdrs[i]); /* The path mx_mbox_check() -> imap_check_mailbox() -> * imap_expunge_mailbox() -> mx_update_tables() * can occur before a call to mx_mbox_sync(), resulting in * last_tag being stale if it's not reset here. */ - if (ctx->last_tag == ctx->hdrs[i]) + if (ctx->last_tag == ctx->mailbox->hdrs[i]) ctx->last_tag = NULL; - mutt_header_free(&ctx->hdrs[i]); + mutt_header_free(&ctx->mailbox->hdrs[i]); } } ctx->mailbox->msg_count = j; @@ -935,8 +940,8 @@ int mx_mbox_sync(struct Context *ctx, int *index_hint) { for (int i = 0; i < ctx->mailbox->msg_count; i++) { - ctx->hdrs[i]->deleted = false; - ctx->hdrs[i]->purge = false; + ctx->mailbox->hdrs[i]->deleted = false; + ctx->mailbox->hdrs[i]->purge = false; } ctx->deleted = 0; } @@ -1171,25 +1176,27 @@ void mx_alloc_memory(struct Context *ctx) { size_t s = MAX(sizeof(struct Header *), sizeof(int)); - if ((ctx->hdrmax + 25) * s < ctx->hdrmax * s) + if ((ctx->mailbox->hdrmax + 25) * s < ctx->mailbox->hdrmax * s) { mutt_error(_("Out of memory")); mutt_exit(1); } - if (ctx->hdrs) + if (ctx->mailbox->hdrs) { - mutt_mem_realloc(&ctx->hdrs, sizeof(struct Header *) * (ctx->hdrmax += 25)); - mutt_mem_realloc(&ctx->v2r, sizeof(int) * ctx->hdrmax); + mutt_mem_realloc(&ctx->mailbox->hdrs, + sizeof(struct Header *) * (ctx->mailbox->hdrmax += 25)); + mutt_mem_realloc(&ctx->v2r, sizeof(int) * ctx->mailbox->hdrmax); } else { - ctx->hdrs = mutt_mem_calloc((ctx->hdrmax += 25), sizeof(struct Header *)); - ctx->v2r = mutt_mem_calloc(ctx->hdrmax, sizeof(int)); + ctx->mailbox->hdrs = + mutt_mem_calloc((ctx->mailbox->hdrmax += 25), sizeof(struct Header *)); + ctx->v2r = mutt_mem_calloc(ctx->mailbox->hdrmax, sizeof(int)); } - for (int i = ctx->mailbox->msg_count; i < ctx->hdrmax; i++) + for (int i = ctx->mailbox->msg_count; i < ctx->mailbox->hdrmax; i++) { - ctx->hdrs[i] = NULL; + ctx->mailbox->hdrs[i] = NULL; ctx->v2r[i] = -1; } } @@ -1208,7 +1215,7 @@ void mx_update_context(struct Context *ctx, int new_messages) for (int msgno = ctx->mailbox->msg_count - new_messages; msgno < ctx->mailbox->msg_count; msgno++) { - h = ctx->hdrs[msgno]; + h = ctx->mailbox->hdrs[msgno]; if (WithCrypto) { diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 92a217515..725ac6f17 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -832,7 +832,7 @@ void crypt_extract_keys_from_messages(struct Header *h) if (!message_is_tagged(Context, i)) continue; - struct Header *hi = Context->hdrs[i]; + struct Header *hi = Context->mailbox->hdrs[i]; mutt_parse_mime_message(Context, hi); if (hi->security & ENCRYPT && !crypt_valid_passphrase(hi->security)) diff --git a/nntp/newsrc.c b/nntp/newsrc.c index f170263f0..26c6a014b 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -354,9 +354,9 @@ void nntp_newsrc_gen_entries(struct Context *ctx) { /* We don't actually check sequential order, since we mark * "missing" entries as read/deleted */ - last = NHDR(ctx->hdrs[i])->article_num; - if (last >= nntp_data->first_message && !ctx->hdrs[i]->deleted && - !ctx->hdrs[i]->read) + last = NHDR(ctx->mailbox->hdrs[i])->article_num; + if (last >= nntp_data->first_message && !ctx->mailbox->hdrs[i]->deleted && + !ctx->mailbox->hdrs[i]->read) { if (nntp_data->newsrc_len >= entries) { @@ -373,12 +373,12 @@ void nntp_newsrc_gen_entries(struct Context *ctx) /* search for first read */ else { - if (ctx->hdrs[i]->deleted || ctx->hdrs[i]->read) + if (ctx->mailbox->hdrs[i]->deleted || ctx->mailbox->hdrs[i]->read) { first = last + 1; series = true; } - last = NHDR(ctx->hdrs[i])->article_num; + last = NHDR(ctx->mailbox->hdrs[i])->article_num; } } @@ -1327,7 +1327,7 @@ struct NntpData *mutt_newsgroup_catchup(struct NntpServer *nserv, char *group) if (Context && Context->mailbox->data == nntp_data) { for (unsigned int i = 0; i < Context->mailbox->msg_count; i++) - mutt_set_flag(Context, Context->hdrs[i], MUTT_READ, 1); + mutt_set_flag(Context, Context->mailbox->hdrs[i], MUTT_READ, 1); } return nntp_data; } @@ -1361,7 +1361,7 @@ struct NntpData *mutt_newsgroup_uncatchup(struct NntpServer *nserv, char *group) { nntp_data->unread = Context->mailbox->msg_count; for (unsigned int i = 0; i < Context->mailbox->msg_count; i++) - mutt_set_flag(Context, Context->hdrs[i], MUTT_READ, 0); + mutt_set_flag(Context, Context->mailbox->hdrs[i], MUTT_READ, 0); } else { @@ -1393,7 +1393,7 @@ void nntp_mailbox(char *buf, size_t buflen) unsigned int unread = 0; for (unsigned int j = 0; j < Context->mailbox->msg_count; j++) - if (!Context->hdrs[j]->read && !Context->hdrs[j]->deleted) + if (!Context->mailbox->hdrs[j]->read && !Context->mailbox->hdrs[j]->deleted) unread++; if (!unread) continue; diff --git a/nntp/nntp.c b/nntp/nntp.c index c830c8cb2..93e20e1ea 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -1185,12 +1185,12 @@ static int parse_overview_line(char *line, void *data) rewind(fp); /* allocate memory for headers */ - if (ctx->mailbox->msg_count >= ctx->hdrmax) + if (ctx->mailbox->msg_count >= ctx->mailbox->hdrmax) mx_alloc_memory(ctx); /* parse header */ - ctx->hdrs[ctx->mailbox->msg_count] = mutt_header_new(); - hdr = ctx->hdrs[ctx->mailbox->msg_count]; + ctx->mailbox->hdrs[ctx->mailbox->msg_count] = mutt_header_new(); + hdr = ctx->mailbox->hdrs[ctx->mailbox->msg_count]; hdr->env = mutt_rfc822_read_header(fp, hdr, false, false); hdr->env->newsgroups = mutt_str_strdup(nntp_data->group); hdr->received = hdr->date_sent; @@ -1209,7 +1209,7 @@ static int parse_overview_line(char *line, void *data) mutt_debug(2, "mutt_hcache_fetch %s\n", buf); mutt_header_free(&hdr); hdr = mutt_hcache_restore(hdata); - ctx->hdrs[ctx->mailbox->msg_count] = hdr; + ctx->mailbox->hdrs[ctx->mailbox->msg_count] = hdr; mutt_hcache_free(fc->hc, &hdata); hdr->data = NULL; hdr->read = false; @@ -1369,7 +1369,7 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first, continue; /* allocate memory for headers */ - if (ctx->mailbox->msg_count >= ctx->hdrmax) + if (ctx->mailbox->msg_count >= ctx->mailbox->hdrmax) mx_alloc_memory(ctx); #ifdef USE_HCACHE @@ -1379,7 +1379,7 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first, { mutt_debug(2, "mutt_hcache_fetch %s\n", buf); hdr = mutt_hcache_restore(hdata); - ctx->hdrs[ctx->mailbox->msg_count] = hdr; + ctx->mailbox->hdrs[ctx->mailbox->msg_count] = hdr; mutt_hcache_free(fc.hc, &hdata); hdr->data = NULL; @@ -1452,8 +1452,8 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first, } /* parse header */ - ctx->hdrs[ctx->mailbox->msg_count] = mutt_header_new(); - hdr = ctx->hdrs[ctx->mailbox->msg_count]; + ctx->mailbox->hdrs[ctx->mailbox->msg_count] = mutt_header_new(); + hdr = ctx->mailbox->hdrs[ctx->mailbox->msg_count]; hdr->env = mutt_rfc822_read_header(fp, hdr, false, false); hdr->received = hdr->date_sent; mutt_file_fclose(&fp); @@ -1644,7 +1644,7 @@ static int nntp_mbox_open(struct Context *ctx) static int nntp_msg_open(struct Context *ctx, struct Message *msg, int msgno) { struct NntpData *nntp_data = ctx->mailbox->data; - struct Header *hdr = ctx->hdrs[msgno]; + struct Header *hdr = ctx->mailbox->hdrs[msgno]; char article[16]; /* try to get article from cache */ @@ -1938,7 +1938,7 @@ static int check_mailbox(struct Context *ctx) if (nntp_data->last_message < nntp_data->last_loaded) { for (int i = 0; i < ctx->mailbox->msg_count; i++) - mutt_header_free(&ctx->hdrs[i]); + mutt_header_free(&ctx->mailbox->hdrs[i]); ctx->mailbox->msg_count = 0; ctx->tagged = 0; @@ -1974,7 +1974,7 @@ static int check_mailbox(struct Context *ctx) for (int i = 0; i < ctx->mailbox->msg_count; i++) { bool flagged = false; - anum = NHDR(ctx->hdrs[i])->article_num; + anum = NHDR(ctx->mailbox->hdrs[i])->article_num; #ifdef USE_HCACHE /* check hcache for flagged and deleted flags */ @@ -2000,24 +2000,24 @@ static int check_mailbox(struct Context *ctx) /* header marked as deleted, removing from context */ if (deleted) { - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_TAG, 0); - mutt_header_free(&ctx->hdrs[i]); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_TAG, 0); + mutt_header_free(&ctx->mailbox->hdrs[i]); continue; } } } #endif - if (!ctx->hdrs[i]->changed) + if (!ctx->mailbox->hdrs[i]->changed) { - ctx->hdrs[i]->flagged = flagged; - ctx->hdrs[i]->read = false; - ctx->hdrs[i]->old = false; - nntp_article_status(ctx, ctx->hdrs[i], NULL, anum); - if (!ctx->hdrs[i]->read) - nntp_parse_xref(ctx, ctx->hdrs[i]); + ctx->mailbox->hdrs[i]->flagged = flagged; + ctx->mailbox->hdrs[i]->read = false; + ctx->mailbox->hdrs[i]->old = false; + nntp_article_status(ctx, ctx->mailbox->hdrs[i], NULL, anum); + if (!ctx->mailbox->hdrs[i]->read) + nntp_parse_xref(ctx, ctx->mailbox->hdrs[i]); } - ctx->hdrs[j++] = ctx->hdrs[i]; + ctx->mailbox->hdrs[j++] = ctx->mailbox->hdrs[i]; } #ifdef USE_HCACHE @@ -2034,11 +2034,11 @@ static int check_mailbox(struct Context *ctx) if (hdata) { mutt_debug(2, "#2 mutt_hcache_fetch %s\n", buf); - if (ctx->mailbox->msg_count >= ctx->hdrmax) + if (ctx->mailbox->msg_count >= ctx->mailbox->hdrmax) mx_alloc_memory(ctx); hdr = mutt_hcache_restore(hdata); - ctx->hdrs[ctx->mailbox->msg_count] = hdr; + ctx->mailbox->hdrs[ctx->mailbox->msg_count] = hdr; mutt_hcache_free(hc, &hdata); hdr->data = NULL; if (hdr->deleted) @@ -2166,7 +2166,7 @@ static int nntp_mbox_sync(struct Context *ctx, int *index_hint) for (int i = 0; i < ctx->mailbox->msg_count; i++) { - struct Header *hdr = ctx->hdrs[i]; + struct Header *hdr = ctx->mailbox->hdrs[i]; char buf[16]; snprintf(buf, sizeof(buf), "%d", NHDR(hdr)->article_num); @@ -2475,10 +2475,10 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid) } /* parse header */ - if (ctx->mailbox->msg_count == ctx->hdrmax) + if (ctx->mailbox->msg_count == ctx->mailbox->hdrmax) mx_alloc_memory(ctx); - ctx->hdrs[ctx->mailbox->msg_count] = mutt_header_new(); - struct Header *hdr = ctx->hdrs[ctx->mailbox->msg_count]; + ctx->mailbox->hdrs[ctx->mailbox->msg_count] = mutt_header_new(); + struct Header *hdr = ctx->mailbox->hdrs[ctx->mailbox->msg_count]; hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData)); hdr->env = mutt_rfc822_read_header(fp, hdr, false, false); mutt_file_fclose(&fp); @@ -2533,7 +2533,7 @@ static int fetch_children(char *line, void *data) if (!line || sscanf(line, ANUM, &anum) != 1) return 0; for (unsigned int i = 0; i < cc->ctx->mailbox->msg_count; i++) - if (NHDR(cc->ctx->hdrs[i])->article_num == anum) + if (NHDR(cc->ctx->mailbox->hdrs[i])->article_num == anum) return 0; if (cc->num >= cc->max) { diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 2275f3fc3..c888248eb 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -1154,7 +1154,7 @@ static void append_message(struct Context *ctx, notmuch_query_t *q, mutt_debug(2, "nm: appending message, i=%d, id=%s, path=%s\n", ctx->mailbox->msg_count, notmuch_message_get_message_id(msg), path); - if (ctx->mailbox->msg_count >= ctx->hdrmax) + if (ctx->mailbox->msg_count >= ctx->mailbox->hdrmax) { mutt_debug(2, "nm: allocate mx memory\n"); mx_alloc_memory(ctx); @@ -1195,7 +1195,7 @@ static void append_message(struct Context *ctx, notmuch_query_t *q, h->active = true; h->index = ctx->mailbox->msg_count; ctx->size += h->content->length + h->content->offset - h->content->hdr_offset; - ctx->hdrs[ctx->mailbox->msg_count] = h; + ctx->mailbox->hdrs[ctx->mailbox->msg_count] = h; ctx->mailbox->msg_count++; if (newpath) @@ -2501,7 +2501,7 @@ static int nm_mbox_close(struct Context *ctx) for (int i = 0; i < ctx->mailbox->msg_count; i++) { - struct Header *h = ctx->hdrs[i]; + struct Header *h = ctx->mailbox->hdrs[i]; if (h) { free_hdrdata(h->data); @@ -2553,7 +2553,7 @@ static int nm_mbox_check(struct Context *ctx, int *index_hint) data->noprogress = true; for (int i = 0; i < ctx->mailbox->msg_count; i++) - ctx->hdrs[i]->active = false; + ctx->mailbox->hdrs[i]->active = false; limit = get_limit(data); @@ -2615,7 +2615,7 @@ static int nm_mbox_check(struct Context *ctx, int *index_hint) for (int i = 0; i < ctx->mailbox->msg_count; i++) { - if (!ctx->hdrs[i]->active) + if (!ctx->mailbox->hdrs[i]->active) { occult = true; break; @@ -2671,7 +2671,7 @@ static int nm_mbox_sync(struct Context *ctx, int *index_hint) for (int i = 0; i < ctx->mailbox->msg_count; i++) { char old[PATH_MAX], new[PATH_MAX]; - struct Header *h = ctx->hdrs[i]; + struct Header *h = ctx->mailbox->hdrs[i]; struct NmHdrData *hd = h->data; if (!ctx->quiet) @@ -2738,7 +2738,7 @@ static int nm_msg_open(struct Context *ctx, struct Message *msg, int msgno) { if (!ctx || !msg) return 1; - struct Header *cur = ctx->hdrs[msgno]; + struct Header *cur = ctx->mailbox->hdrs[msgno]; char path[PATH_MAX]; char *folder = nm_header_get_folder(cur); diff --git a/pager.c b/pager.c index 335b95231..f66eb65a3 100644 --- a/pager.c +++ b/pager.c @@ -2357,7 +2357,7 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e { for (i = oldcount; i < Context->mailbox->msg_count; i++) { - struct Header *h = Context->hdrs[i]; + struct Header *h = Context->mailbox->hdrs[i]; if (h && !h->read) { @@ -2376,7 +2376,7 @@ 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->hdrs[Context->v2r[rd.index->current]]->index; + index_hint = Context->mailbox->hdrs[Context->v2r[rd.index->current]]->index; bool q = Context->quiet; Context->quiet = true; @@ -2389,9 +2389,9 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e * 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->hdrs[Context->v2r[rd.index->current]]) + if (extra->hdr != Context->mailbox->hdrs[Context->v2r[rd.index->current]]) { - extra->hdr = Context->hdrs[Context->v2r[rd.index->current]]; + extra->hdr = Context->mailbox->hdrs[Context->v2r[rd.index->current]]; break; } } diff --git a/pattern.c b/pattern.c index 1c52bc898..5b79f87a3 100644 --- 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)->hdrs[(c)->v2r[(c)->menu->current]])) +#define CTX_MSGNO(c) (HMSG((c)->mailbox->hdrs[(c)->v2r[(c)->menu->current]])) #define MUTT_MAXRANGE -1 @@ -981,7 +981,7 @@ static bool msg_search(struct Context *ctx, struct Pattern *pat, int msgno) FILE *fp = NULL; long lng = 0; - struct Header *h = ctx->hdrs[msgno]; + struct Header *h = ctx->mailbox->hdrs[msgno]; #ifdef USE_FMEMOPEN char *temp = NULL; size_t tempsize; @@ -2187,17 +2187,17 @@ bool mutt_limit_current_thread(struct Header *h) for (int i = 0; i < Context->mailbox->msg_count; i++) { - Context->hdrs[i]->virtual = -1; - Context->hdrs[i]->limited = false; - Context->hdrs[i]->collapsed = false; - Context->hdrs[i]->num_hidden = 0; + Context->mailbox->hdrs[i]->virtual = -1; + Context->mailbox->hdrs[i]->limited = false; + Context->mailbox->hdrs[i]->collapsed = false; + Context->mailbox->hdrs[i]->num_hidden = 0; - if (top_of_thread(Context->hdrs[i]) == me) + if (top_of_thread(Context->mailbox->hdrs[i]) == me) { - struct Body *body = Context->hdrs[i]->content; + struct Body *body = Context->mailbox->hdrs[i]->content; - Context->hdrs[i]->virtual = Context->vcount; - Context->hdrs[i]->limited = true; + Context->mailbox->hdrs[i]->virtual = Context->vcount; + Context->mailbox->hdrs[i]->limited = true; Context->v2r[Context->vcount] = i; Context->vcount++; Context->vsize += (body->length + body->offset - body->hdr_offset); @@ -2261,17 +2261,18 @@ int mutt_pattern_func(int op, char *prompt) { mutt_progress_update(&progress, i, -1); /* new limit pattern implicitly uncollapses all threads */ - Context->hdrs[i]->virtual = -1; - Context->hdrs[i]->limited = false; - Context->hdrs[i]->collapsed = false; - Context->hdrs[i]->num_hidden = 0; - if (mutt_pattern_exec(pat, MUTT_MATCH_FULL_ADDRESS, Context, Context->hdrs[i], NULL)) + Context->mailbox->hdrs[i]->virtual = -1; + Context->mailbox->hdrs[i]->limited = false; + Context->mailbox->hdrs[i]->collapsed = false; + Context->mailbox->hdrs[i]->num_hidden = 0; + if (mutt_pattern_exec(pat, MUTT_MATCH_FULL_ADDRESS, Context, + Context->mailbox->hdrs[i], NULL)) { - Context->hdrs[i]->virtual = Context->vcount; - Context->hdrs[i]->limited = true; + Context->mailbox->hdrs[i]->virtual = Context->vcount; + Context->mailbox->hdrs[i]->limited = true; Context->v2r[Context->vcount] = i; Context->vcount++; - struct Body *b = Context->hdrs[i]->content; + struct Body *b = Context->mailbox->hdrs[i]->content; Context->vsize += b->length + b->offset - b->hdr_offset + padding; } } @@ -2282,21 +2283,21 @@ int mutt_pattern_func(int op, char *prompt) { mutt_progress_update(&progress, i, -1); if (mutt_pattern_exec(pat, MUTT_MATCH_FULL_ADDRESS, Context, - Context->hdrs[Context->v2r[i]], NULL)) + Context->mailbox->hdrs[Context->v2r[i]], NULL)) { switch (op) { case MUTT_UNDELETE: - mutt_set_flag(Context, Context->hdrs[Context->v2r[i]], MUTT_PURGE, 0); + mutt_set_flag(Context, Context->mailbox->hdrs[Context->v2r[i]], MUTT_PURGE, 0); /* fallthrough */ case MUTT_DELETE: - mutt_set_flag(Context, Context->hdrs[Context->v2r[i]], MUTT_DELETE, - (op == MUTT_DELETE)); + mutt_set_flag(Context, Context->mailbox->hdrs[Context->v2r[i]], + MUTT_DELETE, (op == MUTT_DELETE)); break; case MUTT_TAG: case MUTT_UNTAG: - mutt_set_flag(Context, Context->hdrs[Context->v2r[i]], MUTT_TAG, - (op == MUTT_TAG)); + mutt_set_flag(Context, Context->mailbox->hdrs[Context->v2r[i]], + MUTT_TAG, (op == MUTT_TAG)); break; } } @@ -2398,7 +2399,7 @@ int mutt_search_command(int cur, int op) if (OptSearchInvalid) { for (int i = 0; i < Context->mailbox->msg_count; i++) - Context->hdrs[i]->searched = false; + Context->mailbox->hdrs[i]->searched = false; #ifdef USE_IMAP if (Context->mailbox->magic == MUTT_IMAP && imap_search(Context, SearchPattern) < 0) return -1; @@ -2440,7 +2441,7 @@ int mutt_search_command(int cur, int op) } } - struct Header *h = Context->hdrs[Context->v2r[i]]; + struct Header *h = Context->mailbox->hdrs[Context->v2r[i]]; if (h->searched) { /* if we've already evaluated this message, use the cached value */ diff --git a/pop/pop.c b/pop/pop.c index 4c4be1c72..32a9652a8 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -219,25 +219,25 @@ static int fetch_uidl(char *line, void *data) return -1; for (i = 0; i < ctx->mailbox->msg_count; i++) - if (mutt_str_strcmp(line, ctx->hdrs[i]->data) == 0) + if (mutt_str_strcmp(line, ctx->mailbox->hdrs[i]->data) == 0) break; if (i == ctx->mailbox->msg_count) { mutt_debug(1, "new header %d %s\n", index, line); - if (i >= ctx->hdrmax) + if (i >= ctx->mailbox->hdrmax) mx_alloc_memory(ctx); ctx->mailbox->msg_count++; - ctx->hdrs[i] = mutt_header_new(); - ctx->hdrs[i]->data = mutt_str_strdup(line); + ctx->mailbox->hdrs[i] = mutt_header_new(); + ctx->mailbox->hdrs[i]->data = mutt_str_strdup(line); } - else if (ctx->hdrs[i]->index != index - 1) + else if (ctx->mailbox->hdrs[i]->index != index - 1) pop_data->clear_cache = true; - ctx->hdrs[i]->refno = index; - ctx->hdrs[i]->index = index - 1; + ctx->mailbox->hdrs[i]->refno = index; + ctx->mailbox->hdrs[i]->index = index - 1; return 0; } @@ -263,7 +263,8 @@ static int msg_cache_check(const char *id, struct BodyCache *bcache, void *data) for (int i = 0; i < ctx->mailbox->msg_count; i++) { /* if the id we get is known for a header: done (i.e. keep in cache) */ - if (ctx->hdrs[i]->data && (mutt_str_strcmp(ctx->hdrs[i]->data, id) == 0)) + if (ctx->mailbox->hdrs[i]->data && + (mutt_str_strcmp(ctx->mailbox->hdrs[i]->data, id) == 0)) return 0; } @@ -324,7 +325,7 @@ static int pop_fetch_headers(struct Context *ctx) pop_data->clear_cache = false; for (int i = 0; i < ctx->mailbox->msg_count; i++) - ctx->hdrs[i]->refno = -1; + ctx->mailbox->hdrs[i]->refno = -1; const int old_count = ctx->mailbox->msg_count; int ret = pop_fetch_data(pop_data, "UIDL\r\n", NULL, fetch_uidl, ctx); @@ -361,9 +362,9 @@ static int pop_fetch_headers(struct Context *ctx) int i, deleted; for (i = 0, deleted = 0; i < old_count; i++) { - if (ctx->hdrs[i]->refno == -1) + if (ctx->mailbox->hdrs[i]->refno == -1) { - ctx->hdrs[i]->deleted = true; + ctx->mailbox->hdrs[i]->deleted = true; deleted++; } } @@ -381,12 +382,13 @@ static int pop_fetch_headers(struct Context *ctx) if (!ctx->quiet) mutt_progress_update(&progress, i + 1 - old_count, -1); #ifdef USE_HCACHE - void *data = mutt_hcache_fetch(hc, ctx->hdrs[i]->data, strlen(ctx->hdrs[i]->data)); + void *data = mutt_hcache_fetch(hc, ctx->mailbox->hdrs[i]->data, + strlen(ctx->mailbox->hdrs[i]->data)); if (data) { - char *uidl = mutt_str_strdup(ctx->hdrs[i]->data); - int refno = ctx->hdrs[i]->refno; - int index = ctx->hdrs[i]->index; + char *uidl = mutt_str_strdup(ctx->mailbox->hdrs[i]->data); + int refno = ctx->mailbox->hdrs[i]->refno; + int index = ctx->mailbox->hdrs[i]->index; /* - POP dynamically numbers headers and relies on h->refno * to map messages; so restore header and overwrite restored * refno with current refno, same for index @@ -397,23 +399,23 @@ static int pop_fetch_headers(struct Context *ctx) */ struct Header *h = mutt_hcache_restore((unsigned char *) data); mutt_hcache_free(hc, &data); - mutt_header_free(&ctx->hdrs[i]); - ctx->hdrs[i] = h; - ctx->hdrs[i]->refno = refno; - ctx->hdrs[i]->index = index; - ctx->hdrs[i]->data = uidl; + mutt_header_free(&ctx->mailbox->hdrs[i]); + ctx->mailbox->hdrs[i] = h; + ctx->mailbox->hdrs[i]->refno = refno; + ctx->mailbox->hdrs[i]->index = index; + ctx->mailbox->hdrs[i]->data = uidl; ret = 0; hcached = true; } else #endif - if ((ret = pop_read_header(pop_data, ctx->hdrs[i])) < 0) + if ((ret = pop_read_header(pop_data, ctx->mailbox->hdrs[i])) < 0) break; #ifdef USE_HCACHE else { - mutt_hcache_store(hc, ctx->hdrs[i]->data, strlen(ctx->hdrs[i]->data), - ctx->hdrs[i], 0); + mutt_hcache_store(hc, ctx->mailbox->hdrs[i]->data, + strlen(ctx->mailbox->hdrs[i]->data), ctx->mailbox->hdrs[i], 0); } #endif @@ -429,20 +431,20 @@ static int pop_fetch_headers(struct Context *ctx) * - if we don't have a body: new */ const bool bcached = - (mutt_bcache_exists(pop_data->bcache, cache_id(ctx->hdrs[i]->data)) == 0); - ctx->hdrs[i]->old = false; - ctx->hdrs[i]->read = false; + (mutt_bcache_exists(pop_data->bcache, cache_id(ctx->mailbox->hdrs[i]->data)) == 0); + ctx->mailbox->hdrs[i]->old = false; + ctx->mailbox->hdrs[i]->read = false; if (hcached) { if (bcached) - ctx->hdrs[i]->read = true; + ctx->mailbox->hdrs[i]->read = true; else if (MarkOld) - ctx->hdrs[i]->old = true; + ctx->mailbox->hdrs[i]->old = true; } else { if (bcached) - ctx->hdrs[i]->read = true; + ctx->mailbox->hdrs[i]->read = true; } ctx->mailbox->msg_count++; @@ -459,7 +461,7 @@ static int pop_fetch_headers(struct Context *ctx) if (ret < 0) { for (int i = ctx->mailbox->msg_count; i < new_count; i++) - mutt_header_free(&ctx->hdrs[i]); + mutt_header_free(&ctx->mailbox->hdrs[i]); return ret; } @@ -614,7 +616,7 @@ static int pop_msg_open(struct Context *ctx, struct Message *msg, int msgno) struct Progress progressbar; struct PopData *pop_data = ctx->mailbox->data; struct PopCache *cache = NULL; - struct Header *h = ctx->hdrs[msgno]; + struct Header *h = ctx->mailbox->hdrs[msgno]; unsigned short bcache = 1; /* see if we already have the message in body cache */ @@ -733,7 +735,7 @@ static int pop_msg_open(struct Context *ctx, struct Message *msg, int msgno) fgets(buf, sizeof(buf), msg->fp); while (!feof(msg->fp)) { - ctx->hdrs[msgno]->lines++; + ctx->mailbox->hdrs[msgno]->lines++; fgets(buf, sizeof(buf), msg->fp); } @@ -794,27 +796,28 @@ static int pop_mbox_sync(struct Context *ctx, int *index_hint) for (i = 0, j = 0, ret = 0; ret == 0 && i < ctx->mailbox->msg_count; i++) { - if (ctx->hdrs[i]->deleted && ctx->hdrs[i]->refno != -1) + if (ctx->mailbox->hdrs[i]->deleted && ctx->mailbox->hdrs[i]->refno != -1) { j++; if (!ctx->quiet) mutt_progress_update(&progress, j, -1); - snprintf(buf, sizeof(buf), "DELE %d\r\n", ctx->hdrs[i]->refno); + snprintf(buf, sizeof(buf), "DELE %d\r\n", ctx->mailbox->hdrs[i]->refno); ret = pop_query(pop_data, buf, sizeof(buf)); if (ret == 0) { - mutt_bcache_del(pop_data->bcache, cache_id(ctx->hdrs[i]->data)); + mutt_bcache_del(pop_data->bcache, cache_id(ctx->mailbox->hdrs[i]->data)); #ifdef USE_HCACHE - mutt_hcache_delete(hc, ctx->hdrs[i]->data, strlen(ctx->hdrs[i]->data)); + mutt_hcache_delete(hc, ctx->mailbox->hdrs[i]->data, + strlen(ctx->mailbox->hdrs[i]->data)); #endif } } #ifdef USE_HCACHE - if (ctx->hdrs[i]->changed) + if (ctx->mailbox->hdrs[i]->changed) { - mutt_hcache_store(hc, ctx->hdrs[i]->data, strlen(ctx->hdrs[i]->data), - ctx->hdrs[i], 0); + mutt_hcache_store(hc, ctx->mailbox->hdrs[i]->data, + strlen(ctx->mailbox->hdrs[i]->data), ctx->mailbox->hdrs[i], 0); } #endif } diff --git a/pop/pop_lib.c b/pop/pop_lib.c index 29976d794..47179a499 100644 --- a/pop/pop_lib.c +++ b/pop/pop_lib.c @@ -589,9 +589,9 @@ static int check_uidl(char *line, void *data) for (int i = 0; i < ctx->mailbox->msg_count; i++) { - if (mutt_str_strcmp(ctx->hdrs[i]->data, line) == 0) + if (mutt_str_strcmp(ctx->mailbox->hdrs[i]->data, line) == 0) { - ctx->hdrs[i]->refno = index; + ctx->mailbox->hdrs[i]->refno = index; break; } } @@ -626,7 +626,7 @@ int pop_reconnect(struct Context *ctx) MUTT_PROGRESS_SIZE, NetInc, 0); for (int i = 0; i < ctx->mailbox->msg_count; i++) - ctx->hdrs[i]->refno = -1; + ctx->mailbox->hdrs[i]->refno = -1; ret = pop_fetch_data(pop_data, "UIDL\r\n", &progressbar, check_uidl, ctx); if (ret == -2) diff --git a/postpone.c b/postpone.c index 364331a86..45b07d217 100644 --- a/postpone.c +++ b/postpone.c @@ -197,8 +197,8 @@ static void post_entry(char *buf, size_t buflen, struct Menu *menu, int num) { struct Context *ctx = menu->data; - mutt_make_string_flags(buf, buflen, NONULL(IndexFormat), ctx, ctx->hdrs[num], - MUTT_FORMAT_ARROWCURSOR); + mutt_make_string_flags(buf, buflen, NONULL(IndexFormat), ctx, + ctx->mailbox->hdrs[num], MUTT_FORMAT_ARROWCURSOR); } /** @@ -233,7 +233,7 @@ static struct Header *select_msg(void) case OP_DELETE: case OP_UNDELETE: /* should deleted draft messages be saved in the trash folder? */ - mutt_set_flag(PostContext, PostContext->hdrs[menu->current], + mutt_set_flag(PostContext, PostContext->mailbox->hdrs[menu->current], MUTT_DELETE, (i == OP_DELETE) ? 1 : 0); PostCount = PostContext->mailbox->msg_count - PostContext->deleted; if (Resolve && menu->current < menu->max - 1) @@ -266,7 +266,7 @@ static struct Header *select_msg(void) Sort = orig_sort; mutt_menu_pop_current(menu); mutt_menu_destroy(&menu); - return r > -1 ? PostContext->hdrs[r] : NULL; + return r > -1 ? PostContext->mailbox->hdrs[r] : NULL; } /** @@ -310,7 +310,7 @@ int mutt_get_postponed(struct Context *ctx, struct Header *hdr, if (PostContext->mailbox->msg_count == 1) { /* only one message, so just use that one. */ - h = PostContext->hdrs[0]; + h = PostContext->mailbox->hdrs[0]; } else if (!(h = select_msg())) { diff --git a/score.c b/score.c index 99540ed30..f70f246e5 100644 --- a/score.c +++ b/score.c @@ -78,8 +78,8 @@ void mutt_check_rescore(struct Context *ctx) for (int i = 0; ctx && i < ctx->mailbox->msg_count; i++) { - mutt_score_message(ctx, ctx->hdrs[i], true); - ctx->hdrs[i]->pair = 0; + mutt_score_message(ctx, ctx->mailbox->hdrs[i], true); + ctx->mailbox->hdrs[i]->pair = 0; } } OptNeedRescore = false; diff --git a/send.c b/send.c index 55dac6629..8cf32cad0 100644 --- a/send.c +++ b/send.c @@ -911,7 +911,7 @@ static void make_reference_headers(struct Envelope *curenv, for (int i = 0; i < ctx->mailbox->msg_count; i++) { if (message_is_tagged(ctx, i)) - mutt_add_to_reference_headers(env, ctx->hdrs[i]->env); + mutt_add_to_reference_headers(env, ctx->mailbox->hdrs[i]->env); } } else @@ -950,7 +950,7 @@ static int envelope_defaults(struct Envelope *env, struct Context *ctx, if (!message_is_tagged(ctx, i)) continue; - cur = ctx->hdrs[i]; + cur = ctx->mailbox->hdrs[i]; curenv = cur->env; break; } @@ -991,7 +991,7 @@ static int envelope_defaults(struct Envelope *env, struct Context *ctx, if (!message_is_tagged(ctx, i)) continue; - if (mutt_fetch_recips(env, ctx->hdrs[i]->env, flags) == -1) + if (mutt_fetch_recips(env, ctx->mailbox->hdrs[i]->env, flags) == -1) return -1; } } @@ -1052,7 +1052,7 @@ static int generate_body(FILE *tempfp, struct Header *msg, int flags, if (!message_is_tagged(ctx, i)) continue; - if (include_reply(ctx, ctx->hdrs[i], tempfp) == -1) + if (include_reply(ctx, ctx->mailbox->hdrs[i], tempfp) == -1) { mutt_error(_("Could not include all requested messages")); return -1; @@ -1091,7 +1091,7 @@ static int generate_body(FILE *tempfp, struct Header *msg, int flags, if (!message_is_tagged(ctx, i)) continue; - tmp = mutt_make_message_attach(ctx, ctx->hdrs[i], false); + tmp = mutt_make_message_attach(ctx, ctx->mailbox->hdrs[i], false); if (last) { last->next = tmp; @@ -1114,7 +1114,7 @@ static int generate_body(FILE *tempfp, struct Header *msg, int flags, for (i = 0; i < ctx->mailbox->msg_count; i++) { if (message_is_tagged(ctx, i)) - include_forward(ctx, ctx->hdrs[i], tempfp); + include_forward(ctx, ctx->mailbox->hdrs[i], tempfp); } } } @@ -2419,7 +2419,8 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, { if (message_is_tagged(ctx, i)) { - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_REPLIED, is_reply(ctx->hdrs[i], msg)); + mutt_set_flag(ctx, ctx->mailbox->hdrs[i], MUTT_REPLIED, + is_reply(ctx->mailbox->hdrs[i], msg)); } } } diff --git a/sendlib.c b/sendlib.c index a75eedd6a..fe198d38b 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2968,7 +2968,7 @@ static int bounce_message(FILE *fp, struct Header *h, struct Address *to, /* Try to bounce each message out, aborting if we get any failures. */ for (int i = 0; i < Context->mailbox->msg_count; i++) if (message_is_tagged(Context, i)) - rc |= bounce_message(fp, Context->hdrs[i], to, resent_from, env_from); + rc |= bounce_message(fp, Context->mailbox->hdrs[i], to, resent_from, env_from); return rc; } diff --git a/sort.c b/sort.c index 363b800d5..082fd34aa 100644 --- a/sort.c +++ b/sort.c @@ -378,7 +378,7 @@ void mutt_sort_headers(struct Context *ctx, bool init) if (OptNeedRescore && Score) { for (int i = 0; i < ctx->mailbox->msg_count; i++) - mutt_score_message(ctx, ctx->hdrs[i], true); + mutt_score_message(ctx, ctx->mailbox->hdrs[i], true); } OptNeedRescore = false; @@ -413,13 +413,14 @@ void mutt_sort_headers(struct Context *ctx, bool init) return; } else - qsort((void *) ctx->hdrs, ctx->mailbox->msg_count, sizeof(struct Header *), sortfunc); + qsort((void *) ctx->mailbox->hdrs, ctx->mailbox->msg_count, + sizeof(struct Header *), sortfunc); /* adjust the virtual message numbers */ ctx->vcount = 0; for (int i = 0; i < ctx->mailbox->msg_count; i++) { - struct Header *cur = ctx->hdrs[i]; + struct Header *cur = ctx->mailbox->hdrs[i]; if (cur->virtual != -1 || (cur->collapsed && (!ctx->pattern || cur->limited))) { cur->virtual = ctx->vcount;