diff --git a/compmbox/compress.c b/compmbox/compress.c index 1b7174176f0..3c191f23d9d 100644 --- a/compmbox/compress.c +++ b/compmbox/compress.c @@ -557,7 +557,6 @@ static int comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) /** * comp_mbox_check - Check for new mail - Implements MxOps::mbox_check() * @param m Mailbox - * @param index_hint Currently selected mailbox * @retval 0 Mailbox OK * @retval #MUTT_REOPENED The mailbox was closed and reopened * @retval -1 Mailbox bad @@ -569,7 +568,7 @@ static int comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) * * The return codes are picked to match mx_mbox_check(). */ -static int comp_mbox_check(struct Mailbox *m, int *index_hint) +static int comp_mbox_check(struct Mailbox *m) { if (!m || !m->compress_info) return -1; @@ -596,7 +595,7 @@ static int comp_mbox_check(struct Mailbox *m, int *index_hint) if (rc == 0) return -1; - return ops->mbox_check(m, index_hint); + return ops->mbox_check(m); } /** @@ -605,7 +604,7 @@ static int comp_mbox_check(struct Mailbox *m, int *index_hint) * Changes in NeoMutt only affect the tmp file. * Calling comp_mbox_sync() will commit them to the compressed file. */ -static int comp_mbox_sync(struct Mailbox *m, int *index_hint) +static int comp_mbox_sync(struct Mailbox *m) { if (!m || !m->compress_info) return -1; @@ -628,11 +627,11 @@ static int comp_mbox_sync(struct Mailbox *m, int *index_hint) return -1; } - int rc = comp_mbox_check(m, index_hint); + int rc = comp_mbox_check(m); if (rc != 0) goto sync_cleanup; - rc = ops->mbox_sync(m, index_hint); + rc = ops->mbox_sync(m); if (rc != 0) goto sync_cleanup; diff --git a/imap/imap.c b/imap/imap.c index 1899fc1f99a..0c93c1d103b 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2102,12 +2102,11 @@ static int imap_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) /** * imap_mbox_check - Check for new mail - Implements MxOps::mbox_check() - * @param m Mailbox - * @param index_hint Remember our place in the index + * @param m Mailbox * @retval >0 Success, e.g. #MUTT_REOPENED * @retval -1 Failure */ -static int imap_mbox_check(struct Mailbox *m, int *index_hint) +static int imap_mbox_check(struct Mailbox *m) { if (!m) return -1; diff --git a/index.c b/index.c index b40fefc13bf..0c13b9a4867 100644 --- a/index.c +++ b/index.c @@ -608,22 +608,14 @@ static void update_index_unthreaded(struct Context *ctx, int check, int oldcount * @param ctx Mailbox * @param check Flags, e.g. #MUTT_REOPENED * @param oldcount How many items are currently in the index - * @param index_hint Remember our place in the index + * @param curr_msgid Remember our place in the index */ -void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcount, int index_hint) +void update_index(struct Menu *menu, struct Context *ctx, int check, + int oldcount, const char *curr_msgid) { if (!menu || !ctx) return; - /* take note of the current message */ - if (oldcount) - { - if (menu->current < ctx->mailbox->vcount) - menu->oldcurrent = index_hint; - else - oldcount = 0; /* invalid message number! */ - } - if ((C_Sort & SORT_MASK) == SORT_THREADS) update_index_threaded(ctx, check, oldcount); else @@ -638,7 +630,7 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun struct Email *e = mutt_get_virt_email(ctx->mailbox, i); if (!e) continue; - if (e->index == menu->oldcurrent) + if (mutt_str_equal(e->env->message_id, curr_msgid)) { menu->current = i; break; @@ -675,11 +667,11 @@ static int mailbox_index_observer(struct NotifyCallback *nc) * @param menu Current Menu * @param m Mailbox * @param oldcount How many items are currently in the index - * @param index_hint Remember our place in the index + * @param curr_msgid Remember our place in the index * @param read_only Open Mailbox in read-only mode */ -static void change_folder_mailbox(struct Menu *menu, struct Mailbox *m, - int *oldcount, int *index_hint, bool read_only) +static void change_folder_mailbox(struct Menu *menu, struct Mailbox *m, int *oldcount, + const char *curr_msgid, bool read_only) { if (!m) return; @@ -710,7 +702,7 @@ static void change_folder_mailbox(struct Menu *menu, struct Mailbox *m, mutt_monitor_add(NULL); #endif if ((check == MUTT_NEW_MAIL) || (check == MUTT_REOPENED)) - update_index(menu, Context, check, *oldcount, *index_hint); + update_index(menu, Context, check, *oldcount, curr_msgid); FREE(&new_last_folder); OptSearchInvalid = true; @@ -779,11 +771,12 @@ static void change_folder_mailbox(struct Menu *menu, struct Mailbox *m, * @param buf Folder to change to * @param buflen Length of buffer * @param oldcount How many items are currently in the index - * @param index_hint Remember our place in the index + * @param curr_msgid Remember our place in the index * @param read_only Open Mailbox in read-only mode */ -static struct Mailbox *change_folder_notmuch(struct Menu *menu, char *buf, int buflen, - int *oldcount, int *index_hint, bool read_only) +static struct Mailbox *change_folder_notmuch(struct Menu *menu, char *buf, + int buflen, int *oldcount, + const char *curr_msgid, bool read_only) { if (!nm_url_from_query(NULL, buf, buflen)) { @@ -792,7 +785,7 @@ static struct Mailbox *change_folder_notmuch(struct Menu *menu, char *buf, int b } struct Mailbox *m_query = mx_path_resolve(buf); - change_folder_mailbox(menu, m_query, oldcount, index_hint, read_only); + change_folder_mailbox(menu, m_query, oldcount, curr_msgid, read_only); return m_query; } #endif @@ -803,12 +796,13 @@ static struct Mailbox *change_folder_notmuch(struct Menu *menu, char *buf, int b * @param buf Folder to change to * @param buflen Length of buffer * @param oldcount How many items are currently in the index - * @param index_hint Remember our place in the index + * @param curr_msgid Remember our place in the index * @param pager_return Return to the pager afterwards * @param read_only Open Mailbox in read-only mode */ -static void change_folder_string(struct Menu *menu, char *buf, size_t buflen, int *oldcount, - int *index_hint, bool *pager_return, bool read_only) +static void change_folder_string(struct Menu *menu, char *buf, size_t buflen, + int *oldcount, const char *curr_msgid, + bool *pager_return, bool read_only) { #ifdef USE_NNTP if (OptNews) @@ -829,7 +823,7 @@ static void change_folder_string(struct Menu *menu, char *buf, size_t buflen, in struct Mailbox *m = mailbox_find_name(buf); if (m) { - change_folder_mailbox(menu, m, oldcount, index_hint, read_only); + change_folder_mailbox(menu, m, oldcount, curr_msgid, read_only); *pager_return = false; } else @@ -841,7 +835,7 @@ static void change_folder_string(struct Menu *menu, char *buf, size_t buflen, in *pager_return = false; struct Mailbox *m = mx_path_resolve(buf); - change_folder_mailbox(menu, m, oldcount, index_hint, read_only); + change_folder_mailbox(menu, m, oldcount, curr_msgid, read_only); } /** @@ -1143,7 +1137,7 @@ int mutt_index_menu(struct MuttWindow *dlg) bool tag = false; /* has the tag-prefix command been pressed? */ int newcount = -1; int oldcount = -1; - int index_hint = 0; /* used to restore cursor position */ + char *curr_msgid = NULL; /* used to restore cursor position */ bool do_mailbox_notify = true; int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */ int attach_msg = OptAttachMsg; @@ -1225,9 +1219,9 @@ int mutt_index_menu(struct MuttWindow *dlg) * modified underneath us.) */ struct Email *e_cur = get_cur_email(Context, menu); - index_hint = e_cur ? e_cur->index : 0; + mutt_str_replace(&curr_msgid, e_cur ? e_cur->env->message_id : NULL); - int check = mx_mbox_check(Context->mailbox, &index_hint); + int check = mx_mbox_check(Context->mailbox); if (check < 0) { if (!Context->mailbox || (mutt_buffer_is_empty(&Context->mailbox->pathbuf))) @@ -1278,7 +1272,7 @@ int mutt_index_menu(struct MuttWindow *dlg) { bool verbose = Context->mailbox->verbose; Context->mailbox->verbose = false; - update_index(menu, Context, check, oldcount, index_hint); + update_index(menu, Context, check, oldcount, curr_msgid); Context->mailbox->verbose = verbose; menu->max = Context->mailbox->vcount; } @@ -1867,7 +1861,7 @@ int mutt_index_menu(struct MuttWindow *dlg) else { if ((check == MUTT_NEW_MAIL) || (check == MUTT_REOPENED)) - update_index(menu, Context, check, oldcount, index_hint); + update_index(menu, Context, check, oldcount, curr_msgid); menu->redraw = REDRAW_FULL; /* new mail arrived? */ OptSearchInvalid = true; @@ -2015,7 +2009,7 @@ int mutt_index_menu(struct MuttWindow *dlg) if (check != 0) { if ((check == MUTT_NEW_MAIL) || (check == MUTT_REOPENED)) - update_index(menu, Context, check, oldcount, index_hint); + update_index(menu, Context, check, oldcount, curr_msgid); OptSearchInvalid = true; menu->redraw = REDRAW_FULL; break; @@ -2056,7 +2050,7 @@ int mutt_index_menu(struct MuttWindow *dlg) e = mutt_get_virt_email(Context->mailbox, newidx); } - int check = mx_mbox_sync(Context->mailbox, &index_hint); + int check = mx_mbox_sync(Context->mailbox); if (check == 0) { if (e && (Context->mailbox->vcount != ovc)) @@ -2074,7 +2068,7 @@ int mutt_index_menu(struct MuttWindow *dlg) OptSearchInvalid = true; } else if ((check == MUTT_NEW_MAIL) || (check == MUTT_REOPENED)) - update_index(menu, Context, check, oc, index_hint); + update_index(menu, Context, check, oc, curr_msgid); /* do a sanity check even if mx_mbox_sync failed. */ @@ -2150,7 +2144,7 @@ int mutt_index_menu(struct MuttWindow *dlg) if (buf[strlen(buf) - 1] == '>') buf[strlen(buf) - 1] = '\0'; - change_folder_notmuch(menu, buf, sizeof(buf), &oldcount, &index_hint, false); + change_folder_notmuch(menu, buf, sizeof(buf), &oldcount, curr_msgid, false); // If notmuch doesn't contain the message, we're left in an empty // vfolder. No messages are found, but nm_read_entire_thread assumes @@ -2324,7 +2318,7 @@ int mutt_index_menu(struct MuttWindow *dlg) char *query_unencoded = mutt_str_dup(buf); struct Mailbox *m_query = - change_folder_notmuch(menu, buf, sizeof(buf), &oldcount, &index_hint, + change_folder_notmuch(menu, buf, sizeof(buf), &oldcount, curr_msgid, (op == OP_MAIN_VFOLDER_FROM_QUERY_READONLY)); if (m_query) { @@ -2355,7 +2349,7 @@ int mutt_index_menu(struct MuttWindow *dlg) } nm_query_window_backward(); mutt_str_copy(buf, C_NmQueryWindowCurrentSearch, sizeof(buf)); - change_folder_notmuch(menu, buf, sizeof(buf), &oldcount, &index_hint, false); + change_folder_notmuch(menu, buf, sizeof(buf), &oldcount, curr_msgid, false); break; } @@ -2375,14 +2369,14 @@ int mutt_index_menu(struct MuttWindow *dlg) } nm_query_window_forward(); mutt_str_copy(buf, C_NmQueryWindowCurrentSearch, sizeof(buf)); - change_folder_notmuch(menu, buf, sizeof(buf), &oldcount, &index_hint, false); + change_folder_notmuch(menu, buf, sizeof(buf), &oldcount, curr_msgid, false); break; } #endif #ifdef USE_SIDEBAR case OP_SIDEBAR_OPEN: - change_folder_mailbox(menu, sb_get_highlight(), &oldcount, &index_hint, false); + change_folder_mailbox(menu, sb_get_highlight(), &oldcount, curr_msgid, false); break; #endif @@ -2404,7 +2398,7 @@ int mutt_index_menu(struct MuttWindow *dlg) break; } - change_folder_mailbox(menu, m, &oldcount, &index_hint, false); + change_folder_mailbox(menu, m, &oldcount, curr_msgid, false); break; } @@ -2455,13 +2449,13 @@ int mutt_index_menu(struct MuttWindow *dlg) struct Mailbox *m = mx_mbox_find2(mutt_b2s(folderbuf)); if (m) { - change_folder_mailbox(menu, m, &oldcount, &index_hint, read_only); + change_folder_mailbox(menu, m, &oldcount, curr_msgid, read_only); pager_return = false; } else { change_folder_string(menu, folderbuf->data, folderbuf->dsize, - &oldcount, &index_hint, &pager_return, read_only); + &oldcount, curr_msgid, &pager_return, read_only); } changefoldercleanup: @@ -2527,13 +2521,13 @@ int mutt_index_menu(struct MuttWindow *dlg) struct Mailbox *m = mx_mbox_find2(mutt_b2s(folderbuf)); if (m) { - change_folder_mailbox(menu, m, &oldcount, &index_hint, read_only); + change_folder_mailbox(menu, m, &oldcount, curr_msgid, read_only); pager_return = false; } else { change_folder_string(menu, folderbuf->data, folderbuf->dsize, - &oldcount, &index_hint, &pager_return, read_only); + &oldcount, curr_msgid, &pager_return, read_only); } menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_MAIN, IndexNewsHelp); @@ -2581,7 +2575,7 @@ int mutt_index_menu(struct MuttWindow *dlg) e_cur = get_cur_email(Context, menu); if (!e_cur) break; - int hint = e_cur->index; + mutt_str_replace(&curr_msgid, e_cur->env->message_id); op = mutt_display_message(win_index, win_ibar, win_pager, win_pbar, Context->mailbox, e_cur); @@ -2597,7 +2591,7 @@ int mutt_index_menu(struct MuttWindow *dlg) in_pager = true; menu->oldcurrent = menu->current; if (Context && Context->mailbox) - update_index(menu, Context, MUTT_NEW_MAIL, Context->mailbox->msg_count, hint); + update_index(menu, Context, MUTT_NEW_MAIL, Context->mailbox->msg_count, curr_msgid); continue; } @@ -3980,6 +3974,7 @@ int mutt_index_menu(struct MuttWindow *dlg) mutt_menu_pop_current(menu); mutt_menu_free(&menu); + FREE(&curr_msgid); return close; } diff --git a/index.h b/index.h index bd9ad066289..e7bab58e047 100644 --- a/index.h +++ b/index.h @@ -48,7 +48,7 @@ void index_make_entry(char *buf, size_t buflen, struct Menu *menu, int line); void mutt_draw_statusline(int cols, const char *buf, size_t buflen); int mutt_index_menu(struct MuttWindow *dlg); void mutt_set_header_color(struct Mailbox *m, struct Email *e); -void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcount, int index_hint); +void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcount, const char *curr_msgid); struct MuttWindow *index_pager_init(void); void index_pager_shutdown(struct MuttWindow *dlg); int mutt_dlgindex_observer(struct NotifyCallback *nc); diff --git a/maildir/maildir.c b/maildir/maildir.c index f0037de8269..d56b29cb119 100644 --- a/maildir/maildir.c +++ b/maildir/maildir.c @@ -364,7 +364,7 @@ static int maildir_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) * already knew about. We don't treat either subdirectory differently, as mail * could be copied directly into the cur directory from another agent. */ -int maildir_mbox_check(struct Mailbox *m, int *index_hint) +int maildir_mbox_check(struct Mailbox *m) { if (!m) return -1; diff --git a/maildir/mh.c b/maildir/mh.c index 4ee5b6d227e..b02422217ef 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -590,7 +590,7 @@ static int mh_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) * * Don't change this code unless you _really_ understand what happens. */ -int mh_mbox_check(struct Mailbox *m, int *index_hint) +int mh_mbox_check(struct Mailbox *m) { if (!m) return -1; diff --git a/maildir/private.h b/maildir/private.h index 6dca608f80a..71dceb91ca1 100644 --- a/maildir/private.h +++ b/maildir/private.h @@ -75,13 +75,13 @@ struct MhSequences /* MXAPI shared functions */ int maildir_ac_add (struct Account *a, struct Mailbox *m); struct Account *maildir_ac_find (struct Account *a, const char *path); -int maildir_mbox_check (struct Mailbox *m, int *index_hint); +int maildir_mbox_check (struct Mailbox *m); int maildir_path_canon (char *buf, size_t buflen); int maildir_path_parent(char *buf, size_t buflen); int maildir_path_pretty(char *buf, size_t buflen, const char *folder); -int mh_mbox_check (struct Mailbox *m, int *index_hint); +int mh_mbox_check (struct Mailbox *m); int mh_mbox_close (struct Mailbox *m); -int mh_mbox_sync (struct Mailbox *m, int *index_hint); +int mh_mbox_sync (struct Mailbox *m); int mh_msg_close (struct Mailbox *m, struct Message *msg); int mh_msg_save_hcache (struct Mailbox *m, struct Email *e); diff --git a/maildir/shared.c b/maildir/shared.c index 5c5c5aa5eee..adc9b361778 100644 --- a/maildir/shared.c +++ b/maildir/shared.c @@ -1698,7 +1698,7 @@ int maildir_path_parent(char *buf, size_t buflen) * * @note The flag retvals come from a call to a backend sync function */ -int mh_mbox_sync(struct Mailbox *m, int *index_hint) +int mh_mbox_sync(struct Mailbox *m) { if (!m) return -1; @@ -1709,9 +1709,9 @@ int mh_mbox_sync(struct Mailbox *m, int *index_hint) int check; if (m->type == MUTT_MH) - check = mh_mbox_check(m, index_hint); + check = mh_mbox_check(m); else - check = maildir_mbox_check(m, index_hint); + check = maildir_mbox_check(m); if (check < 0) return check; diff --git a/mbox/mbox.c b/mbox/mbox.c index 1913206f9c1..bfd22099719 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -534,11 +534,10 @@ static int mbox_parse_mailbox(struct Mailbox *m) /** * reopen_mailbox - Close and reopen a mailbox * @param m Mailbox - * @param index_hint Current email * @retval >0 Success, e.g. #MUTT_REOPENED, #MUTT_NEW_MAIL * @retval -1 Error */ -static int reopen_mailbox(struct Mailbox *m, int *index_hint) +static int reopen_mailbox(struct Mailbox *m) { if (!m) return -1; @@ -672,10 +671,7 @@ static int reopen_mailbox(struct Mailbox *m, int *index_hint) if (found) { - /* this is best done here */ - if (index_hint && (*index_hint == j)) - *index_hint = i; - + m->changed = true; if (e_old[j]->changed) { /* Only update the flags if the old header was changed; @@ -1028,14 +1024,13 @@ static int mbox_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) /** * mbox_mbox_check - Check for new mail - Implements MxOps::mbox_check() * @param[in] m Mailbox - * @param[out] index_hint Keep track of current index selection * @retval #MUTT_REOPENED Mailbox has been reopened * @retval #MUTT_NEW_MAIL New mail has arrived * @retval #MUTT_LOCKED Couldn't lock the file * @retval 0 No change * @retval -1 Error */ -static int mbox_mbox_check(struct Mailbox *m, int *index_hint) +static int mbox_mbox_check(struct Mailbox *m) { if (!m) return -1; @@ -1137,7 +1132,7 @@ static int mbox_mbox_check(struct Mailbox *m, int *index_hint) if (modified) { - if (reopen_mailbox(m, index_hint) != -1) + if (reopen_mailbox(m) != -1) { mailbox_changed(m, NT_MAILBOX_INVALID); if (unlock) @@ -1161,7 +1156,7 @@ static int mbox_mbox_check(struct Mailbox *m, int *index_hint) /** * mbox_mbox_sync - Save changes to the Mailbox - Implements MxOps::mbox_sync() */ -static int mbox_mbox_sync(struct Mailbox *m, int *index_hint) +static int mbox_mbox_sync(struct Mailbox *m) { if (!m) return -1; @@ -1215,7 +1210,7 @@ static int mbox_mbox_sync(struct Mailbox *m, int *index_hint) } /* Check to make sure that the file hasn't changed on disk */ - i = mbox_mbox_check(m, index_hint); + i = mbox_mbox_check(m); if ((i == MUTT_NEW_MAIL) || (i == MUTT_REOPENED)) { /* new mail arrived, or mailbox reopened */ diff --git a/mutt/string.c b/mutt/string.c index fd19dc78eb7..d130c953c67 100644 --- a/mutt/string.c +++ b/mutt/string.c @@ -439,6 +439,7 @@ char *mutt_strn_cat(char *d, size_t l, const char *s, size_t sl) * mutt_str_replace - Replace one string with another * @param[out] p String to replace * @param[in] s New string + * @retval ptr Replaced string * * This function free()s the original string, strdup()s the new string and * overwrites the pointer to the first string. @@ -447,13 +448,14 @@ char *mutt_strn_cat(char *d, size_t l, const char *s, size_t sl) * * @note Free *p afterwards to handle the case that *p and s reference the same memory */ -void mutt_str_replace(char **p, const char *s) +char *mutt_str_replace(char **p, const char *s) { if (!p) - return; + return NULL; const char *tmp = *p; *p = mutt_str_dup(s); FREE(&tmp); + return *p; } /** diff --git a/mutt/string2.h b/mutt/string2.h index ecc72478893..43c44c8ff1e 100644 --- a/mutt/string2.h +++ b/mutt/string2.h @@ -75,7 +75,7 @@ size_t mutt_str_lws_len(const char *s, size_t n); size_t mutt_str_lws_rlen(const char *s, size_t n); const char *mutt_str_next_word(const char *s); void mutt_str_remove_trailing_ws(char *s); -void mutt_str_replace(char **p, const char *s); +char * mutt_str_replace(char **p, const char *s); char * mutt_str_skip_email_wsp(const char *s); char * mutt_str_skip_whitespace(const char *p); const char *mutt_str_sysexit(int e); diff --git a/mutt_header.c b/mutt_header.c index 50092e99d01..a3adb34ab0f 100644 --- a/mutt_header.c +++ b/mutt_header.c @@ -107,8 +107,7 @@ static bool label_message(struct Mailbox *m, struct Email *e, char *new_label) if (e->env->x_label) label_ref_dec(m, e->env->x_label); - mutt_str_replace(&e->env->x_label, new_label); - if (e->env->x_label) + if (mutt_str_replace(&e->env->x_label, new_label)) label_ref_inc(m, e->env->x_label); e->changed = true; diff --git a/mx.c b/mx.c index 923b06ce09b..677cde56bf1 100644 --- a/mx.c +++ b/mx.c @@ -459,11 +459,10 @@ void mx_fastclose_mailbox(struct Mailbox *m) /** * sync_mailbox - save changes to disk * @param m Mailbox - * @param index_hint Current email * @retval 0 Success * @retval -1 Failure */ -static int sync_mailbox(struct Mailbox *m, int *index_hint) +static int sync_mailbox(struct Mailbox *m) { if (!m || !m->mx_ops || !m->mx_ops->mbox_sync) return -1; @@ -474,7 +473,7 @@ static int sync_mailbox(struct Mailbox *m, int *index_hint) mutt_message(_("Writing %s..."), mailbox_path(m)); } - int rc = m->mx_ops->mbox_sync(m, index_hint); + int rc = m->mx_ops->mbox_sync(m); if (rc != 0) { mutt_debug(LL_DEBUG2, "mbox_sync returned: %d\n", rc); @@ -842,7 +841,7 @@ int mx_mbox_close(struct Context **ptr) if (m->changed || (m->msg_deleted != 0)) { - int check = sync_mailbox(ctx->mailbox, NULL); + int check = sync_mailbox(ctx->mailbox); if (check != 0) { rc = check; @@ -903,7 +902,6 @@ int mx_mbox_close(struct Context **ptr) /** * mx_mbox_sync - Save changes to mailbox * @param[in] m Mailbox - * @param[out] index_hint Currently selected Email * @retval #MUTT_REOPENED mailbox has been externally modified * @retval #MUTT_NEW_MAIL new mail has arrived * @retval 0 Success @@ -911,7 +909,7 @@ int mx_mbox_close(struct Context **ptr) * * @note The flag retvals come from a call to a backend sync function */ -int mx_mbox_sync(struct Mailbox *m, int *index_hint) +int mx_mbox_sync(struct Mailbox *m) { if (!m) return -1; @@ -992,7 +990,7 @@ int mx_mbox_sync(struct Mailbox *m, int *index_hint) rc = imap_sync_mailbox(m, purge, false); else #endif - rc = sync_mailbox(m, index_hint); + rc = sync_mailbox(m); if (rc >= 0) { #ifdef USE_IMAP @@ -1109,17 +1107,16 @@ struct Message *mx_msg_open_new(struct Mailbox *m, struct Email *e, MsgOpenFlags /** * mx_mbox_check - Check for new mail - Wrapper for MxOps::mbox_check() * @param m Mailbox - * @param index_hint Current email * @retval >0 Success, e.g. #MUTT_NEW_MAIL * @retval 0 Success, no change * @retval -1 Failure */ -int mx_mbox_check(struct Mailbox *m, int *index_hint) +int mx_mbox_check(struct Mailbox *m) { if (!m || !m->mx_ops) return -1; - int rc = m->mx_ops->mbox_check(m, index_hint); + int rc = m->mx_ops->mbox_check(m); if ((rc == MUTT_NEW_MAIL) || (rc == MUTT_REOPENED)) mailbox_changed(m, NT_MAILBOX_INVALID); diff --git a/mx.h b/mx.h index e7a5cda95f3..93df0a7ff3d 100644 --- a/mx.h +++ b/mx.h @@ -147,11 +147,10 @@ struct MxOps /** * mbox_check - Check for new mail * @param m Mailbox - * @param index_hint Remember our place in the index * @retval >0 Success, e.g. #MUTT_REOPENED * @retval -1 Error */ - int (*mbox_check) (struct Mailbox *m, int *index_hint); + int (*mbox_check) (struct Mailbox *m); /** * mbox_check_stats - Check the Mailbox statistics @@ -166,11 +165,10 @@ struct MxOps /** * mbox_sync - Save changes to the Mailbox * @param m Mailbox to sync - * @param index_hint Remember our place in the index * @retval 0 Success * @retval -1 Failure */ - int (*mbox_sync) (struct Mailbox *m, int *index_hint); + int (*mbox_sync) (struct Mailbox *m); /** * mbox_close - Close a Mailbox @@ -294,11 +292,11 @@ struct MxOps }; /* Wrappers for the Mailbox API, see MxOps */ -int mx_mbox_check (struct Mailbox *m, int *index_hint); +int mx_mbox_check (struct Mailbox *m); int mx_mbox_check_stats(struct Mailbox *m, int flags); int mx_mbox_close (struct Context **ptr); struct Context *mx_mbox_open (struct Mailbox *m, OpenMailboxFlags flags); -int mx_mbox_sync (struct Mailbox *m, int *index_hint); +int mx_mbox_sync (struct Mailbox *m); int mx_msg_close (struct Mailbox *m, struct Message **msg); int mx_msg_commit (struct Mailbox *m, struct Message *msg); struct Message *mx_msg_open_new (struct Mailbox *m, struct Email *e, MsgOpenFlags flags); diff --git a/nntp/nntp.c b/nntp/nntp.c index d6b1c451ed5..923e6f1e860 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -2578,13 +2578,12 @@ static int nntp_mbox_open(struct Mailbox *m) /** * nntp_mbox_check - Check for new mail - Implements MxOps::mbox_check() * @param m Mailbox - * @param index_hint Current message (UNUSED) * @retval #MUTT_REOPENED Articles have been renumbered or removed from server * @retval #MUTT_NEW_MAIL New articles found * @retval 0 No change * @retval -1 Lost connection */ -static int nntp_mbox_check(struct Mailbox *m, int *index_hint) +static int nntp_mbox_check(struct Mailbox *m) { if (!m) return -1; @@ -2604,7 +2603,7 @@ static int nntp_mbox_check(struct Mailbox *m, int *index_hint) * * @note May also return values from check_mailbox() */ -static int nntp_mbox_sync(struct Mailbox *m, int *index_hint) +static int nntp_mbox_sync(struct Mailbox *m) { if (!m) return -1; diff --git a/notmuch/notmuch.c b/notmuch/notmuch.c index 80f3817ca3c..33d2f7fe186 100644 --- a/notmuch/notmuch.c +++ b/notmuch/notmuch.c @@ -2196,14 +2196,13 @@ static int nm_mbox_open(struct Mailbox *m) /** * nm_mbox_check - Check for new mail - Implements MxOps::mbox_check() * @param m Mailbox - * @param index_hint Remember our place in the index * @retval -1 Error * @retval 0 Success * @retval #MUTT_NEW_MAIL New mail has arrived * @retval #MUTT_REOPENED Mailbox closed and reopened * @retval #MUTT_FLAGS Flags have changed */ -static int nm_mbox_check(struct Mailbox *m, int *index_hint) +static int nm_mbox_check(struct Mailbox *m) { if (!m) return -1; @@ -2335,7 +2334,7 @@ static int nm_mbox_check(struct Mailbox *m, int *index_hint) /** * nm_mbox_sync - Save changes to the Mailbox - Implements MxOps::mbox_sync() */ -static int nm_mbox_sync(struct Mailbox *m, int *index_hint) +static int nm_mbox_sync(struct Mailbox *m) { if (!m) return -1; diff --git a/pager.c b/pager.c index 57914f08160..cbcf636321e 100644 --- a/pager.c +++ b/pager.c @@ -2351,10 +2351,9 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P if (Context && Context->mailbox && !OptAttachMsg) { - int index_hint = 0; /* used to restore cursor position */ int oldcount = Context->mailbox->msg_count; /* check for new mail */ - int check = mx_mbox_check(Context->mailbox, &index_hint); + int check = mx_mbox_check(Context->mailbox); if (check < 0) { if (!Context->mailbox || mutt_buffer_is_empty(&Context->mailbox->pathbuf)) @@ -2395,11 +2394,9 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P if (!e) continue; - index_hint = e->index; - bool verbose = Context->mailbox->verbose; Context->mailbox->verbose = false; - update_index(rd.menu, Context, check, oldcount, index_hint); + update_index(rd.menu, Context, check, oldcount, e->env->message_id); Context->mailbox->verbose = verbose; rd.menu->max = Context->mailbox->vcount; diff --git a/pop/pop.c b/pop/pop.c index 2fa36b13dd0..698a73334ed 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -881,7 +881,7 @@ static int pop_mbox_open(struct Mailbox *m) /** * pop_mbox_check - Check for new mail - Implements MxOps::mbox_check() */ -static int pop_mbox_check(struct Mailbox *m, int *index_hint) +static int pop_mbox_check(struct Mailbox *m) { if (!m) return -1; @@ -922,7 +922,7 @@ static int pop_mbox_check(struct Mailbox *m, int *index_hint) * * Update POP mailbox, delete messages from server */ -static int pop_mbox_sync(struct Mailbox *m, int *index_hint) +static int pop_mbox_sync(struct Mailbox *m) { if (!m) return -1; diff --git a/postpone.c b/postpone.c index d38541176a1..7e60c626a2d 100644 --- a/postpone.c +++ b/postpone.c @@ -359,7 +359,7 @@ int mutt_get_postponed(struct Context *ctx, struct Email *hdr, * segvs, but probably the flag needs to be reset after downloading * headers in imap_open_mailbox(). */ - mx_mbox_check(ctx_post->mailbox, NULL); + mx_mbox_check(ctx_post->mailbox); if (ctx_post->mailbox->msg_count == 0) {