static int bcache_path(struct Account *account, const char *mailbox, char *dst, size_t dstlen)
{
char host[STRING];
- char path[_POSIX_PATH_MAX];
struct Url url;
int len;
return -1;
}
- mutt_encode_path(path, sizeof(path), NONULL(mailbox));
-
- int plen = mutt_str_strlen(path);
- if (plen == 0)
- return -1;
+ size_t mailboxlen = mutt_str_strlen(mailbox);
+ len = snprintf(dst, dstlen - 1, "%s/%s%s%s", MessageCachedir, host,
+ NONULL(mailbox),
+ (mailboxlen != 0 && mailbox[mailboxlen - 1] == '/') ? "" : "/");
- len = snprintf(dst, dstlen - 1, "%s/%s%s%s", MessageCachedir, host, path,
- (*path && path[plen - 1] == '/') ? "" : "/");
+ mutt_encode_path(dst, dstlen, dst);
mutt_debug(3, "rc: %d, path: '%s'\n", len, dst);
{
/* An existing file or a non-existing path not ending with a slash */
snprintf(hcpath, sizeof(hcpath), "%s%s", path, suffix);
+ mutt_encode_path(hcpath, sizeof(hcpath), hcpath);
return hcpath;
}
rc = snprintf(hcpath, sizeof(hcpath), "%s%s%s%s", path, slash ? "" : "/", name, suffix);
}
+ mutt_encode_path(hcpath, sizeof(hcpath), hcpath);
+
if (rc < 0) /* namer or fprintf failed.. should not happen */
return path;
static char *get_foldername(const char *folder)
{
char *p = NULL;
- char path[_POSIX_PATH_MAX];
-
- mutt_encode_path(path, sizeof(path), folder);
/* if the folder is local, canonify the path to avoid
* to ensure equivalent paths share the hcache */
p = mutt_mem_malloc(PATH_MAX + 1);
- if (!realpath(path, p))
- mutt_str_replace(&p, path);
+ if (!realpath(folder, p))
+ mutt_str_replace(&p, folder);
return p;
}
void mutt_encode_path(char *dest, size_t dlen, const char *src)
{
char *p = mutt_str_strdup(src);
- int rc = mutt_ch_convert_string(&p, Charset, "utf-8", 0);
+ int rc = mutt_ch_convert_string(&p, Charset, "us-ascii", 0);
/* `src' may be NULL, such as when called from the pop3 driver. */
- mutt_str_strfcpy(dest, (rc == 0) ? NONULL(p) : NONULL(src), dlen);
+ size_t len = mutt_str_strfcpy(dest, (rc == 0) ? NONULL(p) : NONULL(src), dlen);
+
+ /* convert the path to POSIX "Portable Filename Character Set" */
+ for (size_t i = 0; i < len; ++i)
+ {
+ if (!isalnum(dest[i]) && !strchr("/.-_", dest[i]))
+ {
+ dest[i] = '_';
+ }
+ }
FREE(&p);
}
if (*c == '/')
*c = '\0';
mutt_expand_path(dst, dstlen);
+ mutt_encode_path(dst, dstlen, dst);
}
/**