From: Kevin McCarthy Date: Sat, 22 Jun 2019 20:33:11 +0000 (-0700) Subject: Remove mutt_rfc1524_expand_filename() return value and checks X-Git-Tag: 2019-10-25~159^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d5059bd31312f8332ca556ac8c94ab83d3a613b;p=neomutt Remove mutt_rfc1524_expand_filename() return value and checks The return value was of dubious value. It returned 0 only for the case that a nametemplate was specified and it already matched the supplied oldfile. However, just because the nametemplate matched does not mean attachment handling in send-mode should skip the mutt_adv_mktemp() conversion, which includes a call to mutt_sanitize_filename(). We didn't do so if *no* nametemplate was supplied. Remove the return value from the function, and remove the checks and "special handing" in mutt_attach.c calls. Co-authored-by: Richard Russon --- diff --git a/mutt_attach.c b/mutt_attach.c index 43d823929..cf08b9dc4 100644 --- a/mutt_attach.c +++ b/mutt_attach.c @@ -134,20 +134,16 @@ int mutt_compose_attachment(struct Body *a) else mutt_buffer_strcpy(cmd, entry->composecommand); - if (mutt_rfc1524_expand_filename(entry->nametemplate, a->filename, newfile)) + mutt_rfc1524_expand_filename(entry->nametemplate, a->filename, newfile); + mutt_debug(LL_DEBUG1, "oldfile: %s\t newfile: %s\n", a->filename, mutt_b2s(newfile)); + if (mutt_file_symlink(a->filename, mutt_b2s(newfile)) == -1) { - mutt_debug(LL_DEBUG1, "oldfile: %s\t newfile: %s\n", a->filename, mutt_b2s(newfile)); - if (mutt_file_symlink(a->filename, mutt_b2s(newfile)) == -1) - { - if (mutt_yesorno(_("Can't match 'nametemplate', continue?"), MUTT_YES) != MUTT_YES) - goto bailout; - mutt_buffer_strcpy(newfile, a->filename); - } - else - unlink_newfile = true; + if (mutt_yesorno(_("Can't match 'nametemplate', continue?"), MUTT_YES) != MUTT_YES) + goto bailout; + mutt_buffer_strcpy(newfile, a->filename); } else - mutt_buffer_strcpy(newfile, a->filename); + unlink_newfile = true; if (mutt_rfc1524_expand_command(a, mutt_b2s(newfile), type, cmd)) { @@ -272,20 +268,16 @@ int mutt_edit_attachment(struct Body *a) if (entry->editcommand) { mutt_buffer_strcpy(cmd, entry->editcommand); - if (mutt_rfc1524_expand_filename(entry->nametemplate, a->filename, newfile)) + mutt_rfc1524_expand_filename(entry->nametemplate, a->filename, newfile); + mutt_debug(LL_DEBUG1, "oldfile: %s\t newfile: %s\n", a->filename, mutt_b2s(newfile)); + if (mutt_file_symlink(a->filename, mutt_b2s(newfile)) == -1) { - mutt_debug(LL_DEBUG1, "oldfile: %s\t newfile: %s\n", a->filename, mutt_b2s(newfile)); - if (mutt_file_symlink(a->filename, mutt_b2s(newfile)) == -1) - { - if (mutt_yesorno(_("Can't match 'nametemplate', continue?"), MUTT_YES) != MUTT_YES) - goto bailout; - mutt_buffer_strcpy(newfile, a->filename); - } - else - unlink_newfile = true; + if (mutt_yesorno(_("Can't match 'nametemplate', continue?"), MUTT_YES) != MUTT_YES) + goto bailout; + mutt_buffer_strcpy(newfile, a->filename); } else - mutt_buffer_strcpy(newfile, a->filename); + unlink_newfile = true; if (mutt_rfc1524_expand_command(a, mutt_b2s(newfile), type, cmd)) { @@ -456,27 +448,22 @@ int mutt_view_attachment(FILE *fp, struct Body *a, enum ViewAttachMode mode, else fname = a->filename; - if (mutt_rfc1524_expand_filename(entry->nametemplate, fname, tmpfile)) + mutt_rfc1524_expand_filename(entry->nametemplate, fname, tmpfile); + /* send case: the file is already there; symlink to it */ + if (!fp) { - if (!fp) + if (mutt_file_symlink(a->filename, mutt_b2s(tmpfile)) == -1) { - /* send case: the file is already there */ - if (mutt_file_symlink(a->filename, mutt_b2s(tmpfile)) == -1) - { - if (mutt_yesorno(_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES) - goto return_error; - mutt_buffer_strcpy(tmpfile, a->filename); - } - else - unlink_tempfile = true; + if (mutt_yesorno(_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES) + goto return_error; + mutt_buffer_strcpy(tmpfile, a->filename); } + else + unlink_tempfile = true; } - else if (!fp) /* send case */ - mutt_buffer_strcpy(tmpfile, a->filename); - - if (fp) + /* recv case: we need to save the attachment to a file */ + else { - /* recv case: we need to save the attachment to a file */ FREE(&fname); if (mutt_save_attachment(fp, a, mutt_b2s(tmpfile), MUTT_SAVE_NO_FLAGS, NULL) == -1) goto return_error; @@ -1055,29 +1042,25 @@ int mutt_print_attachment(FILE *fp, struct Body *a) struct Rfc1524MailcapEntry *entry = rfc1524_new_entry(); rfc1524_mailcap_lookup(a, type, entry, MUTT_MC_PRINT); - if (mutt_rfc1524_expand_filename(entry->nametemplate, a->filename, newfile)) + mutt_rfc1524_expand_filename(entry->nametemplate, a->filename, newfile); + /* send mode: symlink from existing file to the newfile */ + if (!fp) { - if (!fp) + if (mutt_file_symlink(a->filename, mutt_b2s(newfile)) == -1) { - if (mutt_file_symlink(a->filename, mutt_b2s(newfile)) == -1) + if (mutt_yesorno(_("Can't match 'nametemplate', continue?"), MUTT_YES) != MUTT_YES) { - if (mutt_yesorno(_("Can't match 'nametemplate', continue?"), MUTT_YES) != MUTT_YES) - { - rfc1524_free_entry(&entry); - goto out; - } - mutt_buffer_strcpy(newfile, a->filename); + rfc1524_free_entry(&entry); + goto out; } - else - unlink_newfile = true; + mutt_buffer_strcpy(newfile, a->filename); } + else + unlink_newfile = true; } - else if (!fp) /* send case */ - mutt_buffer_strcpy(newfile, a->filename); - /* in recv mode, save file to newfile first */ - if (fp && (mutt_save_attachment(fp, a, mutt_b2s(newfile), MUTT_SAVE_NO_FLAGS, NULL) != 0)) - return 0; + else + mutt_save_attachment(fp, a, mutt_b2s(newfile), 0, NULL); mutt_buffer_strcpy(cmd, entry->printcommand); piped = mutt_rfc1524_expand_command(a, mutt_b2s(newfile), type, cmd); diff --git a/rfc1524.c b/rfc1524.c index 56fee53e3..0860c3bf6 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -499,8 +499,6 @@ bool rfc1524_mailcap_lookup(struct Body *a, char *type, * @param nametemplate Template * @param oldfile Original filename * @param newfile Buffer for new filename - * @retval 0 if the left and right components of the oldfile and newfile match - * @retval 1 otherwise * * If there is no nametemplate, the stripped oldfile name is used as the * template for newfile. @@ -512,8 +510,8 @@ bool rfc1524_mailcap_lookup(struct Body *a, char *type, * for a "%s". If none is found, the nametemplate is used as the template for * newfile. The first path component of the nametemplate and oldfile are ignored. */ -int mutt_rfc1524_expand_filename(const char *nametemplate, const char *oldfile, - struct Buffer *newfile) +void mutt_rfc1524_expand_filename(const char *nametemplate, const char *oldfile, + struct Buffer *newfile) { int i, j, k; char *s = NULL; @@ -612,9 +610,4 @@ int mutt_rfc1524_expand_filename(const char *nametemplate, const char *oldfile, } mutt_adv_mktemp(newfile); - - if (rmatch && lmatch) - return 0; - else - return 1; } diff --git a/rfc1524.h b/rfc1524.h index 2845d60f1..21a0741b7 100644 --- a/rfc1524.h +++ b/rfc1524.h @@ -63,7 +63,7 @@ enum MailcapLookup struct Rfc1524MailcapEntry *rfc1524_new_entry(void); void rfc1524_free_entry(struct Rfc1524MailcapEntry **entry); -int mutt_rfc1524_expand_filename(const char *nametemplate, const char *oldfile, struct Buffer *newfile); +void mutt_rfc1524_expand_filename(const char *nametemplate, const char *oldfile, struct Buffer *newfile); bool rfc1524_mailcap_lookup(struct Body *a, char *type, struct Rfc1524MailcapEntry *entry, enum MailcapLookup opt); int mutt_rfc1524_expand_command(struct Body *a, const char *filename, const char *type, struct Buffer *command);