- case '/':
- for (dp = cp; *dp == '/'; dp++)
- continue;
- strcpy (cp--, dp);
- continue;
-
- case '.':
- if (strcmp (cp, DOT) == 0) {
- if (cp > f + 1)
- cp--;
- *cp = '\0';
- break;
- }
- if (strcmp (cp, DOTDOT) == 0) {
- for (cp -= 2; cp > f; cp--)
- if (*cp == '/')
- break;
- if (cp <= f)
- cp = f + 1;
- *cp = '\0';
- break;
- }
- if (strncmp (cp, PWD, NPWD) == 0) {
- for (dp = cp - 2; dp > f; dp--)
- if (*dp == '/')
- break;
- if (dp <= f)
- dp = f;
- strcpy (dp, cp + NPWD - 1);
- cp = dp;
- continue;
- }
- if (strncmp (cp, CWD, NCWD) == 0) {
- strcpy (cp - 1, cp + NCWD - 1);
- cp--;
- continue;
- }
- continue;
-
- default:
- cp++;
- continue;
- }
- break;
+/*
+** Anypath to absolute directory path
+** Convert any kind of path into an abs dirpath
+** A path without distinguishing prefix is assumed to be an abs folpath
+** Abs dirpaths are passed unchanged
+** Rel dirpaths ('.') get prefixed with the (abs) cwd
+** Return pointer to static memory
+**
+** To get the dir path of the mail storage root, call: toabsdir("+")
+**
+** TODO: check lengths for copies
+*/
+char *
+toabsdir(char *path)
+{
+ static char buf[BUFSIZ];
+
+ if (*path == '/') {
+ /* nothing to do */
+ strncpy(buf, path, sizeof buf);
+ packpath(buf);
+ return buf;
+
+ } else if (*path == '.') {
+ /* rel dir path */
+ strncpy(buf, expanddir(path), sizeof buf);
+ return buf;
+
+ } else {
+ /* folder path */
+ char *cp=buf, *pp;
+
+ if (!(pp = context_find("path")) || !*pp) {
+ adios(NULL, "Non-empty profile entry `Path' required");
+ }
+ if (*pp != '/') {
+ /* Path is relative to $HOME */
+ snprintf(buf, sizeof buf, "%s/", mypath);
+ cp += strlen(buf);
+ }
+ strcpy(cp, pp);
+ packpath(buf);
+ /* append the mail folder */
+ cp = buf + strlen(buf);
+ *cp++ = '/';
+ strcpy(cp, expandfol(path));
+ return buf;