addr = NULL;
if (addr)
{
- char tmp[PATH_MAX];
- mutt_safe_path(tmp, sizeof(tmp), addr);
- snprintf(path, pathlen, "=%s", tmp);
+ struct Buffer *tmp = mutt_buffer_pool_get();
+ mutt_safe_path(tmp, addr);
+ snprintf(path, pathlen, "=%s", mutt_b2s(tmp));
+ mutt_buffer_pool_release(&tmp);
}
}
if ((C_SaveName || C_ForceName) && (to || cc || bcc))
{
const struct Address *addr = to ? to : (cc ? cc : bcc);
- char buf[PATH_MAX];
- mutt_safe_path(buf, sizeof(buf), addr);
- mutt_path_concat(path, NONULL(C_Folder), buf, pathlen);
+ struct Buffer *buf = mutt_buffer_pool_get();
+ mutt_safe_path(buf, addr);
+ mutt_path_concat(path, NONULL(C_Folder), mutt_b2s(buf), pathlen);
+ mutt_buffer_pool_release(&buf);
if (!C_ForceName && (mx_access(path, W_OK) != 0))
mutt_str_strfcpy(path, C_Record, pathlen);
}
*buf = '\0';
}
+/**
+ * mutt_buffer_save_path - Make a safe filename from an email address
+ * @param dest Buffer for the result
+ * @param a Address to use
+ */
+void mutt_buffer_save_path(struct Buffer *dest, const struct Address *a)
+{
+ if (a && a->mailbox)
+ {
+ mutt_buffer_strcpy(dest, a->mailbox);
+ if (!C_SaveAddress)
+ {
+ char *p = strpbrk(dest->data, "%@");
+ if (p)
+ {
+ *p = '\0';
+ mutt_buffer_fix_dptr(dest);
+ }
+ }
+ mutt_str_strlower(dest->data);
+ }
+ else
+ mutt_buffer_reset(dest);
+}
+
/**
* mutt_safe_path - Make a safe filename from an email address
- * @param buf Buffer for the result
- * @param buflen Length of buffer
- * @param a Address to use
+ * @param dest Buffer for the result
+ * @param a Address to use
*
* The filename will be stripped of '/', space, etc to make it safe.
*/
-void mutt_safe_path(char *buf, size_t buflen, const struct Address *a)
+void mutt_safe_path(struct Buffer *dest, const struct Address *a)
{
- mutt_save_path(buf, buflen, a);
- for (char *p = buf; *p; p++)
+ mutt_buffer_save_path(dest, a);
+ for (char *p = dest->data; *p; p++)
if ((*p == '/') || IS_SPACE(*p) || !IsPrint((unsigned char) *p))
*p = '_';
}
void mutt_buffer_expand_path_regex(struct Buffer *buf, bool regex);
void mutt_buffer_pretty_mailbox(struct Buffer *s);
void mutt_buffer_sanitize_filename (struct Buffer *buf, const char *path, short slash);
+void mutt_buffer_save_path(struct Buffer *dest, const struct Address *a);
int mutt_check_overwrite(const char *attname, const char *path, struct Buffer *fname, enum SaveAttach *opt, char **directory);
void mutt_encode_path(char *dest, size_t dlen, const char *src);
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags);
uint64_t mutt_rand64(void);
void mutt_rand_base32(void *out, size_t len);
int mutt_randbuf(void *out, size_t len);
-void mutt_safe_path(char *s, size_t l, const struct Address *a);
+void mutt_safe_path(struct Buffer *dest, const struct Address *a);
int mutt_save_confirm(const char *s, struct stat *st);
void mutt_save_path(char *d, size_t dsize, const struct Address *a);
void mutt_sleep(short s);