From: Richard Russon Date: Fri, 11 Jan 2019 14:09:58 +0000 (+0000) Subject: mutt_make_string: separate Context from Mailbox X-Git-Tag: 2019-10-25~384 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fa5e3cfafc53349e6c1dbe284d5bd3f195a68b80;p=neomutt mutt_make_string: separate Context from Mailbox --- diff --git a/copy.c b/copy.c index 4beed6546..32966b125 100644 --- a/copy.c +++ b/copy.c @@ -632,7 +632,8 @@ int mutt_copy_message_fp(FILE *fpout, FILE *fpin, struct Email *e, int flags, in if (TextFlowed) mutt_str_strfcpy(prefix, ">", sizeof(prefix)); else - mutt_make_string_flags(prefix, sizeof(prefix), NONULL(IndentString), Context, e, 0); + mutt_make_string(prefix, sizeof(prefix), NONULL(IndentString), Context, + Context->mailbox, e); } if ((flags & MUTT_CM_NOHEADER) == 0) diff --git a/edit.c b/edit.c index bc2dd6549..68a97da23 100644 --- a/edit.c +++ b/edit.c @@ -226,7 +226,7 @@ static char **be_include_messages(char *msg, char **buf, int *bufmax, { setlocale(LC_TIME, NONULL(AttributionLocale)); mutt_make_string(tmp, sizeof(tmp) - 1, Attribution, Context, - Context->mailbox->emails[n]); + Context->mailbox, Context->mailbox->emails[n]); setlocale(LC_TIME, ""); strcat(tmp, "\n"); } diff --git a/hdrline.c b/hdrline.c index e9775f40f..5488d4ce2 100644 --- a/hdrline.c +++ b/hdrline.c @@ -560,6 +560,7 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co struct Email *e = hfi->email; struct Context *ctx = hfi->ctx; + struct Mailbox *m = hfi->m; if (!e || !e->env) return src; @@ -627,13 +628,13 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co /* fallthrough */ case 'b': - if (ctx) + if (m) { - p = strrchr(ctx->mailbox->path, '/'); + p = strrchr(m->path, '/'); if (p) mutt_str_strfcpy(buf, p + 1, buflen); else - mutt_str_strfcpy(buf, ctx->mailbox->path, buflen); + mutt_str_strfcpy(buf, m->path, buflen); } else mutt_str_strfcpy(buf, "(null)", buflen); @@ -849,16 +850,16 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co case 'e': snprintf(fmt, sizeof(fmt), "%%%sd", prec); - snprintf(buf, buflen, fmt, mutt_messages_in_thread(ctx->mailbox, e, 1)); + snprintf(buf, buflen, fmt, mutt_messages_in_thread(m, e, 1)); break; case 'E': if (!optional) { snprintf(fmt, sizeof(fmt), "%%%sd", prec); - snprintf(buf, buflen, fmt, mutt_messages_in_thread(ctx->mailbox, e, 0)); + snprintf(buf, buflen, fmt, mutt_messages_in_thread(m, e, 0)); } - else if (mutt_messages_in_thread(ctx->mailbox, e, 0) <= 1) + else if (mutt_messages_in_thread(m, e, 0) <= 1) optional = 0; break; @@ -1019,10 +1020,10 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co break; case 'm': - if (ctx) + if (m) { snprintf(fmt, sizeof(fmt), "%%%sd", prec); - snprintf(buf, buflen, fmt, ctx->mailbox->msg_count); + snprintf(buf, buflen, fmt, m->msg_count); } else mutt_str_strfcpy(buf, "(null)", buflen); @@ -1243,7 +1244,7 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co case 'X': { - int count = mutt_count_body_parts(ctx->mailbox, e); + int count = mutt_count_body_parts(m, e); /* The recursion allows messages without depth to return 0. */ if (optional) @@ -1447,17 +1448,19 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co * @param buf Buffer for the result * @param buflen Buffer length * @param s printf-line format string - * @param ctx Mailbox + * @param ctx Mailbox Context + * @param m Mailbox * @param e Email * @param flags Format flags */ -void mutt_make_string_flags(char *buf, size_t buflen, const char *s, - struct Context *ctx, struct Email *e, enum FormatFlag flags) +void mutt_make_string_flags(char *buf, size_t buflen, const char *s, struct Context *ctx, + struct Mailbox *m, struct Email *e, enum FormatFlag flags) { struct HdrFormatInfo hfi; hfi.email = e; hfi.ctx = ctx; + hfi.m = m; hfi.pager_progress = 0; mutt_expando_format(buf, buflen, 0, MuttIndexWindow->cols, s, diff --git a/hdrline.h b/hdrline.h index 0f706f1f2..76b14753f 100644 --- a/hdrline.h +++ b/hdrline.h @@ -43,15 +43,20 @@ extern struct MbTable *ToChars; struct HdrFormatInfo { struct Context *ctx; + struct Mailbox *m; struct Email *email; const char *pager_progress; }; bool mutt_is_mail_list(struct Address *addr); bool mutt_is_subscribed_list(struct Address *addr); -void mutt_make_string_flags(char *buf, size_t buflen, const char *s, struct Context *ctx, struct Email *e, enum FormatFlag flags); -void mutt_make_string_info(char *buf, size_t buflen, int cols, const char *s, struct HdrFormatInfo *hfi, enum FormatFlag flags); - -#define mutt_make_string(A, B, C, D, E) mutt_make_string_flags(A, B, C, D, E, 0) +void mutt_make_string_flags(char *buf, size_t buflen, const char *s, + struct Context *ctx, struct Mailbox *m, + struct Email *e, enum FormatFlag flags); +void mutt_make_string_info(char *buf, size_t buflen, int cols, const char *s, + struct HdrFormatInfo *hfi, enum FormatFlag flags); + +#define mutt_make_string(BUF, BUFLEN, S, CTX, M, E) \ + mutt_make_string_flags(BUF, BUFLEN, S, CTX, M, E, 0) #endif /* MUTT_HDRLINE_H */ diff --git a/hook.c b/hook.c index 9bd5bba6d..def309621 100644 --- a/hook.c +++ b/hook.c @@ -514,7 +514,8 @@ static int addr_hook(char *path, size_t pathlen, int type, struct Context *ctx, struct Mailbox *m = ctx ? ctx->mailbox : NULL; if ((mutt_pattern_exec(hook->pattern, 0, m, e, &cache) > 0) ^ hook->regex.not) { - mutt_make_string_flags(path, pathlen, hook->command, ctx, e, MUTT_FORMAT_PLAIN); + mutt_make_string_flags(path, pathlen, hook->command, ctx, ctx->mailbox, + e, MUTT_FORMAT_PLAIN); return 0; } } diff --git a/index.c b/index.c index 728cf3224..9f76869cd 100644 --- a/index.c +++ b/index.c @@ -732,7 +732,8 @@ void index_make_entry(char *buf, size_t buflen, struct Menu *menu, int line) } } - mutt_make_string_flags(buf, buflen, NONULL(IndexFormat), Context, e, flag); + mutt_make_string_flags(buf, buflen, NONULL(IndexFormat), Context, + Context->mailbox, e, flag); } /** diff --git a/postpone.c b/postpone.c index 5c2f30ea4..157a5e9b7 100644 --- a/postpone.c +++ b/postpone.c @@ -201,7 +201,7 @@ static void post_make_entry(char *buf, size_t buflen, struct Menu *menu, int lin { struct Context *ctx = menu->data; - mutt_make_string_flags(buf, buflen, NONULL(IndexFormat), ctx, + mutt_make_string_flags(buf, buflen, NONULL(IndexFormat), ctx, ctx->mailbox, ctx->mailbox->emails[line], MUTT_FORMAT_ARROWCURSOR); } diff --git a/recvattach.c b/recvattach.c index 58894db0e..dc102a9f9 100644 --- a/recvattach.c +++ b/recvattach.c @@ -258,7 +258,7 @@ const char *attach_format_str(char *buf, size_t buflen, size_t col, int cols, MessageFormat && aptr->content->email) { char s[SHORT_STRING]; - mutt_make_string_flags(s, sizeof(s), MessageFormat, NULL, + mutt_make_string_flags(s, sizeof(s), MessageFormat, NULL, NULL, aptr->content->email, MUTT_FORMAT_FORCESUBJ | MUTT_FORMAT_ARROWCURSOR); if (*s) diff --git a/recvcmd.c b/recvcmd.c index 05f1b81d3..6c632fa52 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -407,8 +407,8 @@ static void include_header(bool quote, FILE *ifp, struct Email *e, FILE *ofp, ch mutt_str_strfcpy(prefix2, prefix, sizeof(prefix2)); else if (!TextFlowed) { - mutt_make_string_flags(prefix2, sizeof(prefix2), NONULL(IndentString), - Context, e, 0); + mutt_make_string(prefix2, sizeof(prefix2), NONULL(IndentString), Context, + Context->mailbox, e); } else mutt_str_strfcpy(prefix2, ">", sizeof(prefix2)); @@ -501,8 +501,8 @@ static void attach_forward_bodies(FILE *fp, struct Email *e, struct AttachCtx *a { if (!TextFlowed) { - mutt_make_string_flags(prefix, sizeof(prefix), NONULL(IndentString), - Context, parent_hdr, 0); + mutt_make_string(prefix, sizeof(prefix), NONULL(IndentString), Context, + Context->mailbox, parent_hdr); } else mutt_str_strfcpy(prefix, ">", sizeof(prefix)); @@ -985,8 +985,8 @@ void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx, if (!TextFlowed) { - mutt_make_string_flags(prefix, sizeof(prefix), NONULL(IndentString), - Context, parent_hdr, 0); + mutt_make_string(prefix, sizeof(prefix), NONULL(IndentString), Context, + Context->mailbox, parent_hdr); } else mutt_str_strfcpy(prefix, ">", sizeof(prefix)); diff --git a/send.c b/send.c index c27897081..c1165710f 100644 --- a/send.c +++ b/send.c @@ -459,7 +459,7 @@ void mutt_forward_intro(struct Context *ctx, struct Email *cur, FILE *fp) char buf[LONG_STRING]; setlocale(LC_TIME, NONULL(AttributionLocale)); - mutt_make_string(buf, sizeof(buf), ForwardAttributionIntro, ctx, cur); + mutt_make_string(buf, sizeof(buf), ForwardAttributionIntro, ctx, ctx->mailbox, cur); setlocale(LC_TIME, ""); fputs(buf, fp); fputs("\n\n", fp); @@ -478,7 +478,7 @@ void mutt_forward_trailer(struct Context *ctx, struct Email *cur, FILE *fp) char buf[LONG_STRING]; setlocale(LC_TIME, NONULL(AttributionLocale)); - mutt_make_string(buf, sizeof(buf), ForwardAttributionTrailer, ctx, cur); + mutt_make_string(buf, sizeof(buf), ForwardAttributionTrailer, ctx, ctx->mailbox, cur); setlocale(LC_TIME, ""); fputc('\n', fp); fputs(buf, fp); @@ -543,7 +543,7 @@ void mutt_make_attribution(struct Context *ctx, struct Email *cur, FILE *out) char buf[LONG_STRING]; setlocale(LC_TIME, NONULL(AttributionLocale)); - mutt_make_string(buf, sizeof(buf), Attribution, ctx, cur); + mutt_make_string(buf, sizeof(buf), Attribution, ctx, ctx->mailbox, cur); setlocale(LC_TIME, ""); fputs(buf, out); fputc('\n', out); @@ -561,7 +561,7 @@ void mutt_make_post_indent(struct Context *ctx, struct Email *cur, FILE *out) return; char buf[STRING]; - mutt_make_string(buf, sizeof(buf), PostIndentString, ctx, cur); + mutt_make_string(buf, sizeof(buf), PostIndentString, ctx, ctx->mailbox, cur); fputs(buf, out); fputc('\n', out); } @@ -813,7 +813,7 @@ void mutt_make_forward_subject(struct Envelope *env, struct Context *ctx, struct char buf[STRING]; /* set the default subject for the message. */ - mutt_make_string(buf, sizeof(buf), NONULL(ForwardFormat), ctx, cur); + mutt_make_string(buf, sizeof(buf), NONULL(ForwardFormat), ctx, ctx->mailbox, cur); mutt_str_replace(&env->subject, buf); }