Skip to content

Commit

Permalink
config: handler.c
Browse files Browse the repository at this point in the history
Eliminate Config global variables from handler.c
  • Loading branch information
flatcap committed Mar 24, 2021
1 parent 6693e97 commit 682d103
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 54 deletions.
55 changes: 31 additions & 24 deletions handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@
#include <libintl.h>
#endif

/* These Config Variables are only used in handler.c */
bool C_HonorDisposition; ///< Config: Don't display MIME parts inline if they have a disposition of 'attachment'
bool C_ImplicitAutoview; ///< Config: Display MIME attachments inline if a 'copiousoutput' mailcap entry exists
bool C_IncludeEncrypted; ///< Config: Whether to include encrypted content when replying
bool C_IncludeOnlyFirst; ///< Config: Only include the first attachment when replying
struct Slist *C_PreferredLanguages; ///< Config: Preferred languages for multilingual MIME
bool C_ReflowText; ///< Config: Reformat paragraphs of 'format=flowed' text
char *C_ShowMultipartAlternative; ///< Config: How to display 'multipart/alternative' MIME parts

#define BUFI_SIZE 1000
#define BUFO_SIZE 2000

Expand Down Expand Up @@ -488,7 +479,9 @@ static bool is_autoview(struct Body *b)

snprintf(type, sizeof(type), "%s/%s", TYPE(b), b->subtype);

