[dovecot-cvs] dovecot/src/lib-storage mail-storage-private.h, 1.42, 1.43 mail-storage.c, 1.70, 1.71 mail-storage.h, 1.126, 1.127 mailbox-list-private.h, 1.2, 1.3 mailbox-list.c, 1.7, 1.8 mailbox-list.h, 1.6, 1.7
tss at dovecot.org
tss at dovecot.org
Thu Mar 29 10:59:18 EEST 2007
- Previous message: [dovecot-cvs] dovecot/src/plugins/quota quota-plugin.c, 1.6, 1.7 quota-plugin.h, 1.2, 1.3 quota-storage.c, 1.12, 1.13 quota.c, 1.19, 1.20
- Next message: [dovecot-cvs] dovecot/src/lib-storage/index/dbox dbox-file.c, 1.13, 1.14 dbox-storage.c, 1.38, 1.39 dbox-storage.h, 1.17, 1.18 dbox-sync-expunge.c, 1.22, 1.23 dbox-sync-full.c, 1.10, 1.11 dbox-uidlist.c, 1.46, 1.47
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /var/lib/cvs/dovecot/src/lib-storage
In directory talvi:/tmp/cvs-serv11000/lib-storage
Modified Files:
mail-storage-private.h mail-storage.c mail-storage.h
mailbox-list-private.h mailbox-list.c mailbox-list.h
Log Message:
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
work with either fs/maildir++ directory layout. They can be changed by
appending :LAYOUT=fs|maildir++ to mail_location.
Index: mail-storage-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage-private.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- mail-storage-private.h 21 Dec 2006 15:20:29 -0000 1.42
+++ mail-storage-private.h 29 Mar 2007 07:59:15 -0000 1.43
@@ -4,11 +4,6 @@
#include "file-lock.h"
#include "mail-storage.h"
-/* Some error strings that should be used everywhere to avoid
- permissions checks from revealing mailbox's existence */
-#define MAIL_STORAGE_ERR_MAILBOX_NOT_FOUND "Mailbox doesn't exist: %s"
-#define MAIL_STORAGE_ERR_NO_PERMISSION "Permission denied"
-
/* Called after mail storage has been created */
extern void (*hook_mail_storage_created)(struct mail_storage *storage);
/* Called after mailbox has been opened */
@@ -37,15 +32,6 @@
int (*mailbox_create)(struct mail_storage *storage, const char *name,
bool directory);
- int (*mailbox_delete)(struct mail_storage *storage, const char *name);
- int (*mailbox_rename)(struct mail_storage *storage, const char *oldname,
- const char *newname);
-
- int (*is_mailbox)(struct mail_storage *storage,
- const char *dir, const char *fname,
- enum mailbox_list_iter_flags iter_flags,
- enum mailbox_info_flags *flags,
- enum mailbox_list_file_type type);
const char *(*get_last_error)(struct mail_storage *storage,
bool *syntax_error_r,
@@ -289,10 +275,6 @@
enum mailbox_list_flags
mail_storage_get_list_flags(enum mail_storage_flags storage_flags);
-int mailbox_storage_list_is_mailbox(const char *dir, const char *fname,
- enum mailbox_list_file_type type,
- enum mailbox_list_iter_flags iter_flags,
- enum mailbox_info_flags *flags,
- void *context);
+bool mail_storage_errno2str(const char **error_r);
#endif
Index: mail-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- mail-storage.c 18 Jan 2007 16:57:43 -0000 1.70
+++ mail-storage.c 29 Mar 2007 07:59:15 -0000 1.71
@@ -1,10 +1,11 @@
-/* Copyright (C) 2002-2006 Timo Sirainen */
+/* Copyright (C) 2002-2007 Timo Sirainen */
#include "lib.h"
#include "ioloop.h"
#include "array.h"
#include "var-expand.h"
#include "mail-index-private.h"
+#include "mailbox-list-private.h"
#include "mail-storage-private.h"
#include <stdlib.h>
@@ -318,17 +319,6 @@
return storage->v.mailbox_create(storage, name, directory);
}
-int mail_storage_mailbox_delete(struct mail_storage *storage, const char *name)
-{
- return storage->v.mailbox_delete(storage, name);
-}
-
-int mail_storage_mailbox_rename(struct mail_storage *storage,
- const char *oldname, const char *newname)
-{
- return storage->v.mailbox_rename(storage, oldname, newname);
-}
-
const char *mail_storage_get_last_error(struct mail_storage *storage,
bool *syntax_error_r,
bool *temporary_error_r)
@@ -385,27 +375,17 @@
return list_flags;
}
-int mailbox_storage_list_is_mailbox(const char *dir, const char *fname,
- enum mailbox_list_file_type type,
- enum mailbox_list_iter_flags iter_flags,
- enum mailbox_info_flags *flags,
- void *context)
-{
- struct mail_storage *storage = context;
-
- return mail_storage_is_mailbox(storage, dir, fname, iter_flags,
- flags, type);
-}
-
-
-int mail_storage_is_mailbox(struct mail_storage *storage,
- const char *dir, const char *fname,
- enum mailbox_list_iter_flags iter_flags,
- enum mailbox_info_flags *flags,
- enum mailbox_list_file_type type)
+bool mail_storage_errno2str(const char **error_r)
{
- return storage->v.is_mailbox(storage, dir, fname, iter_flags,
- flags, type);
+ if (ENOACCESS(errno))
+ *error_r = MAILBOX_LIST_ERR_NO_PERMISSION;
+ else if (ENOSPACE(errno))
+ *error_r = "Not enough disk space";
+ else if (ENOTFOUND(errno))
+ *error_r = "Directory structure is broken";
+ else
+ return FALSE;
+ return TRUE;
}
struct mailbox *mailbox_open(struct mail_storage *storage, const char *name,
Index: mail-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage.h,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -d -r1.126 -r1.127
--- mail-storage.h 21 Mar 2007 19:19:55 -0000 1.126
+++ mail-storage.h 29 Mar 2007 07:59:15 -0000 1.127
@@ -229,18 +229,6 @@
created as long as it shows in LIST. */
int mail_storage_mailbox_create(struct mail_storage *storage, const char *name,
bool directory);
-/* Only the specified mailbox is deleted, ie. folders under the
- specified mailbox must not be deleted. */
-int mail_storage_mailbox_delete(struct mail_storage *storage, const char *name);
-/* If the name has inferior hierarchical names, then the inferior
- hierarchical names MUST also be renamed (ie. foo -> bar renames
- also foo/bar -> bar/bar). newname may contain multiple new
- hierarchies.
-
- If oldname is case-insensitively "INBOX", the mails are moved
- into new folder but the INBOX folder must not be deleted. */
-int mail_storage_mailbox_rename(struct mail_storage *storage,
- const char *oldname, const char *newname);
/* Returns the error message of last occurred error. */
const char *mail_storage_get_last_error(struct mail_storage *storage,
@@ -262,12 +250,6 @@
const char *mail_storage_get_mailbox_index_dir(struct mail_storage *storage,
const char *name);
-int mail_storage_is_mailbox(struct mail_storage *storage,
- const char *dir, const char *fname,
- enum mailbox_list_iter_flags iter_flags,
- enum mailbox_info_flags *flags,
- enum mailbox_list_file_type type);
-
/* Open a mailbox. If input stream is given, mailbox is opened read-only
using it as a backend. If storage doesn't support stream backends and its
tried to be used, NULL is returned.
Index: mailbox-list-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mailbox-list-private.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mailbox-list-private.h 25 Nov 2006 22:17:41 -0000 1.2
+++ mailbox-list-private.h 29 Mar 2007 07:59:15 -0000 1.3
@@ -1,6 +1,11 @@
#ifndef __MAILBOX_LIST_PRIVATE_H
#define __MAILBOX_LIST_PRIVATE_H
+/* Some error strings that should be used everywhere to avoid
+ permissions checks from revealing mailbox's existence */
+#define MAILBOX_LIST_ERR_MAILBOX_NOT_FOUND "Mailbox doesn't exist: %s"
+#define MAILBOX_LIST_ERR_NO_PERMISSION "Permission denied"
+
#include "mailbox-list.h"
struct dirent;
@@ -32,8 +37,18 @@
(*iter_next)(struct mailbox_list_iterate_context *ctx);
int (*iter_deinit)(struct mailbox_list_iterate_context *ctx);
+ /* Returns -1 if error, 0 if it's not a valid mailbox, 1 if it is.
+ flags may be updated (especially the children flags). */
+ int (*iter_is_mailbox)(struct mailbox_list_iterate_context *ctx,
+ const char *dir, const char *fname,
+ enum mailbox_list_file_type type,
+ enum mailbox_info_flags *flags_r);
+
int (*set_subscribed)(struct mailbox_list *list,
const char *name, bool set);
+ int (*delete_mailbox)(struct mailbox_list *list, const char *name);
+ int (*rename_mailbox)(struct mailbox_list *list, const char *oldname,
+ const char *newname);
};
struct mailbox_list {
@@ -51,9 +66,6 @@
char *error;
bool temporary_error;
- mailbox_list_is_mailbox_t *callback;
- void *context;
-
ARRAY_DEFINE(module_contexts, void);
};
@@ -69,6 +81,9 @@
extern void (*hook_mailbox_list_created)(struct mailbox_list *list);
+int mailbox_list_delete_index_control(struct mailbox_list *list,
+ const char *name);
+
bool mailbox_list_name_is_too_large(const char *name, char sep);
enum mailbox_list_file_type mailbox_list_get_file_type(const struct dirent *d);
Index: mailbox-list.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mailbox-list.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mailbox-list.c 15 Mar 2007 01:47:10 -0000 1.7
+++ mailbox-list.c 29 Mar 2007 07:59:15 -0000 1.8
@@ -1,9 +1,10 @@
-/* Copyright (C) 2006 Timo Sirainen */
+/* Copyright (C) 2006-2007 Timo Sirainen */
#include "lib.h"
#include "array.h"
#include "ioloop.h"
#include "mkdir-parents.h"
+#include "unlink-directory.h"
#include "mailbox-list-private.h"
#include <time.h>
@@ -76,7 +77,6 @@
int mailbox_list_init(const char *driver,
const struct mailbox_list_settings *set,
enum mailbox_list_flags flags,
- mailbox_list_is_mailbox_t *callback, void *context,
struct mailbox_list **list_r, const char **error_r)
{
const struct mailbox_list *const *class_p;
@@ -95,8 +95,6 @@
list = (*class_p)->v.alloc();
list->flags = flags;
- list->callback = callback;
- list->context = context;
/* copy settings */
list->set.root_dir = p_strdup(list->pool, set->root_dir);
@@ -234,6 +232,60 @@
return list->v.set_subscribed(list, name, set);
}
+int mailbox_list_delete_mailbox(struct mailbox_list *list, const char *name)
+{
+ return list->v.delete_mailbox(list, name);
+}
+
+int mailbox_list_rename_mailbox(struct mailbox_list *list,
+ const char *oldname, const char *newname)
+{
+ return list->v.rename_mailbox(list, oldname, newname);
+}
+
+int mailbox_list_delete_index_control(struct mailbox_list *list,
+ const char *name)
+{
+ const char *path, *index_dir, *dir;
+
+ if (strcmp(name, "INBOX") == 0) {
+ mailbox_list_set_error(list, "INBOX can't be deleted.");
+ return -1;
+ }
+
+ if (!mailbox_list_is_valid_existing_name(list, name)) {
+ mailbox_list_set_error(list, "Invalid mailbox name");
+ return -1;
+ }
+
+ path = mailbox_list_get_path(list, name,
+ MAILBOX_LIST_PATH_TYPE_MAILBOX);
+
+ /* delete the index directory first, so that if we crash we don't
+ leave indexes for deleted mailboxes lying around */
+ index_dir = mailbox_list_get_path(list, name,
+ MAILBOX_LIST_PATH_TYPE_INDEX);
+ if (*index_dir != '\0' && strcmp(index_dir, path) != 0) {
+ if (unlink_directory(index_dir, TRUE) < 0 && errno != ENOENT) {
+ mailbox_list_set_critical(list,
+ "unlink_directory(%s) failed: %m", index_dir);
+ return -1;
+ }
+ }
+
+ /* control directory next */
+ dir = mailbox_list_get_path(list, name, MAILBOX_LIST_PATH_TYPE_CONTROL);
+ if (*dir != '\0' && strcmp(dir, path) != 0 &&
+ strcmp(dir, index_dir) != 0) {
+ if (unlink_directory(dir, TRUE) < 0 && errno != ENOENT) {
+ mailbox_list_set_critical(list,
+ "unlink_directory(%s) failed: %m", dir);
+ return -1;
+ }
+ }
+ return 0;
+}
+
bool mailbox_list_name_is_too_large(const char *name, char sep)
{
unsigned int levels = 1, level_len = 0;
Index: mailbox-list.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mailbox-list.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mailbox-list.h 28 Dec 2006 16:28:32 -0000 1.6
+++ mailbox-list.h 29 Mar 2007 07:59:15 -0000 1.7
@@ -42,9 +42,9 @@
};
enum mailbox_list_path_type {
- /* Return directory's path (eg. /home/user/mail) */
+ /* Return directory's path (eg. ~/dbox/INBOX) */
MAILBOX_LIST_PATH_TYPE_DIR,
- /* Return mailbox path (dir + maildir_name) */
+ /* Return mailbox path (eg. ~/dbox/INBOX/dbox-Mails) */
MAILBOX_LIST_PATH_TYPE_MAILBOX,
/* Return control directory */
MAILBOX_LIST_PATH_TYPE_CONTROL,
@@ -92,14 +92,6 @@
enum mailbox_info_flags flags;
};
-/* Returns -1 if error, 0 if it's not a valid mailbox, 1 if it is.
- flags may be updated (especially the children flags). */
-typedef int mailbox_list_is_mailbox_t(const char *dir, const char *fname,
- enum mailbox_list_file_type type,
- enum mailbox_list_iter_flags iter_flags,
- enum mailbox_info_flags *flags_r,
- void *context);
-
/* register all drivers */
void mailbox_list_register_all(void);
@@ -110,7 +102,6 @@
int mailbox_list_init(const char *driver,
const struct mailbox_list_settings *set,
enum mailbox_list_flags flags,
- mailbox_list_is_mailbox_t *callback, void *context,
struct mailbox_list **list_r, const char **error_r);
void mailbox_list_deinit(struct mailbox_list *list);
@@ -161,6 +152,18 @@
int mailbox_list_set_subscribed(struct mailbox_list *list,
const char *name, bool set);
+/* Delete the given mailbox. If it has children, they aren't deleted. */
+int mailbox_list_delete_mailbox(struct mailbox_list *list, const char *name);
+/* If the name has inferior hierarchical names, then the inferior
+ hierarchical names MUST also be renamed (ie. foo -> bar renames
+ also foo/bar -> bar/bar). newname may contain multiple new
+ hierarchies.
+
+ If oldname is case-insensitively "INBOX", the mails are moved
+ into new mailbox but the INBOX mailbox must not be deleted. */
+int mailbox_list_rename_mailbox(struct mailbox_list *list,
+ const char *oldname, const char *newname);
+
/* Returns the error message of last occurred error. */
const char *mailbox_list_get_last_error(struct mailbox_list *list,
bool *temporary_error_r);
- Previous message: [dovecot-cvs] dovecot/src/plugins/quota quota-plugin.c, 1.6, 1.7 quota-plugin.h, 1.2, 1.3 quota-storage.c, 1.12, 1.13 quota.c, 1.19, 1.20
- Next message: [dovecot-cvs] dovecot/src/lib-storage/index/dbox dbox-file.c, 1.13, 1.14 dbox-storage.c, 1.38, 1.39 dbox-storage.h, 1.17, 1.18 dbox-sync-expunge.c, 1.22, 1.23 dbox-sync-full.c, 1.10, 1.11 dbox-uidlist.c, 1.46, 1.47
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list