enum mail_storage_flags flags = _storage->flags;
struct mailbox_list_settings list_set;
struct mailbox_list *list;
- const char *layout;
+ const char *layout, *dir;
struct stat st;
if (maildir_get_list_settings(&list_set, data, _storage, &layout,
storage->stat_dirs = getenv("MAILDIR_STAT_DIRS") != NULL;
storage->temp_prefix = mailbox_list_get_temp_prefix(list);
- if (list_set.control_dir == NULL) {
+ if (list_set.control_dir == NULL &&
+ (_storage->ns->flags & NAMESPACE_FLAG_INBOX) != 0) {
/* put the temp files into tmp/ directory preferrably */
- storage->temp_prefix =
- p_strconcat(_storage->pool,
- "tmp/", storage->temp_prefix, NULL);
+ storage->temp_prefix = p_strconcat(_storage->pool, "tmp/",
+ storage->temp_prefix, NULL);
+ dir = mailbox_list_get_path(list, NULL,
+ MAILBOX_LIST_PATH_TYPE_DIR);
+ } else {
+ /* control dir should also be writable */
+ dir = mailbox_list_get_path(list, NULL,
+ MAILBOX_LIST_PATH_TYPE_CONTROL);
}
+ _storage->temp_path_prefix = p_strconcat(_storage->pool, dir, "/",
+ storage->temp_prefix, NULL);
return 0;
}
path = storage->list_module_ctx.super.get_path(list, name, type);
if (type == MAILBOX_LIST_PATH_TYPE_CONTROL ||
type == MAILBOX_LIST_PATH_TYPE_INDEX) {
+ if (name == NULL)
+ return t_strconcat(path, "/"MBOX_INDEX_DIR_NAME, NULL);
+
p = strrchr(path, '/');
if (p == NULL)
return "";
{
struct mbox_storage *storage = (struct mbox_storage *)_storage;
struct mailbox_list_settings list_set;
- const char *layout;
+ const char *layout, *dir;
if (mbox_get_list_settings(&list_set, data, _storage,
&layout, error_r) < 0)
mailbox_list_init(_storage->list, _storage->ns, &list_set,
mail_storage_get_list_flags(_storage->flags) |
MAILBOX_LIST_FLAG_MAILBOX_FILES);
+
+ dir = mailbox_list_get_path(_storage->list, NULL,
+ MAILBOX_LIST_PATH_TYPE_INDEX);
+ if (*dir == '\0') {
+ /* no index directory. just fallback to writing to root. */
+ dir = mailbox_list_get_path(_storage->list, NULL,
+ MAILBOX_LIST_PATH_TYPE_DIR);
+ }
+ _storage->temp_path_prefix = p_strconcat(_storage->pool, dir, "/",
+ mailbox_list_get_temp_prefix(_storage->list), NULL);
return 0;
}
const struct mail_storage *storage_class;
struct mail_namespace *ns;
struct mailbox_list *list;
+ const char *temp_path_prefix;
enum mail_storage_flags flags;
enum file_lock_method lock_method;
value = getenv("MAIL_MAX_KEYWORD_LENGTH");
storage->keyword_max_len = value != NULL ?
atoi(value) : DEFAULT_MAX_KEYWORD_LENGTH;
-
+
if (hook_mail_storage_created != NULL) {
T_BEGIN {
hook_mail_storage_created(storage);
MAILBOX_LIST_PATH_TYPE_INDEX);
}
+const char *mail_storage_get_temp_prefix(struct mail_storage *storage)
+{
+ const char *dir;
+
+ if (storage->temp_path_prefix == NULL) {
+ dir = mailbox_list_get_path(storage->list, NULL,
+ MAILBOX_LIST_PATH_TYPE_DIR);
+ storage->temp_path_prefix = p_strconcat(storage->pool, dir, "/",
+ mailbox_list_get_temp_prefix(storage->list), NULL);
+ }
+
+ return storage->temp_path_prefix;
+}
+
enum mailbox_list_flags
mail_storage_get_list_flags(enum mail_storage_flags storage_flags)
{
in-memory indexes or mailbox doesn't exist. */
const char *mail_storage_get_mailbox_index_dir(struct mail_storage *storage,
const char *name);
+/* Returns path + file prefix for creating a temporary file. */
+const char *mail_storage_get_temp_prefix(struct mail_storage *storage);
/* 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
#include "lib.h"
#include "array.h"
+#include "hostpid.h"
#include "auth-master.h"
#include "mail-namespace.h"
+#include "mail-storage.h"
#include "mail-user.h"
#include <stdlib.h>
return 0;
}
+const char *mail_user_get_temp_prefix(struct mail_user *user)
+{
+ struct mail_namespace *ns;
+
+ if (user->_home != NULL) {
+ return t_strconcat(user->_home, "/.temp.", my_hostname, ".",
+ my_pid, ".", NULL);
+ }
+
+ ns = mail_namespace_find_inbox(user->namespaces);
+ if (ns == NULL)
+ ns = user->namespaces;
+ return mail_storage_get_temp_prefix(ns->storage);
+}
+
void mail_users_init(const char *auth_socket_path, bool debug)
{
const char *base_dir;
successfully, 0 if there is no home directory (either user doesn't exist or
has no home directory) or -1 if lookup failed. */
int mail_user_get_home(struct mail_user *user, const char **home_r);
+/* Returns path + file prefix for creating a temporary file. Uses home
+ directory if possible, fallbacks to mail directory. */
+const char *mail_user_get_temp_prefix(struct mail_user *user);
/* Add more namespaces to user's namespaces. The ->next pointers may be
changed, so the namespaces pointer will be updated to user->namespaces. */