virtual-storage.c revision 90f29b3af0a645a4ef71889640f6eb6daac8c310
/* Copyright (c) 2008 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "ioloop.h"
#include "str.h"
#include "mkdir-parents.h"
#include "unlink-directory.h"
#include "index-mail.h"
#include "mail-copy.h"
#include "mail-search.h"
#include "virtual-plugin.h"
#include "virtual-storage.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#define VIRTUAL_LIST_CONTEXT(obj) \
extern struct mail_storage virtual_storage;
extern struct mailbox virtual_mailbox;
static int
static int
enum mailbox_list_file_type type,
enum mailbox_info_flags *flags);
static int
{
*layout_r = "fs";
/* we won't do any guessing for this format. */
if (debug)
i_info("virtual: mailbox location not given");
*error_r = "Root mail directory not given";
return -1;
}
if (debug)
error_r);
}
static struct mail_storage *virtual_alloc(void)
{
struct virtual_storage *storage;
}
const char **error_r)
{
struct mailbox_list_settings list_set;
const char *layout;
return -1;
"Root mail directory doesn't exist: %s",
} else {
}
return -1;
}
return -1;
/* finish list init after we've overridden vfuncs */
return 0;
}
struct virtual_backend_box *
{
struct virtual_backend_box *const *bboxes;
unsigned int i, count;
if (mailbox_id == 0)
return NULL;
return bboxes[i];
}
return NULL;
}
enum mailbox_open_flags open_flags)
{
struct virtual_backend_box *const *bboxes;
struct mail_namespace *ns;
unsigned int i, count;
enum mail_error error;
for (i = 0; i < count; i++) {
NULL, open_flags);
break;
}
}
if (i == count)
return 0;
else {
/* failed */
for (; i > 0; i--) {
}
return -1;
}
}
static struct mailbox *
enum mailbox_open_flags flags)
{
struct virtual_mailbox *mbox;
struct mail_index *index;
const char *path;
sizeof(struct virtual_mail_index_record),
sizeof(uint32_t));
if (virtual_config_read(mbox) < 0 ||
pool_unref(&pool);
return NULL;
}
}
static struct mailbox *
{
const char *path;
"virtual doesn't support streamed mailboxes");
return NULL;
}
} else {
path);
}
return NULL;
}
{
struct virtual_backend_box **bboxes;
unsigned int i, count;
int ret = 0;
for (i = 0; i < count; i++) {
ret = -1;
}
}
const char *name ATTR_UNUSED,
bool directory ATTR_UNUSED)
{
"Can't create virtual mailboxes");
return -1;
}
static int
const char *name)
{
struct dirent *d;
unsigned int dir_len;
bool unlinked_something = FALSE;
if (!mailbox_list_set_error_from_errno(list)) {
"opendir(%s) failed: %m", path);
}
return -1;
}
errno = 0;
if (d->d_name[0] == '.') {
/* skip . and .. */
continue;
continue;
}
/* trying to unlink() a directory gives either EPERM or EISDIR
(non-POSIX). it doesn't really work anywhere in practise,
so don't bother stat()ing the file first */
"unlink(%s) failed: %m",
}
}
path);
}
return -1;
}
if (!unlinked_something) {
t_strdup_printf("Directory %s isn't empty, "
"can't delete it.", name));
return -1;
}
return 0;
}
static int
{
const char *src;
/* Make sure the indexes are closed before trying to delete the
directory that contains them. It can still fail with some NFS
implementations if indexes are opened by another session, but
that can't really be helped. */
/* delete the index and control directories */
return -1;
/* check if the mailbox actually exists */
return -1;
}
}
{
// FIXME
}
static int
enum mailbox_list_file_type type,
enum mailbox_info_flags *flags)
{
const char *path, *maildir_path;
int ret = 1;
/* try to avoid stat() with these checks */
if (type != MAILBOX_LIST_FILE_TYPE_DIR &&
/* it's a file */
return 0;
}
/* need to stat() then */
/* non-directory */
ret = 0;
/* no subdirectories */
*flags |= MAILBOX_NOCHILDREN;
/* non-default configuration: we have one directory
containing the mailboxes. if there are 3 links,
either this is a selectable mailbox without children
or non-selectable mailbox with children */
*flags |= MAILBOX_CHILDREN;
} else {
/* default configuration: all subdirectories are
child mailboxes. */
*flags |= MAILBOX_CHILDREN;
}
} else {
/* non-selectable. probably either access denied, or symlink
destination not found. don't bother logging errors. */
*flags |= MAILBOX_NOSELECT;
}
if ((*flags & MAILBOX_NOSELECT) == 0) {
/* make sure it's a selectable mailbox */
*flags |= MAILBOX_NOSELECT;
}
return ret;
}
static int
const char *from_envelope ATTR_UNUSED,
struct mail_save_context **ctx_r)
{
"Can't save to virtual mailboxes");
return -1;
}
static void virtual_class_init(void)
{
}
static void virtual_class_deinit(void)
{
}
struct mail_storage virtual_storage = {
{
NULL,
}
};
struct mailbox virtual_mailbox = {
{
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
}
};