- snprintf (tmpfile, sizeof(tmpfile), "%s.tmp", filename);
+ /* use mutt_adv_mktemp() to get a tempfile in the same
+ * directory as filename is so that we can follow symlinks
+ * via rename(2); as dirname(2) may modify its argument,
+ * temporarily use buf as copy of it
+ */
+ strncpy (buf, filename, sizeof (buf));
+ strncpy (tmpfile, basename (filename), sizeof (tmpfile));
+ mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));