static char* get_foldername(const char *folder) {
size_t flen = mutt_strlen (folder);
- char* p = safe_strdup(folder);
+ char *p = NULL;
+ struct stat st;
- if (flen > 0 && folder[flen-1] == '/')
+ /* if the folder exists and doesn't start with /,
+ * prepend cwd to always use the same hcache per folder */
+ if (stat (folder, &st) == 0 && flen > 0 && *folder != '/')
+ {
+ p = safe_malloc (_POSIX_PATH_MAX+1);
+ if (!realpath (folder, p))
+ mutt_str_replace (&p, folder);
+ } else
+ p = safe_strdup (folder);
+
+ /* make sure we have no trailing / as added by tab completion */
+ if (flen > 0 && p[flen-1] == '/')
p[flen-1] = '\0';
return p;