--- /dev/null
+/* Copyright (c) 2008 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "array.h"
+#include "mail-namespace.h"
+#include "mail-user.h"
+
+struct mail_user_module_register mail_user_module_register = { 0 };
+void (*hook_mail_user_created)(struct mail_user *user) = NULL;
+
+static void mail_user_deinit_base(struct mail_user *user)
+{
+ mail_namespaces_deinit(&user->namespaces);
+ pool_unref(&user->pool);
+}
+
+struct mail_user *mail_user_init(const char *username, const char *home)
+{
+ struct mail_user *user;
+ pool_t pool;
+
+ i_assert(username != NULL);
+
+ pool = pool_alloconly_create("mail user", 512);
+ user = p_new(pool, struct mail_user, 1);
+ user->pool = pool;
+ user->username = p_strdup(pool, username);
+ user->home = p_strdup(pool, home);
+ user->v.deinit = mail_user_deinit_base;
+ p_array_init(&user->module_contexts, user->pool, 5);
+
+ if (hook_mail_user_created != NULL)
+ hook_mail_user_created(user);
+ return user;
+}
+
+void mail_user_deinit(struct mail_user **_user)
+{
+ struct mail_user *user = *_user;
+
+ *_user = NULL;
+ user->v.deinit(user);
+}
--- /dev/null
+#ifndef MAIL_USER_H
+#define MAIL_USER_H
+
+struct mail_user;
+
+struct mail_user_vfuncs {
+ void (*deinit)(struct mail_user *user);
+};
+
+struct mail_user {
+ pool_t pool;
+ struct mail_user_vfuncs v;
+
+ const char *username;
+ const char *home;
+
+ struct mail_namespace *namespaces;
+
+ /* Module-specific contexts. See mail_storage_module_id. */
+ ARRAY_DEFINE(module_contexts, union mail_user_module_context *);
+};
+
+struct mail_user_module_register {
+ unsigned int id;
+};
+
+union mail_user_module_context {
+ struct mail_user_vfuncs super;
+ struct mail_user_module_register *reg;
+};
+extern struct mail_user_module_register mail_user_module_register;
+
+/* Called after user has been created */
+extern void (*hook_mail_user_created)(struct mail_user *user);
+
+struct mail_user *mail_user_init(const char *username, const char *home);
+void mail_user_deinit(struct mail_user **user);
+
+#endif