summaryrefslogtreecommitdiffstats
path: root/attach.c
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2019-06-22 13:33:11 -0700
committerKevin McCarthy <kevin@8t8.us>2019-06-22 13:33:11 -0700
commit6b44b8e3a33e3401b9ed88ede9563d16e9eb3d65 (patch)
tree9b63e8be33c723970ac36f016f0d8d4e4134a9cf /attach.c
parent03f6a9cbc825a43f2de96dde2f4556cdf98c0b4d (diff)
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 attach.c calls.
Diffstat (limited to 'attach.c')
-rw-r--r--attach.c109
1 files changed, 48 insertions, 61 deletions
diff --git a/attach.c b/attach.c
index 552a1767..f00f1382 100644
--- a/attach.c
+++ b/attach.c
@@ -112,22 +112,19 @@ int mutt_compose_attachment (BODY *a)
else
mutt_buffer_strcpy (command, entry->composecommand);
- if (mutt_rfc1524_expand_filename (entry->nametemplate,
- a->filename, newfile))
+ mutt_rfc1524_expand_filename (entry->nametemplate,
+ a->filename, newfile);
+ dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n",
+ a->filename, mutt_b2s (newfile)));
+
+ if (safe_symlink (a->filename, mutt_b2s (newfile)) == -1)
{
- dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n",
- a->filename, mutt_b2s (newfile)));
- if (safe_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 = 1;
+ 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 = 1;
if (mutt_rfc1524_expand_command (a, mutt_b2s (newfile), type, command))
{
@@ -248,22 +245,19 @@ int mutt_edit_attachment (BODY *a)
{
mutt_buffer_strcpy (command, entry->editcommand);
- if (mutt_rfc1524_expand_filename (entry->nametemplate,
- a->filename, newfile))
+ mutt_rfc1524_expand_filename (entry->nametemplate,
+ a->filename, newfile);
+ dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n",
+ a->filename, mutt_b2s (newfile)));
+
+ if (safe_symlink (a->filename, mutt_b2s (newfile)) == -1)
{
- dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n",
- a->filename, mutt_b2s (newfile)));
- if (safe_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 = 1;
+ 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 = 1;
if (mutt_rfc1524_expand_command (a, mutt_b2s (newfile), type, command))
{
@@ -412,28 +406,24 @@ int mutt_view_attachment (FILE *fp, BODY *a, int flag, HEADER *hdr,
else
fname = a->filename;
- if (mutt_rfc1524_expand_filename (entry->nametemplate, fname,
- tempfile))
+ mutt_rfc1524_expand_filename (entry->nametemplate, fname,
+ tempfile);
+
+ /* send case: the file is already there; symlink to it */
+ if (fp == NULL)
{
- if (fp == NULL)
+ if (safe_symlink (a->filename, mutt_b2s (tempfile)) == -1)
{
- /* send case: the file is already there */
- if (safe_symlink (a->filename, mutt_b2s (tempfile)) == -1)
- {
- if (mutt_yesorno (_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES)
- goto return_error;
- mutt_buffer_strcpy (tempfile, a->filename);
- }
- else
- unlink_tempfile = 1;
+ if (mutt_yesorno (_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES)
+ goto return_error;
+ mutt_buffer_strcpy (tempfile, a->filename);
}
+ else
+ unlink_tempfile = 1;
}
- else if (fp == NULL) /* send case */
- mutt_buffer_strcpy (tempfile, 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 (tempfile), 0, NULL) == -1)
goto return_error;
@@ -949,29 +939,26 @@ int mutt_print_attachment (FILE *fp, BODY *a)
entry = rfc1524_new_entry ();
rfc1524_mailcap_lookup (a, type, entry, MUTT_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 (safe_symlink (a->filename, mutt_b2s (newfile)) == -1)
{
- if (safe_symlink(a->filename, mutt_b2s (newfile)) == -1)
- {
- if (mutt_yesorno (_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES)
- {
- rfc1524_free_entry (&entry);
- goto out;
- }
- mutt_buffer_strcpy (newfile, a->filename);
- }
- else
- unlink_newfile = 1;
+ if (mutt_yesorno (_("Can't match nametemplate, continue?"), MUTT_YES) != MUTT_YES)
+ {
+ rfc1524_free_entry (&entry);
+ goto out;
+ }
+ mutt_buffer_strcpy (newfile, a->filename);
}
+ else
+ unlink_newfile = 1;
}
- else if (!fp) /* send case */
- mutt_buffer_strcpy (newfile, a->filename);
-
/* in recv mode, save file to newfile first */
- if (fp)
+ else
mutt_save_attachment (fp, a, mutt_b2s (newfile), 0, NULL);
mutt_buffer_strcpy (command, entry->printcommand);