From: Ralph Corderoy Date: Mon, 14 Nov 2016 00:14:31 +0000 (+0000) Subject: mhstoresbr.c: Factor MIME-parameter-can-be-used-for-filename test. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/d3ddf0ff20a6dfddae0b1905fb54f215394ffe90?ds=sidebyside;hp=a59060598f60ebb02d85ff7f1efb2f9ca2f699f4 mhstoresbr.c: Factor MIME-parameter-can-be-used-for-filename test. It was several lines repeated each time, and it saves having to check they're all identical. The original test pressed on if the MIME parameter's value was an empty string; preserve that as it's spotted later on. --- diff --git a/uip/mhstoresbr.c b/uip/mhstoresbr.c index 210a91be..515699d8 100644 --- a/uip/mhstoresbr.c +++ b/uip/mhstoresbr.c @@ -40,6 +40,8 @@ struct mhstoreinfo { enum clobber_policy_t clobber_policy; /* -clobber selection */ }; +static bool use_param_as_filename(const char *p); + mhstoreinfo_t mhstoreinfo_create (CT *ct, char *pwd, const char *csw, int asw, int vsw) { mhstoreinfo_t info; @@ -431,12 +433,7 @@ store_external (CT ct, mhstoreinfo_t info) if (info->autosw) { char *cp; - if ((cp = e->eb_name) - && *cp != '/' - && *cp != '.' - && *cp != '|' - && *cp != '!' - && !strchr (cp, '%')) { + if ((cp = e->eb_name) && use_param_as_filename(cp)) { if (!ct->c_storeproc) ct->c_storeproc = mh_xstrdup(cp); if (!p->c_storeproc) @@ -1068,12 +1065,8 @@ get_storeproc (CT ct) * use that (RFC-2183). */ if (ct->c_dispo) { - if ((cp = get_param(ct->c_dispo_first, "filename", '_', 0)) - && *cp != '/' - && *cp != '.' - && *cp != '|' - && *cp != '!' - && !strchr (cp, '%')) { + if ((cp = get_param(ct->c_dispo_first, "filename", '_', 0)) && + use_param_as_filename(cp)) { ct->c_storeproc = mh_xstrdup(cp); free(cp); return; @@ -1087,12 +1080,8 @@ get_storeproc (CT ct) * the storeproc. */ ci = &ct->c_ctinfo; - if ((cp = get_param(ci->ci_first_pm, "name", '_', 0)) - && *cp != '/' - && *cp != '.' - && *cp != '|' - && *cp != '!' - && !strchr (cp, '%')) { + if ((cp = get_param(ci->ci_first_pm, "name", '_', 0)) && + use_param_as_filename(cp)) { ct->c_storeproc = mh_xstrdup(cp); } @@ -1349,5 +1338,12 @@ clobber_check (char *original_file, mhstoreinfo_t info) { return file; } +static bool use_param_as_filename(const char *p) +{ + /* Preserve result of original test that considered an empty string + * OK. */ + return !*p || (!strchr("/.|!", *p) && !strchr(p, '%')); +} + /* -clobber support */ /******************************************************************************/