]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Create "maildirfolder" file only with maildir storage.
authorTimo Sirainen <tss@iki.fi>
Tue, 25 Sep 2012 20:38:14 +0000 (23:38 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 25 Sep 2012 20:38:14 +0000 (23:38 +0300)
Previously it was created for all storages, as long as they used
LAYOUT=maildir++. The file is mainly meant for MDAs that want to update
maildirsize quota, but that's only available for Maildir storage.

src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/list/mailbox-list-maildir.c

index 1cd253429825ef3824d26e84bc08e452496b6eec..4f2bdbce9b7729e89ab0173224cbcfd01203415f 100644 (file)
@@ -17,6 +17,7 @@
 
 #define MAILDIR_LIST_CONTEXT(obj) \
        MODULE_CONTEXT(obj, maildir_mailbox_list_module)
+#define MAILDIR_SUBFOLDER_FILENAME "maildirfolder"
 
 struct maildir_mailbox_list_context {
        union mailbox_list_module_context module_ctx;
@@ -436,6 +437,52 @@ maildir_mailbox_update(struct mailbox *box, const struct mailbox_update *update)
        return ret;
 }
 
+static int maildir_create_maildirfolder_file(struct mailbox *box)
+{
+       const struct mailbox_permissions *perm = mailbox_get_permissions(box);
+       const char *path;
+       mode_t old_mask;
+       int fd;
+
+       /* Maildir++ spec wants that maildirfolder named file is created for
+          all subfolders. Do this only with Maildir++ layout. */
+       if (strcmp(box->list->name, MAILBOX_LIST_NAME_MAILDIRPLUSPLUS) != 0)
+               return 0;
+
+       path = t_strconcat(mailbox_get_path(box),
+                          "/"MAILDIR_SUBFOLDER_FILENAME, NULL);
+       old_mask = umask(0);
+       fd = open(path, O_CREAT | O_WRONLY, perm->file_create_mode);
+       umask(old_mask);
+       if (fd != -1) {
+               /* ok */
+       } else if (errno == ENOENT) {
+               mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
+                       "Mailbox was deleted while it was being created");
+               return -1;
+       } else {
+               mail_storage_set_critical(box->storage,
+                       "open(%s, O_CREAT) failed: %m", path);
+               return -1;
+       }
+
+       if (perm->file_create_gid != (gid_t)-1) {
+               if (fchown(fd, (uid_t)-1, perm->file_create_gid) == 0) {
+                       /* ok */
+               } else if (errno == EPERM) {
+                       mail_storage_set_critical(box->storage, "%s",
+                               eperm_error_get_chgrp("fchown", path,
+                                                     perm->file_create_gid,
+                                                     perm->file_create_gid_origin));
+               } else {
+                       mail_storage_set_critical(box->storage,
+                               "fchown(%s) failed: %m", path);
+               }
+       }
+       i_close_fd(&fd);
+       return 0;
+}
+
 static int
 maildir_mailbox_create(struct mailbox *box, const struct mailbox_update *update,
                       bool directory)
@@ -459,6 +506,7 @@ maildir_mailbox_create(struct mailbox *box, const struct mailbox_update *update,
 
        if (create_maildir(box, FALSE) < 0)
                return -1;
+       maildir_create_maildirfolder_file(box);
 
        /* if dovecot-shared exists in the root dir, copy it to newly
           created mailboxes */
index 179a183ff7b512fadc5707e9d53398a7cf4c03b5..83ba74577862b10004c81e2b8c86ee4edae94a4f 100644 (file)
@@ -14,7 +14,6 @@
 #include <stdio.h>
 #include <sys/stat.h>
 
-#define MAILDIR_SUBFOLDER_FILENAME "maildirfolder"
 #define MAILDIR_GLOBAL_TEMP_PREFIX "temp."
 #define IMAPDIR_GLOBAL_TEMP_PREFIX ".temp."
 
@@ -180,49 +179,6 @@ static int maildir_list_set_subscribed(struct mailbox_list *_list,
                                       name, set);
 }
 
-static int
-maildir_list_create_maildirfolder_file(struct mailbox_list *list,
-                                      const char *dir, mode_t file_mode,
-                                      gid_t gid, const char *gid_origin)
-{
-       const char *path;
-       mode_t old_mask;
-       int fd;
-
-       /* Maildir++ spec wants that maildirfolder named file is created for
-          all subfolders. */
-       path = t_strconcat(dir, "/" MAILDIR_SUBFOLDER_FILENAME, NULL);
-       old_mask = umask(0);
-       fd = open(path, O_CREAT | O_WRONLY, file_mode);
-       umask(old_mask);
-       if (fd != -1) {
-               /* ok */
-       } else if (errno == ENOENT) {
-               mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND,
-                       "Mailbox was deleted while it was being created");
-               return -1;
-       } else {
-               mailbox_list_set_critical(list,
-                       "open(%s, O_CREAT) failed: %m", path);
-               return -1;
-       }
-
-       if (gid != (gid_t)-1) {
-               if (fchown(fd, (uid_t)-1, gid) == 0) {
-                       /* ok */
-               } else if (errno == EPERM) {
-                       mailbox_list_set_critical(list, "%s",
-                               eperm_error_get_chgrp("fchown", path,
-                                                     gid, gid_origin));
-               } else {
-                       mailbox_list_set_critical(list,
-                               "fchown(%s) failed: %m", path);
-               }
-       }
-       i_close_fd(&fd);
-       return 0;
-}
-
 static int
 maildir_list_create_mailbox_dir(struct mailbox_list *list, const char *name,
                                enum mailbox_dir_create_type type)
@@ -243,7 +199,6 @@ maildir_list_create_mailbox_dir(struct mailbox_list *list, const char *name,
                path = t_strdup_until(path, p);
        }
 
-       root_dir = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_MAILBOX);
        mailbox_list_get_permissions(list, name, &perm);
        if (mkdir_parents_chgrp(path, perm.dir_create_mode,
                                perm.file_create_gid,
@@ -253,6 +208,8 @@ maildir_list_create_mailbox_dir(struct mailbox_list *list, const char *name,
                if (create_parent_dir)
                        return 0;
                if (type == MAILBOX_DIR_CREATE_TYPE_MAILBOX) {
+                       root_dir = mailbox_list_get_root_path(list,
+                                               MAILBOX_LIST_PATH_TYPE_MAILBOX);
                        if (strcmp(path, root_dir) == 0) {
                                /* even though the root directory exists,
                                   the mailbox might not */
@@ -269,11 +226,7 @@ maildir_list_create_mailbox_dir(struct mailbox_list *list, const char *name,
                mailbox_list_set_critical(list, "mkdir(%s) failed: %m", path);
                return -1;
        }
-       return create_parent_dir || strcmp(path, root_dir) == 0 ? 0 :
-               maildir_list_create_maildirfolder_file(list, path,
-                                                      perm.file_create_mode,
-                                                      perm.file_create_gid,
-                                                      perm.file_create_gid_origin);
+       return 0;
 }
 
 static const char *