- snprintf (tmpfile, sizeof(tmpfile), "%s.tmp", filename);
- debug_print (1, ("Opening %s\n", tmpfile));
+ /* 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
+ */
+ m_strcpy(buf, sizeof(buf), filename);
+ m_strcpy(tmpfile, sizeof(tmpfile), basename(filename));
+ mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));