mbox-storage.c revision b59940fd3a702796e4f2a9e7dda4ed7d8fd1e3c9
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (C) 2002-2003 Timo Sirainen */
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen#include "subscription-file/subscription-file.h"
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen#define CREATE_MODE 0770 /* umask() should limit it more */
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen/* NOTE: must be sorted for istream-header-filter. */
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainenconst char *mbox_hide_headers[] = {
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen "Content-Length",
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen "X-IMAPbase",
7dc4bf28c0c4c673a198070edd1ed54e14ae39aeTimo Sirainen "X-Keywords",
7dc4bf28c0c4c673a198070edd1ed54e14ae39aeTimo Sirainenint mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function)
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen mail_storage_set_critical(STORAGE(mbox->storage),
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen "%s failed with mbox file %s: %m", function, mbox->path);
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainenstatic int mbox_handle_errors(struct index_storage *istorage)
2129efcd74a72d051d182171b7e07916308e386dTimo Sirainen struct mail_storage *storage = &istorage->storage;
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen mail_storage_set_error(storage, "Permission denied");
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen mail_storage_set_error(storage, "Not enough disk space");
a943ed0f901e312445fd393249b91932797bba79Josef 'Jeff' Sipek mail_storage_set_error(storage, "Directory structure is broken");
623eaaf530b2bd9cddbaeb88a211873ec9dee436Timo Sirainenstatic int mbox_is_file(const char *path, const char *name, int debug)
623eaaf530b2bd9cddbaeb88a211873ec9dee436Timo Sirainen i_info("mbox autodetect: %s: stat(%s) failed: %m",
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen i_info("mbox autodetect: %s: is a directory (%s)",
009217abb57a24a4076092e8e4e165545747839eStephan Bosch i_info("mbox autodetect: %s: no R/W access (%s)",
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen i_info("mbox autodetect: %s: yes (%s)", name, path);
7dc4bf28c0c4c673a198070edd1ed54e14ae39aeTimo Sirainenstatic int mbox_is_dir(const char *path, const char *name, int debug)
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen i_info("mbox autodetect: %s: stat(%s) failed: %m",
2129efcd74a72d051d182171b7e07916308e386dTimo Sirainen i_info("mbox autodetect: %s: is not a directory (%s)",
2129efcd74a72d051d182171b7e07916308e386dTimo Sirainen i_info("mbox autodetect: %s: no R/W/X access (%s)",
e303353998b1959d1fa914a6be2e85cb9a2615c4Timo Sirainen i_info("mbox autodetect: %s: yes (%s)", name, path);
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainenstatic int mbox_autodetect(const char *data, enum mail_storage_flags flags)
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen int debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
abb404575a238f27ea03b6049880f30f1656ddc4Timo Sirainen i_info("mbox autodetect: data=%s, splitting ':' -> %s",
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen if (*path != '\0' && mbox_is_file(path, "INBOX file", debug))
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen if (mbox_is_dir(t_strconcat(path, "/.imap", NULL), "has .imap/", debug))
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen if (mbox_is_file(t_strconcat(path, "/inbox", NULL), "has inbox", debug))
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen if (mbox_is_file(t_strconcat(path, "/mbox", NULL), "has mbox", debug))
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainenstatic const char *get_root_dir(enum mail_storage_flags flags)
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen int debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
return path;
if (debug)
if (debug)
return path;
if (debug)
if (debug)
if (debug)
return NULL;
if (debug)
return path;
if (debug)
if (debug)
return path;
if (debug)
if (debug)
return path;
return NULL;
return NULL;
if (debug)
return path;
static struct mail_storage *
int autodetect;
if (autodetect) {
if (debug)
if (p == NULL) {
return NULL;
} while (p != NULL);
return NULL;
return NULL;
return NULL;
if (debug) {
int newdir;
return TRUE;
return FALSE;
return FALSE;
return TRUE;
const char *name)
return FALSE;
const char *name)
return FALSE;
const char *name)
return NULL;
if (p == NULL)
const char *name)
const char *index_dir;
int fd;
return FALSE;
static struct mbox_mailbox *
return NULL;
return mbox;
static struct mailbox *
return NULL;
static struct mailbox *
return NULL;
return NULL;
static struct mailbox *
const char *path;
return NULL;
return NULL;
return NULL;
return NULL;
name);
path);
return NULL;
int directory)
const char *path, *p;
int fd;
if (p != NULL) {
if (directory) {
name);
if (p != NULL) {
newpath);
const char *path;
const char *name,
const char *path;
int ret = 0;
return ret;