dovecot-2.2: lib-storage: Create "maildirfolder" file only with ...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Sep 25 23:38:28 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/f6225edc2c1e
changeset: 15109:f6225edc2c1e
user: Timo Sirainen <tss at iki.fi>
date: Tue Sep 25 23:38:14 2012 +0300
description:
lib-storage: Create "maildirfolder" file only with maildir storage.
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.
diffstat:
src/lib-storage/index/maildir/maildir-storage.c | 48 ++++++++++++++++++++++
src/lib-storage/list/mailbox-list-maildir.c | 53 +-----------------------
2 files changed, 51 insertions(+), 50 deletions(-)
diffs (163 lines):
diff -r 3275a9b5136a -r f6225edc2c1e src/lib-storage/index/maildir/maildir-storage.c
--- a/src/lib-storage/index/maildir/maildir-storage.c Tue Sep 25 23:23:53 2012 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c Tue Sep 25 23:38:14 2012 +0300
@@ -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 @@
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 @@
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 */
diff -r 3275a9b5136a -r f6225edc2c1e src/lib-storage/list/mailbox-list-maildir.c
--- a/src/lib-storage/list/mailbox-list-maildir.c Tue Sep 25 23:23:53 2012 +0300
+++ b/src/lib-storage/list/mailbox-list-maildir.c Tue Sep 25 23:38:14 2012 +0300
@@ -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."
@@ -181,49 +180,6 @@
}
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 @@
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 @@
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 @@
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 *
More information about the dovecot-cvs
mailing list