From: Guyzmo Date: Tue, 10 Jan 2017 17:10:13 +0000 (+0100) Subject: Support for aborting mailbox loading X-Git-Tag: neomutt-20170128~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2b6a7543d5b95d86c14595b395380198d5f9c04;p=neomutt Support for aborting mailbox loading - Added new return value for mx_ops.open() signature: -2 value means aborted mailbox load ; - Added check for SigInt in mail loading routine Added support for Notmuch, Maildir and mbox. Closes #248 Closes #292 --- diff --git a/mbox.c b/mbox.c index f6000feaf..ee9fc0e14 100644 --- a/mbox.c +++ b/mbox.c @@ -126,6 +126,9 @@ int mmdf_parse_mailbox (CONTEXT *ctx) if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL) break; + if (SigInt == 1) + break; + if (mutt_strcmp (buf, MMDF_SEP) == 0) { loc = ftello (ctx->fp); @@ -220,7 +223,13 @@ int mmdf_parse_mailbox (CONTEXT *ctx) if (ctx->msgcount > oldmsgcount) mx_update_context (ctx, ctx->msgcount - oldmsgcount); - return (0); + if (SigInt == 1) + { + SigInt = 0; + return -2; + } + + return 0; } /* Note that this function is also called when new mail is appended to the @@ -273,7 +282,7 @@ int mbox_parse_mailbox (CONTEXT *ctx) } loc = ftello (ctx->fp); - while (fgets (buf, sizeof (buf), ctx->fp) != NULL) + while ((fgets (buf, sizeof (buf), ctx->fp) != NULL) && (SigInt != 0)) { if (is_from (buf, return_path, sizeof (return_path), &t)) { @@ -408,7 +417,13 @@ int mbox_parse_mailbox (CONTEXT *ctx) mx_update_context (ctx, count); } - return (0); + if (SigInt == 1) + { + SigInt = 0; + return -2; + } + + return 0; } #undef PREV diff --git a/mh.c b/mh.c index 792e3b91c..13f65484b 100644 --- a/mh.c +++ b/mh.c @@ -842,7 +842,7 @@ static int maildir_parse_dir (CONTEXT * ctx, struct maildir ***last, if ((dirp = opendir (buf)) == NULL) return -1; - while ((de = readdir (dirp)) != NULL) + while (((de = readdir (dirp)) != NULL) && (SigInt != 1)) { if ((ctx->magic == MUTT_MH && !mh_valid_message (de->d_name)) || (ctx->magic == MUTT_MAILDIR && *de->d_name == '.')) @@ -885,6 +885,12 @@ static int maildir_parse_dir (CONTEXT * ctx, struct maildir ***last, closedir (dirp); + if (SigInt == 1) + { + SigInt = 0; + return -2; + } + return 0; } diff --git a/mutt_notmuch.c b/mutt_notmuch.c index b693217fc..7646a25f2 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -1243,20 +1243,20 @@ static void append_thread(CONTEXT *ctx, notmuch_query_t *q, } } -static void read_mesgs_query(CONTEXT *ctx, notmuch_query_t *q, int dedup) +static bool read_mesgs_query(CONTEXT *ctx, notmuch_query_t *q, int dedup) { struct nm_ctxdata *data = get_ctxdata(ctx); int limit; notmuch_messages_t *msgs; if (!data) - return; + return false; limit = get_limit(data); #if LIBNOTMUCH_CHECK_VERSION(4,3,0) if (notmuch_query_search_messages_st(q, &msgs) != NOTMUCH_STATUS_SUCCESS) - return; + return false; #else msgs = notmuch_query_search_messages(q); #endif @@ -1264,24 +1264,30 @@ static void read_mesgs_query(CONTEXT *ctx, notmuch_query_t *q, int dedup) for (; notmuch_messages_valid(msgs) && ((limit == 0) || (ctx->msgcount < limit)); notmuch_messages_move_to_next(msgs)) { + if (SigInt == 1) + { + SigInt = 0; + return false; + } notmuch_message_t *m = notmuch_messages_get(msgs); append_message(ctx, q, m, dedup); notmuch_message_destroy(m); } + return true; } -static void read_threads_query(CONTEXT *ctx, notmuch_query_t *q, int dedup, +static bool read_threads_query(CONTEXT *ctx, notmuch_query_t *q, int dedup, int limit) { struct nm_ctxdata *data = get_ctxdata(ctx); notmuch_threads_t *threads; if (!data) - return; + return false; #if LIBNOTMUCH_CHECK_VERSION(4,3,0) if (notmuch_query_search_threads_st(q, &threads) != NOTMUCH_STATUS_SUCCESS) - return; + return false; #else threads = notmuch_query_search_threads(q); #endif @@ -1290,10 +1296,16 @@ static void read_threads_query(CONTEXT *ctx, notmuch_query_t *q, int dedup, ((limit == 0) || (ctx->msgcount < limit)); notmuch_threads_move_to_next(threads)) { + if (SigInt == 1) + { + SigInt = 0; + return false; + } notmuch_thread_t *thread = notmuch_threads_get(threads); append_thread(ctx, q, thread, dedup); notmuch_thread_destroy(thread); } + return true; } static notmuch_message_t *get_nm_message(notmuch_database_t *db, HEADER *hdr) @@ -2127,17 +2139,19 @@ static int nm_open_mailbox(CONTEXT *ctx) q = get_query(data, false); if (q) { + rc = 0; switch (get_query_type(data)) { case NM_QUERY_TYPE_MESGS: - read_mesgs_query(ctx, q, 0); + if (!read_mesgs_query(ctx, q, 0)) + rc = -2; break; case NM_QUERY_TYPE_THREADS: - read_threads_query(ctx, q, 0, get_limit(data)); + if (!read_threads_query(ctx, q, 0, get_limit(data))) + rc = -2; break; } notmuch_query_destroy(q); - rc = 0; } if (!is_longrun(data)) diff --git a/mx.c b/mx.c index a6781ba4d..7666e5408 100644 --- a/mx.c +++ b/mx.c @@ -672,7 +672,7 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx) rc = ctx->mx_ops->open(ctx); - if (rc == 0) + if ((rc == 0) || (rc == -2)) { if ((flags & MUTT_NOSORT) == 0) { @@ -684,6 +684,8 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx) } if (!ctx->quiet) mutt_clear_error (); + if (rc == -2) + mutt_error(_("Reading from %s interrupted..."), ctx->path); } else {