From: Rocco Rutte Date: Tue, 15 Jan 2008 16:34:44 +0000 (+0100) Subject: Prepend './' to (some) suggested filenames when saving attachments. X-Git-Tag: mutt-1-5-18-rel~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3848cefa09a4dd3ade7464bdb8de00bee211d7a7;p=mutt Prepend './' to (some) suggested filenames when saving attachments. Attachment filenames may start with characters that are special to mutt_expand_path() may cause undesired expansion. Closes #1719. --- diff --git a/recvattach.c b/recvattach.c index 0722e838..611643ab 100644 --- a/recvattach.c +++ b/recvattach.c @@ -386,6 +386,24 @@ int mutt_is_message_type (int type, const char *subtype) return (ascii_strcasecmp (subtype, "rfc822") == 0 || ascii_strcasecmp (subtype, "news") == 0); } +static void prepend_curdir (char *dst, size_t dstlen) +{ + size_t l; + + if (!dst || !*dst || *dst == '/' || dstlen < 3 || + /* XXX bad modularization, these are special to mutt_expand_path() */ + !strchr ("~=+@<>!-^", *dst)) + return; + + dstlen -= 3; + l = strlen (dst) + 2; + l = (l > dstlen ? dstlen : l); + memmove (dst + 2, dst, l); + dst[0] = '.'; + dst[1] = '/'; + dst[l + 2] = 0; +} + static int mutt_query_save_attachment (FILE *fp, BODY *body, HEADER *hdr, char **directory) { char *prompt; @@ -409,6 +427,8 @@ static int mutt_query_save_attachment (FILE *fp, BODY *body, HEADER *hdr, char * else buf[0] = 0; + prepend_curdir (buf, sizeof (buf)); + prompt = _("Save to file: "); while (prompt) { @@ -485,6 +505,7 @@ void mutt_save_attachment_list (FILE *fp, int tag, BODY *top, HEADER *hdr, MUTTM { int append = 0; + prepend_curdir (buf, sizeof (buf)); strfcpy (buf, mutt_basename (NONULL (top->filename)), sizeof (buf)); if (mutt_get_field (_("Save to file: "), buf, sizeof (buf),