if (C_ImplicitAutoview)
const bool c_implicit_autoview =
cs_subset_bool(NeoMutt->sub, "implicit_autoview");
if (c_implicit_autoview)
{
/* $implicit_autoview is essentially the same as "auto_view *" */
is_av = true;
Expand Down Expand Up @@ -686,7 +679,8 @@ static int text_plain_handler(struct Body *b, struct State *s)

while ((buf = mutt_file_read_line(buf, &sz, s->fp_in, NULL, MUTT_RL_NO_FLAGS)))
{
if (!mutt_str_equal(buf, "-- ") && C_TextFlowed)
const bool c_text_flowed = cs_subset_bool(NeoMutt->sub, "text_flowed");
if (!mutt_str_equal(buf, "-- ") && c_text_flowed)
{
size_t len = mutt_str_len(buf);
while ((len > 0) && (buf[len - 1] == ' '))
Expand Down Expand Up @@ -1067,13 +1061,15 @@ static int alternative_handler(struct Body *a, struct State *s)
mutt_file_copy_bytes(s->fp_in, s->fp_out, choice->offset - choice->hdr_offset);
}

if (mutt_str_equal("info", C_ShowMultipartAlternative))
const char *const c_show_multipart_alternative =
cs_subset_string(NeoMutt->sub, "show_multipart_alternative");
if (mutt_str_equal("info", c_show_multipart_alternative))
{
print_part_line(s, choice, 0);
}
mutt_body_handler(choice, s);

if (mutt_str_equal("info", C_ShowMultipartAlternative))
if (mutt_str_equal("info", c_show_multipart_alternative))
{
if (a->parts)
b = a->parts;
Expand Down Expand Up @@ -1148,15 +1144,17 @@ static int multilingual_handler(struct Body *a, struct State *s)
struct Body *zxx_part = NULL;
struct ListNode *np = NULL;

if (C_PreferredLanguages)
const struct Slist *c_preferred_languages =
cs_subset_slist(NeoMutt->sub, "preferred_languages");
if (c_preferred_languages)
{
struct Buffer *langs = mutt_buffer_pool_get();
cs_subset_str_string_get(NeoMutt->sub, "preferred_languages", langs);
mutt_debug(LL_DEBUG2, "RFC8255 >> preferred_languages set in config to '%s'\n",
mutt_buffer_string(langs));
mutt_buffer_pool_release(&langs);

STAILQ_FOREACH(np, &C_PreferredLanguages->head, entries)
STAILQ_FOREACH(np, &c_preferred_languages->head, entries)
{
while (b)
{
Expand Down Expand Up @@ -1269,7 +1267,9 @@ static int multipart_handler(struct Body *a, struct State *s)
TYPE(p), NONULL(p->subtype));
}

if ((s->flags & MUTT_REPLYING) && C_IncludeOnlyFirst && (s->flags & MUTT_FIRSTDONE))
const bool c_include_only_first =
cs_subset_bool(NeoMutt->sub, "include_only_first");
if ((s->flags & MUTT_REPLYING) && c_include_only_first && (s->flags & MUTT_FIRSTDONE))
{
break;
}
Expand Down Expand Up @@ -1627,14 +1627,15 @@ int mutt_body_handler(struct Body *b, struct State *s)
{
if (mutt_istr_equal("plain", b->subtype))
{
const bool c_reflow_text = cs_subset_bool(NeoMutt->sub, "reflow_text");
/* avoid copying this part twice since removing the transfer-encoding is
* the only operation needed. */
if (((WithCrypto & APPLICATION_PGP) != 0) && mutt_is_application_pgp(b))
{
encrypted_handler = crypt_pgp_application_handler;
handler = encrypted_handler;
}
else if (C_ReflowText && mutt_istr_equal("flowed", mutt_param_get(&b->parameter, "format")))
else if (c_reflow_text && mutt_istr_equal("flowed", mutt_param_get(&b->parameter, "format")))
{
handler = rfc3676_handler;
}
Expand All @@ -1659,12 +1660,14 @@ int mutt_body_handler(struct Body *b, struct State *s)
}
else if (b->type == TYPE_MULTIPART)
{
if (!mutt_str_equal("inline", C_ShowMultipartAlternative) &&
const char *const c_show_multipart_alternative =
cs_subset_string(NeoMutt->sub, "show_multipart_alternative");
if (!mutt_str_equal("inline", c_show_multipart_alternative) &&
mutt_istr_equal("alternative", b->subtype))
{
handler = alternative_handler;
}
else if (!mutt_str_equal("inline", C_ShowMultipartAlternative) &&
else if (!mutt_str_equal("inline", c_show_multipart_alternative) &&
mutt_istr_equal("multilingual", b->subtype))
{
handler = multilingual_handler;
Expand Down Expand Up @@ -1716,15 +1719,19 @@ int mutt_body_handler(struct Body *b, struct State *s)
}
}

const bool c_honor_disposition =
cs_subset_bool(NeoMutt->sub, "honor_disposition");
/* only respect disposition == attachment if we're not
* displaying from the attachment menu (i.e. pager) */
if ((!C_HonorDisposition || ((b->disposition != DISP_ATTACH) || OptViewAttach)) &&
if ((!c_honor_disposition || ((b->disposition != DISP_ATTACH) || OptViewAttach)) &&
(plaintext || handler))
{
/* Prevent encrypted attachments from being included in replies
* unless $include_encrypted is set. */
const bool c_include_encrypted =
cs_subset_bool(NeoMutt->sub, "include_encrypted");
if ((s->flags & MUTT_REPLYING) && (s->flags & MUTT_FIRSTDONE) &&
encrypted_handler && !C_IncludeEncrypted)
encrypted_handler && !c_include_encrypted)
{
goto cleanup;
}
Expand All @@ -1743,7 +1750,7 @@ int mutt_body_handler(struct Body *b, struct State *s)
if (km_expand_key(keystroke, sizeof(keystroke),
km_find_func(MENU_PAGER, OP_VIEW_ATTACHMENTS)))
{
if (C_HonorDisposition && (b->disposition == DISP_ATTACH))
if (c_honor_disposition && (b->disposition == DISP_ATTACH))
{
/* L10N: %s expands to a keystroke/key binding, e.g. 'v'. */
mutt_buffer_printf(&msg, _("[-- This is an attachment (use '%s' to view this part) --]\n"),
Expand All @@ -1759,7 +1766,7 @@ int mutt_body_handler(struct Body *b, struct State *s)
}
else
{
if (C_HonorDisposition && (b->disposition == DISP_ATTACH))
if (c_honor_disposition && (b->disposition == DISP_ATTACH))
{
mutt_buffer_strcpy(&msg, _("[-- This is an attachment (need "
"'view-attachments' bound to key) --]\n"));
Expand All @@ -1774,7 +1781,7 @@ int mutt_body_handler(struct Body *b, struct State *s)
}
else
{
if (C_HonorDisposition && (b->disposition == DISP_ATTACH))
if (c_honor_disposition && (b->disposition == DISP_ATTACH))
{
mutt_buffer_strcpy(&msg, _("[-- This is an attachment --]\n"));
}
Expand Down
9 changes: 0 additions & 9 deletions handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@
struct Body;
struct State;

/* These Config Variables are only used in handler.c */
extern bool C_HonorDisposition;
extern bool C_ImplicitAutoview;
extern bool C_IncludeEncrypted;
extern bool C_IncludeOnlyFirst;
extern struct Slist *C_PreferredLanguages;
extern bool C_ReflowText;
extern char *C_ShowMultipartAlternative;

int mutt_body_handler(struct Body *b, struct State *s);
bool mutt_can_decode(struct Body *a);
void mutt_decode_attachment(struct Body *b, struct State *s);
Expand Down
42 changes: 21 additions & 21 deletions mutt_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,9 @@ struct ConfigDef MainVars[] = {
{ "header", DT_BOOL, &C_Header, false, 0, NULL,
"Include the message headers in the reply email (Weed applies)"
},
{ "honor_disposition", DT_BOOL, &C_HonorDisposition, false, 0, NULL,
"Don't display MIME parts inline if they have a disposition of 'attachment'"
},
{ "hostname", DT_STRING, &C_Hostname, 0, 0, NULL,
"Fully-qualified domain name of this machine"
},
{ "implicit_autoview", DT_BOOL, &C_ImplicitAutoview, false, 0, NULL,
"Display MIME attachments inline if a 'copiousoutput' mailcap entry exists"
},
{ "include_encrypted", DT_BOOL, &C_IncludeEncrypted, false, 0, NULL,
"Whether to include encrypted content when replying"
},
{ "include_only_first", DT_BOOL, &C_IncludeOnlyFirst, false, 0, NULL,
"Only include the first attachment when replying"
},
{ "indent_string", DT_STRING, &C_IndentString, IP "> ", 0, NULL,
"String used to indent 'reply' text"
},
Expand Down Expand Up @@ -388,9 +376,6 @@ struct ConfigDef MainVars[] = {
{ "postponed", DT_STRING|DT_MAILBOX|R_INDEX, &C_Postponed, IP "~/postponed", 0, NULL,
"Folder to store postponed messages"
},
{ "preferred_languages", DT_SLIST|SLIST_SEP_COMMA, &C_PreferredLanguages, 0, 0, NULL,
"Preferred languages for multilingual MIME"
},
{ "print", DT_QUAD, &C_Print, MUTT_ASKNO, 0, NULL,
"Confirm before printing a message"
},
Expand Down Expand Up @@ -421,9 +406,6 @@ struct ConfigDef MainVars[] = {
{ "reflow_space_quotes", DT_BOOL, &C_ReflowSpaceQuotes, true, 0, NULL,
"Insert spaces into reply quotes for 'format=flowed' messages"
},
{ "reflow_text", DT_BOOL, &C_ReflowText, true, 0, NULL,
"Reformat paragraphs of 'format=flowed' text"
},
{ "reflow_wrap", DT_NUMBER, &C_ReflowWrap, 78, 0, NULL,
"Maximum paragraph width for reformatting 'format=flowed' text"
},
Expand Down Expand Up @@ -463,9 +445,6 @@ struct ConfigDef MainVars[] = {
{ "shell", DT_STRING|DT_COMMAND, &C_Shell, IP "/bin/sh", 0, NULL,
"External command to run subshells in"
},
{ "show_multipart_alternative", DT_STRING, &C_ShowMultipartAlternative, 0, 0, multipart_validator,
"How to display 'multipart/alternative' MIME parts"
},
{ "simple_search", DT_STRING, &C_SimpleSearch, IP "~f %s | ~s %s", 0, NULL,
"Pattern to search for when search doesn't contain ~'s"
},
Expand Down Expand Up @@ -643,6 +622,9 @@ struct ConfigDef MainNoVars[] = {
{ "hide_top_missing", DT_BOOL|R_TREE|R_INDEX, NULL, true, 0, NULL,
"Don't indicate missing top message, in the thread tree"
},
{ "honor_disposition", DT_BOOL, NULL, false, 0, NULL,
"Don't display MIME parts inline if they have a disposition of 'attachment'"
},
#ifdef HAVE_LIBIDN
{ "idn_decode", DT_BOOL|R_MENU, NULL, true, 0, NULL,
"(idn) Decode international domain names"
Expand All @@ -651,6 +633,15 @@ struct ConfigDef MainNoVars[] = {
"(idn) Encode international domain names"
},
#endif
{ "implicit_autoview", DT_BOOL, NULL, false, 0, NULL,
"Display MIME attachments inline if a 'copiousoutput' mailcap entry exists"
},
{ "include_encrypted", DT_BOOL, NULL, false, 0, NULL,
"Whether to include encrypted content when replying"
},
{ "include_only_first", DT_BOOL, NULL, false, 0, NULL,
"Only include the first attachment when replying"
},
{ "keep_flagged", DT_BOOL, NULL, false, 0, NULL,
"Don't move flagged messages from `$spool_file` to `$mbox`"
},
Expand Down Expand Up @@ -699,6 +690,9 @@ struct ConfigDef MainNoVars[] = {
{ "pipe_split", DT_BOOL, NULL, false, 0, NULL,
"Run the pipe command on each message separately"
},
{ "preferred_languages", DT_SLIST|SLIST_SEP_COMMA, NULL, 0, 0, NULL,
"Preferred languages for multilingual MIME"
},
{ "print_decode", DT_BOOL, NULL, true, 0, NULL,
"Decode message before printing it"
},
Expand All @@ -708,6 +702,9 @@ struct ConfigDef MainNoVars[] = {
{ "prompt_after", DT_BOOL, NULL, true, 0, NULL,
"Pause after running an external pager"
},
{ "reflow_text", DT_BOOL, NULL, true, 0, NULL,
"Reformat paragraphs of 'format=flowed' text"
},
{ "reply_regex", DT_REGEX|R_INDEX|R_RESORT, NULL, IP "^((re|aw|sv)(\\[[0-9]+\\])*:[ \t]*)*", 0, reply_validator,
"Regex to match message reply subjects like 're: '"
},
Expand All @@ -717,6 +714,9 @@ struct ConfigDef MainNoVars[] = {
{ "send_charset", DT_STRING|DT_CHARSET_STRICT, NULL, IP "us-ascii:iso-8859-1:utf-8", 0, charset_validator,
"Character sets for outgoing mail"
},
{ "show_multipart_alternative", DT_STRING, NULL, 0, 0, multipart_validator,
"How to display 'multipart/alternative' MIME parts"
},
{ "sort_browser", DT_SORT|DT_SORT_REVERSE, NULL, SORT_ALPHA, IP SortBrowserMethods, NULL,
"Sort method for the browser"
},
Expand Down

0 comments on commit 682d103

Please sign in to comment.