- while ((c = strchr((c + 1), '/')) != NULL) {
- *c = (char)0;
- if (access(path, X_OK)) {
- if (errno != ENOENT){
- advise (dir, "unable to create directory");
- return 0;
- }
- if (mkdir(path, 0775)) {
- advise (dir, "unable to create directory");
- return 0;
- }
- }
- *c = '/';
- }
-
- if (mkdir (dir, 0755) == -1) {
+ /* Because mh-profile.man documents "Folder-Protect:" as an octal constant,
+ and we don't want to force the user to remember to include a leading
+ zero, we call atooi(folder_perms_ASCII) here rather than
+ strtoul(folder_perms_ASCII, NULL, 0). Therefore, if anyone ever tries to
+ specify a mode in say, hex, they'll get garbage. (I guess nmh uses its
+ atooi() function rather than calling strtoul() with a radix of 8 because
+ some ancient platforms are missing that functionality. */
+ folder_perms = atooi(folder_perms_ASCII);
+
+ /* Folders have definite desired permissions that are set -- we don't want
+ to interact with the umask. Clear it temporarily. */
+ saved_umask = umask(0);
+
+ if (getuid () == geteuid ()) {
+ c = strncpy(path, dir, sizeof(path));
+
+ while (!had_an_error && (c = strchr((c + 1), '/')) != NULL) {
+ *c = (char)0;
+ if (access(path, X_OK)) {
+ if (errno != ENOENT){