Mercurial > dovecot > core-2.2
changeset 3260:6a179bf1272e HEAD
Moved several getenv()s from lib-storage to main code. deliver binary was
missing several getenvs..
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 03 Apr 2005 14:36:06 +0300 |
parents | 9ea318f232e0 |
children | 74f5843576d0 |
files | src/deliver/deliver.c src/imap/namespace.c src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/maildir/maildir-save.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/mbox/mbox-save.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/pop3/client.c src/pop3/main.c |
diffstat | 13 files changed, 162 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/src/deliver/deliver.c Sun Apr 03 01:44:05 2005 +0300 +++ b/src/deliver/deliver.c Sun Apr 03 14:36:06 2005 +0300 @@ -340,9 +340,12 @@ const char *auth_socket = DEFAULT_AUTH_SOCKET_PATH; const char *destination, *mail; const struct var_expand_table *table; + enum mail_storage_flags flags; + enum mail_storage_lock_method lock_method; struct mail_storage *storage; struct istream *input; int i, ret; + const char *str; lib_init(); lib_init_signals(sig_quit); @@ -402,8 +405,35 @@ table = get_var_expand_table(destination, getenv("HOME")); mail = expand_mail_env(mail, table); + flags = 0; + if (getenv("FULL_FILESYSTEM_ACCESS") != NULL) + flags |= MAIL_STORAGE_FLAG_FULL_FS_ACCESS; + if (getenv("DEBUG") != NULL) + flags |= MAIL_STORAGE_FLAG_DEBUG; + if (getenv("MMAP_DISABLE") != NULL) + flags |= MAIL_STORAGE_FLAG_MMAP_DISABLE; + if (getenv("MMAP_NO_WRITE") != NULL) + flags |= MAIL_STORAGE_FLAG_MMAP_NO_WRITE; + if (getenv("MAIL_READ_MMAPED") != NULL) + flags |= MAIL_STORAGE_FLAG_MMAP_MAILS; + if (getenv("MAIL_SAVE_CRLF") != NULL) + flags |= MAIL_STORAGE_FLAG_SAVE_CRLF; + /*FIXME:if ((uidl_keymask & UIDL_MD5) != 0) + flags |= MAIL_STORAGE_FLAG_KEEP_HEADER_MD5;*/ + + str = getenv("LOCK_METHOD"); + if (str == NULL || strcmp(str, "fcntl") == 0) + lock_method = MAIL_STORAGE_LOCK_FCNTL; + else if (strcmp(str, "flock") == 0) + lock_method = MAIL_STORAGE_LOCK_FLOCK; + else if (strcmp(str, "dotlock") == 0) + lock_method = MAIL_STORAGE_LOCK_DOTLOCK; + else + i_fatal("Unknown lock_method: %s", str); + /* FIXME: how should we handle namespaces? */ - storage = mail_storage_create_with_data(mail, destination, 0); + storage = mail_storage_create_with_data(mail, destination, + flags, lock_method); if (storage == NULL) { i_fatal_status(EX_CONFIG, "Failed to create storage for '%s' with mail '%s'",
--- a/src/imap/namespace.c Sun Apr 03 01:44:05 2005 +0300 +++ b/src/imap/namespace.c Sun Apr 03 14:36:06 2005 +0300 @@ -27,7 +27,8 @@ static struct namespace * namespace_add_env(pool_t pool, const char *data, unsigned int num, - const char *user, enum mail_storage_flags flags) + const char *user, enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method) { struct namespace *ns; const char *sep, *type, *prefix; @@ -68,7 +69,8 @@ ns->inbox = inbox; ns->hidden = hidden; ns->subscriptions = subscriptions; - ns->storage = mail_storage_create_with_data(data, user, flags); + ns->storage = mail_storage_create_with_data(data, user, flags, + lock_method); if (ns->storage == NULL) { i_fatal("Failed to create storage for '%s' with data: %s", ns->prefix, data); @@ -83,8 +85,9 @@ struct namespace *namespace_init(pool_t pool, const char *user) { struct namespace *namespaces, *ns, **ns_p; - enum mail_storage_flags flags; - const char *mail, *data; + enum mail_storage_flags flags; + enum mail_storage_lock_method lock_method; + const char *str, *mail, *data; unsigned int i; flags = 0; @@ -92,6 +95,24 @@ flags |= MAIL_STORAGE_FLAG_FULL_FS_ACCESS; if (getenv("DEBUG") != NULL) flags |= MAIL_STORAGE_FLAG_DEBUG; + if (getenv("MMAP_DISABLE") != NULL) + flags |= MAIL_STORAGE_FLAG_MMAP_DISABLE; + if (getenv("MMAP_NO_WRITE") != NULL) + flags |= MAIL_STORAGE_FLAG_MMAP_NO_WRITE; + if (getenv("MAIL_READ_MMAPED") != NULL) + flags |= MAIL_STORAGE_FLAG_MMAP_MAILS; + if (getenv("MAIL_SAVE_CRLF") != NULL) + flags |= MAIL_STORAGE_FLAG_SAVE_CRLF; + + str = getenv("LOCK_METHOD"); + if (str == NULL || strcmp(str, "fcntl") == 0) + lock_method = MAIL_STORAGE_LOCK_FCNTL; + else if (strcmp(str, "flock") == 0) + lock_method = MAIL_STORAGE_LOCK_FLOCK; + else if (strcmp(str, "dotlock") == 0) + lock_method = MAIL_STORAGE_LOCK_DOTLOCK; + else + i_fatal("Unknown lock_method: %s", str); namespaces = NULL; ns_p = &namespaces; @@ -105,7 +126,8 @@ break; t_push(); - *ns_p = namespace_add_env(pool, data, i, user, flags); + *ns_p = namespace_add_env(pool, data, i, user, flags, + lock_method); t_pop(); ns_p = &(*ns_p)->next; @@ -124,7 +146,8 @@ } ns = p_new(pool, struct namespace, 1); - ns->storage = mail_storage_create_with_data(mail, user, flags); + ns->storage = mail_storage_create_with_data(mail, user, flags, + lock_method); if (ns->storage == NULL) { if (mail != NULL && *mail != '\0') i_fatal("Failed to create storage with data: %s", mail);
--- a/src/lib-storage/index/index-storage.c Sun Apr 03 01:44:05 2005 +0300 +++ b/src/lib-storage/index/index-storage.c Sun Apr 03 14:36:06 2005 +0300 @@ -40,9 +40,12 @@ static int index_storage_refcount = 0; void index_storage_init(struct index_storage *storage, - enum mail_storage_flags flags) + enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method) { storage->storage.flags = flags; + storage->storage.lock_method = lock_method; + ARRAY_CREATE(&storage->storage.module_contexts, storage->storage.pool, void *, 5); index_storage_refcount++; @@ -288,29 +291,30 @@ { enum mail_index_open_flags index_flags; enum mail_index_lock_method lock_method = 0; - const char *str; i_assert(name != NULL); index_flags = MAIL_INDEX_OPEN_FLAG_CREATE; if ((flags & MAILBOX_OPEN_FAST) != 0) index_flags |= MAIL_INDEX_OPEN_FLAG_FAST; - if (getenv("MMAP_DISABLE") != NULL) + if ((ibox->box.storage->flags & MAIL_STORAGE_FLAG_MMAP_DISABLE) != 0) index_flags |= MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE; #ifndef MMAP_CONFLICTS_WRITE - if (getenv("MMAP_NO_WRITE") != NULL) + if ((ibox->box.storage->flags & MAIL_STORAGE_FLAG_MMAP_NO_WRITE) != 0) #endif index_flags |= MAIL_INDEX_OPEN_FLAG_MMAP_NO_WRITE; - str = getenv("LOCK_METHOD"); - if (str == NULL || strcmp(str, "fcntl") == 0) + switch (ibox->storage->storage.lock_method) { + case MAIL_STORAGE_LOCK_FCNTL: lock_method = MAIL_INDEX_LOCK_FCNTL; - else if (strcmp(str, "flock") == 0) + break; + case MAIL_STORAGE_LOCK_FLOCK: lock_method = MAIL_INDEX_LOCK_FLOCK; - else if (strcmp(str, "dotlock") == 0) + break; + case MAIL_STORAGE_LOCK_DOTLOCK: lock_method = MAIL_INDEX_LOCK_DOTLOCK; - else - i_fatal("Unknown lock_method: %s", str); + break; + } do { ibox->box.storage = &ibox->storage->storage; @@ -324,7 +328,8 @@ ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL; ibox->commit_log_file_seq = 0; - ibox->mail_read_mmaped = getenv("MAIL_READ_MMAPED") != NULL; + ibox->mail_read_mmaped = (ibox->box.storage->flags & + MAIL_STORAGE_FLAG_MMAP_MAILS) != 0; if (mail_index_open(index, index_flags, lock_method) < 0) break;
--- a/src/lib-storage/index/index-storage.h Sun Apr 03 01:44:05 2005 +0300 +++ b/src/lib-storage/index/index-storage.h Sun Apr 03 14:36:06 2005 +0300 @@ -134,7 +134,8 @@ void index_storage_destroy_unrefed(void); void index_storage_init(struct index_storage *storage, - enum mail_storage_flags flags); + enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method); void index_storage_deinit(struct index_storage *storage); int index_storage_mailbox_init(struct index_mailbox *ibox,
--- a/src/lib-storage/index/maildir/maildir-save.c Sun Apr 03 01:44:05 2005 +0300 +++ b/src/lib-storage/index/maildir/maildir-save.c Sun Apr 03 14:36:06 2005 +0300 @@ -37,7 +37,6 @@ time_t received_date; uint32_t seq; - unsigned int save_crlf:1; unsigned int failed:1; }; @@ -96,8 +95,6 @@ ctx->tmpdir = p_strconcat(pool, ibox->path, "/tmp", NULL); ctx->newdir = p_strconcat(pool, ibox->path, "/new", NULL); ctx->curdir = p_strconcat(pool, ibox->path, "/cur", NULL); - - ctx->save_crlf = getenv("MAIL_SAVE_CRLF") != NULL; return ctx; } @@ -141,7 +138,8 @@ ctx->input = input; output = o_stream_create_file(ctx->fd, system_pool, 0, FALSE); - ctx->output = ctx->save_crlf ? + ctx->output = (ctx->ibox->storage->storage.flags & + MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? o_stream_create_crlf(default_pool, output) : o_stream_create_lf(default_pool, output); o_stream_unref(output);
--- a/src/lib-storage/index/maildir/maildir-storage.c Sun Apr 03 01:44:05 2005 +0300 +++ b/src/lib-storage/index/maildir/maildir-storage.c Sun Apr 03 14:36:06 2005 +0300 @@ -32,7 +32,8 @@ static struct mail_storage * maildir_create(const char *data, const char *user, - enum mail_storage_flags flags) + enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method) { int debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0; struct index_storage *storage; @@ -131,7 +132,7 @@ storage->control_dir = p_strdup(pool, home_expand(control_dir)); storage->user = p_strdup(pool, user); storage->callbacks = p_new(pool, struct mail_storage_callbacks, 1); - index_storage_init(storage, flags); + index_storage_init(storage, flags, lock_method); (void)verify_inbox(storage); return &storage->storage;
--- a/src/lib-storage/index/mbox/mbox-save.c Sun Apr 03 01:44:05 2005 +0300 +++ b/src/lib-storage/index/mbox/mbox-save.c Sun Apr 03 14:36:06 2005 +0300 @@ -44,7 +44,6 @@ unsigned int synced:1; unsigned int failed:1; - unsigned int save_crlf:1; }; static char my_hostdomain[256] = ""; @@ -344,7 +343,6 @@ ctx->trans = t->ictx.trans; ctx->append_offset = (uoff_t)-1; ctx->headers = str_new(default_pool, 512); - ctx->save_crlf = getenv("MAIL_SAVE_CRLF") != NULL; ctx->mail_offset = (uoff_t)-1; } @@ -396,7 +394,9 @@ mbox_hide_headers_count, save_header_callback, ctx); - ctx->body_output = getenv("MAIL_SAVE_CRLF") != NULL ? + ctx->body_output = + (ctx->ibox->storage->storage.flags & + MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? o_stream_create_crlf(default_pool, ctx->output) : o_stream_create_lf(default_pool, ctx->output); if (ctx->ibox->mbox_save_md5 && ctx->synced)
--- a/src/lib-storage/index/mbox/mbox-storage.c Sun Apr 03 01:44:05 2005 +0300 +++ b/src/lib-storage/index/mbox/mbox-storage.c Sun Apr 03 14:36:06 2005 +0300 @@ -243,7 +243,8 @@ } static struct mail_storage * -mbox_create(const char *data, const char *user, enum mail_storage_flags flags) +mbox_create(const char *data, const char *user, enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method) { int debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0; struct index_storage *storage; @@ -338,7 +339,7 @@ storage->index_dir = p_strdup(pool, home_expand(index_dir)); storage->user = p_strdup(pool, user); storage->callbacks = p_new(pool, struct mail_storage_callbacks, 1); - index_storage_init(storage, flags); + index_storage_init(storage, flags, lock_method); return &storage->storage; } @@ -511,7 +512,7 @@ ibox->md5hdr_ext_idx = mail_index_ext_register(ibox->index, "header-md5", 0, 16, 1); - if ((flags & MAILBOX_OPEN_KEEP_HEADER_MD5) != 0) + if ((storage->storage.flags & MAIL_STORAGE_FLAG_KEEP_HEADER_MD5) != 0) ibox->mbox_save_md5 = TRUE; return ibox; }
--- a/src/lib-storage/mail-storage-private.h Sun Apr 03 01:44:05 2005 +0300 +++ b/src/lib-storage/mail-storage-private.h Sun Apr 03 14:36:06 2005 +0300 @@ -8,8 +8,10 @@ extern unsigned int mail_storage_module_id; struct mail_storage_vfuncs { - struct mail_storage *(*create)(const char *data, const char *user, - enum mail_storage_flags flags); + struct mail_storage * + (*create)(const char *data, const char *user, + enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method); void (*destroy)(struct mail_storage *storage); int (*autodetect)(const char *data, enum mail_storage_flags flags); @@ -59,6 +61,7 @@ char *error; enum mail_storage_flags flags; + enum mail_storage_lock_method lock_method; /* Module-specific contexts. See mail_storage_module_id. */ array_t ARRAY_DEFINE(module_contexts, void);
--- a/src/lib-storage/mail-storage.c Sun Apr 03 01:44:05 2005 +0300 +++ b/src/lib-storage/mail-storage.c Sun Apr 03 14:36:06 2005 +0300 @@ -70,7 +70,8 @@ struct mail_storage * mail_storage_create(const char *name, const char *data, const char *user, - enum mail_storage_flags flags) + enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method) { struct mail_storage_list *list; @@ -78,20 +79,23 @@ for (list = storages; list != NULL; list = list->next) { if (strcasecmp(list->storage->name, name) == 0) - return list->storage->v.create(data, user, flags); + return list->storage->v.create(data, user, flags, + lock_method); } return NULL; } struct mail_storage * -mail_storage_create_default(const char *user, enum mail_storage_flags flags) +mail_storage_create_default(const char *user, enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method) { struct mail_storage_list *list; struct mail_storage *storage; for (list = storages; list != NULL; list = list->next) { - storage = list->storage->v.create(NULL, user, flags); + storage = list->storage->v.create(NULL, user, flags, + lock_method); if (storage != NULL) return storage; } @@ -114,13 +118,14 @@ struct mail_storage * mail_storage_create_with_data(const char *data, const char *user, - enum mail_storage_flags flags) + enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method) { struct mail_storage *storage; const char *p, *name; if (data == NULL || *data == '\0') - return mail_storage_create_default(user, flags); + return mail_storage_create_default(user, flags, lock_method); /* check if we're in the form of mailformat:data (eg. maildir:Maildir) */ @@ -129,11 +134,14 @@ if (*p == ':') { name = t_strdup_until(data, p); - storage = mail_storage_create(name, p+1, user, flags); + storage = mail_storage_create(name, p+1, user, flags, + lock_method); } else { storage = mail_storage_autodetect(data, flags); - if (storage != NULL) - storage = storage->v.create(data, user, flags); + if (storage != NULL) { + storage = storage->v.create(data, user, flags, + lock_method); + } } return storage;
--- a/src/lib-storage/mail-storage.h Sun Apr 03 01:44:05 2005 +0300 +++ b/src/lib-storage/mail-storage.h Sun Apr 03 14:36:06 2005 +0300 @@ -9,7 +9,25 @@ /* Print debugging information while initializing the storage */ MAIL_STORAGE_FLAG_DEBUG = 0x01, /* Allow full filesystem access with absolute or relative paths. */ - MAIL_STORAGE_FLAG_FULL_FS_ACCESS = 0x02 + MAIL_STORAGE_FLAG_FULL_FS_ACCESS = 0x02, + /* Don't try to mmap() files */ + MAIL_STORAGE_FLAG_MMAP_DISABLE = 0x04, + /* Don't try to write() to mmap()ed files. Required for the few + OSes that don't have unified buffer cache + (currently OpenBSD <= 3.5) */ + MAIL_STORAGE_FLAG_MMAP_NO_WRITE = 0x08, + /* Remember message headers' MD5 sum */ + MAIL_STORAGE_FLAG_KEEP_HEADER_MD5 = 0x10, + /* Use mmap() for reading mail files. */ + MAIL_STORAGE_FLAG_MMAP_MAILS = 0x20, + /* Use CRLF linefeeds when saving mails. */ + MAIL_STORAGE_FLAG_SAVE_CRLF = 0x40 +}; + +enum mail_storage_lock_method { + MAIL_STORAGE_LOCK_FCNTL, + MAIL_STORAGE_LOCK_FLOCK, + MAIL_STORAGE_LOCK_DOTLOCK }; enum mailbox_open_flags { @@ -19,9 +37,7 @@ (eg. when opening mailbox just for STATUS). */ MAILBOX_OPEN_FAST = 0x02, /* Don't reset MAIL_RECENT flags when syncing */ - MAILBOX_OPEN_KEEP_RECENT = 0x04, - /* Remember message headers' MD5 sum */ - MAILBOX_OPEN_KEEP_HEADER_MD5 = 0x08 + MAILBOX_OPEN_KEEP_RECENT = 0x04 }; enum mailbox_list_flags { @@ -205,14 +221,17 @@ hierarchy_sep overrides the default separator if it's not '\0'. */ struct mail_storage * mail_storage_create(const char *name, const char *data, const char *user, - enum mail_storage_flags flags); + enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method); void mail_storage_destroy(struct mail_storage *storage); struct mail_storage * -mail_storage_create_default(const char *user, enum mail_storage_flags flags); +mail_storage_create_default(const char *user, enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method); struct mail_storage * mail_storage_create_with_data(const char *data, const char *user, - enum mail_storage_flags flags); + enum mail_storage_flags flags, + enum mail_storage_lock_method lock_method); char mail_storage_get_hierarchy_sep(struct mail_storage *storage);
--- a/src/pop3/client.c Sun Apr 03 01:44:05 2005 +0300 +++ b/src/pop3/client.c Sun Apr 03 14:36:06 2005 +0300 @@ -151,8 +151,6 @@ flags = 0; if (no_flag_updates) flags |= MAILBOX_OPEN_KEEP_RECENT; - if ((uidl_keymask & UIDL_MD5) != 0) - flags |= MAILBOX_OPEN_KEEP_HEADER_MD5; client->mailbox = mailbox_open(storage, "INBOX", NULL, flags); if (client->mailbox == NULL) { i_error("Couldn't open INBOX: %s",
--- a/src/pop3/main.c Sun Apr 03 01:44:05 2005 +0300 +++ b/src/pop3/main.c Sun Apr 03 14:36:06 2005 +0300 @@ -142,8 +142,9 @@ static int main_init(void) { enum mail_storage_flags flags; + enum mail_storage_lock_method lock_method; struct mail_storage *storage; - const char *mail; + const char *str, *mail; lib_init_signals(sig_quit); @@ -183,8 +184,29 @@ flags |= MAIL_STORAGE_FLAG_FULL_FS_ACCESS; if (getenv("DEBUG") != NULL) flags |= MAIL_STORAGE_FLAG_DEBUG; + if (getenv("MMAP_DISABLE") != NULL) + flags |= MAIL_STORAGE_FLAG_MMAP_DISABLE; + if (getenv("MMAP_NO_WRITE") != NULL) + flags |= MAIL_STORAGE_FLAG_MMAP_NO_WRITE; + if (getenv("MAIL_READ_MMAPED") != NULL) + flags |= MAIL_STORAGE_FLAG_MMAP_MAILS; + if (getenv("MAIL_SAVE_CRLF") != NULL) + flags |= MAIL_STORAGE_FLAG_SAVE_CRLF; + if ((uidl_keymask & UIDL_MD5) != 0) + flags |= MAIL_STORAGE_FLAG_KEEP_HEADER_MD5; - storage = mail_storage_create_with_data(mail, getenv("USER"), flags); + str = getenv("LOCK_METHOD"); + if (str == NULL || strcmp(str, "fcntl") == 0) + lock_method = MAIL_STORAGE_LOCK_FCNTL; + else if (strcmp(str, "flock") == 0) + lock_method = MAIL_STORAGE_LOCK_FLOCK; + else if (strcmp(str, "dotlock") == 0) + lock_method = MAIL_STORAGE_LOCK_DOTLOCK; + else + i_fatal("Unknown lock_method: %s", str); + + storage = mail_storage_create_with_data(mail, getenv("USER"), + flags, lock_method); if (storage == NULL) { /* failed */ if (mail != NULL && *mail != '\0')