changeset 903:fd8888f6f037 HEAD

Naming style changes, finally got tired of most of the typedefs. Also the previous enum -> macro change reverted so that we don't use the highest bit anymore, that's incompatible with old indexes so they will be rebuilt.
author Timo Sirainen <tss@iki.fi>
date Sun, 05 Jan 2003 15:09:51 +0200
parents 5043e48c022f
children 77a0eb2b5397
files configure.in src/auth/auth-digest-md5.c src/auth/auth-interface.h src/auth/auth-plain.c src/auth/auth.c src/auth/auth.h src/auth/common.h src/auth/cookie.c src/auth/cookie.h src/auth/login-connection.c src/auth/login-connection.h src/auth/main.c src/auth/master.c src/auth/userinfo-pam.c src/auth/userinfo-passwd-file.c src/auth/userinfo-passwd.c src/auth/userinfo-passwd.h src/auth/userinfo-shadow.c src/auth/userinfo-vpopmail.c src/auth/userinfo.c src/auth/userinfo.h src/imap/client.c src/imap/client.h src/imap/cmd-append.c src/imap/cmd-authenticate.c src/imap/cmd-capability.c src/imap/cmd-check.c src/imap/cmd-close.c src/imap/cmd-copy.c src/imap/cmd-create.c src/imap/cmd-delete.c src/imap/cmd-examine.c src/imap/cmd-expunge.c src/imap/cmd-fetch.c src/imap/cmd-list.c src/imap/cmd-login.c src/imap/cmd-logout.c src/imap/cmd-lsub.c src/imap/cmd-noop.c src/imap/cmd-rename.c src/imap/cmd-search.c src/imap/cmd-select.c src/imap/cmd-sort.c src/imap/cmd-status.c src/imap/cmd-store.c src/imap/cmd-subscribe.c src/imap/cmd-uid.c src/imap/cmd-unsubscribe.c src/imap/commands-util.c src/imap/commands-util.h src/imap/commands.h src/imap/common.h src/imap/mail-storage-callbacks.c src/imap/main.c src/imap/rawlog.c src/lib-charset/charset-iconv.c src/lib-charset/charset-utf8.c src/lib-charset/charset-utf8.h src/lib-imap/imap-base-subject.c src/lib-imap/imap-base-subject.h src/lib-imap/imap-bodystructure.c src/lib-imap/imap-bodystructure.h src/lib-imap/imap-envelope.c src/lib-imap/imap-envelope.h src/lib-imap/imap-match.c src/lib-imap/imap-match.h src/lib-imap/imap-message-cache.c src/lib-imap/imap-message-cache.h src/lib-imap/imap-parser.c src/lib-imap/imap-parser.h src/lib-imap/imap-quote.c src/lib-imap/imap-quote.h src/lib-imap/imap-util.c src/lib-imap/imap-util.h src/lib-index/mail-custom-flags.c src/lib-index/mail-custom-flags.h src/lib-index/mail-index-compress.c src/lib-index/mail-index-data.c src/lib-index/mail-index-data.h src/lib-index/mail-index-fsck.c src/lib-index/mail-index-open.c src/lib-index/mail-index-update-cache.c src/lib-index/mail-index-update.c src/lib-index/mail-index-util.c src/lib-index/mail-index-util.h src/lib-index/mail-index.c src/lib-index/mail-index.h src/lib-index/mail-lockdir.c src/lib-index/mail-lockdir.h src/lib-index/mail-modifylog.c src/lib-index/mail-modifylog.h src/lib-index/mail-tree-redblack.c src/lib-index/mail-tree.c src/lib-index/mail-tree.h src/lib-index/maildir/maildir-build.c src/lib-index/maildir/maildir-index.c src/lib-index/maildir/maildir-index.h src/lib-index/maildir/maildir-open.c src/lib-index/maildir/maildir-rebuild.c src/lib-index/maildir/maildir-sync.c src/lib-index/maildir/maildir-update.c src/lib-index/mbox/mbox-append.c src/lib-index/mbox/mbox-from.c src/lib-index/mbox/mbox-index.c src/lib-index/mbox/mbox-index.h src/lib-index/mbox/mbox-lock.c src/lib-index/mbox/mbox-lock.h src/lib-index/mbox/mbox-open.c src/lib-index/mbox/mbox-rebuild.c src/lib-index/mbox/mbox-rewrite.c src/lib-index/mbox/mbox-sync-full.c src/lib-index/mbox/mbox-sync.c src/lib-mail/Makefile.am src/lib-mail/message-address.c src/lib-mail/message-address.h src/lib-mail/message-body-search.c src/lib-mail/message-body-search.h src/lib-mail/message-content-parser.c src/lib-mail/message-date.c src/lib-mail/message-date.h src/lib-mail/message-header-decode.c src/lib-mail/message-header-search.c src/lib-mail/message-header-search.h src/lib-mail/message-parser.c src/lib-mail/message-parser.h src/lib-mail/message-part-serialize.c src/lib-mail/message-part-serialize.h src/lib-mail/message-send.c src/lib-mail/message-send.h src/lib-mail/message-size.c src/lib-mail/message-size.h src/lib-mail/message-tokenize.c src/lib-mail/message-tokenize.h src/lib-mail/quoted-printable.c src/lib-mail/quoted-printable.h src/lib-mail/rfc822-address.c src/lib-mail/rfc822-address.h src/lib-mail/rfc822-date.c src/lib-mail/rfc822-date.h src/lib-mail/rfc822-tokenize.c src/lib-mail/rfc822-tokenize.h src/lib-storage/index/index-copy.c src/lib-storage/index/index-expunge.c src/lib-storage/index/index-fetch-section.c src/lib-storage/index/index-fetch.c src/lib-storage/index/index-fetch.h src/lib-storage/index/index-mailbox-check.c src/lib-storage/index/index-messageset.c src/lib-storage/index/index-messageset.h src/lib-storage/index/index-msgcache.c src/lib-storage/index/index-save.c src/lib-storage/index/index-search.c src/lib-storage/index/index-sort.c src/lib-storage/index/index-sort.h src/lib-storage/index/index-status.c src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/index-sync.c src/lib-storage/index/index-update-flags.c src/lib-storage/index/maildir/maildir-copy.c src/lib-storage/index/maildir/maildir-expunge.c src/lib-storage/index/maildir/maildir-list.c src/lib-storage/index/maildir/maildir-save.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/maildir/maildir-storage.h src/lib-storage/index/mbox/mbox-expunge.c src/lib-storage/index/mbox/mbox-list.c src/lib-storage/index/mbox/mbox-save.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/mbox/mbox-storage.h src/lib-storage/mail-search.c src/lib-storage/mail-search.h src/lib-storage/mail-sort.c src/lib-storage/mail-sort.h src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/lib-storage/subscription-file/subscription-file.c src/lib-storage/subscription-file/subscription-file.h src/lib/base64.c src/lib/base64.h src/lib/buffer.c src/lib/buffer.h src/lib/compat.h src/lib/data-stack.c src/lib/env-util.c src/lib/failures.h src/lib/hash.c src/lib/hash.h src/lib/hex-binary.c src/lib/hex-binary.h src/lib/imem.c src/lib/imem.h src/lib/ioloop-internal.h src/lib/ioloop-poll.c src/lib/ioloop-select.c src/lib/ioloop.c src/lib/ioloop.h src/lib/iostream-internal.h src/lib/iostream.c src/lib/istream-data.c src/lib/istream-file.c src/lib/istream-internal.h src/lib/istream-mmap.c src/lib/istream.c src/lib/istream.h src/lib/lib.h src/lib/macros.h src/lib/md5.c src/lib/md5.h src/lib/mempool-alloconly.c src/lib/mempool-datastack.c src/lib/mempool-system.c src/lib/mempool.h src/lib/network.c src/lib/network.h src/lib/ostream-file.c src/lib/ostream-internal.h src/lib/ostream.c src/lib/ostream.h src/lib/str.c src/lib/str.h src/lib/strescape.c src/lib/strescape.h src/lib/strfuncs.c src/lib/strfuncs.h src/login/auth-connection.c src/login/auth-connection.h src/login/client-authenticate.c src/login/client-authenticate.h src/login/client.c src/login/client.h src/login/main.c src/login/master.c src/login/master.h src/login/ssl-proxy-gnutls.c src/login/ssl-proxy-openssl.c src/master/auth-process.c src/master/auth-process.h src/master/common.h src/master/imap-process.c src/master/login-process.c src/master/main.c src/master/master-interface.h src/master/settings.c src/master/settings.h src/master/ssl-init.c
diffstat 246 files changed, 5051 insertions(+), 4755 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Sun Jan 05 11:23:13 2003 +0200
+++ b/configure.in	Sun Jan 05 15:09:51 2003 +0200
@@ -773,7 +773,7 @@
 echo '#include "lib.h"' >> $file
 echo '#include "mail-storage.h"' >> $file
 for storage in $STORAGE; do
-	echo "extern MailStorage ${storage}_storage;" >> $file
+	echo "extern struct mail_storage ${storage}_storage;" >> $file
 done
 echo "void mail_storage_register_all(void) {" >> $file
 for storage in $STORAGE; do
--- a/src/auth/auth-digest-md5.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/auth-digest-md5.c	Sun Jan 05 15:09:51 2003 +0200
@@ -21,23 +21,23 @@
 /* Linear whitespace */
 #define IS_LWS(c) ((c) == ' ' || (c) == '\t')
 
-typedef enum {
+enum qop_option {
 	QOP_AUTH	= 0x01,	/* authenticate */
 	QOP_AUTH_INT	= 0x02, /* + integrity protection, not supported yet */
 	QOP_AUTH_CONF	= 0x04, /* + encryption, not supported yet */
 
 	QOP_COUNT	= 3
-} QopOption;
+};
 
 static char *qop_names[] = { "auth", "auth-int", "auth-conf" };
 
-typedef struct {
-	Pool pool;
+struct auth_data {
+	pool_t pool;
 	unsigned int authenticated:1;
 
 	/* requested: */
 	char *nonce;
-	QopOption qop;
+	enum qop_option qop;
 
 	/* received: */
 	char *realm; /* may be NULL */
@@ -52,13 +52,13 @@
 
 	/* final reply: */
 	char *rspauth;
-        AuthCookieReplyData cookie_reply;
-} AuthData;
+        struct auth_cookie_reply_data cookie_reply;
+};
 
-static const char *get_digest_challenge(AuthData *auth)
+static const char *get_digest_challenge(struct auth_data *auth)
 {
-	String *qoplist, *realms;
-	Buffer *buf;
+	string_t *qoplist, *realms;
+	buffer_t *buf;
 	const char *const *tmp;
 	unsigned char nonce[16];
 	int i;
@@ -109,9 +109,9 @@
 			   NULL);
 }
 
-static int verify_auth(AuthData *auth)
+static int verify_auth(struct auth_data *auth)
 {
-	MD5Context ctx;
+	struct md5_context ctx;
 	unsigned char digest[16];
 	const char *a1_hex, *a2_hex, *response_hex;
 	int i;
@@ -170,8 +170,10 @@
 			md5_update(&ctx, auth->digest_uri,
 				   strlen(auth->digest_uri));
 		}
-		if (auth->qop == QOP_AUTH_INT || auth->qop == QOP_AUTH_CONF)
-			md5_update(&ctx, ":00000000000000000000000000000000", 33);
+		if (auth->qop == QOP_AUTH_INT || auth->qop == QOP_AUTH_CONF) {
+			md5_update(&ctx, ":00000000000000000000000000000000",
+				   33);
+		}
 		md5_final(&ctx, digest);
 		a2_hex = binary_to_hex(digest, 16);
 
@@ -286,7 +288,7 @@
 	return ret;
 }
 
-static int auth_handle_response(AuthData *auth, char *key, char *value,
+static int auth_handle_response(struct auth_data *auth, char *key, char *value,
 				const char **error)
 {
 	int i;
@@ -449,7 +451,7 @@
 	return TRUE;
 }
 
-static int parse_digest_response(AuthData *auth, const char *data,
+static int parse_digest_response(struct auth_data *auth, const char *data,
 				 size_t size, const char **error)
 {
 	char *copy, *key, *value;
@@ -516,13 +518,14 @@
 	return !failed;
 }
 
-static void auth_digest_md5_continue(CookieData *cookie,
-				     AuthContinuedRequestData *request,
-				     const unsigned char *data,
-				     AuthCallback callback, void *context)
+static void
+auth_digest_md5_continue(struct cookie_data *cookie,
+			 struct auth_continued_request_data *request,
+			 const unsigned char *data,
+			 AuthCallback callback, void *context)
 {
-	AuthData *auth = cookie->context;
-	AuthReplyData reply;
+	struct auth_data *auth = cookie->context;
+	struct auth_reply_data reply;
 	const char *error;
 
 	/* initialize reply */
@@ -557,40 +560,41 @@
 	cookie_remove(cookie->cookie);
 }
 
-static int auth_digest_md5_fill_reply(CookieData *cookie,
-				      AuthCookieReplyData *reply)
+static int auth_digest_md5_fill_reply(struct cookie_data *cookie,
+				      struct auth_cookie_reply_data *reply)
 {
-	AuthData *auth = cookie->context;
+	struct auth_data *auth = cookie->context;
 
 	if (!auth->authenticated)
 		return FALSE;
 
-	memcpy(reply, &auth->cookie_reply, sizeof(AuthCookieReplyData));
+	memcpy(reply, &auth->cookie_reply,
+	       sizeof(struct auth_cookie_reply_data));
 	return TRUE;
 }
 
-static void auth_digest_md5_free(CookieData *cookie)
+static void auth_digest_md5_free(struct cookie_data *cookie)
 {
-	pool_unref(((AuthData *) cookie->context)->pool);
+	pool_unref(((struct auth_data *) cookie->context)->pool);
 }
 
 static void auth_digest_md5_init(unsigned int login_pid,
-				 AuthInitRequestData *request,
+				 struct auth_init_request_data *request,
 				 AuthCallback callback, void *context)
 {
-	CookieData *cookie;
-	AuthReplyData reply;
-	AuthData *auth;
-	Pool pool;
+	struct cookie_data *cookie;
+	struct auth_reply_data reply;
+	struct auth_data *auth;
+	pool_t pool;
 	const char *challenge;
 
 	pool = pool_alloconly_create("Digest-MD5", 2048);
-	auth = p_new(pool, AuthData, 1);
+	auth = p_new(pool, struct auth_data, 1);
 	auth->pool = pool;
 
 	auth->qop = QOP_AUTH;
 
-	cookie = p_new(pool, CookieData, 1);
+	cookie = p_new(pool, struct cookie_data, 1);
 	cookie->login_pid = login_pid;
 	cookie->auth_fill_reply = auth_digest_md5_fill_reply;
 	cookie->auth_continue = auth_digest_md5_continue;
@@ -615,7 +619,7 @@
 	t_pop();
 }
 
-AuthModule auth_digest_md5 = {
+struct auth_module auth_digest_md5 = {
 	AUTH_METHOD_DIGEST_MD5,
 	auth_digest_md5_init
 };
--- a/src/auth/auth-interface.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/auth-interface.h	Sun Jan 05 15:09:51 2003 +0200
@@ -11,76 +11,76 @@
 #define AUTH_MAX_HOME_LEN		256
 #define AUTH_MAX_MAIL_LEN		256
 
-typedef enum {
+enum auth_request_type {
 	AUTH_REQUEST_NONE, /* must not be requested */
 	AUTH_REQUEST_INIT,
         AUTH_REQUEST_CONTINUE
-} AuthRequestType;
+};
 
-typedef enum {
+enum auth_result {
 	AUTH_RESULT_INTERNAL_FAILURE, /* never sent by imap-auth */
 
 	AUTH_RESULT_CONTINUE,
 	AUTH_RESULT_SUCCESS,
 	AUTH_RESULT_FAILURE
-} AuthResult;
+};
 
-typedef enum {
+enum auth_method {
 	AUTH_METHOD_PLAIN	= 0x01,
 	AUTH_METHOD_DIGEST_MD5	= 0x02,
 
 	AUTH_METHODS_COUNT	= 2
-} AuthMethod;
+};
 
 /* Initialization reply, sent after client is connected */
-typedef struct {
+struct auth_init_data {
 	unsigned int auth_process; /* unique auth process identifier */
-	AuthMethod auth_methods; /* valid authentication methods */
-} AuthInitData;
+	enum auth_method auth_methods; /* valid authentication methods */
+};
 
 /* Initialization handshake from client. */
-typedef struct {
+struct client_auth_init_data {
 	unsigned int pid; /* unique identifier for client process */
-} ClientAuthInitData;
+};
 
 /* New authentication request */
-typedef struct {
-	AuthRequestType type; /* AUTH_REQUEST_INIT */
+struct auth_init_request_data {
+	enum auth_request_type type; /* AUTH_REQUEST_INIT */
 
-	AuthMethod method;
+	enum auth_method method;
 	unsigned int id; /* AuthReplyData.id will contain this value */
-} AuthInitRequestData;
+};
 
 /* Continued authentication request */
-typedef struct {
-	AuthRequestType type; /* AUTH_REQUEST_CONTINUE */
+struct auth_continued_request_data {
+	enum auth_request_type type; /* AUTH_REQUEST_CONTINUE */
 
 	unsigned char cookie[AUTH_COOKIE_SIZE];
 	unsigned int id; /* AuthReplyData.id will contain this value */
 
 	size_t data_size;
 	/* unsigned char data[]; */
-} AuthContinuedRequestData;
+};
 
 /* Reply to authentication */
-typedef struct {
+struct auth_reply_data {
 	unsigned int id;
 	unsigned char cookie[AUTH_COOKIE_SIZE];
-	AuthResult result;
+	enum auth_result result;
 
 	size_t data_size;
 	/* unsigned char data[]; */
-} AuthReplyData;
+};
 
 /* Request data associated to cookie */
-typedef struct {
+struct auth_cookie_request_data {
 	unsigned int id;
 	unsigned int login_pid;
 	unsigned char cookie[AUTH_COOKIE_SIZE];
-} AuthCookieRequestData;
+};
 
 /* Reply to cookie request */
-typedef struct {
+struct auth_cookie_reply_data {
 	unsigned int id;
 	int success; /* FALSE if cookie wasn't found */
 
@@ -93,6 +93,6 @@
 	char mail[AUTH_MAX_MAIL_LEN];
 
 	int chroot; /* chroot to home directory */
-} AuthCookieReplyData;
+};
 
 #endif
--- a/src/auth/auth-plain.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/auth-plain.c	Sun Jan 05 15:09:51 2003 +0200
@@ -6,13 +6,13 @@
 #include "cookie.h"
 #include "userinfo.h"
 
-static void auth_plain_continue(CookieData *cookie,
-				AuthContinuedRequestData *request,
+static void auth_plain_continue(struct cookie_data *cookie,
+				struct auth_continued_request_data *request,
 				const unsigned char *data,
 				AuthCallback callback, void *context)
 {
-	AuthCookieReplyData *cookie_reply = cookie->context;
-	AuthReplyData reply;
+	struct auth_cookie_reply_data *cookie_reply = cookie->context;
+	struct auth_reply_data reply;
 	const char *user;
 	char *pass;
 	size_t i, count, len;
@@ -62,37 +62,38 @@
 	}
 }
 
-static int auth_plain_fill_reply(CookieData *cookie, AuthCookieReplyData *reply)
+static int auth_plain_fill_reply(struct cookie_data *cookie,
+				 struct auth_cookie_reply_data *reply)
 {
-	AuthCookieReplyData *cookie_reply;
+	struct auth_cookie_reply_data *cookie_reply;
 
 	cookie_reply = cookie->context;
 	if (!cookie_reply->success)
 		return FALSE;
 
-	memcpy(reply, cookie_reply, sizeof(AuthCookieReplyData));
+	memcpy(reply, cookie_reply, sizeof(struct auth_cookie_reply_data));
 	return TRUE;
 }
 
-static void auth_plain_free(CookieData *cookie)
+static void auth_plain_free(struct cookie_data *cookie)
 {
 	i_free(cookie->context);
 	i_free(cookie);
 }
 
 static void auth_plain_init(unsigned int login_pid,
-			    AuthInitRequestData *request,
+			    struct auth_init_request_data *request,
 			    AuthCallback callback, void *context)
 {
-	CookieData *cookie;
-	AuthReplyData reply;
+	struct cookie_data *cookie;
+	struct auth_reply_data reply;
 
-	cookie = i_new(CookieData, 1);
+	cookie = i_new(struct cookie_data, 1);
 	cookie->login_pid = login_pid;
 	cookie->auth_fill_reply = auth_plain_fill_reply;
 	cookie->auth_continue = auth_plain_continue;
 	cookie->free = auth_plain_free;
-	cookie->context = i_new(AuthCookieReplyData, 1);
+	cookie->context = i_new(struct auth_cookie_reply_data, 1);
 
 	cookie_add(cookie);
 
@@ -105,7 +106,7 @@
 	callback(&reply, NULL, context);
 }
 
-AuthModule auth_plain = {
+struct auth_module auth_plain = {
 	AUTH_METHOD_PLAIN,
 	auth_plain_init
 };
--- a/src/auth/auth.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/auth.c	Sun Jan 05 15:09:51 2003 +0200
@@ -6,38 +6,36 @@
 
 #include <stdlib.h>
 
-typedef struct _AuthModuleList AuthModuleList;
+struct auth_module_list {
+	struct auth_module_list *next;
 
-struct _AuthModuleList {
-	AuthModuleList *next;
-
-	AuthModule module;
+	struct auth_module module;
 };
 
-AuthMethod auth_methods;
+enum auth_method auth_methods;
 const char *const *auth_realms;
 
-static AuthModuleList *auth_modules;
-static AuthReplyData failure_reply;
+static struct auth_module_list *auth_modules;
+static struct auth_reply_data failure_reply;
 
-void auth_register_module(AuthModule *module)
+void auth_register_module(struct auth_module *module)
 {
-	AuthModuleList *list;
+	struct auth_module_list *list;
 
 	i_assert((auth_methods & module->method) == 0);
 
 	auth_methods |= module->method;
 
-	list = i_new(AuthModuleList, 1);
-	memcpy(&list->module, module, sizeof(AuthModule));
+	list = i_new(struct auth_module_list, 1);
+	memcpy(&list->module, module, sizeof(struct auth_module));
 
 	list->next = auth_modules;
 	auth_modules = list;
 }
 
-void auth_unregister_module(AuthModule *module)
+void auth_unregister_module(struct auth_module *module)
 {
-	AuthModuleList **pos, *list;
+	struct auth_module_list **pos, *list;
 
 	if ((auth_methods & module->method) == 0)
 		return; /* not registered */
@@ -55,10 +53,10 @@
 }
 
 void auth_init_request(unsigned int login_pid,
-		       AuthInitRequestData *request,
+		       struct auth_init_request_data *request,
 		       AuthCallback callback, void *context)
 {
-	AuthModuleList *list;
+	struct auth_module_list *list;
 
 	if ((auth_methods & request->method) == 0) {
 		/* unsupported method */
@@ -81,11 +79,11 @@
 }
 
 void auth_continue_request(unsigned int login_pid,
-			   AuthContinuedRequestData *request,
+			   struct auth_continued_request_data *request,
 			   const unsigned char *data,
 			   AuthCallback callback, void *context)
 {
-	CookieData *cookie_data;
+	struct cookie_data *cookie_data;
 
 	cookie_data = cookie_lookup(request->cookie);
 	if (cookie_data == NULL) {
@@ -100,8 +98,8 @@
 	}
 }
 
-extern AuthModule auth_plain;
-extern AuthModule auth_digest_md5;
+extern struct auth_module auth_plain;
+extern struct auth_module auth_digest_md5;
 
 void auth_init(void)
 {
--- a/src/auth/auth.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/auth.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,28 +3,28 @@
 
 #include "auth-interface.h"
 
-typedef void (*AuthCallback) (AuthReplyData *reply, const unsigned char *data,
-			      void *context);
+typedef void (*AuthCallback)(struct auth_reply_data *reply,
+			     const unsigned char *data, void *context);
 
-typedef struct {
-	AuthMethod method;
+struct auth_module {
+	enum auth_method method;
 
 	void (*init)(unsigned int login_pid,
-		     AuthInitRequestData *request,
+		     struct auth_init_request_data *request,
 		     AuthCallback callback, void *context);
-} AuthModule;
+};
 
-extern AuthMethod auth_methods;
+extern enum auth_method auth_methods;
 extern const char *const *auth_realms;
 
-void auth_register_module(AuthModule *module);
-void auth_unregister_module(AuthModule *module);
+void auth_register_module(struct auth_module *module);
+void auth_unregister_module(struct auth_module *module);
 
 void auth_init_request(unsigned int login_pid,
-		       AuthInitRequestData *request,
+		       struct auth_init_request_data *request,
 		       AuthCallback callback, void *context);
 void auth_continue_request(unsigned int login_pid,
-			   AuthContinuedRequestData *request,
+			   struct auth_continued_request_data *request,
 			   const unsigned char *data,
 			   AuthCallback callback, void *context);
 
--- a/src/auth/common.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/common.h	Sun Jan 05 15:09:51 2003 +0200
@@ -7,6 +7,6 @@
 #define MASTER_SOCKET_FD 0
 #define LOGIN_LISTEN_FD 3
 
-extern IOLoop ioloop;
+extern struct ioloop *ioloop;
 
 #endif
--- a/src/auth/cookie.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/cookie.c	Sun Jan 05 15:09:51 2003 +0200
@@ -12,19 +12,17 @@
 /* 30 seconds should be more than enough */
 #define COOKIE_TIMEOUT 30
 
-typedef struct _CookieList CookieList;
-
-struct _CookieList {
-	CookieList *next;
+struct cookie_list {
+	struct cookie_list *next;
 	time_t created;
 
-	CookieData *data;
+	struct cookie_data *data;
 };
 
-static HashTable *cookies;
-static CookieList *oldest_cookie, **next_cookie;
+static struct hash_table *cookies;
+static struct cookie_list *oldest_cookie, **next_cookie;
 
-static Timeout to;
+static struct timeout *to;
 
 /* a char* hash function from ASU -- from glib */
 static unsigned int cookie_hash(const void *p)
@@ -57,16 +55,16 @@
 	return 0;
 }
 
-void cookie_add(CookieData *data)
+void cookie_add(struct cookie_data *data)
 {
-	CookieList *list;
+	struct cookie_list *list;
 
 	do {
 		random_fill(data->cookie, AUTH_COOKIE_SIZE);
 	} while (hash_lookup(cookies, data->cookie));
 
 	/* add to linked list */
-	list = i_new(CookieList, 1);
+	list = i_new(struct cookie_list, 1);
 	list->created = ioloop_time;
 	list->data = data;
 
@@ -80,7 +78,7 @@
 static void cookie_destroy(unsigned char cookie[AUTH_COOKIE_SIZE],
 			   int free_data)
 {
-	CookieList **pos, *list;
+	struct cookie_list **pos, *list;
 
 	hash_remove(cookies, cookie);
 
@@ -103,7 +101,7 @@
 	i_free(list);
 }
 
-CookieData *cookie_lookup(unsigned char cookie[AUTH_COOKIE_SIZE])
+struct cookie_data *cookie_lookup(unsigned char cookie[AUTH_COOKIE_SIZE])
 {
 	return hash_lookup(cookies, cookie);
 }
@@ -113,10 +111,11 @@
 	cookie_destroy(cookie, TRUE);
 }
 
-CookieData *cookie_lookup_and_remove(unsigned int login_pid,
-				     unsigned char cookie[AUTH_COOKIE_SIZE])
+struct cookie_data *
+cookie_lookup_and_remove(unsigned int login_pid,
+			 unsigned char cookie[AUTH_COOKIE_SIZE])
 {
-	CookieData *data;
+	struct cookie_data *data;
 
 	data = hash_lookup(cookies, cookie);
 	if (data != NULL) {
@@ -130,7 +129,7 @@
 
 void cookies_remove_login_pid(unsigned int login_pid)
 {
-	CookieList *list, *next;
+	struct cookie_list *list, *next;
 
 	/* FIXME: slow */
 	for (list = oldest_cookie; list != NULL; list = next) {
@@ -142,7 +141,7 @@
 }
 
 static void cookie_timeout(void *context __attr_unused__,
-			   Timeout timeout __attr_unused__)
+			   struct timeout *timeout __attr_unused__)
 {
 	time_t remove_time;
 
--- a/src/auth/cookie.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/cookie.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,23 +3,22 @@
 
 #include "auth-interface.h"
 
-typedef struct _CookieData CookieData;
-
-struct _CookieData {
+struct cookie_data {
 	unsigned int login_pid;
 	unsigned char cookie[AUTH_COOKIE_SIZE];
 
 	/* continue authentication */
-	void (*auth_continue)(CookieData *cookie,
-			      AuthContinuedRequestData *request,
+	void (*auth_continue)(struct cookie_data *cookie,
+			      struct auth_continued_request_data *request,
 			      const unsigned char *data,
 			      AuthCallback callback, void *context);
 
 	/* fills reply from cookie, returns TRUE if successful */
-	int (*auth_fill_reply)(CookieData *cookie, AuthCookieReplyData *reply);
+	int (*auth_fill_reply)(struct cookie_data *cookie,
+			       struct auth_cookie_reply_data *reply);
 
 	/* Free all data related to cookie */
-	void (*free)(CookieData *cookie);
+	void (*free)(struct cookie_data *cookie);
 
 	void *context;
 };
@@ -27,14 +26,15 @@
 typedef void (*CookieFreeFunc)(void *data);
 
 /* data->cookie is filled */
-void cookie_add(CookieData *data);
+void cookie_add(struct cookie_data *data);
 /* Looks up the cookie */
-CookieData *cookie_lookup(unsigned char cookie[AUTH_COOKIE_SIZE]);
+struct cookie_data *cookie_lookup(unsigned char cookie[AUTH_COOKIE_SIZE]);
 /* Removes and frees the cookie */
 void cookie_remove(unsigned char cookie[AUTH_COOKIE_SIZE]);
 /* Looks up the cookie and removes it, you have to free the returned data. */
-CookieData *cookie_lookup_and_remove(unsigned int login_pid,
-				     unsigned char cookie[AUTH_COOKIE_SIZE]);
+struct cookie_data *
+cookie_lookup_and_remove(unsigned int login_pid,
+			 unsigned char cookie[AUTH_COOKIE_SIZE]);
 
 /* Remove all cookies created by a login process. */
 void cookies_remove_login_pid(unsigned int login_pid);
--- a/src/auth/login-connection.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/login-connection.c	Sun Jan 05 15:09:51 2003 +0200
@@ -13,33 +13,34 @@
 #include <syslog.h>
 
 #define MAX_INBUF_SIZE \
-	(sizeof(AuthContinuedRequestData) + AUTH_MAX_REQUEST_DATA_SIZE)
+	(sizeof(struct auth_continued_request_data) + \
+	 AUTH_MAX_REQUEST_DATA_SIZE)
 #define MAX_OUTBUF_SIZE \
-	(10 * (sizeof(AuthReplyData) + AUTH_MAX_REPLY_DATA_SIZE))
+	(10 * (sizeof(struct auth_reply_data) + AUTH_MAX_REPLY_DATA_SIZE))
 
-struct _LoginConnection {
-	LoginConnection *next;
+struct login_connection {
+	struct login_connection *next;
 
 	int fd;
-	IO io;
-	IStream *input;
-	OStream *output;
+	struct io *io;
+	struct istream *input;
+	struct ostream *output;
 
 	unsigned int pid;
-	AuthRequestType type;
+	enum auth_request_type type;
 };
 
-static AuthInitData auth_init_data;
-static LoginConnection *connections;
+static struct auth_init_data auth_init_data;
+static struct login_connection *connections;
 
-static void request_callback(AuthReplyData *reply, const unsigned char *data,
-			     void *context)
+static void request_callback(struct auth_reply_data *reply,
+			     const unsigned char *data, void *context)
 {
-	LoginConnection *conn = context;
+	struct login_connection *conn = context;
 
 	i_assert(reply->data_size <= AUTH_MAX_REPLY_DATA_SIZE);
 
-	if (o_stream_send(conn->output, reply, sizeof(AuthReplyData)) < 0)
+	if (o_stream_send(conn->output, reply, sizeof(*reply)) < 0)
 		login_connection_destroy(conn);
 	else if (reply->data_size > 0) {
 		if (o_stream_send(conn->output, data, reply->data_size) < 0)
@@ -47,9 +48,9 @@
 	}
 }
 
-static LoginConnection *login_find_pid(unsigned int pid)
+static struct login_connection *login_find_pid(unsigned int pid)
 {
-	LoginConnection *conn;
+	struct login_connection *conn;
 
 	for (conn = connections; conn != NULL; conn = conn->next) {
 		if (conn->pid == pid)
@@ -59,14 +60,14 @@
 	return NULL;
 }
 
-static void login_input_handshake(LoginConnection *conn)
+static void login_input_handshake(struct login_connection *conn)
 {
-        ClientAuthInitData rec;
+        struct client_auth_init_data rec;
         unsigned char *data;
 	size_t size;
 
 	data = i_stream_get_modifyable_data(conn->input, &size);
-	if (size < sizeof(ClientAuthInitData))
+	if (size < sizeof(struct client_auth_init_data))
 		return;
 
 	/* Don't just cast because of alignment issues. */
@@ -86,24 +87,24 @@
 	}
 }
 
-static void login_input_request(LoginConnection *conn)
+static void login_input_request(struct login_connection *conn)
 {
         unsigned char *data;
 	size_t size;
 
 	data = i_stream_get_modifyable_data(conn->input, &size);
-	if (size < sizeof(AuthRequestType))
+	if (size < sizeof(enum auth_request_type))
 		return;
 
 	/* note that we can't directly cast the received data pointer into
 	   structures, as it may not be aligned properly. */
 	if (conn->type == AUTH_REQUEST_NONE) {
 		/* get the request type */
-		memcpy(&conn->type, data, sizeof(AuthRequestType));
+		memcpy(&conn->type, data, sizeof(enum auth_request_type));
 	}
 
 	if (conn->type == AUTH_REQUEST_INIT) {
-		AuthInitRequestData request;
+		struct auth_init_request_data request;
 
 		if (size < sizeof(request))
 			return;
@@ -115,7 +116,7 @@
 		auth_init_request(conn->pid, &request, request_callback, conn);
 		conn->type = AUTH_REQUEST_NONE;
 	} else if (conn->type == AUTH_REQUEST_CONTINUE) {
-                AuthContinuedRequestData request;
+                struct auth_continued_request_data request;
 
 		if (size < sizeof(request))
 			return;
@@ -143,9 +144,9 @@
 }
 
 static void login_input(void *context, int fd __attr_unused__,
-			IO io __attr_unused__)
+			struct io *io __attr_unused__)
 {
-	LoginConnection *conn  = context;
+	struct login_connection *conn  = context;
 
 	switch (i_stream_read(conn->input)) {
 	case 0:
@@ -168,11 +169,11 @@
 		login_input_request(conn);
 }
 
-LoginConnection *login_connection_create(int fd)
+struct login_connection *login_connection_create(int fd)
 {
-	LoginConnection *conn;
+	struct login_connection *conn;
 
-	conn = i_new(LoginConnection, 1);
+	conn = i_new(struct login_connection, 1);
 
 	conn->fd = fd;
 	conn->input = i_stream_create_file(fd, default_pool, MAX_INBUF_SIZE,
@@ -194,9 +195,9 @@
 	return conn;
 }
 
-void login_connection_destroy(LoginConnection *conn)
+void login_connection_destroy(struct login_connection *conn)
 {
-	LoginConnection **pos;
+	struct login_connection **pos;
 
 	for (pos = &connections; *pos != NULL; pos = &(*pos)->next) {
 		if (*pos == conn) {
@@ -232,7 +233,7 @@
 
 void login_connections_deinit(void)
 {
-	LoginConnection *next;
+	struct login_connection *next;
 
 	while (connections != NULL) {
 		next = connections->next;
--- a/src/auth/login-connection.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/login-connection.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,10 +1,8 @@
 #ifndef __LOGIN_CONNECTION_H
 #define __LOGIN_CONNECTION_H
 
-typedef struct _LoginConnection LoginConnection;
-
-LoginConnection *login_connection_create(int fd);
-void login_connection_destroy(LoginConnection *conn);
+struct login_connection *login_connection_create(int fd);
+void login_connection_destroy(struct login_connection *conn);
 
 void login_connections_init(void);
 void login_connections_deinit(void);
--- a/src/auth/main.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/main.c	Sun Jan 05 15:09:51 2003 +0200
@@ -16,8 +16,8 @@
 #include <stdlib.h>
 #include <syslog.h>
 
-IOLoop ioloop;
-static IO io_listen;
+struct ioloop *ioloop;
+static struct io *io_listen;
 
 static void sig_quit(int signo __attr_unused__)
 {
@@ -25,7 +25,7 @@
 }
 
 static void auth_accept(void *context __attr_unused__, int listen_fd,
-			IO io __attr_unused__)
+			struct io *io __attr_unused__)
 {
 	int fd;
 
--- a/src/auth/master.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/master.c	Sun Jan 05 15:09:51 2003 +0200
@@ -7,21 +7,21 @@
 #include "cookie.h"
 #include "master.h"
 
-#define MAX_OUTBUF_SIZE (10 * sizeof(AuthCookieReplyData))
+#define MAX_OUTBUF_SIZE (10 * sizeof(struct auth_cookie_reply_data))
 
-static AuthCookieReplyData failure_reply;
+static struct auth_cookie_reply_data failure_reply;
 
-static OStream *output;
-static IO io_master;
+static struct ostream *output;
+static struct io *io_master;
 
 static unsigned int master_pos;
-static char master_buf[sizeof(AuthCookieRequestData)];
+static char master_buf[sizeof(struct auth_cookie_request_data)];
 
-static void master_handle_request(AuthCookieRequestData *request,
+static void master_handle_request(struct auth_cookie_request_data *request,
 				  int fd __attr_unused__)
 {
-	CookieData *cookie;
-        AuthCookieReplyData *reply, temp_reply;
+	struct cookie_data *cookie;
+        struct auth_cookie_reply_data *reply, temp_reply;
 
 	cookie = cookie_lookup_and_remove(request->login_pid, request->cookie);
 	if (cookie == NULL)
@@ -35,7 +35,7 @@
 	}
 
 	reply->id = request->id;
-	switch (o_stream_send(output, reply, sizeof(AuthCookieReplyData))) {
+	switch (o_stream_send(output, reply, sizeof(*reply))) {
 	case -2:
 		i_fatal("Master transmit buffer full, aborting");
 	case -1:
@@ -46,7 +46,7 @@
 }
 
 static void master_input(void *context __attr_unused__, int fd,
-			 IO io __attr_unused__)
+			 struct io *io __attr_unused__)
 {
 	int ret;
 
@@ -63,7 +63,8 @@
 		return;
 
 	/* reply is now read */
-	master_handle_request((AuthCookieRequestData *) master_buf, fd);
+	master_handle_request((struct auth_cookie_request_data *) master_buf,
+			      fd);
 	master_pos = 0;
 }
 
--- a/src/auth/userinfo-pam.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/userinfo-pam.c	Sun Jan 05 15:09:51 2003 +0200
@@ -50,10 +50,10 @@
 #  define USERPASS_USER_FIXED		3
 #endif
 
-typedef struct {
+struct pam_userpass {
 	const char *user;
 	const char *pass;
-} pam_userpass_t;
+};
 
 static char *service_name;
 
@@ -61,7 +61,7 @@
 	struct pam_response **resp, void *appdata_ptr)
 {
 	/* @UNSAFE */
-	pam_userpass_t *userpass = (pam_userpass_t *)appdata_ptr;
+	struct pam_userpass *userpass = (struct pam_userpass *) appdata_ptr;
 #ifdef AUTH_PAM_USERPASS
 	pamc_bp_t prompt;
 	const char *input;
@@ -172,10 +172,10 @@
 }
 
 static int pam_verify_plain(const char *user, const char *password,
-			    AuthCookieReplyData *reply)
+			    struct auth_cookie_reply_data *reply)
 {
 	pam_handle_t *pamh;
-	pam_userpass_t userpass;
+	struct pam_userpass userpass;
 	struct pam_conv conv;
 	struct passwd *pw;
 	int status, status2;
@@ -219,7 +219,7 @@
 	i_free(service_name);
 }
 
-UserInfoModule userinfo_pam = {
+struct user_info_module userinfo_pam = {
 	pam_init,
 	pam_deinit,
 
--- a/src/auth/userinfo-passwd-file.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/userinfo-passwd-file.c	Sun Jan 05 15:09:51 2003 +0200
@@ -18,23 +18,23 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 
-typedef struct {
-	Pool pool;
+struct passwd_file {
+	pool_t pool;
 
 	char *path;
 	time_t stamp;
 	int fd;
 
-	HashTable *users;
-} PasswdFile;
+	struct hash_table *users;
+};
 
-typedef enum {
+enum password_type {
 	PASSWORD_DES,
 	PASSWORD_MD5,
 	PASSWORD_DIGEST_MD5
-} PasswordType;
+};
 
-typedef struct {
+struct passwd_user {
 	char *user_realm; /* user:realm */
 	const char *realm; /* NULL or points to user_realm */
 	char *password;
@@ -44,15 +44,16 @@
 	uid_t uid;
 	gid_t gid;
 
-	PasswordType password_type;
+	enum password_type password_type;
 	unsigned int chroot:1;
-} PasswdUser;
+};
 
-static PasswdFile *passwd_file;
+static struct passwd_file *passwd_file;
 
 static void passwd_file_sync(void);
 
-static int get_reply_data(PasswdUser *pu, AuthCookieReplyData *reply)
+static int get_reply_data(struct passwd_user *pu,
+			  struct auth_cookie_reply_data *reply)
 {
 	const char *user;
 	struct passwd *pw;
@@ -104,9 +105,9 @@
 }
 
 static int passwd_file_verify_plain(const char *user, const char *password,
-				    AuthCookieReplyData *reply)
+				    struct auth_cookie_reply_data *reply)
 {
-	PasswdUser *pu;
+	struct passwd_user *pu;
 	const char *const *tmp;
 	unsigned char digest[16];
 	const char *str;
@@ -162,11 +163,11 @@
 
 static int passwd_file_lookup_digest_md5(const char *user, const char *realm,
 					 unsigned char digest[16],
-					 AuthCookieReplyData *reply)
+					 struct auth_cookie_reply_data *reply)
 {
 	const char *id;
-	PasswdUser *pu;
-	Buffer *buf;
+	struct passwd_user *pu;
+	buffer_t *buf;
 
 	passwd_file_sync();
 
@@ -189,11 +190,11 @@
 	return get_reply_data(pu, reply);
 }
 
-static void passwd_file_add(PasswdFile *pw, const char *username,
+static void passwd_file_add(struct passwd_file *pw, const char *username,
 			    const char *pass, const char *const *args)
 {
 	/* args = uid, gid, user info, home dir, shell, realm, mail, chroot */
-	PasswdUser *pu;
+	struct passwd_user *pu;
 	const char *p;
 
 	if (strlen(username) >= AUTH_MAX_USER_LEN) {
@@ -202,7 +203,7 @@
 		return;
 	}
 
-	pu = p_new(pw->pool, PasswdUser, 1);
+	pu = p_new(pw->pool, struct passwd_user, 1);
 
 	p = strchr(pass, '[');
 	if (p == NULL) {
@@ -309,9 +310,9 @@
 	hash_insert(pw->users, pu->user_realm, pu);
 }
 
-static void passwd_file_parse_file(PasswdFile *pw)
+static void passwd_file_parse_file(struct passwd_file *pw)
 {
-	IStream *input;
+	struct istream *input;
 	const char *const *args;
 	const char *line;
 
@@ -338,10 +339,10 @@
 	i_stream_unref(input);
 }
 
-static PasswdFile *passwd_file_parse(const char *path)
+static struct passwd_file *passwd_file_parse(const char *path)
 {
-	PasswdFile *pw;
-	Pool pool;
+	struct passwd_file *pw;
+	pool_t pool;
 	struct stat st;
 	int fd;
 
@@ -353,8 +354,8 @@
 	if (fstat(fd, &st) != 0)
 		i_fatal("fstat() failed for passwd-file %s: %m", path);
 
-	pool = pool_alloconly_create("PasswdFile", 10240);
-	pw = p_new(pool, PasswdFile, 1);
+	pool = pool_alloconly_create("passwd_file", 10240);
+	pw = p_new(pool, struct passwd_file, 1);
 	pw->pool = pool;
 	pw->path = p_strdup(pool, path);
 	pw->stamp = st.st_mtime;
@@ -365,7 +366,7 @@
 	return pw;
 }
 
-static void passwd_file_free(PasswdFile *pw)
+static void passwd_file_free(struct passwd_file *pw)
 {
 	pool_unref(pw->pool);
 }
@@ -395,7 +396,7 @@
 	}
 }
 
-UserInfoModule userinfo_passwd_file = {
+struct user_info_module userinfo_passwd_file = {
 	passwd_file_init,
 	passwd_file_deinit,
 
--- a/src/auth/userinfo-passwd.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/userinfo-passwd.c	Sun Jan 05 15:09:51 2003 +0200
@@ -10,7 +10,8 @@
 
 #include "userinfo-passwd.h"
 
-void passwd_fill_cookie_reply(struct passwd *pw, AuthCookieReplyData *reply)
+void passwd_fill_cookie_reply(struct passwd *pw,
+			      struct auth_cookie_reply_data *reply)
 {
 	reply->uid = pw->pw_uid;
 	reply->gid = pw->pw_gid;
@@ -30,7 +31,7 @@
 #include "mycrypt.h"
 
 static int passwd_verify_plain(const char *user, const char *password,
-			       AuthCookieReplyData *reply)
+			       struct auth_cookie_reply_data *reply)
 {
 	struct passwd *pw;
 	int result;
@@ -58,7 +59,7 @@
 	endpwent();
 }
 
-UserInfoModule userinfo_passwd = {
+struct user_info_module userinfo_passwd = {
 	NULL,
 	passwd_deinit,
 
--- a/src/auth/userinfo-passwd.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/userinfo-passwd.h	Sun Jan 05 15:09:51 2003 +0200
@@ -10,6 +10,7 @@
 #define IS_VALID_PASSWD(pass) \
 	((pass)[0] != '\0' && (pass)[0] != '*' && (pass)[0] != '!')
 
-void passwd_fill_cookie_reply(struct passwd *pw, AuthCookieReplyData *reply);
+void passwd_fill_cookie_reply(struct passwd *pw,
+			      struct auth_cookie_reply_data *reply);
 
 #endif
--- a/src/auth/userinfo-shadow.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/userinfo-shadow.c	Sun Jan 05 15:09:51 2003 +0200
@@ -16,7 +16,7 @@
 #include <shadow.h>
 
 static int shadow_verify_plain(const char *user, const char *password,
-			       AuthCookieReplyData *reply)
+			       struct auth_cookie_reply_data *reply)
 {
 	struct passwd *pw;
 	struct spwd *spw;
@@ -50,7 +50,7 @@
         endspent();
 }
 
-UserInfoModule userinfo_shadow = {
+struct user_info_module userinfo_shadow = {
 	NULL,
 	shadow_deinit,
 
--- a/src/auth/userinfo-vpopmail.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/userinfo-vpopmail.c	Sun Jan 05 15:09:51 2003 +0200
@@ -108,7 +108,7 @@
 	vclose();
 }
 
-UserInfoModule userinfo_vpopmail = {
+struct user_info_module userinfo_vpopmail = {
 	NULL,
 	vpopmail_deinit,
 
--- a/src/auth/userinfo.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/userinfo.c	Sun Jan 05 15:09:51 2003 +0200
@@ -5,7 +5,7 @@
 
 #include <stdlib.h>
 
-UserInfoModule *userinfo;
+struct user_info_module *userinfo;
 
 void userinfo_init(void)
 {
--- a/src/auth/userinfo.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/auth/userinfo.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 
 #include "auth-interface.h"
 
-typedef struct {
+struct user_info_module {
 	void (*init)(const char *args);
 	void (*deinit)(void);
 
@@ -11,7 +11,7 @@
 	   information. reply should have been initialized (zeroed) before
 	   calling this function. */
 	int (*verify_plain)(const char *user, const char *password,
-			    AuthCookieReplyData *reply);
+			    struct auth_cookie_reply_data *reply);
 
 	/* Digest-MD5 specific password lookup. The digest is filled with
 	   the MD5 password which consists of a MD5 sum of
@@ -19,16 +19,16 @@
 	   in UTF-8, otherwise ISO-8859-1. Returns TRUE if user was found. */
 	int (*lookup_digest_md5)(const char *user, const char *realm,
 				 unsigned char digest[16],
-				 AuthCookieReplyData *reply);
-} UserInfoModule;
+				 struct auth_cookie_reply_data *reply);
+};
 
-extern UserInfoModule *userinfo;
+extern struct user_info_module *userinfo;
 
-extern UserInfoModule userinfo_passwd;
-extern UserInfoModule userinfo_shadow;
-extern UserInfoModule userinfo_pam;
-extern UserInfoModule userinfo_passwd_file;
-extern UserInfoModule userinfo_vpopmail;
+extern struct user_info_module userinfo_passwd;
+extern struct user_info_module userinfo_shadow;
+extern struct user_info_module userinfo_pam;
+extern struct user_info_module userinfo_passwd_file;
+extern struct user_info_module userinfo_vpopmail;
 
 void userinfo_init(void);
 void userinfo_deinit(void);
--- a/src/imap/client.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/client.c	Sun Jan 05 15:09:51 2003 +0200
@@ -29,16 +29,16 @@
 /* Disconnect client after idling this many seconds */
 #define CLIENT_IDLE_TIMEOUT (60*30)
 
-extern MailStorageCallbacks mail_storage_callbacks;
+extern struct mail_storage_callbacks mail_storage_callbacks;
 
-static Client *my_client; /* we don't need more than one currently */
-static Timeout to_idle;
+static struct client *my_client; /* we don't need more than one currently */
+static struct timeout *to_idle;
 
-static void client_input(Client *client);
+static void client_input(struct client *client);
 
 static void client_output_timeout(void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 
 	i_stream_close(client->input);
 	o_stream_close(client->output);
@@ -46,18 +46,18 @@
 
 static void client_input_timeout(void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 
 	client_send_line(my_client, "* BYE Disconnected for inactivity "
 			 "while waiting for command data.");
 	o_stream_close(client->output);
 }
 
-Client *client_create(int hin, int hout, MailStorage *storage)
+struct client *client_create(int hin, int hout, struct mail_storage *storage)
 {
-	Client *client;
+	struct client *client;
 
-	client = i_new(Client, 1);
+	client = i_new(struct client, 1);
 	client->input = i_stream_create_file(hin, default_pool,
 					     MAX_INBUF_SIZE, FALSE);
 	client->output = o_stream_create_file(hout, default_pool, 4096,
@@ -86,7 +86,7 @@
 	return client;
 }
 
-void client_destroy(Client *client)
+void client_destroy(struct client *client)
 {
 	o_stream_flush(client->output);
 
@@ -107,7 +107,7 @@
 	io_loop_stop(ioloop);
 }
 
-void client_disconnect(Client *client)
+void client_disconnect(struct client *client)
 {
 	o_stream_flush(client->output);
 
@@ -115,7 +115,7 @@
 	o_stream_close(client->output);
 }
 
-void client_send_line(Client *client, const char *data)
+void client_send_line(struct client *client, const char *data)
 {
 	if (client->output->closed)
 		return;
@@ -124,7 +124,7 @@
 	(void)o_stream_send(client->output, "\r\n", 2);
 }
 
-void client_send_tagline(Client *client, const char *data)
+void client_send_tagline(struct client *client, const char *data)
 {
 	const char *tag = client->cmd_tag;
 
@@ -140,7 +140,7 @@
 	(void)o_stream_send(client->output, "\r\n", 2);
 }
 
-void client_send_command_error(Client *client, const char *msg)
+void client_send_command_error(struct client *client, const char *msg)
 {
 	const char *error;
 
@@ -158,8 +158,8 @@
 	}
 }
 
-int client_read_args(Client *client, unsigned int count, unsigned int flags,
-		     ImapArg **args)
+int client_read_args(struct client *client, unsigned int count,
+		     unsigned int flags, struct imap_arg **args)
 {
 	int ret;
 
@@ -178,9 +178,9 @@
 	}
 }
 
-int client_read_string_args(Client *client, unsigned int count, ...)
+int client_read_string_args(struct client *client, unsigned int count, ...)
 {
-	ImapArg *imap_args;
+	struct imap_arg *imap_args;
 	va_list va;
 	const char *str;
 	unsigned int i;
@@ -207,7 +207,7 @@
 	return TRUE;
 }
 
-static void client_reset_command(Client *client)
+static void client_reset_command(struct client *client)
 {
 	client->cmd_tag = NULL;
 	client->cmd_name = NULL;
@@ -218,7 +218,7 @@
         imap_parser_reset(client->parser);
 }
 
-static void client_command_finished(Client *client)
+static void client_command_finished(struct client *client)
 {
 	client->input_skip_line = TRUE;
         client_reset_command(client);
@@ -226,7 +226,7 @@
 
 /* Skip incoming data until newline is found,
    returns TRUE if newline was found. */
-static int client_skip_line(Client *client)
+static int client_skip_line(struct client *client)
 {
 	const unsigned char *data;
 	size_t i, data_size;
@@ -244,7 +244,7 @@
 	return !client->input_skip_line;
 }
 
-static int client_handle_input(Client *client)
+static int client_handle_input(struct client *client)
 {
         if (client->cmd_func != NULL) {
 		/* command is being executed - continue it */
@@ -301,7 +301,7 @@
 	return TRUE;
 }
 
-static void client_input(Client *client)
+static void client_input(struct client *client)
 {
 	client->last_input = ioloop_time;
 
@@ -331,7 +331,7 @@
 }
 
 static void idle_timeout(void *context __attr_unused__,
-			 Timeout timeout __attr_unused__)
+			 struct timeout *timeout __attr_unused__)
 {
 	if (my_client == NULL)
 		return;
--- a/src/imap/client.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/client.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,23 +4,23 @@
 #include "imap-parser.h"
 #include "mail-storage.h"
 
-typedef struct _Client Client;
+struct client;
 
-typedef int (*ClientCommandFunc) (Client *client);
+typedef int (*ClientCommandFunc) (struct client *client);
 
-struct _Client {
+struct client {
 	int socket;
-	IO io;
-	IStream *input;
-	OStream *output;
+	struct io *io;
+	struct istream *input;
+	struct ostream *output;
 
-	MailStorage *storage;
-	Mailbox *mailbox;
+	struct mail_storage *storage;
+	struct mailbox *mailbox;
 
 	time_t last_input;
 	unsigned int bad_counter;
 
-	ImapParser *parser;
+	struct imap_parser *parser;
 	const char *cmd_tag; /* tag of command (allocated from parser pool), */
 	const char *cmd_name; /* command name (allocated from parser pool) */
 	ClientCommandFunc cmd_func;
@@ -35,27 +35,27 @@
 
 /* Create new client with specified input/output handles. socket specifies
    if the handle is a socket. */
-Client *client_create(int hin, int hout, MailStorage *storage);
-void client_destroy(Client *client);
+struct client *client_create(int hin, int hout, struct mail_storage *storage);
+void client_destroy(struct client *client);
 
 /* Disconnect client connection */
-void client_disconnect(Client *client);
+void client_disconnect(struct client *client);
 
 /* Send a line of data to client */
-void client_send_line(Client *client, const char *data);
+void client_send_line(struct client *client, const char *data);
 /* Send line of data to client, prefixed with client->tag */
-void client_send_tagline(Client *client, const char *data);
+void client_send_tagline(struct client *client, const char *data);
 
 /* Send BAD command error to client. msg can be NULL. */
-void client_send_command_error(Client *client, const char *msg);
+void client_send_command_error(struct client *client, const char *msg);
 
 /* Read a number of arguments. Returns TRUE if everything was read or
    FALSE if either needs more data or error occured. */
-int client_read_args(Client *client, unsigned int count, unsigned int flags,
-		     ImapArg **args);
+int client_read_args(struct client *client, unsigned int count,
+		     unsigned int flags, struct imap_arg **args);
 /* Reads a number of string arguments. ... is a list of pointers where to
    store the arguments. */
-int client_read_string_args(Client *client, unsigned int count, ...);
+int client_read_string_args(struct client *client, unsigned int count, ...);
 
 void clients_init(void);
 void clients_deinit(void);
--- a/src/imap/cmd-append.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-append.c	Sun Jan 05 15:09:51 2003 +0200
@@ -12,11 +12,12 @@
 /* Returns -1 = error, 0 = need more data, 1 = successful. flags and
    internal_date may be NULL as a result, but mailbox and msg_size are always
    set when successful. */
-static int validate_args(Client *client, const char **mailbox,
-			 ImapArgList **flags, const char **internal_date,
+static int validate_args(struct client *client, const char **mailbox,
+			 struct imap_arg_list **flags,
+			 const char **internal_date,
 			 uoff_t *msg_size, unsigned int count)
 {
-	ImapArg *args;
+	struct imap_arg *args;
 
 	i_assert(count >= 2 && count <= 4);
 
@@ -71,11 +72,11 @@
 	return 1;
 }
 
-int cmd_append(Client *client)
+int cmd_append(struct client *client)
 {
-	ImapArgList *flags_list;
-	Mailbox *box;
-	MailFlags flags;
+	struct imap_arg_list *flags_list;
+	struct mailbox *box;
+	enum mail_flags flags;
 	time_t internal_date;
 	const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT];
 	const char *mailbox, *internal_date_str;
--- a/src/imap/cmd-authenticate.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-authenticate.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_authenticate(Client *client)
+int cmd_authenticate(struct client *client)
 {
 	client_send_tagline(client, "OK Already authenticated.");
 	return TRUE;
--- a/src/imap/cmd-capability.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-capability.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_capability(Client *client)
+int cmd_capability(struct client *client)
 {
 	client_send_line(client, "* CAPABILITY " CAPABILITY_STRING);
 
--- a/src/imap/cmd-check.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-check.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_check(Client *client)
+int cmd_check(struct client *client)
 {
 	if (!client_verify_open_mailbox(client))
 		return TRUE;
--- a/src/imap/cmd-close.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-close.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-static void client_send_untagged_storage_error(Client *client)
+static void client_send_untagged_storage_error(struct client *client)
 {
 	const char *error;
 	int syntax;
@@ -13,7 +13,7 @@
 			 t_strconcat(syntax ? "* BAD " : "* NO ", error, NULL));
 }
 
-int cmd_close(Client *client)
+int cmd_close(struct client *client)
 {
 	if (!client_verify_open_mailbox(client))
 		return TRUE;
--- a/src/imap/cmd-copy.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-copy.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,9 +3,9 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_copy(Client *client)
+int cmd_copy(struct client *client)
 {
-	Mailbox *destbox;
+	struct mailbox *destbox;
 	const char *messageset, *mailbox;
 
 	/* <message set> <mailbox> */
--- a/src/imap/cmd-create.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-create.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_create(Client *client)
+int cmd_create(struct client *client)
 {
 	const char *mailbox;
 	int ignore;
--- a/src/imap/cmd-delete.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-delete.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_delete(Client *client)
+int cmd_delete(struct client *client)
 {
 	const char *mailbox;
 
--- a/src/imap/cmd-examine.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-examine.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_examine(Client *client)
+int cmd_examine(struct client *client)
 {
 	return _cmd_select_full(client, TRUE);
 }
--- a/src/imap/cmd-expunge.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-expunge.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_expunge(Client *client)
+int cmd_expunge(struct client *client)
 {
 	if (!client_verify_open_mailbox(client))
 		return TRUE;
--- a/src/imap/cmd-fetch.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-fetch.c	Sun Jan 05 15:09:51 2003 +0200
@@ -24,15 +24,15 @@
 }
 
 /* BODY[] and BODY.PEEK[] items. item points to next character after '[' */
-static int parse_body_section(Client *client, const char *item,
-			      MailFetchData *data, int peek)
+static int parse_body_section(struct client *client, const char *item,
+			      struct mail_fetch_data *data, int peek)
 {
-	MailFetchBodyData *body;
+	struct mail_fetch_body_data *body;
 	uoff_t num;
 	const char *section;
 	char *p;
 
-	body = t_new(MailFetchBodyData, 1);
+	body = t_new(struct mail_fetch_body_data, 1);
 	body->peek = peek;
 
 	p = t_strdup_noconst(item);
@@ -95,7 +95,8 @@
 	return TRUE;
 }
 
-static int parse_arg(Client *client, ImapArg *arg, MailFetchData *data)
+static int parse_arg(struct client *client, struct imap_arg *arg,
+		     struct mail_fetch_data *data)
 {
 	char *item;
 
@@ -221,10 +222,10 @@
 	return TRUE;
 }
 
-int cmd_fetch(Client *client)
+int cmd_fetch(struct client *client)
 {
-	ImapArg *args, *listargs;
-	MailFetchData data;
+	struct imap_arg *args, *listargs;
+	struct mail_fetch_data data;
 	const char *messageset;
 	int all_found;
 
@@ -242,7 +243,7 @@
 	}
 
 	/* parse items argument */
-	memset(&data, 0, sizeof(MailFetchData));
+	memset(&data, 0, sizeof(struct mail_fetch_data));
 	if (args[1].type == IMAP_ARG_ATOM) {
 		if (!parse_arg(client, &args[1], &data))
 			return TRUE;
--- a/src/imap/cmd-list.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-list.c	Sun Jan 05 15:09:51 2003 +0200
@@ -5,23 +5,21 @@
 #include "commands.h"
 #include "imap-match.h"
 
-typedef struct _ListNode ListNode;
-
-struct _ListNode {
-	ListNode *next;
-	ListNode *children;
+struct list_node {
+	struct list_node *next;
+	struct list_node *children;
 
 	char *name; /* escaped */
-	MailboxFlags flags;
+	enum mailbox_flags flags;
 };
 
-typedef struct {
-	Pool pool;
-	ListNode *nodes;
-	MailStorage *storage;
-} ListContext;
+struct list_context {
+	pool_t pool;
+	struct list_node *nodes;
+	struct mail_storage *storage;
+};
 
-static const char *mailbox_flags2str(MailboxFlags flags)
+static const char *mailbox_flags2str(enum mailbox_flags flags)
 {
 	const char *str;
 
@@ -34,8 +32,8 @@
 	return *str == '\0' ? "" : str+1;
 }
 
-static ListNode *list_node_get(Pool pool, ListNode **node,
-			       const char *path, char separator)
+static struct list_node *list_node_get(pool_t pool, struct list_node **node,
+				       const char *path, char separator)
 {
 	const char *name, *parent;
 
@@ -61,7 +59,7 @@
 
 		if (*node == NULL) {
 			/* not found, create it */
-			*node = p_new(pool, ListNode, 1);
+			*node = p_new(pool, struct list_node, 1);
 			(*node)->name = p_strdup(pool, name);
 			(*node)->flags = MAILBOX_NOSELECT;
 		}
@@ -79,11 +77,11 @@
 	return *node;
 }
 
-static void list_func(MailStorage *storage __attr_unused__, const char *name,
-		      MailboxFlags flags, void *context)
+static void list_func(struct mail_storage *storage __attr_unused__,
+		      const char *name, enum mailbox_flags flags, void *context)
 {
-	ListContext *ctx = context;
-	ListNode *node;
+	struct list_context *ctx = context;
+	struct list_node *node;
 
 	node = list_node_get(ctx->pool, &ctx->nodes, name,
 			     ctx->storage->hierarchy_sep);
@@ -93,8 +91,9 @@
 	node->flags = flags;
 }
 
-static void list_send(Client *client, ListNode *node, const char *cmd,
-		      const char *path, const char *sep, ImapMatchGlob *glob)
+static void list_send(struct client *client, struct list_node *node,
+		      const char *cmd, const char *path, const char *sep,
+		      struct imap_match_glob *glob)
 {
 	const char *name, *str;
 
@@ -124,9 +123,9 @@
 	}
 }
 
-int _cmd_list_full(Client *client, int subscribed)
+int _cmd_list_full(struct client *client, int subscribed)
 {
-	ListContext ctx;
+	struct list_context ctx;
 	const char *ref, *pattern;
 	char sep_chr, sep[3];
 	int failed;
@@ -167,7 +166,7 @@
 			}
 		}
 
-		ctx.pool = pool_alloconly_create("ListContext", 10240);
+		ctx.pool = pool_alloconly_create("list_context", 10240);
 		ctx.nodes = NULL;
 		ctx.storage = client->storage;
 
@@ -199,7 +198,7 @@
 	return TRUE;
 }
 
-int cmd_list(Client *client)
+int cmd_list(struct client *client)
 {
 	return _cmd_list_full(client, FALSE);
 }
--- a/src/imap/cmd-login.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-login.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_login(Client *client)
+int cmd_login(struct client *client)
 {
 	client_send_tagline(client, "OK Already logged in.");
 	return TRUE;
--- a/src/imap/cmd-logout.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-logout.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_logout(Client *client)
+int cmd_logout(struct client *client)
 {
 	client_send_line(client, "* BYE Logging out");
 
--- a/src/imap/cmd-lsub.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-lsub.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_lsub(Client *client)
+int cmd_lsub(struct client *client)
 {
 	return _cmd_list_full(client, TRUE);
 }
--- a/src/imap/cmd-noop.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-noop.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_noop(Client *client)
+int cmd_noop(struct client *client)
 {
 	client_sync_full(client);
 	client_send_tagline(client, "OK NOOP completed.");
--- a/src/imap/cmd-rename.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-rename.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_rename(Client *client)
+int cmd_rename(struct client *client)
 {
 	const char *oldname, *newname;
 
--- a/src/imap/cmd-search.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-search.c	Sun Jan 05 15:09:51 2003 +0200
@@ -4,12 +4,12 @@
 #include "commands.h"
 #include "mail-search.h"
 
-int cmd_search(Client *client)
+int cmd_search(struct client *client)
 {
-	MailSearchArg *sargs;
-	ImapArg *args;
+	struct mail_search_arg *sargs;
+	struct imap_arg *args;
 	int args_count;
-	Pool pool;
+	pool_t pool;
 	const char *error, *charset;
 
 	args_count = imap_parser_read_args(client->parser, 0, 0, &args);
--- a/src/imap/cmd-select.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-select.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,10 +3,10 @@
 #include "common.h"
 #include "commands.h"
 
-int _cmd_select_full(Client *client, int readonly)
+int _cmd_select_full(struct client *client, int readonly)
 {
-	Mailbox *box;
-	MailboxStatus status;
+	struct mailbox *box;
+	struct mailbox_status status;
 	const char *mailbox;
 
 	/* <mailbox> */
@@ -71,7 +71,7 @@
 	return TRUE;
 }
 
-int cmd_select(Client *client)
+int cmd_select(struct client *client)
 {
 	return _cmd_select_full(client, FALSE);
 }
--- a/src/imap/cmd-sort.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-sort.c	Sun Jan 05 15:09:51 2003 +0200
@@ -6,12 +6,12 @@
 #include "mail-search.h"
 #include "mail-sort.h"
 
-typedef struct {
-	MailSortType type;
+struct sort_name {
+	enum mail_sort_type type;
 	const char *name;
-} SortName;
+};
 
-static SortName sort_names[] = {
+static struct sort_name sort_names[] = {
 	{ MAIL_SORT_ARRIVAL,	"arrival" },
 	{ MAIL_SORT_CC,		"cc" },
 	{ MAIL_SORT_DATE,	"date" },
@@ -24,13 +24,15 @@
 	{ MAIL_SORT_END,	NULL }
 };
 
-static MailSortType *get_sort_program(Client *client, ImapArg *args)
+static enum mail_sort_type *
+get_sort_program(struct client *client, struct imap_arg *args)
 {
-	MailSortType type;
-	Buffer *buf;
+	enum mail_sort_type type;
+	buffer_t *buf;
 	int i;
 
-	buf = buffer_create_dynamic(data_stack_pool, 32 * sizeof(MailSortType),
+	buf = buffer_create_dynamic(data_stack_pool,
+				    32 * sizeof(enum mail_sort_type),
 				    (size_t)-1);
 
 	while (args->type == IMAP_ARG_ATOM || args->type == IMAP_ARG_STRING) {
@@ -47,7 +49,8 @@
 			return NULL;
 		}
 
-		buffer_append(buf, &sort_names[i].type, sizeof(MailSortType));
+		buffer_append(buf, &sort_names[i].type,
+			      sizeof(enum mail_sort_type));
 		args++;
 	}
 
@@ -63,13 +66,13 @@
 	return buffer_free_without_data(buf);
 }
 
-int cmd_sort(Client *client)
+int cmd_sort(struct client *client)
 {
-	MailSearchArg *sargs;
-	MailSortType *sorting;
-	ImapArg *args;
+	struct mail_search_arg *sargs;
+	enum mail_sort_type *sorting;
+	struct imap_arg *args;
 	int args_count;
-	Pool pool;
+	pool_t pool;
 	const char *error, *charset;
 
 	args_count = imap_parser_read_args(client->parser, 0, 0, &args);
--- a/src/imap/cmd-status.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-status.c	Sun Jan 05 15:09:51 2003 +0200
@@ -5,10 +5,11 @@
 #include "commands.h"
 
 /* Returns status items, or -1 if error */
-static MailboxStatusItems get_status_items(Client *client, ImapArg *args)
+static enum mailbox_status_items
+get_status_items(struct client *client, struct imap_arg *args)
 {
 	const char *item;
-	MailboxStatusItems items;
+	enum mailbox_status_items items;
 
 	items = 0;
 	for (; args->type != IMAP_ARG_EOL; args++) {
@@ -49,10 +50,11 @@
 	return strcasecmp(box1, "INBOX") == 0 && strcasecmp(box2, "INBOX") == 0;
 }
 
-static int get_mailbox_status(Client *client, const char *mailbox,
-			      MailboxStatusItems items, MailboxStatus *status)
+static int get_mailbox_status(struct client *client, const char *mailbox,
+			      enum mailbox_status_items items,
+			      struct mailbox_status *status)
 {
-	Mailbox *box;
+	struct mailbox *box;
 	int failed;
 
 	if (client->mailbox != NULL &&
@@ -75,13 +77,13 @@
 	return !failed;
 }
 
-int cmd_status(Client *client)
+int cmd_status(struct client *client)
 {
-	ImapArg *args;
-	MailboxStatus status;
-	MailboxStatusItems items;
+	struct imap_arg *args;
+	struct mailbox_status status;
+	enum mailbox_status_items items;
 	const char *mailbox;
-	String *str;
+	string_t *str;
 
 	/* <mailbox> <status items> */
 	if (!client_read_args(client, 2, 0, &args))
@@ -95,7 +97,7 @@
 
 	/* get the items client wants */
 	items = get_status_items(client, IMAP_ARG_LIST(&args[1])->args);
-	if (items == (MailboxStatusItems)-1) {
+	if (items == (enum mailbox_status_items)-1) {
 		/* error */
 		return TRUE;
 	}
--- a/src/imap/cmd-store.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-store.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,8 +3,8 @@
 #include "common.h"
 #include "commands.h"
 
-static int get_modify_type(Client *client, const char *item,
-			   ModifyType *modify_type, int *silent)
+static int get_modify_type(struct client *client, const char *item,
+			   enum modify_type *modify_type, int *silent)
 {
 	if (*item == '+') {
 		*modify_type = MODIFY_ADD;
@@ -32,11 +32,11 @@
 	return TRUE;
 }
 
-int cmd_store(Client *client)
+int cmd_store(struct client *client)
 {
-	ImapArg *args;
-	MailFlags flags;
-	ModifyType modify_type;
+	struct imap_arg *args;
+	enum mail_flags flags;
+	enum modify_type modify_type;
 	const char *custflags[MAIL_CUSTOM_FLAGS_COUNT];
 	const char *messageset, *item;
 	int silent, all_found;
--- a/src/imap/cmd-subscribe.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-subscribe.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int _cmd_subscribe_full(Client *client, int subscribe)
+int _cmd_subscribe_full(struct client *client, int subscribe)
 {
 	const char *mailbox;
 
@@ -26,7 +26,7 @@
 	return TRUE;
 }
 
-int cmd_subscribe(Client *client)
+int cmd_subscribe(struct client *client)
 {
 	return _cmd_subscribe_full(client, TRUE);
 }
--- a/src/imap/cmd-uid.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-uid.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_uid(Client *client)
+int cmd_uid(struct client *client)
 {
 	const char *cmd;
 
--- a/src/imap/cmd-unsubscribe.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/cmd-unsubscribe.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 #include "common.h"
 #include "commands.h"
 
-int cmd_unsubscribe(Client *client)
+int cmd_unsubscribe(struct client *client)
 {
 	return _cmd_subscribe_full(client, FALSE);
 }
--- a/src/imap/commands-util.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/commands-util.c	Sun Jan 05 15:09:51 2003 +0200
@@ -11,10 +11,10 @@
    to them, mbox/maildir currently allow paths only up to PATH_MAX. */
 #define MAILBOX_MAX_NAME_LEN 512
 
-int client_verify_mailbox_name(Client *client, const char *mailbox,
+int client_verify_mailbox_name(struct client *client, const char *mailbox,
 			       int should_exist, int should_not_exist)
 {
-	MailboxNameStatus mailbox_status;
+	enum mailbox_name_status mailbox_status;
 	const char *p;
 	char sep;
 
@@ -80,7 +80,7 @@
 	return FALSE;
 }
 
-int client_verify_open_mailbox(Client *client)
+int client_verify_open_mailbox(struct client *client)
 {
 	if (client->mailbox != NULL)
 		return TRUE;
@@ -90,19 +90,19 @@
 	}
 }
 
-void client_sync_full(Client *client)
+void client_sync_full(struct client *client)
 {
 	if (client->mailbox != NULL)
 		(void)client->mailbox->sync(client->mailbox, TRUE);
 }
 
-void client_sync_without_expunges(Client *client)
+void client_sync_without_expunges(struct client *client)
 {
 	if (client->mailbox != NULL)
 		(void)client->mailbox->sync(client->mailbox, FALSE);
 }
 
-void client_send_storage_error(Client *client)
+void client_send_storage_error(struct client *client)
 {
 	const char *error;
 	int syntax;
@@ -121,8 +121,8 @@
 						error, NULL));
 }
 
-int client_parse_mail_flags(Client *client, ImapArg *args, size_t args_count,
-			    MailFlags *flags,
+int client_parse_mail_flags(struct client *client, struct imap_arg *args,
+			    size_t args_count, enum mail_flags *flags,
 			    const char *custflags[MAIL_CUSTOM_FLAGS_COUNT])
 {
 	char *atom;
@@ -155,7 +155,8 @@
 				*flags |= MAIL_DRAFT;
 			else {
 				client_send_tagline(client, t_strconcat(
-					"BAD Invalid system flag ", atom, NULL));
+					"BAD Invalid system flag ",
+					atom, NULL));
 				return FALSE;
 			}
 		} else {
@@ -186,7 +187,7 @@
 static const char *get_custom_flags_string(const char *custom_flags[],
 					   unsigned int custom_flags_count)
 {
-	String *str;
+	string_t *str;
 	unsigned int i;
 
 	/* first see if there even is custom flags */
@@ -210,7 +211,7 @@
 
 #define SYSTEM_FLAGS "\\Answered \\Flagged \\Deleted \\Seen \\Draft"
 
-void client_send_mailbox_flags(Client *client, Mailbox *box,
+void client_send_mailbox_flags(struct client *client, struct mailbox *box,
 			       const char *custom_flags[],
 			       unsigned int custom_flags_count)
 {
--- a/src/imap/commands-util.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/commands-util.h	Sun Jan 05 15:09:51 2003 +0200
@@ -7,32 +7,32 @@
 
    If should_exist is FALSE, the should_not_exist specifies if we should
    return TRUE or FALSE if mailbox doesn't exist. */
-int client_verify_mailbox_name(Client *client, const char *mailbox,
+int client_verify_mailbox_name(struct client *client, const char *mailbox,
 			       int should_exist, int should_not_exist);
 
 /* Returns TRUE if mailbox is selected. If not, sends "No mailbox selected"
    error message to client. */
-int client_verify_open_mailbox(Client *client);
+int client_verify_open_mailbox(struct client *client);
 
 /* Synchronize selected mailbox with client by sending EXPUNGE,
    FETCH FLAGS, EXISTS and RECENT responses. */
-void client_sync_full(Client *client);
+void client_sync_full(struct client *client);
 
 /* Synchronize all but expunges with client. */
-void client_sync_without_expunges(Client *client);
+void client_sync_without_expunges(struct client *client);
 
 /* Send last mail storage error message to client. */
-void client_send_storage_error(Client *client);
+void client_send_storage_error(struct client *client);
 
 /* Parse flags, stores custom flag names into custflags[]. The names point to
    strings in ImapArgList. Returns TRUE if successful, if not sends an error
    message to client. */
-int client_parse_mail_flags(Client *client, ImapArg *args, size_t args_count,
-			    MailFlags *flags,
+int client_parse_mail_flags(struct client *client, struct imap_arg *args,
+			    size_t args_count, enum mail_flags *flags,
 			    const char *custflags[MAIL_CUSTOM_FLAGS_COUNT]);
 
 /* Send FLAGS + PERMANENTFLAGS to client. */
-void client_send_mailbox_flags(Client *client, Mailbox *box,
+void client_send_mailbox_flags(struct client *client, struct mailbox *box,
 			       const char *custom_flags[],
 			       unsigned int custom_flags_count);
 
--- a/src/imap/commands.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/commands.h	Sun Jan 05 15:09:51 2003 +0200
@@ -7,44 +7,44 @@
 ClientCommandFunc client_command_find(const char *name);
 
 /* Non-Authenticated State */
-int cmd_authenticate(Client *client);
-int cmd_login(Client *client);
-int cmd_logout(Client *client);
+int cmd_authenticate(struct client *client);
+int cmd_login(struct client *client);
+int cmd_logout(struct client *client);
 
-int cmd_capability(Client *client);
-int cmd_noop(Client *client);
+int cmd_capability(struct client *client);
+int cmd_noop(struct client *client);
 
 /* Authenticated State */
-int cmd_select(Client *client);
-int cmd_examine(Client *client);
+int cmd_select(struct client *client);
+int cmd_examine(struct client *client);
 
-int cmd_create(Client *client);
-int cmd_delete(Client *client);
-int cmd_rename(Client *client);
+int cmd_create(struct client *client);
+int cmd_delete(struct client *client);
+int cmd_rename(struct client *client);
 
-int cmd_subscribe(Client *client);
-int cmd_unsubscribe(Client *client);
+int cmd_subscribe(struct client *client);
+int cmd_unsubscribe(struct client *client);
 
-int cmd_list(Client *client);
-int cmd_lsub(Client *client);
+int cmd_list(struct client *client);
+int cmd_lsub(struct client *client);
 
-int cmd_status(Client *client);
-int cmd_append(Client *client);
+int cmd_status(struct client *client);
+int cmd_append(struct client *client);
 
 /* Selected state */
-int cmd_check(Client *client);
-int cmd_close(Client *client);
-int cmd_expunge(Client *client);
-int cmd_search(Client *client);
-int cmd_sort(Client *client);
-int cmd_fetch(Client *client);
-int cmd_store(Client *client);
-int cmd_copy(Client *client);
-int cmd_uid(Client *client);
+int cmd_check(struct client *client);
+int cmd_close(struct client *client);
+int cmd_expunge(struct client *client);
+int cmd_search(struct client *client);
+int cmd_sort(struct client *client);
+int cmd_fetch(struct client *client);
+int cmd_store(struct client *client);
+int cmd_copy(struct client *client);
+int cmd_uid(struct client *client);
 
 /* private: */
-int _cmd_list_full(Client *client, int subscribed);
-int _cmd_select_full(Client *client, int readonly);
-int _cmd_subscribe_full(Client *client, int subscribe);
+int _cmd_list_full(struct client *client, int subscribed);
+int _cmd_select_full(struct client *client, int readonly);
+int _cmd_subscribe_full(struct client *client, int subscribe);
 
 #endif
--- a/src/imap/common.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/common.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,6 +4,6 @@
 #include "lib.h"
 #include "client.h"
 
-extern IOLoop ioloop;
+extern struct ioloop *ioloop;
 
 #endif
--- a/src/imap/mail-storage-callbacks.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/mail-storage-callbacks.c	Sun Jan 05 15:09:51 2003 +0200
@@ -5,35 +5,36 @@
 #include "imap-util.h"
 #include "commands-util.h"
 
-static void alert_no_diskspace(Mailbox *mailbox __attr_unused__, void *context)
+static void alert_no_diskspace(struct mailbox *mailbox __attr_unused__,
+			       void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 
 	client_send_line(client, "* NO [ALERT] "
 			 "Disk space is full, delete some messages.");
 }
 
-static void notify_ok(Mailbox *mailbox __attr_unused__,
+static void notify_ok(struct mailbox *mailbox __attr_unused__,
 		      const char *text, void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 
 	client_send_line(client, t_strconcat("* OK ", text, NULL));
 	o_stream_flush(client->output);
 }
 
-static void notify_no(Mailbox *mailbox __attr_unused__,
+static void notify_no(struct mailbox *mailbox __attr_unused__,
 		      const char *text, void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 
 	client_send_line(client, t_strconcat("* NO ", text, NULL));
 	o_stream_flush(client->output);
 }
 
-static void expunge(Mailbox *mailbox, unsigned int seq, void *context)
+static void expunge(struct mailbox *mailbox, unsigned int seq, void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 	char str[MAX_INT_STRLEN+20];
 
 	if (client->mailbox != mailbox)
@@ -43,11 +44,12 @@
 	client_send_line(client, str);
 }
 
-static void update_flags(Mailbox *mailbox, unsigned int seq, unsigned int uid,
-			 MailFlags flags, const char *custom_flags[],
+static void update_flags(struct mailbox *mailbox,
+			 unsigned int seq, unsigned int uid,
+			 enum mail_flags flags, const char *custom_flags[],
 			 unsigned int custom_flags_count, void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 	const char *str;
 
 	if (client->mailbox != mailbox)
@@ -67,10 +69,10 @@
 	t_pop();
 }
 
-static void new_messages(Mailbox *mailbox, unsigned int messages_count,
+static void new_messages(struct mailbox *mailbox, unsigned int messages_count,
 			 unsigned int recent_count, void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 	char str[MAX_INT_STRLEN+20];
 
 	if (client->mailbox != mailbox)
@@ -83,10 +85,11 @@
 	client_send_line(client, str);
 }
 
-static void new_custom_flags(Mailbox *mailbox, const char *custom_flags[],
+static void new_custom_flags(struct mailbox *mailbox,
+			     const char *custom_flags[],
 			     unsigned int custom_flags_count, void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 
 	if (client->mailbox != mailbox)
 		return;
@@ -95,7 +98,7 @@
 				  custom_flags_count);
 }
 
-MailStorageCallbacks mail_storage_callbacks = {
+struct mail_storage_callbacks mail_storage_callbacks = {
 	alert_no_diskspace,
 	notify_ok,
 	notify_no,
--- a/src/imap/main.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/main.c	Sun Jan 05 15:09:51 2003 +0200
@@ -14,7 +14,7 @@
 #define IS_STANDALONE() \
         (getenv("LOGIN_TAG") == NULL)
 
-IOLoop ioloop;
+struct ioloop *ioloop;
 static char log_prefix[128]; /* syslog() needs this to be permanent */
 
 static void sig_quit(int signo __attr_unused__)
@@ -58,8 +58,8 @@
 
 static void main_init(void)
 {
-	Client *client;
-	MailStorage *storage;
+	struct client *client;
+	struct mail_storage *storage;
 	const char *mail;
 	int hin, hout;
 
--- a/src/imap/rawlog.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/imap/rawlog.c	Sun Jan 05 15:09:51 2003 +0200
@@ -19,7 +19,7 @@
 #define TIMESTAMP_WAIT_TIME 5
 #define TIMESTAMP_FORMAT " * OK [RAWLOG TIMESTAMP] %Y-%m-%d %H:%M:%S\n"
 
-static IOLoop ioloop;
+static ioloop *ioloop;
 static int client_in, client_out, imap_in, imap_out;
 static int log_in, log_out;
 
@@ -90,7 +90,7 @@
 
 void rawlog_open(int *hin, int *hout)
 {
-	IO io_imap, io_client;
+	struct io *io_imap, *io_client;
 	const char *home, *path, *fname;
 	char timestamp[50];
 	struct tm *tm;
--- a/src/lib-charset/charset-iconv.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-charset/charset-iconv.c	Sun Jan 05 15:09:51 2003 +0200
@@ -15,15 +15,15 @@
 #  define ICONV_CONST
 #endif
 
-struct _CharsetTranslation {
+struct charset_translation {
 	iconv_t cd;
 	int ascii;
 };
 
-CharsetTranslation *charset_to_utf8_begin(const char *charset,
-					  int *unknown_charset)
+struct charset_translation *charset_to_utf8_begin(const char *charset,
+						  int *unknown_charset)
 {
-	CharsetTranslation *t;
+	struct charset_translation *t;
 	iconv_t cd;
 	int ascii;
 
@@ -48,33 +48,34 @@
 		}
 	}
 
-	t = i_new(CharsetTranslation, 1);
+	t = i_new(struct charset_translation, 1);
 	t->cd = cd;
 	t->ascii = ascii;
 	return t;
 }
 
-void charset_to_utf8_end(CharsetTranslation *t)
+void charset_to_utf8_end(struct charset_translation *t)
 {
 	if (t->cd != NULL)
 		iconv_close(t->cd);
 	i_free(t);
 }
 
-void charset_to_utf8_reset(CharsetTranslation *t)
+void charset_to_utf8_reset(struct charset_translation *t)
 {
 	if (t->cd != NULL)
 		(void)iconv(t->cd, NULL, NULL, NULL, NULL);
 }
 
-CharsetResult
-charset_to_ucase_utf8(CharsetTranslation *t,
-		      const unsigned char *src, size_t *src_size, Buffer *dest)
+enum charset_result
+charset_to_ucase_utf8(struct charset_translation *t,
+		      const unsigned char *src, size_t *src_size,
+		      buffer_t *dest)
 {
 	ICONV_CONST char *ic_srcbuf;
 	char *ic_destbuf;
 	size_t srcleft, destpos, destleft, size;
-        CharsetResult ret;
+        enum charset_result ret;
 
 	destpos = buffer_get_used_size(dest);
 	destleft = buffer_get_size(dest) - destpos;
--- a/src/lib-charset/charset-utf8.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-charset/charset-utf8.c	Sun Jan 05 15:09:51 2003 +0200
@@ -7,7 +7,7 @@
 #include <ctype.h>
 
 void _charset_utf8_ucase(const unsigned char *src, size_t src_size,
-			 Buffer *dest, size_t destpos)
+			 buffer_t *dest, size_t destpos)
 {
 	char *destbuf;
 	size_t i;
@@ -20,7 +20,7 @@
 const char *_charset_utf8_ucase_strdup(const unsigned char *data, size_t size,
 				       size_t *utf8_size_r)
 {
-	Buffer *dest;
+	buffer_t *dest;
 
 	dest = buffer_create_dynamic(data_stack_pool, size, (size_t)-1);
 	_charset_utf8_ucase(data, size, dest, 0);
@@ -39,10 +39,10 @@
 	int dummy;
 };
 
-static CharsetTranslation ascii_translation, utf8_translation;
+static struct charset_translation ascii_translation, utf8_translation;
 
-CharsetTranslation *charset_to_utf8_begin(const char *charset,
-					  int *unknown_charset)
+struct charset_translation *charset_to_utf8_begin(const char *charset,
+						  int *unknown_charset)
 {
 	if (unknown_charset != NULL)
 		*unknown_charset = FALSE;
@@ -61,17 +61,18 @@
 	return NULL;
 }
 
-void charset_to_utf8_end(CharsetTranslation *t __attr_unused__)
+void charset_to_utf8_end(struct charset_translation *t __attr_unused__)
 {
 }
 
-void charset_to_utf8_reset(CharsetTranslation *t __attr_unused__)
+void charset_to_utf8_reset(struct charset_translation *t __attr_unused__)
 {
 }
 
-CharsetResult
-charset_to_ucase_utf8(CharsetTranslation *t __attr_unused__,
-		      const unsigned char *src, size_t *src_size, Buffer *dest)
+enum charset_result
+charset_to_ucase_utf8(struct charset_translation *t __attr_unused__,
+		      const unsigned char *src, size_t *src_size,
+		      buffer_t *dest)
 {
 	size_t destpos, destleft;
 
--- a/src/lib-charset/charset-utf8.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-charset/charset-utf8.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,28 +1,27 @@
 #ifndef __CHARSET_UTF8_H
 #define __CHARSET_UTF8_H
 
-typedef enum {
+enum charset_result {
 	CHARSET_RET_OK = 1,
 	CHARSET_RET_OUTPUT_FULL = 0,
 	CHARSET_RET_INCOMPLETE_INPUT = -1,
 	CHARSET_RET_INVALID_INPUT = -2
-} CharsetResult;
-
-typedef struct _CharsetTranslation CharsetTranslation;
+};
 
 /* Begin translation to UTF-8. */
-CharsetTranslation *charset_to_utf8_begin(const char *charset,
-					  int *unknown_charset);
+struct charset_translation *charset_to_utf8_begin(const char *charset,
+						  int *unknown_charset);
 
-void charset_to_utf8_end(CharsetTranslation *t);
+void charset_to_utf8_end(struct charset_translation *t);
 
-void charset_to_utf8_reset(CharsetTranslation *t);
+void charset_to_utf8_reset(struct charset_translation *t);
 
 /* Translate src to UTF-8. If src_size is updated to contain the number of
    characters actually translated from src. */
-CharsetResult
-charset_to_ucase_utf8(CharsetTranslation *t,
-		      const unsigned char *src, size_t *src_size, Buffer *dest);
+enum charset_result
+charset_to_ucase_utf8(struct charset_translation *t,
+		      const unsigned char *src, size_t *src_size,
+		      buffer_t *dest);
 
 /* Simple wrappers for above functions. If utf8_size is non-NULL, it's set
    to same as strlen(returned data). */
@@ -36,7 +35,7 @@
 			     size_t *utf8_size_r);
 
 void _charset_utf8_ucase(const unsigned char *src, size_t src_size,
-			 Buffer *dest, size_t destpos);
+			 buffer_t *dest, size_t destpos);
 const char *_charset_utf8_ucase_strdup(const unsigned char *data, size_t size,
 				       size_t *utf8_size_r);
 
--- a/src/lib-imap/imap-base-subject.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-base-subject.c	Sun Jan 05 15:09:51 2003 +0200
@@ -9,7 +9,7 @@
 static int header_decode(const unsigned char *data, size_t size,
 			 const char *charset, void *context)
 {
-	Buffer *buf = context;
+	buffer_t *buf = context;
 	const char *utf8_str;
 	unsigned char *buf_data;
 	size_t i, used_size;
@@ -19,7 +19,8 @@
 		buffer_append(buf, data, size);
 	} else {
 		t_push();
-		utf8_str = charset_to_utf8_string(charset, NULL, data, size, &size);
+		utf8_str = charset_to_utf8_string(charset, NULL, data,
+						  size, &size);
 		if (utf8_str == NULL)
 			size = 0;
 		else
@@ -40,7 +41,7 @@
 	return TRUE;
 }
 
-static void pack_whitespace(Buffer *buf)
+static void pack_whitespace(buffer_t *buf)
 {
 	char *data, *dest;
 	int last_lwsp;
@@ -78,7 +79,7 @@
 	buffer_set_used_size(buf, (size_t) (dest - data)+1);
 }
 
-static void remove_subj_trailers(Buffer *buf)
+static void remove_subj_trailers(buffer_t *buf)
 {
 	const char *data;
 	size_t orig_size, size;
@@ -125,7 +126,7 @@
 	return TRUE;
 }
 
-static int remove_subj_leader(Buffer *buf)
+static int remove_subj_leader(buffer_t *buf)
 {
 	const char *data, *orig_data;
 	int ret = FALSE;
@@ -175,7 +176,7 @@
 	return TRUE;
 }
 
-static int remove_blob_when_nonempty(Buffer *buf)
+static int remove_blob_when_nonempty(buffer_t *buf)
 {
 	const char *data, *orig_data;
 
@@ -189,7 +190,7 @@
 	return FALSE;
 }
 
-static int remove_subj_fwd_hdr(Buffer *buf)
+static int remove_subj_fwd_hdr(buffer_t *buf)
 {
 	const char *data;
 	size_t size;
@@ -212,9 +213,9 @@
 	return TRUE;
 }
 
-const char *imap_get_base_subject_cased(Pool pool, const char *subject)
+const char *imap_get_base_subject_cased(pool_t pool, const char *subject)
 {
-	Buffer *buf;
+	buffer_t *buf;
 	size_t subject_len;
 	int found;
 
--- a/src/lib-imap/imap-base-subject.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-base-subject.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,6 +4,6 @@
 /* Returns the base subject of the given string, according to
    draft-ietf-imapext-sort-10. String is returned so that it's suitable for
    strcmp() comparing with another base subject. */
-const char *imap_get_base_subject_cased(Pool pool, const char *subject);
+const char *imap_get_base_subject_cased(pool_t pool, const char *subject);
 
 #endif
--- a/src/lib-imap/imap-bodystructure.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-bodystructure.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,9 +3,9 @@
 #include "lib.h"
 #include "istream.h"
 #include "str.h"
-#include "rfc822-tokenize.h"
 #include "message-parser.h"
 #include "message-content-parser.h"
+#include "message-tokenize.h"
 #include "imap-parser.h"
 #include "imap-quote.h"
 #include "imap-envelope.h"
@@ -14,9 +14,9 @@
 #define EMPTY_BODYSTRUCTURE \
         "(\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 0 0)"
 
-typedef struct {
-	Pool pool;
-	String *str;
+struct message_part_body_data {
+	pool_t pool;
+	string_t *str;
 	char *content_type, *content_subtype;
 	char *content_type_params;
 	char *content_transfer_encoding;
@@ -27,16 +27,16 @@
 	char *content_md5;
 	char *content_language;
 
-	MessagePartEnvelopeData *envelope;
-} MessagePartBodyData;
+	struct message_part_envelope_data *envelope;
+};
 
-static void part_write_bodystructure(MessagePart *part, String *str,
-				     int extended);
+static void part_write_bodystructure(struct message_part *part,
+				     string_t *str, int extended);
 
 static void parse_content_type(const unsigned char *value, size_t value_len,
 			       void *context)
 {
-        MessagePartBodyData *data = context;
+        struct message_part_body_data *data = context;
 	size_t i;
 
 	for (i = 0; i < value_len; i++) {
@@ -62,7 +62,7 @@
 				   int value_quoted __attr_unused__,
 				   void *context)
 {
-        MessagePartBodyData *data = context;
+        struct message_part_body_data *data = context;
 
 	if (str_len(data->str) != 0)
 		str_append_c(data->str, ' ');
@@ -79,7 +79,7 @@
 static void parse_content_transfer_encoding(const unsigned char *value,
 					    size_t value_len, void *context)
 {
-        MessagePartBodyData *data = context;
+        struct message_part_body_data *data = context;
 
 	data->content_transfer_encoding =
 		imap_quote_value(data->pool, value, value_len);
@@ -88,29 +88,29 @@
 static void parse_content_disposition(const unsigned char *value,
 				      size_t value_len, void *context)
 {
-        MessagePartBodyData *data = context;
+        struct message_part_body_data *data = context;
 
 	data->content_disposition =
 		imap_quote_value(data->pool, value, value_len);
 }
 
 static void parse_content_language(const unsigned char *value, size_t value_len,
-				   MessagePartBodyData *data)
+				   struct message_part_body_data *data)
 {
-	Rfc822TokenizeContext *ctx;
-        Rfc822Token token;
-	String *str;
+	struct message_tokenizer *tok;
+        enum message_token token;
+	string_t *str;
 	int quoted;
 
 	/* Content-Language: en-US, az-arabic (comments allowed) */
 
-	ctx = rfc822_tokenize_init(value, value_len, NULL, NULL);
+	tok = message_tokenize_init(value, value_len, NULL, NULL);
 
 	t_push();
 	str = t_str_new(256);
 
 	quoted = FALSE;
-	while ((token = rfc822_tokenize_next(ctx)) != TOKEN_LAST) {
+	while ((token = message_tokenize_next(tok)) != TOKEN_LAST) {
 		if (token == ',') {
 			/* list separator */
 			if (quoted) {
@@ -131,8 +131,8 @@
 			if (!IS_TOKEN_STRING(token))
 				str_append_c(str, token);
 			else {
-				value = rfc822_tokenize_get_value(ctx,
-								  &value_len);
+				value = message_tokenize_get_value(tok,
+								   &value_len);
 				str_append_n(str, value, value_len);
 			}
 		}
@@ -145,16 +145,16 @@
 
 	t_pop();
 
-	rfc822_tokenize_deinit(ctx);
+	message_tokenize_deinit(tok);
 }
 
-static void parse_header(MessagePart *part,
+static void parse_header(struct message_part *part,
 			 const unsigned char *name, size_t name_len,
 			 const unsigned char *value, size_t value_len,
 			 void *context)
 {
-	Pool pool = context;
-	MessagePartBodyData *part_data;
+	pool_t pool = context;
+	struct message_part_body_data *part_data;
 	int parent_rfc822;
 
 	parent_rfc822 = part->parent != NULL &&
@@ -166,7 +166,7 @@
 	if (part->context == NULL) {
 		/* initialize message part data */
 		part->context = part_data =
-			p_new(pool, MessagePartBodyData, 1);
+			p_new(pool, struct message_part_body_data, 1);
 		part_data->pool = pool;
 	}
 	part_data = part->context;
@@ -245,8 +245,8 @@
 	t_pop();
 }
 
-static void part_parse_headers(MessagePart *part, IStream *input,
-			       uoff_t start_offset, Pool pool)
+static void part_parse_headers(struct message_part *part, struct istream *input,
+			       uoff_t start_offset, pool_t pool)
 {
 	while (part != NULL) {
 		/* note that we want to parse the header of all
@@ -266,14 +266,14 @@
 	}
 }
 
-static void part_write_body_multipart(MessagePart *part, String *str,
-				      int extended)
+static void part_write_body_multipart(struct message_part *part,
+				      string_t *str, int extended)
 {
-	MessagePartBodyData *data = part->context;
+	struct message_part_body_data *data = part->context;
 
 	if (data == NULL) {
 		/* there was no content headers, use an empty structure */
-		data = t_new(MessagePartBodyData, 1);
+		data = t_new(struct message_part_body_data, 1);
 	}
 
 	if (part->children != NULL)
@@ -332,13 +332,14 @@
 	}
 }
 
-static void part_write_body(MessagePart *part, String *str, int extended)
+static void part_write_body(struct message_part *part,
+			    string_t *str, int extended)
 {
-	MessagePartBodyData *data = part->context;
+	struct message_part_body_data *data = part->context;
 
 	if (data == NULL) {
 		/* there was no content headers, use an empty structure */
-		data = t_new(MessagePartBodyData, 1);
+		data = t_new(struct message_part_body_data, 1);
 	}
 
 	/* "content type" "subtype" */
@@ -367,7 +368,7 @@
 		str_printfa(str, " %u", part->body_size.lines);
 	} else if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) {
 		/* message/rfc822 contains envelope + body + line count */
-		MessagePartBodyData *child_data;
+		struct message_part_body_data *child_data;
 
 		i_assert(part->children != NULL);
 		i_assert(part->children->next == NULL);
@@ -428,8 +429,8 @@
 	}
 }
 
-static void part_write_bodystructure(MessagePart *part, String *str,
-				     int extended)
+static void part_write_bodystructure(struct message_part *part,
+				     string_t *str, int extended)
 {
 	i_assert(part->parent != NULL || part->next == NULL);
 
@@ -449,17 +450,18 @@
 	}
 }
 
-static const char *part_get_bodystructure(MessagePart *part, int extended)
+static const char *part_get_bodystructure(struct message_part *part,
+					  int extended)
 {
-	String *str;
+	string_t *str;
 
 	str = t_str_new(2048);
 	part_write_bodystructure(part, str, extended);
 	return str_c(str);
 }
 
-const char *imap_part_get_bodystructure(Pool pool, MessagePart **part,
-					IStream *input, int extended)
+const char *imap_part_get_bodystructure(pool_t pool, struct message_part **part,
+					struct istream *input, int extended)
 {
 	uoff_t start_offset;
 
@@ -473,7 +475,7 @@
 	return part_get_bodystructure(*part, extended);
 }
 
-static int imap_write_list(const ImapArg *args, String *str)
+static int imap_write_list(const struct imap_arg *args, string_t *str)
 {
 	/* don't do any typechecking, just write it out */
 	str_append_c(str, '(');
@@ -506,10 +508,11 @@
 	return TRUE;
 }
 
-static int imap_parse_bodystructure_args(const ImapArg *args, String *str)
+static int imap_parse_bodystructure_args(const struct imap_arg *args,
+					 string_t *str)
 {
-	ImapArg *subargs;
-	ImapArgList *list;
+	struct imap_arg *subargs;
+	struct imap_arg_list *list;
 	int i, multipart, text, message_rfc822;
 
 	multipart = FALSE;
@@ -620,10 +623,10 @@
 
 const char *imap_body_parse_from_bodystructure(const char *bodystructure)
 {
-	IStream *input;
-	ImapParser *parser;
-	ImapArg *args;
-	String *str;
+	struct istream *input;
+	struct imap_parser *parser;
+	struct imap_arg *args;
+	string_t *str;
 	const char *value;
 	size_t len;
 	int ret;
--- a/src/lib-imap/imap-bodystructure.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-bodystructure.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,10 +1,12 @@
 #ifndef __IMAP_BODYSTRUCTURE_H
 #define __IMAP_BODYSTRUCTURE_H
 
+struct message_part;
+
 /* If *part is non-NULL, it's used as base for building the body structure.
-   Otherwise it's set to the root MessagePart and parsed. */
-const char *imap_part_get_bodystructure(Pool pool, MessagePart **part,
-					IStream *input, int extended);
+   Otherwise it's set to the root message_part and parsed. */
+const char *imap_part_get_bodystructure(pool_t pool, struct message_part **part,
+					struct istream *input, int extended);
 
 /* Return BODY part from BODYSTRUCTURE */
 const char *imap_body_parse_from_bodystructure(const char *bodystructure);
--- a/src/lib-imap/imap-envelope.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-envelope.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,89 +3,82 @@
 #include "lib.h"
 #include "istream.h"
 #include "str.h"
-#include "rfc822-address.h"
+#include "message-address.h"
 #include "imap-parser.h"
 #include "imap-envelope.h"
 #include "imap-quote.h"
 
-struct _MessagePartEnvelopeData {
-	Pool pool;
+struct message_part_envelope_data {
+	pool_t pool;
 
 	char *date, *subject;
-	Rfc822Address *from, *sender, *reply_to;
-	Rfc822Address *to, *cc, *bcc;
+	struct message_address *from, *sender, *reply_to;
+	struct message_address *to, *cc, *bcc;
 
 	char *in_reply_to, *message_id;
 };
 
-static Rfc822Address *parse_address(Pool pool, const unsigned char *value,
-				    size_t value_len)
-{
-	return rfc822_address_parse(pool, value, value_len);
-}
-
-void imap_envelope_parse_header(Pool pool, MessagePartEnvelopeData **data,
+void imap_envelope_parse_header(pool_t pool,
+				struct message_part_envelope_data **data,
 				const unsigned char *name, size_t name_len,
 				const unsigned char *value, size_t value_len)
 {
+	struct message_part_envelope_data *d;
+
 	if (*data == NULL) {
-		*data = p_new(pool, MessagePartEnvelopeData, 1);
+		*data = p_new(pool, struct message_part_envelope_data, 1);
 		(*data)->pool = pool;
 	}
+	d = *data;
 
 	t_push();
 
 	switch (name_len) {
 	case 2:
-		if (memcasecmp(name, "To", 2) == 0 && (*data)->to == NULL)
-			(*data)->to = parse_address(pool, value, value_len);
-		else if (memcasecmp(name, "Cc", 2) == 0 && (*data)->cc == NULL)
-			(*data)->cc = parse_address(pool, value, value_len);
+		if (memcasecmp(name, "To", 2) == 0 && d->to == NULL)
+			d->to = message_address_parse(pool, value, value_len);
+		else if (memcasecmp(name, "Cc", 2) == 0 && d->cc == NULL)
+			d->cc = message_address_parse(pool, value, value_len);
 		break;
 	case 3:
-		if (memcasecmp(name, "Bcc", 3) == 0 && (*data)->bcc == NULL)
-			(*data)->bcc = parse_address(pool, value, value_len);
+		if (memcasecmp(name, "Bcc", 3) == 0 && d->bcc == NULL)
+			d->bcc = message_address_parse(pool, value, value_len);
 		break;
 	case 4:
-		if (memcasecmp(name, "From", 4) == 0 && (*data)->from == NULL)
-			(*data)->from = parse_address(pool, value, value_len);
-		else if (memcasecmp(name, "Date", 4) == 0 &&
-			 (*data)->date == NULL) {
-			(*data)->date = imap_quote_value(pool, value,
-							 value_len);
-		}
+		if (memcasecmp(name, "From", 4) == 0 && d->from == NULL)
+			d->from = message_address_parse(pool, value, value_len);
+		else if (memcasecmp(name, "Date", 4) == 0 && d->date == NULL)
+			d->date = imap_quote_value(pool, value, value_len);
 		break;
 	case 6:
-		if (memcasecmp(name, "Sender", 6) == 0 &&
-		    (*data)->sender == NULL)
-			(*data)->sender = parse_address(pool, value, value_len);
+		if (memcasecmp(name, "Sender", 6) == 0 && d->sender == NULL) {
+			d->sender = message_address_parse(pool, value,
+							  value_len);
+		}
 		break;
 	case 7:
-		if (memcasecmp(name, "Subject", 7) == 0 &&
-		    (*data)->subject == NULL) {
-			(*data)->subject = imap_quote_value(pool, value,
-							    value_len);
-		}
+		if (memcasecmp(name, "Subject", 7) == 0 && d->subject == NULL)
+			d->subject = imap_quote_value(pool, value, value_len);
 		break;
 	case 8:
 		if (memcasecmp(name, "Reply-To", 8) == 0 &&
-		    (*data)->reply_to == NULL) {
-			(*data)->reply_to = parse_address(pool, value,
-							  value_len);
+		    d->reply_to == NULL) {
+			d->reply_to =
+				message_address_parse(pool, value, value_len);
 		}
 		break;
 	case 10:
 		if (memcasecmp(name, "Message-Id", 10) == 0 &&
-		    (*data)->message_id == NULL) {
-			(*data)->message_id = imap_quote_value(pool, value,
-							       value_len);
+		    d->message_id == NULL) {
+			d->message_id =
+				imap_quote_value(pool, value, value_len);
 		}
 		break;
 	case 11:
 		if (memcasecmp(name, "In-Reply-To", 11) == 0 &&
-		    (*data)->in_reply_to == NULL) {
-			(*data)->in_reply_to = imap_quote_value(pool, value,
-								value_len);
+		    d->in_reply_to == NULL) {
+			d->in_reply_to =
+				imap_quote_value(pool, value, value_len);
 		}
 		break;
 	}
@@ -93,7 +86,7 @@
 	t_pop();
 }
 
-static void imap_write_address(String *str, Rfc822Address *addr)
+static void imap_write_address(string_t *str, struct message_address *addr)
 {
 	if (addr == NULL) {
 		str_append(str, "NIL");
@@ -117,8 +110,8 @@
 	str_append_c(str, ')');
 }
 
-void imap_envelope_write_part_data(MessagePartEnvelopeData *data,
-				   String *str)
+void imap_envelope_write_part_data(struct message_part_envelope_data *data,
+				   string_t *str)
 {
 	str_append(str, NVL(data->date, "NIL"));
 	str_append_c(str, ' ');
@@ -143,18 +136,20 @@
 	str_append(str, NVL(data->message_id, "NIL"));
 }
 
-const char *imap_envelope_get_part_data(MessagePartEnvelopeData *data)
+const char *
+imap_envelope_get_part_data(struct message_part_envelope_data *data)
 {
-	String *str;
+	string_t *str;
 
 	str = t_str_new(2048);
         imap_envelope_write_part_data(data, str);
 	return str_c(str);
 }
 
-static int imap_address_arg_append(ImapArg *arg, String *str, int *in_group)
+static int imap_address_arg_append(struct imap_arg *arg, string_t *str,
+				   int *in_group)
 {
-	ImapArgList *list;
+	struct imap_arg_list *list;
 	const char *args[4];
 	int i;
 
@@ -220,10 +215,10 @@
 	return TRUE;
 }
 
-static const char *imap_envelope_parse_address(ImapArg *arg)
+static const char *imap_envelope_parse_address(struct imap_arg *arg)
 {
-	ImapArgList *list;
-	String *str;
+	struct imap_arg_list *list;
+	string_t *str;
 	size_t i;
 	int in_group;
 
@@ -242,9 +237,9 @@
 	return str_c(str);
 }
 
-static const char *imap_envelope_parse_first_mailbox(ImapArg *arg)
+static const char *imap_envelope_parse_first_mailbox(struct imap_arg *arg)
 {
-	ImapArgList *list;
+	struct imap_arg_list *list;
 
 	/* ((name route mailbox domain) ...) */
 	if (arg->type != IMAP_ARG_LIST)
@@ -265,9 +260,10 @@
 	return t_strdup(imap_arg_string(&list->args[2]));
 }
 
-static int imap_envelope_parse_arg(ImapArg *arg, ImapEnvelopeField field,
+static int imap_envelope_parse_arg(struct imap_arg *arg,
+				   enum imap_envelope_field field,
 				   const char *envelope,
-				   ImapEnvelopeResult result_type,
+				   enum imap_envelope_result_type result_type,
 				   const char **result)
 {
 	const char *value = NULL;
@@ -278,13 +274,13 @@
 	}
 
 	switch (result_type) {
-	case IMAP_ENVELOPE_RESULT_STRING:
+	case IMAP_ENVELOPE_RESULT_TYPE_STRING:
 		if (field >= IMAP_ENVELOPE_FROM && field <= IMAP_ENVELOPE_BCC)
 			value = imap_envelope_parse_address(arg);
 		else
 			value = t_strdup(imap_arg_string(arg));
 		break;
-	case IMAP_ENVELOPE_RESULT_FIRST_MAILBOX:
+	case IMAP_ENVELOPE_RESULT_TYPE_FIRST_MAILBOX:
 		i_assert(field >= IMAP_ENVELOPE_FROM &&
 			 field <= IMAP_ENVELOPE_BCC);
 		value = imap_envelope_parse_first_mailbox(arg);
@@ -301,12 +297,13 @@
 	}
 }
 
-int imap_envelope_parse(const char *envelope, ImapEnvelopeField field,
-			ImapEnvelopeResult result_type, const char **result)
+int imap_envelope_parse(const char *envelope, enum imap_envelope_field field,
+			enum imap_envelope_result_type result_type,
+			const char **result)
 {
-	IStream *input;
-	ImapParser *parser;
-	ImapArg *args;
+	struct istream *input;
+	struct imap_parser *parser;
+	struct imap_arg *args;
 	int ret;
 
 	i_assert(field < IMAP_ENVELOPE_FIELDS);
--- a/src/lib-imap/imap-envelope.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-envelope.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,9 +1,7 @@
 #ifndef __IMAP_ENVELOPE_H
 #define __IMAP_ENVELOPE_H
 
-typedef struct _MessagePartEnvelopeData MessagePartEnvelopeData;
-
-typedef enum {
+enum imap_envelope_field {
 	/* NOTE: in the same order as listed in ENVELOPE */
 	IMAP_ENVELOPE_DATE = 0,
 	IMAP_ENVELOPE_SUBJECT,
@@ -17,27 +15,32 @@
 	IMAP_ENVELOPE_MESSAGE_ID,
 
 	IMAP_ENVELOPE_FIELDS
-} ImapEnvelopeField;
+};
 
-typedef enum {
-	IMAP_ENVELOPE_RESULT_STRING,
-	IMAP_ENVELOPE_RESULT_FIRST_MAILBOX
-} ImapEnvelopeResult;
+enum imap_envelope_result_type {
+	IMAP_ENVELOPE_RESULT_TYPE_STRING,
+	IMAP_ENVELOPE_RESULT_TYPE_FIRST_MAILBOX
+};
+
+struct message_part_envelope_data;
 
 /* Update envelope data based from given header field */
-void imap_envelope_parse_header(Pool pool, MessagePartEnvelopeData **data,
+void imap_envelope_parse_header(pool_t pool,
+				struct message_part_envelope_data **data,
 				const unsigned char *name, size_t name_len,
 				const unsigned char *value, size_t value_len);
 
 /* Write envelope to given string */
-void imap_envelope_write_part_data(MessagePartEnvelopeData *data,
-				   String *str);
+void imap_envelope_write_part_data(struct message_part_envelope_data *data,
+				   string_t *str);
 /* Return envelope. */
-const char *imap_envelope_get_part_data(MessagePartEnvelopeData *data);
+const char *
+imap_envelope_get_part_data(struct message_part_envelope_data *data);
 
 /* Parse envelope and store specified field to result. NIL is stored as NULL.
    Returns TRUE if successful. */
-int imap_envelope_parse(const char *envelope, ImapEnvelopeField field,
-			ImapEnvelopeResult result_type, const char **result);
+int imap_envelope_parse(const char *envelope, enum imap_envelope_field field,
+			enum imap_envelope_result_type result_type,
+			const char **result);
 
 #endif
--- a/src/lib-imap/imap-match.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-match.c	Sun Jan 05 15:09:51 2003 +0200
@@ -9,7 +9,7 @@
 
 #include <ctype.h>
 
-struct _ImapMatchGlob {
+struct imap_match_glob {
 	int inboxcase;
 	const char *inboxcase_end;
 
@@ -21,14 +21,15 @@
 static const char inbox[] = "INBOX";
 #define INBOXLEN (sizeof(inbox) - 1)
 
-ImapMatchGlob *imap_match_init(const char *mask, int inboxcase, char separator)
+struct imap_match_glob *imap_match_init(const char *mask, int inboxcase,
+					char separator)
 {
-	ImapMatchGlob *glob;
+	struct imap_match_glob *glob;
 	const char *p, *inboxp;
 	char *dst;
 
 	/* +1 from struct */
-	glob = t_malloc(sizeof(ImapMatchGlob) + strlen(mask));
+	glob = t_malloc(sizeof(struct imap_match_glob) + strlen(mask));
 	glob->sep_char = separator;
 
 	/* @UNSAFE: compress the mask */
@@ -85,7 +86,7 @@
 	return glob;
 }
 
-static inline int cmp_chr(const ImapMatchGlob *glob,
+static inline int cmp_chr(const struct imap_match_glob *glob,
 			  const char *data, char maskchr)
 {
 	return *data == maskchr ||
@@ -93,7 +94,7 @@
 		 i_toupper(*data) == i_toupper(maskchr));
 }
 
-static int match_sub(const ImapMatchGlob *glob, const char **data_p,
+static int match_sub(const struct imap_match_glob *glob, const char **data_p,
 		     const char **mask_p)
 {
 	const char *mask, *data;
@@ -149,7 +150,7 @@
 	return 1;
 }
 
-int imap_match(ImapMatchGlob *glob, const char *data)
+int imap_match(struct imap_match_glob *glob, const char *data)
 {
 	const char *mask;
 	int ret;
--- a/src/lib-imap/imap-match.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-match.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,14 +1,15 @@
 #ifndef __IMAP_MATCH_H
 #define __IMAP_MATCH_H
 
-typedef struct _ImapMatchGlob ImapMatchGlob;
+struct imap_match_glob;
 
 /* If inboxcase is TRUE, the "INBOX" string at the beginning of line is
    compared case-insensitively */
-ImapMatchGlob *imap_match_init(const char *mask, int inboxcase, char separator);
+struct imap_match_glob *imap_match_init(const char *mask, int inboxcase,
+					char separator);
 
 /* Returns 1 if matched, 0 if it didn't match, but could match with additional
    hierarchies, -1 if definitely didn't match */
-int imap_match(ImapMatchGlob *glob, const char *data);
+int imap_match(struct imap_match_glob *glob, const char *data);
 
 #endif
--- a/src/lib-imap/imap-message-cache.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-message-cache.c	Sun Jan 05 15:09:51 2003 +0200
@@ -19,18 +19,16 @@
 
 #define DEFAULT_MESSAGE_POOL_SIZE 4096
 
-typedef struct _CachedMessage CachedMessage;
+struct cached_message {
+	struct cached_message *next;
 
-struct _CachedMessage {
-	CachedMessage *next;
-
-	Pool pool;
+	pool_t pool;
 	unsigned int uid;
 
-	MessagePart *part;
-	MessageSize *hdr_size;
-	MessageSize *body_size;
-	MessageSize *partial_size;
+	struct message_part *part;
+	struct message_size *hdr_size;
+	struct message_size *body_size;
+	struct message_size *partial_size;
 
 	time_t internal_date;
 	uoff_t full_virtual_size;
@@ -39,38 +37,39 @@
 	char *cached_bodystructure;
 	char *cached_envelope;
 
-	MessagePartEnvelopeData *envelope;
+	struct message_part_envelope_data *envelope;
 };
 
-struct _ImapMessageCache {
-	ImapMessageCacheIface *iface;
+struct imap_message_cache {
+	struct imap_message_cache_iface *iface;
 
-	CachedMessage *messages;
+	struct cached_message *messages;
 	int messages_count;
 
-	CachedMessage *open_msg;
-	IStream *open_stream;
+	struct cached_message *open_msg;
+	struct istream *open_stream;
 
 	void *context;
 };
 
-ImapMessageCache *imap_msgcache_alloc(ImapMessageCacheIface *iface)
+struct imap_message_cache *
+imap_msgcache_alloc(struct imap_message_cache_iface *iface)
 {
-	ImapMessageCache *cache;
+	struct imap_message_cache *cache;
 
-	cache = i_new(ImapMessageCache, 1);
+	cache = i_new(struct imap_message_cache, 1);
 	cache->iface = iface;
 	return cache;
 }
 
-static void cached_message_free(CachedMessage *msg)
+static void cached_message_free(struct cached_message *msg)
 {
 	pool_unref(msg->pool);
 }
 
-void imap_msgcache_clear(ImapMessageCache *cache)
+void imap_msgcache_clear(struct imap_message_cache *cache)
 {
-	CachedMessage *next;
+	struct cached_message *next;
 
 	imap_msgcache_close(cache);
 
@@ -81,16 +80,17 @@
 	}
 }
 
-void imap_msgcache_free(ImapMessageCache *cache)
+void imap_msgcache_free(struct imap_message_cache *cache)
 {
 	imap_msgcache_clear(cache);
 	i_free(cache);
 }
 
-static CachedMessage *cache_new(ImapMessageCache *cache, unsigned int uid)
+static struct cached_message *
+cache_new(struct imap_message_cache *cache, unsigned int uid)
 {
-	CachedMessage *msg, **msgp;
-	Pool pool;
+	struct cached_message *msg, **msgp;
+	pool_t pool;
 
 	if (cache->messages_count < MAX_CACHED_MESSAGES)
 		cache->messages_count++;
@@ -104,10 +104,10 @@
 		*msgp = NULL;
 	}
 
-	pool = pool_alloconly_create("CachedMessage",
+	pool = pool_alloconly_create("cached_message",
 				     DEFAULT_MESSAGE_POOL_SIZE);
 
-	msg = p_new(pool, CachedMessage, 1);
+	msg = p_new(pool, struct cached_message, 1);
 	msg->pool = pool;
 	msg->uid = uid;
 	msg->internal_date = (time_t)-1;
@@ -118,10 +118,10 @@
 	return msg;
 }
 
-static CachedMessage *cache_open_or_create(ImapMessageCache *cache,
-					   unsigned int uid)
+static struct cached_message *
+cache_open_or_create(struct imap_message_cache *cache, unsigned int uid)
 {
-	CachedMessage **pos, *msg;
+	struct cached_message **pos, *msg;
 
 	pos = &cache->messages;
 	for (; *pos != NULL; pos = &(*pos)->next) {
@@ -146,12 +146,12 @@
 	return msg;
 }
 
-static void parse_envelope_header(MessagePart *part,
+static void parse_envelope_header(struct message_part *part,
 				  const unsigned char *name, size_t name_len,
 				  const unsigned char *value, size_t value_len,
 				  void *context)
 {
-	CachedMessage *msg = context;
+	struct cached_message *msg = context;
 
 	if (part == NULL || part->parent == NULL) {
 		/* parse envelope headers if we're at the root message part */
@@ -160,7 +160,8 @@
 	}
 }
 
-static int imap_msgcache_get_stream(ImapMessageCache *cache, uoff_t offset)
+static int imap_msgcache_get_stream(struct imap_message_cache *cache,
+				    uoff_t offset)
 {
 	if (cache->open_stream == NULL)
 		cache->open_stream = cache->iface->open_mail(cache->context);
@@ -181,7 +182,7 @@
 	return TRUE;
 }
 
-static void msg_get_part(ImapMessageCache *cache)
+static void msg_get_part(struct imap_message_cache *cache)
 {
 	if (cache->open_msg->part == NULL) {
 		cache->open_msg->part =
@@ -191,9 +192,10 @@
 }
 
 /* Caches the fields for given message if possible */
-static int cache_fields(ImapMessageCache *cache, ImapCacheField fields)
+static int cache_fields(struct imap_message_cache *cache,
+			enum imap_cache_field fields)
 {
-        CachedMessage *msg;
+        struct cached_message *msg;
 	const char *value;
 	int failed;
 
@@ -257,8 +259,9 @@
 				/* envelope isn't parsed yet, do it. header
 				   size is calculated anyway so save it */
 				if (msg->hdr_size == NULL) {
-					msg->hdr_size = p_new(msg->pool,
-							      MessageSize, 1);
+					msg->hdr_size =
+						p_new(msg->pool,
+						      struct message_size, 1);
 				}
 
 				message_parse_header(NULL, cache->open_stream,
@@ -283,7 +286,7 @@
 	if ((fields & IMAP_CACHE_MESSAGE_BODY_SIZE) && msg->body_size == NULL) {
 		/* we don't have body size. and since we're already going
 		   to scan the whole message body, we might as well build
-		   the MessagePart. FIXME: this slows down things when it's
+		   the message_part. FIXME: this slows down things when it's
 		   not needed, do we really want to? */
                 fields |= IMAP_CACHE_MESSAGE_PART;
 	}
@@ -314,9 +317,11 @@
 	if ((fields & IMAP_CACHE_MESSAGE_BODY_SIZE) && msg->body_size == NULL) {
 		i_assert(msg->part != NULL);
 
-		msg->body_size = p_new(msg->pool, MessageSize, 1);
-		if (msg->hdr_size == NULL)
-			msg->hdr_size = p_new(msg->pool, MessageSize, 1);
+		msg->body_size = p_new(msg->pool, struct message_size, 1);
+		if (msg->hdr_size == NULL) {
+			msg->hdr_size = p_new(msg->pool,
+					      struct message_size, 1);
+		}
 
 		*msg->hdr_size = msg->part->header_size;
 		*msg->body_size = msg->part->body_size;
@@ -325,14 +330,14 @@
 	if ((fields & IMAP_CACHE_MESSAGE_HDR_SIZE) && msg->hdr_size == NULL) {
 		msg_get_part(cache);
 
-		msg->hdr_size = p_new(msg->pool, MessageSize, 1);
+		msg->hdr_size = p_new(msg->pool, struct message_size, 1);
 		if (msg->part != NULL) {
 			/* easy, get it from root part */
 			*msg->hdr_size = msg->part->header_size;
 
 			if (msg->body_size == NULL) {
 				msg->body_size = p_new(msg->pool,
-						       MessageSize, 1);
+						       struct message_size, 1);
 				*msg->body_size = msg->part->body_size;
 			}
 		} else {
@@ -375,12 +380,12 @@
 	return !failed;
 }
 
-int imap_msgcache_open(ImapMessageCache *cache, unsigned int uid,
-		       ImapCacheField fields,
+int imap_msgcache_open(struct imap_message_cache *cache, unsigned int uid,
+		       enum imap_cache_field fields,
 		       uoff_t vp_header_size, uoff_t vp_body_size,
 		       uoff_t full_virtual_size, void *context)
 {
-	CachedMessage *msg;
+	struct cached_message *msg;
 
 	msg = cache_open_or_create(cache, uid);
 	if (cache->open_msg != msg) {
@@ -392,14 +397,14 @@
 
 	if (vp_header_size != (uoff_t)-1 && msg->hdr_size == NULL) {
 		/* physical size == virtual size */
-		msg->hdr_size = p_new(msg->pool, MessageSize, 1);
+		msg->hdr_size = p_new(msg->pool, struct message_size, 1);
 		msg->hdr_size->physical_size = msg->hdr_size->virtual_size =
 			vp_header_size;
 	}
 
 	if (vp_body_size != (uoff_t)-1 && msg->body_size == NULL) {
 		/* physical size == virtual size */
-		msg->body_size = p_new(msg->pool, MessageSize, 1);
+		msg->body_size = p_new(msg->pool, struct message_size, 1);
 		msg->body_size->physical_size = msg->body_size->virtual_size =
 			vp_body_size;
 	}
@@ -409,7 +414,7 @@
 	return cache_fields(cache, fields);
 }
 
-void imap_msgcache_close(ImapMessageCache *cache)
+void imap_msgcache_close(struct imap_message_cache *cache)
 {
 	if (cache->open_stream != NULL) {
 		i_stream_unref(cache->open_stream);
@@ -420,9 +425,10 @@
 	cache->context = NULL;
 }
 
-const char *imap_msgcache_get(ImapMessageCache *cache, ImapCacheField field)
+const char *imap_msgcache_get(struct imap_message_cache *cache,
+			      enum imap_cache_field field)
 {
-	CachedMessage *msg;
+	struct cached_message *msg;
 
 	i_assert(cache->open_msg != NULL);
 
@@ -447,31 +453,33 @@
 	return NULL;
 }
 
-MessagePart *imap_msgcache_get_parts(ImapMessageCache *cache)
+struct message_part *imap_msgcache_get_parts(struct imap_message_cache *cache)
 {
 	if (cache->open_msg->part == NULL)
 		cache_fields(cache, IMAP_CACHE_MESSAGE_PART);
 	return cache->open_msg->part;
 }
 
-uoff_t imap_msgcache_get_virtual_size(ImapMessageCache *cache)
+uoff_t imap_msgcache_get_virtual_size(struct imap_message_cache *cache)
 {
 	if (cache->open_msg->full_virtual_size == (uoff_t)-1)
 		cache_fields(cache, IMAP_CACHE_VIRTUAL_SIZE);
 	return cache->open_msg->full_virtual_size;
 }
 
-time_t imap_msgcache_get_internal_date(ImapMessageCache *cache)
+time_t imap_msgcache_get_internal_date(struct imap_message_cache *cache)
 {
 	if (cache->open_msg->internal_date == (time_t)-1)
 		cache_fields(cache, IMAP_CACHE_INTERNALDATE);
 	return cache->open_msg->internal_date;
 }
 
-int imap_msgcache_get_rfc822(ImapMessageCache *cache, IStream **stream,
-			     MessageSize *hdr_size, MessageSize *body_size)
+int imap_msgcache_get_rfc822(struct imap_message_cache *cache,
+			     struct istream **stream,
+			     struct message_size *hdr_size,
+			     struct message_size *body_size)
 {
-	CachedMessage *msg;
+	struct cached_message *msg;
 	uoff_t offset;
 
 	i_assert(cache->open_msg != NULL);
@@ -506,17 +514,17 @@
 	return TRUE;
 }
 
-static uoff_t get_partial_size(IStream *stream,
+static uoff_t get_partial_size(struct istream *stream,
 			       uoff_t virtual_skip, uoff_t max_virtual_size,
-			       MessageSize *partial, MessageSize *dest,
-			       int *cr_skipped)
+			       struct message_size *partial,
+			       struct message_size *dest, int *cr_skipped)
 {
 	uoff_t physical_skip;
 	int last_cr;
 
 	/* see if we can use the existing partial */
 	if (partial->virtual_size > virtual_skip)
-		memset(partial, 0, sizeof(MessageSize));
+		memset(partial, 0, sizeof(struct message_size));
 	else {
 		i_stream_skip(stream, partial->physical_size);
 		virtual_skip -= partial->virtual_size;
@@ -550,19 +558,19 @@
 	return physical_skip;
 }
 
-int imap_msgcache_get_rfc822_partial(ImapMessageCache *cache,
+int imap_msgcache_get_rfc822_partial(struct imap_message_cache *cache,
 				     uoff_t virtual_skip,
 				     uoff_t max_virtual_size,
-				     int get_header, MessageSize *size,
-                                     IStream **stream, int *cr_skipped)
+				     int get_header, struct message_size *size,
+                                     struct istream **stream, int *cr_skipped)
 {
-	CachedMessage *msg;
+	struct cached_message *msg;
 	uoff_t physical_skip, full_size;
 	int size_got;
 
 	i_assert(cache->open_msg != NULL);
 
-	memset(size, 0, sizeof(MessageSize));
+	memset(size, 0, sizeof(struct message_size));
 	*stream = NULL;
 	*cr_skipped = FALSE;
 
@@ -588,7 +596,7 @@
 			full_size += msg->hdr_size->virtual_size;
 
 		if (max_virtual_size >= full_size) {
-			memcpy(size, msg->body_size, sizeof(MessageSize));
+			memcpy(size, msg->body_size, sizeof(*size));
 			if (get_header)
 				message_size_add(size, msg->hdr_size);
 			size_got = TRUE;
@@ -601,8 +609,10 @@
 		if (!imap_msgcache_get_stream(cache, 0))
 			return FALSE;
 
-		if (msg->partial_size == NULL)
-			msg->partial_size = p_new(msg->pool, MessageSize, 1);
+		if (msg->partial_size == NULL) {
+			msg->partial_size =
+				p_new(msg->pool, struct message_size, 1);
+		}
 		if (!get_header)
 			virtual_skip += msg->hdr_size->virtual_size;
 
@@ -620,7 +630,8 @@
 	return TRUE;
 }
 
-int imap_msgcache_get_data(ImapMessageCache *cache, IStream **stream)
+int imap_msgcache_get_data(struct imap_message_cache *cache,
+			   struct istream **stream)
 {
 	i_assert(cache->open_msg != NULL);
 
--- a/src/lib-imap/imap-message-cache.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-message-cache.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,6 +1,9 @@
 #ifndef __IMAP_MESSAGE_CACHE_H
 #define __IMAP_MESSAGE_CACHE_H
 
+struct message_part;
+struct message_size;
+
 /* IMAP message cache. Caches are mailbox-specific and must be cleared
    if UID validity changes. Also if message data may have changed,
    imap_msgcache_close() must be called.
@@ -9,9 +12,7 @@
    when client fetches the message in parts.
 */
 
-#include "message-parser.h"
-
-typedef enum {
+enum imap_cache_field {
 	IMAP_CACHE_BODY			= 0x0001,
 	IMAP_CACHE_BODYSTRUCTURE	= 0x0002,
 	IMAP_CACHE_ENVELOPE		= 0x0004,
@@ -22,72 +23,78 @@
 	IMAP_CACHE_MESSAGE_PART		= 0x0400,
 	IMAP_CACHE_MESSAGE_HDR_SIZE	= 0x0800,
 	IMAP_CACHE_MESSAGE_BODY_SIZE	= 0x0100
-} ImapCacheField;
+};
 
-typedef struct {
+struct imap_message_cache_iface {
 	/* Open mail for reading. */
-	IStream *(*open_mail)(void *context);
+	struct istream *(*open_mail)(void *context);
 	/* Rewind stream to beginning, possibly closing the old stream
 	   if it can't directly be rewinded. */
-	IStream *(*stream_rewind)(IStream *stream, void *context);
+	struct istream *(*stream_rewind)(struct istream *stream, void *context);
 
 	/* Returns field if it's already cached, or NULL. */
-	const char *(*get_cached_field)(ImapCacheField field, void *context);
-	/* Returns MessagePart if it's already cached, or NULL. */
-	MessagePart *(*get_cached_parts)(Pool pool, void *context);
+	const char *(*get_cached_field)(enum imap_cache_field field,
+					void *context);
+	/* Returns message_part if it's already cached, or NULL. */
+	struct message_part *(*get_cached_parts)(pool_t pool, void *context);
 
 	/* Returns message's internal date, or (time_t)-1 if error. */
 	time_t (*get_internal_date)(void *context);
-} ImapMessageCacheIface;
+};
 
-typedef struct _ImapMessageCache ImapMessageCache;
+struct imap_message_cache;
 
-ImapMessageCache *imap_msgcache_alloc(ImapMessageCacheIface *iface);
-void imap_msgcache_clear(ImapMessageCache *cache);
-void imap_msgcache_free(ImapMessageCache *cache);
+struct imap_message_cache *
+imap_msgcache_alloc(struct imap_message_cache_iface *iface);
+void imap_msgcache_clear(struct imap_message_cache *cache);
+void imap_msgcache_free(struct imap_message_cache *cache);
 
 /* Open the specified message. Set vp_*_size if both physical and virtual
    sizes are same, otherwise (uoff_t)-1. If full_virtual_size isn't known,
    set it to (uoff_t)-1. Returns TRUE if all specified fields were cached.
    Even if FALSE is returned, it's possible to use the cached data,
    imap_msgcache_get() just returns NULL for those that weren't. */
-int imap_msgcache_open(ImapMessageCache *cache, unsigned int uid,
-		       ImapCacheField fields,
+int imap_msgcache_open(struct imap_message_cache *cache, unsigned int uid,
+		       enum imap_cache_field fields,
 		       uoff_t vp_header_size, uoff_t vp_body_size,
 		       uoff_t full_virtual_size, void *context);
 
 /* Close the IOStream for opened message. */
-void imap_msgcache_close(ImapMessageCache *cache);
+void imap_msgcache_close(struct imap_message_cache *cache);
 
 /* Returns the field from cache, or NULL if it's not cached. */
-const char *imap_msgcache_get(ImapMessageCache *cache, ImapCacheField field);
+const char *imap_msgcache_get(struct imap_message_cache *cache,
+			      enum imap_cache_field field);
 
-/* Returns the root MessagePart for message, or NULL if failed. */
-MessagePart *imap_msgcache_get_parts(ImapMessageCache *cache);
+/* Returns the root message_part for message, or NULL if failed. */
+struct message_part *imap_msgcache_get_parts(struct imap_message_cache *cache);
 
 /* Returns the virtual size of message, or (uoff_t)-1 if failed. */
-uoff_t imap_msgcache_get_virtual_size(ImapMessageCache *cache);
+uoff_t imap_msgcache_get_virtual_size(struct imap_message_cache *cache);
 
 /* Returns the internal date of message, or (time_t)-1 if failed. */
-time_t imap_msgcache_get_internal_date(ImapMessageCache *cache);
+time_t imap_msgcache_get_internal_date(struct imap_message_cache *cache);
 
 /* Returns TRUE if successful. If stream is not NULL, it's set to point to
    beginning of message, or to beginning of message body if hdr_size is NULL. */
-int imap_msgcache_get_rfc822(ImapMessageCache *cache, IStream **stream,
-			     MessageSize *hdr_size, MessageSize *body_size);
+int imap_msgcache_get_rfc822(struct imap_message_cache *cache,
+			     struct istream **stream,
+			     struct message_size *hdr_size,
+			     struct message_size *body_size);
 
 /* Returns TRUE if successful. *stream is set to point to the first non-skipped
    character. size is set to specify the actual message size in
    virtual_skip..max_virtual_size range. cr_skipped is set to TRUE if first
    character in stream is LF, and we should NOT treat it as CR+LF. */
-int imap_msgcache_get_rfc822_partial(ImapMessageCache *cache,
+int imap_msgcache_get_rfc822_partial(struct imap_message_cache *cache,
 				     uoff_t virtual_skip,
 				     uoff_t max_virtual_size,
-				     int get_header, MessageSize *size,
-				     IStream **stream, int *cr_skipped);
+				     int get_header, struct message_size *size,
+				     struct istream **stream, int *cr_skipped);
 
 /* Returns TRUE if successful. *stream is set to point to beginning of
    message. */
-int imap_msgcache_get_data(ImapMessageCache *cache, IStream **stream);
+int imap_msgcache_get_data(struct imap_message_cache *cache,
+			   struct istream **stream);
 
 #endif
--- a/src/lib-imap/imap-parser.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-parser.c	Sun Jan 05 15:09:51 2003 +0200
@@ -11,29 +11,29 @@
 
 #define LIST_ALLOC_SIZE 7
 
-typedef enum {
+enum arg_parse_type {
 	ARG_PARSE_NONE = 0,
 	ARG_PARSE_ATOM,
 	ARG_PARSE_STRING,
 	ARG_PARSE_LITERAL,
 	ARG_PARSE_LITERAL_DATA
-} ArgParseType;
+};
 
-struct _ImapParser {
+struct imap_parser {
 	/* permanent */
-	Pool pool;
-	IStream *input;
-	OStream *output;
+	pool_t pool;
+	struct istream *input;
+	struct ostream *output;
 	size_t max_literal_size, max_elements;
-        ImapParserFlags flags;
+        enum imap_parser_flags flags;
 
 	/* reset by imap_parser_reset(): */
-        ImapArgList *root_list;
-        ImapArgList *cur_list;
-	ImapArg *list_arg;
+        struct imap_arg_list *root_list;
+        struct imap_arg_list *cur_list;
+	struct imap_arg *list_arg;
 	size_t element_count;
 
-	ArgParseType cur_type;
+	enum arg_parse_type cur_type;
 	size_t cur_pos; /* parser position in input buffer */
 
 	int str_first_escape; /* ARG_PARSE_STRING: index to first '\' */
@@ -48,10 +48,12 @@
 
 #define LIST_REALLOC(parser, old_list, size) \
 	p_realloc((parser)->pool, old_list, \
-		  sizeof(ImapArgList) + sizeof(ImapArg) * ((size)-1))
+		  sizeof(struct imap_arg_list) + \
+		  sizeof(struct imap_arg) * ((size)-1))
 
-static void imap_args_realloc(ImapParser *parser, size_t size)
+static void imap_args_realloc(struct imap_parser *parser, size_t size)
 {
+	/* @UNSAFE */
 	parser->cur_list = LIST_REALLOC(parser, parser->cur_list, size);
 	parser->cur_list->alloc = size;
 
@@ -61,12 +63,13 @@
 		parser->list_arg->_data.list = parser->cur_list;
 }
 
-ImapParser *imap_parser_create(IStream *input, OStream *output,
-			       size_t max_literal_size, size_t max_elements)
+struct imap_parser *
+imap_parser_create(struct istream *input, struct ostream *output,
+		   size_t max_literal_size, size_t max_elements)
 {
-	ImapParser *parser;
+	struct imap_parser *parser;
 
-	parser = i_new(ImapParser, 1);
+	parser = i_new(struct imap_parser, 1);
         parser->pool = pool_alloconly_create("IMAP parser", 8192);
 	parser->input = input;
 	parser->output = output;
@@ -77,13 +80,13 @@
 	return parser;
 }
 
-void imap_parser_destroy(ImapParser *parser)
+void imap_parser_destroy(struct imap_parser *parser)
 {
 	pool_unref(parser->pool);
 	i_free(parser);
 }
 
-void imap_parser_reset(ImapParser *parser)
+void imap_parser_reset(struct imap_parser *parser)
 {
 	p_clear(parser->pool);
 
@@ -107,13 +110,13 @@
 	imap_args_realloc(parser, LIST_ALLOC_SIZE);
 }
 
-const char *imap_parser_get_error(ImapParser *parser)
+const char *imap_parser_get_error(struct imap_parser *parser)
 {
 	return parser->error;
 }
 
 /* skip over everything parsed so far, plus the following whitespace */
-static int imap_parser_skip_to_next(ImapParser *parser,
+static int imap_parser_skip_to_next(struct imap_parser *parser,
 				    const unsigned char **data,
 				    size_t *data_size)
 {
@@ -132,9 +135,9 @@
 	return *data_size > 0;
 }
 
-static ImapArg *imap_arg_create(ImapParser *parser)
+static struct imap_arg *imap_arg_create(struct imap_parser *parser)
 {
-	ImapArg *arg;
+	struct imap_arg *arg;
 
 	i_assert(parser->cur_list != NULL);
 
@@ -150,7 +153,7 @@
 	return arg;
 }
 
-static void imap_parser_open_list(ImapParser *parser)
+static void imap_parser_open_list(struct imap_parser *parser)
 {
 	parser->list_arg = imap_arg_create(parser);
 
@@ -163,9 +166,9 @@
 	parser->cur_type = ARG_PARSE_NONE;
 }
 
-static int imap_parser_close_list(ImapParser *parser)
+static int imap_parser_close_list(struct imap_parser *parser)
 {
-	ImapArg *arg;
+	struct imap_arg *arg;
 
 	if (parser->list_arg == NULL) {
 		/* we're not inside list */
@@ -188,10 +191,10 @@
 	return TRUE;
 }
 
-static void imap_parser_save_arg(ImapParser *parser, const unsigned char *data,
-				 size_t size)
+static void imap_parser_save_arg(struct imap_parser *parser,
+				 const unsigned char *data, size_t size)
 {
-	ImapArg *arg;
+	struct imap_arg *arg;
 
 	arg = imap_arg_create(parser);
 
@@ -239,8 +242,8 @@
 	parser->cur_type = ARG_PARSE_NONE;
 }
 
-static int imap_parser_read_atom(ImapParser *parser, const unsigned char *data,
-				 size_t data_size)
+static int imap_parser_read_atom(struct imap_parser *parser,
+				 const unsigned char *data, size_t data_size)
 {
 	size_t i;
 
@@ -276,7 +279,7 @@
 	return parser->cur_type == ARG_PARSE_NONE;
 }
 
-static int imap_parser_read_string(ImapParser *parser,
+static int imap_parser_read_string(struct imap_parser *parser,
 				   const unsigned char *data, size_t data_size)
 {
 	size_t i;
@@ -318,7 +321,7 @@
 	return parser->cur_type == ARG_PARSE_NONE;
 }
 
-static int imap_parser_literal_end(ImapParser *parser)
+static int imap_parser_literal_end(struct imap_parser *parser)
 {
 	if ((parser->flags & IMAP_PARSE_FLAG_LITERAL_SIZE) == 0) {
 		if (parser->literal_size > parser->max_literal_size) {
@@ -340,7 +343,7 @@
 	return TRUE;
 }
 
-static int imap_parser_read_literal(ImapParser *parser,
+static int imap_parser_read_literal(struct imap_parser *parser,
 				    const unsigned char *data,
 				    size_t data_size)
 {
@@ -372,7 +375,7 @@
 	return FALSE;
 }
 
-static int imap_parser_read_literal_data(ImapParser *parser,
+static int imap_parser_read_literal_data(struct imap_parser *parser,
 					 const unsigned char *data,
 					 size_t data_size)
 {
@@ -420,7 +423,7 @@
 
 /* Returns TRUE if argument was fully processed. Also returns TRUE if
    an argument inside a list was processed. */
-static int imap_parser_read_arg(ImapParser *parser)
+static int imap_parser_read_arg(struct imap_parser *parser)
 {
 	const unsigned char *data;
 	size_t data_size;
@@ -507,8 +510,8 @@
         ((parser)->cur_type != ARG_PARSE_NONE || \
 	 (parser)->cur_list != parser->root_list)
 
-int imap_parser_read_args(ImapParser *parser, unsigned int count,
-			  ImapParserFlags flags, ImapArg **args)
+int imap_parser_read_args(struct imap_parser *parser, unsigned int count,
+			  enum imap_parser_flags flags, struct imap_arg **args)
 {
 	parser->flags = flags;
 
@@ -551,7 +554,7 @@
 	}
 }
 
-const char *imap_parser_read_word(ImapParser *parser)
+const char *imap_parser_read_word(struct imap_parser *parser)
 {
 	const unsigned char *data;
 	size_t i, data_size;
@@ -571,7 +574,7 @@
 	}
 }
 
-const char *imap_parser_read_line(ImapParser *parser)
+const char *imap_parser_read_line(struct imap_parser *parser)
 {
 	const unsigned char *data;
 	size_t i, data_size;
@@ -591,7 +594,7 @@
 	}
 }
 
-const char *imap_arg_string(ImapArg *arg)
+const char *imap_arg_string(struct imap_arg *arg)
 {
 	switch (arg->type) {
 	case IMAP_ARG_NIL:
@@ -606,20 +609,20 @@
 	}
 }
 
-char *_imap_arg_str_error(const ImapArg *arg)
+char *_imap_arg_str_error(const struct imap_arg *arg)
 {
-	i_panic("Tried to access ImapArg type %d as string", arg->type);
+	i_panic("Tried to access imap_arg type %d as string", arg->type);
 	return NULL;
 }
 
-uoff_t _imap_arg_literal_size_error(const ImapArg *arg)
+uoff_t _imap_arg_literal_size_error(const struct imap_arg *arg)
 {
-	i_panic("Tried to access ImapArg type %d as literal size", arg->type);
+	i_panic("Tried to access imap_arg type %d as literal size", arg->type);
 	return 0;
 }
 
-ImapArgList *_imap_arg_list_error(const ImapArg *arg)
+struct imap_arg_list *_imap_arg_list_error(const struct imap_arg *arg)
 {
-	i_panic("Tried to access ImapArg type %d as list", arg->type);
+	i_panic("Tried to access imap_arg type %d as list", arg->type);
 	return NULL;
 }
--- a/src/lib-imap/imap-parser.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-parser.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,7 +1,7 @@
 #ifndef __IMAP_PARSER_H
 #define __IMAP_PARSER_H
 
-typedef enum {
+enum imap_parser_flags {
 	/* Set this flag if you wish to read only size of literal argument
 	   and not convert literal into string. Useful when you need to deal
 	   with large literal sizes. The literal must be the last read
@@ -9,9 +9,9 @@
 	IMAP_PARSE_FLAG_LITERAL_SIZE	= 0x01,
 	/* Don't remove '\' chars from string arguments */
 	IMAP_PARSE_FLAG_NO_UNESCAPE	= 0x02,
-} ImapParserFlags;
+};
 
-typedef enum {
+enum imap_arg_type {
 	IMAP_ARG_NIL = 0,
 	IMAP_ARG_ATOM,
 	IMAP_ARG_STRING,
@@ -19,20 +19,18 @@
 	IMAP_ARG_LIST,
 
 	IMAP_ARG_EOL /* end of argument list */
-} ImapArgType;
+};
+
+struct imap_parser;
 
-typedef struct _ImapParser ImapParser;
-typedef struct _ImapArg ImapArg;
-typedef struct _ImapArgList ImapArgList;
-
-struct _ImapArg {
-	ImapArgType type;
-        ImapArg *parent; /* always of type IMAP_ARG_LIST */
+struct imap_arg {
+	enum imap_arg_type type;
+        struct imap_arg *parent; /* always of type IMAP_ARG_LIST */
 
 	union {
 		char *str;
 		uoff_t literal_size;
-		ImapArgList *list;
+		struct imap_arg_list *list;
 	} _data;
 };
 
@@ -49,9 +47,9 @@
 	((arg)->type == IMAP_ARG_LIST ? \
 	 (arg)->_data.list : _imap_arg_list_error(arg))
 
-struct _ImapArgList {
+struct imap_arg_list {
 	size_t size, alloc;
-	ImapArg args[1]; /* variable size */
+	struct imap_arg args[1]; /* variable size */
 };
 
 /* Create new IMAP argument parser. There's no limit in argument sizes, only
@@ -60,15 +58,16 @@
    unset). max_elements sets the number of elements we allow entirely so that
    user can't give huge lists or lists inside lists. output is used for sending
    command continuation requests for literals. */
-ImapParser *imap_parser_create(IStream *input, OStream *output,
-			       size_t max_literal_size, size_t max_elements);
-void imap_parser_destroy(ImapParser *parser);
+struct imap_parser *
+imap_parser_create(struct istream *input, struct ostream *output,
+		   size_t max_literal_size, size_t max_elements);
+void imap_parser_destroy(struct imap_parser *parser);
 
 /* Reset the parser to initial state. */
-void imap_parser_reset(ImapParser *parser);
+void imap_parser_reset(struct imap_parser *parser);
 
 /* Return the last error in parser. */
-const char *imap_parser_get_error(ImapParser *parser);
+const char *imap_parser_get_error(struct imap_parser *parser);
 
 /* Read a number of arguments. This function doesn't call i_stream_read(), you
    need to do that. Returns number of arguments read (may be less than count
@@ -78,22 +77,22 @@
    0 or larger. If all arguments weren't read, they're set to NIL. count
    can be set to 0 to read all arguments in the line. Last element in
    args[size] is always of type IMAP_ARG_EOL. */
-int imap_parser_read_args(ImapParser *parser, unsigned int count,
-			  ImapParserFlags flags, ImapArg **args);
+int imap_parser_read_args(struct imap_parser *parser, unsigned int count,
+			  enum imap_parser_flags flags, struct imap_arg **args);
 
 /* Read one word - used for reading tag and command name.
    Returns NULL if more data is needed. */
-const char *imap_parser_read_word(ImapParser *parser);
+const char *imap_parser_read_word(struct imap_parser *parser);
 
 /* Read the rest of the line. Returns NULL if more data is needed. */
-const char *imap_parser_read_line(ImapParser *parser);
+const char *imap_parser_read_line(struct imap_parser *parser);
 
 /* Returns the imap argument as string. NIL returns "" and list returns NULL. */
-const char *imap_arg_string(ImapArg *arg);
+const char *imap_arg_string(struct imap_arg *arg);
 
 /* Error functions */
-char *_imap_arg_str_error(const ImapArg *arg);
-uoff_t _imap_arg_literal_size_error(const ImapArg *arg);
-ImapArgList *_imap_arg_list_error(const ImapArg *arg);
+char *_imap_arg_str_error(const struct imap_arg *arg);
+uoff_t _imap_arg_literal_size_error(const struct imap_arg *arg);
+struct imap_arg_list *_imap_arg_list_error(const struct imap_arg *arg);
 
 #endif
--- a/src/lib-imap/imap-quote.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-quote.c	Sun Jan 05 15:09:51 2003 +0200
@@ -78,7 +78,7 @@
 	return i;
 }
 
-static void append_quoted_qp(String *str, const unsigned char *value,
+static void append_quoted_qp(string_t *str, const unsigned char *value,
 			     size_t len)
 {
 	size_t i;
@@ -105,7 +105,7 @@
 	}
 }
 
-static void append_quoted(String *str, const unsigned char *value, size_t len)
+static void append_quoted(string_t *str, const unsigned char *value, size_t len)
 {
 	size_t i;
 
@@ -117,9 +117,9 @@
 }
 
 /* does two things: 1) escape '\' and '"' characters, 2) 8bit text -> QP */
-static String *get_quoted_str(const unsigned char *value, size_t value_len)
+static string_t *get_quoted_str(const unsigned char *value, size_t value_len)
 {
-	String *str;
+	string_t *str;
 	size_t token_len;
 	int qp, need_qp, quoted;
 
@@ -170,9 +170,10 @@
 				     strlen(value)));
 }
 
-char *imap_quote_value(Pool pool, const unsigned char *value, size_t value_len)
+char *imap_quote_value(pool_t pool, const unsigned char *value,
+		       size_t value_len)
 {
-	String *str;
+	string_t *str;
 
 	str = get_quoted_str(value, value_len);
 	return p_strndup(pool, str_data(str), str_len(str));
--- a/src/lib-imap/imap-quote.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-quote.h	Sun Jan 05 15:09:51 2003 +0200
@@ -5,6 +5,7 @@
 const char *imap_quote_str_nil(const char *value);
 
 /* Return value quoted and allocated from specified pool. */
-char *imap_quote_value(Pool pool, const unsigned char *value, size_t value_len);
+char *imap_quote_value(pool_t pool, const unsigned char *value,
+		       size_t value_len);
 
 #endif
--- a/src/lib-imap/imap-util.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-util.c	Sun Jan 05 15:09:51 2003 +0200
@@ -4,10 +4,10 @@
 #include "str.h"
 #include "imap-util.h"
 
-const char *imap_write_flags(MailFlags flags, const char *custom_flags[],
+const char *imap_write_flags(enum mail_flags flags, const char *custom_flags[],
 			     unsigned int custom_flags_count)
 {
-	String *str;
+	string_t *str;
 	const char *sysflags, *name;
 	unsigned int i;
 
--- a/src/lib-imap/imap-util.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-imap/imap-util.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,7 +1,7 @@
 #ifndef __IMAP_UTIL_H
 #define __IMAP_UTIL_H
 
-typedef enum {
+enum mail_flags {
 	MAIL_ANSWERED		= 0x0000001,
 	MAIL_FLAGGED		= 0x0000002,
 	MAIL_DELETED		= 0x0000004,
@@ -14,7 +14,7 @@
 
 	MAIL_SYSTEM_FLAGS_MASK	= 0x000003f,
 	MAIL_CUSTOM_FLAGS_MASK	= 0xfffffc0
-} MailFlags;
+};
 
 /* growing number of flags isn't very easy. biggest problem is that they're
    stored into unsigned int, which is 32bit almost everywhere. another thing
@@ -30,7 +30,7 @@
 
 /* Return flags as a space separated string. custom_flags[] is a list of
    names for custom flags, flags having NULL or "" entry are ignored. */
-const char *imap_write_flags(MailFlags flags, const char *custom_flags[],
+const char *imap_write_flags(enum mail_flags flags, const char *custom_flags[],
 			     unsigned int custom_flags_count);
 
 #endif
--- a/src/lib-index/mail-custom-flags.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-custom-flags.c	Sun Jan 05 15:09:51 2003 +0200
@@ -20,8 +20,8 @@
 #define COUNTER_SIZE 4
 #define HEADER_SIZE (COUNTER_SIZE + 1) /* 0000\n */
 
-struct _MailCustomFlags {
-	MailIndex *index;
+struct mail_custom_flags {
+	struct mail_index *index;
 	char *filepath;
 	int fd;
 	int lock_type;
@@ -37,9 +37,9 @@
 	unsigned int changed:1;
 };
 
-static int lock_file(MailCustomFlags *mcf, int type);
+static int lock_file(struct mail_custom_flags *mcf, int type);
 
-static int index_cf_set_syscall_error(MailCustomFlags *mcf,
+static int index_cf_set_syscall_error(struct mail_custom_flags *mcf,
 				      const char *function)
 {
 	i_assert(function != NULL);
@@ -49,7 +49,7 @@
 	return FALSE;
 }
 
-static int update_mmap(MailCustomFlags *mcf)
+static int update_mmap(struct mail_custom_flags *mcf)
 {
 	if (mcf->mmap_base != NULL) {
 		if (munmap(mcf->mmap_base, mcf->mmap_length) < 0)
@@ -66,7 +66,7 @@
 	return TRUE;
 }
 
-static int custom_flags_init(MailCustomFlags *mcf)
+static int custom_flags_init(struct mail_custom_flags *mcf)
 {
 	static char buf[HEADER_SIZE] = "0000\n";
 	int failed;
@@ -102,7 +102,7 @@
 	return !failed;
 }
 
-static void custom_flags_sync(MailCustomFlags *mcf)
+static void custom_flags_sync(struct mail_custom_flags *mcf)
 {
 	char *data, *data_end, *line;
 	unsigned int num;
@@ -165,7 +165,7 @@
 	}
 }
 
-static int custom_flags_check_sync(MailCustomFlags *mcf)
+static int custom_flags_check_sync(struct mail_custom_flags *mcf)
 {
 	if (mcf->noupdate)
 		return TRUE;
@@ -195,7 +195,7 @@
 	return TRUE;
 }
 
-static int lock_file(MailCustomFlags *mcf, int type)
+static int lock_file(struct mail_custom_flags *mcf, int type)
 {
 	if (mcf->lock_type == type)
 		return TRUE;
@@ -224,9 +224,9 @@
 	return TRUE;
 }
 
-int mail_custom_flags_open_or_create(MailIndex *index)
+int mail_custom_flags_open_or_create(struct mail_index *index)
 {
-	MailCustomFlags *mcf;
+	struct mail_custom_flags *mcf;
 	const char *path;
 	int fd;
 
@@ -239,7 +239,7 @@
 		return index_file_set_syscall_error(index, path, "open()");
 	}
 
-	mcf = i_new(MailCustomFlags, 1);
+	mcf = i_new(struct mail_custom_flags, 1);
 	mcf->index = index;
 	mcf->filepath = i_strdup(path);
 	mcf->fd = fd;
@@ -267,7 +267,7 @@
 	return TRUE;
 }
 
-void mail_custom_flags_free(MailCustomFlags *mcf)
+void mail_custom_flags_free(struct mail_custom_flags *mcf)
 {
 	int i;
 
@@ -286,7 +286,7 @@
 	i_free(mcf);
 }
 
-static int custom_flags_update_counter(MailCustomFlags *mcf)
+static int custom_flags_update_counter(struct mail_custom_flags *mcf)
 {
 	int i;
 
@@ -315,7 +315,8 @@
 	return TRUE;
 }
 
-static int custom_flags_add(MailCustomFlags *mcf, int idx, const char *name)
+static int custom_flags_add(struct mail_custom_flags *mcf,
+			    int idx, const char *name)
 {
 	const char *buf;
 	size_t len;
@@ -357,7 +358,7 @@
 	return TRUE;
 }
 
-static int custom_flags_remove(MailCustomFlags *mcf, unsigned int idx)
+static int custom_flags_remove(struct mail_custom_flags *mcf, unsigned int idx)
 {
 	char *data, *data_end, *line;
 	unsigned int num;
@@ -405,7 +406,7 @@
 	return FALSE;
 }
 
-static int find_first_unused_flag(MailCustomFlags *mcf)
+static int find_first_unused_flag(struct mail_custom_flags *mcf)
 {
 	int i;
 
@@ -417,8 +418,8 @@
 	return -1;
 }
 
-static void remove_unused_custom_flags(MailCustomFlags *mcf,
-				       MailFlags used_flags)
+static void remove_unused_custom_flags(struct mail_custom_flags *mcf,
+				       enum mail_flags used_flags)
 {
 	unsigned int i;
 
@@ -432,10 +433,10 @@
 	}
 }
 
-static MailFlags get_used_flags(MailCustomFlags *mcf)
+static enum mail_flags get_used_flags(struct mail_custom_flags *mcf)
 {
-	MailIndexRecord *rec;
-	MailFlags used_flags;
+	struct mail_index_record *rec;
+	enum mail_flags used_flags;
 
 	used_flags = 0;
 
@@ -448,7 +449,7 @@
 	return used_flags;
 }
 
-static int get_flag_index(MailCustomFlags *mcf, const char *flag,
+static int get_flag_index(struct mail_custom_flags *mcf, const char *flag,
 			  int index_hint)
 {
 	int i, first_empty;
@@ -505,10 +506,11 @@
 	return first_empty;
 }
 
-int mail_custom_flags_fix_list(MailCustomFlags *mcf, MailFlags *flags,
+int mail_custom_flags_fix_list(struct mail_custom_flags *mcf,
+			       enum mail_flags *flags,
 			       const char *custom_flags[], unsigned int count)
 {
-	MailFlags oldflags, flag;
+	enum mail_flags oldflags, flag;
 	int i, idx;
 
 	i_assert(count < 32);
@@ -542,12 +544,12 @@
 	return 1;
 }
 
-const char **mail_custom_flags_list_get(MailCustomFlags *mcf)
+const char **mail_custom_flags_list_get(struct mail_custom_flags *mcf)
 {
 	return (const char **) mcf->custom_flags;
 }
 
-int mail_custom_flags_has_changes(MailCustomFlags *mcf)
+int mail_custom_flags_has_changes(struct mail_custom_flags *mcf)
 {
 	if (!mcf->changed)
 		return FALSE;
--- a/src/lib-index/mail-custom-flags.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-custom-flags.h	Sun Jan 05 15:09:51 2003 +0200
@@ -7,24 +7,25 @@
 
 #define CUSTOM_FLAGS_FILE_NAME ".customflags"
 
-int mail_custom_flags_open_or_create(MailIndex *index);
-void mail_custom_flags_free(MailCustomFlags *mcf);
+int mail_custom_flags_open_or_create(struct mail_index *index);
+void mail_custom_flags_free(struct mail_custom_flags *mcf);
 
 /* Change custom flags so that they reflect the real flag numbers in
    the file. Initially flags contains the custom flags in the order of the
    specified list, it's modified to reflect the actual list. Returns 1 if ok,
    0 if number of custom flags exceeded or -1 if error */
-int mail_custom_flags_fix_list(MailCustomFlags *mcf, MailFlags *flags,
+int mail_custom_flags_fix_list(struct mail_custom_flags *mcf,
+			       enum mail_flags *flags,
 			       const char *custom_flags[], unsigned int count);
 
 /* Returns a pointer to list of flags. Note that calls to
    mail_cutom_flags_fix_list() may modify the flags in the returned list.
    It can modify only the flags that aren't in use anywhere, so this should
    be safe. */
-const char **mail_custom_flags_list_get(MailCustomFlags *mcf);
+const char **mail_custom_flags_list_get(struct mail_custom_flags *mcf);
 
 /* Returns TRUE if there's been any changes since this function was
    called last time, or since open if this is the first call. */
-int mail_custom_flags_has_changes(MailCustomFlags *mcf);
+int mail_custom_flags_has_changes(struct mail_custom_flags *mcf);
 
 #endif
--- a/src/lib-index/mail-index-compress.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index-compress.c	Sun Jan 05 15:09:51 2003 +0200
@@ -10,7 +10,7 @@
 #include <stdio.h>
 #include <unistd.h>
 
-int mail_index_truncate(MailIndex *index)
+int mail_index_truncate(struct mail_index *index)
 {
 	uoff_t empty_space, truncate_threshold;
 
@@ -29,9 +29,9 @@
 			(empty_space * INDEX_TRUNCATE_KEEP_PERCENTAGE / 100);
 
 		/* keep the size record-aligned */
-		index->mmap_full_length -=
-			(index->mmap_full_length - sizeof(MailIndexHeader)) %
-			sizeof(MailIndexRecord);
+		index->mmap_full_length -= (index->mmap_full_length -
+					    sizeof(struct mail_index_header)) %
+			sizeof(struct mail_index_record);
 
 		if (index->mmap_full_length < INDEX_FILE_MIN_SIZE)
                         index->mmap_full_length = INDEX_FILE_MIN_SIZE;
@@ -45,9 +45,9 @@
 	return TRUE;
 }
 
-int mail_index_compress(MailIndex *index)
+int mail_index_compress(struct mail_index *index)
 {
-	MailIndexRecord *rec, *hole_rec, *end_rec;
+	struct mail_index_record *rec, *hole_rec, *end_rec;
 	unsigned int idx;
 	int tree_fd;
 
@@ -66,19 +66,16 @@
 	/* if we get interrupted, the whole index is probably corrupted.
 	   so keep rebuild-flag on while doing this */
 	index->header->flags |= MAIL_INDEX_FLAG_REBUILD;
-	if (!mail_index_fmdatasync(index, sizeof(MailIndexHeader)))
+	if (!mail_index_fmdatasync(index, sizeof(struct mail_index_header)))
 		return FALSE;
 
 	/* first actually compress the data */
-	end_rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				       index->mmap_used_length);
-	hole_rec = (MailIndexRecord *) ((char *) index->mmap_base +
-					sizeof(MailIndexHeader)) +
-		index->header->first_hole_index;
+	hole_rec = INDEX_RECORD_AT(index, index->header->first_hole_index);
+	end_rec = INDEX_END_RECORD(index);
 	rec = hole_rec + index->header->first_hole_records;
 	while (rec < end_rec) {
 		if (rec->uid != 0) {
-			memcpy(hole_rec, rec, sizeof(MailIndexRecord));
+			memcpy(hole_rec, rec, sizeof(struct mail_index_record));
 			idx = INDEX_RECORD_INDEX(index, hole_rec);
 			if (!mail_tree_update(index->tree, rec->uid, idx))
 				return FALSE;
@@ -117,11 +114,12 @@
 	return TRUE;
 }
 
-static int mail_index_copy_data(MailIndex *index, int fd, const char *path)
+static int mail_index_copy_data(struct mail_index *index,
+				int fd, const char *path)
 {
-	MailIndexDataHeader data_hdr;
-	MailIndexDataRecordHeader *rec_hdr;
-	MailIndexRecord *rec;
+	struct mail_index_data_header data_hdr;
+	struct mail_index_data_record_header *rec_hdr;
+	struct mail_index_record *rec;
 	unsigned char *mmap_data;
 	size_t mmap_data_size;
 	uoff_t offset;
@@ -144,20 +142,19 @@
 	/* now we'll begin the actual moving. keep rebuild-flag on
 	   while doing it. */
 	index->header->flags |= MAIL_INDEX_FLAG_REBUILD;
-	if (!mail_index_fmdatasync(index, sizeof(MailIndexHeader)))
+	if (!mail_index_fmdatasync(index, sizeof(struct mail_index_header)))
 		return FALSE;
 
 	offset = sizeof(data_hdr);
 	rec = index->lookup(index, 1);
 	while (rec != NULL) {
-		if (rec->data_position +
-		    sizeof(MailIndexDataRecordHeader) > mmap_data_size) {
+		if (rec->data_position + sizeof(*rec_hdr) > mmap_data_size) {
 			index_set_corrupted(index,
 				"data_position points outside file");
 			return FALSE;
 		}
 
-		rec_hdr = (MailIndexDataRecordHeader *)
+		rec_hdr = (struct mail_index_data_record_header *)
 			(mmap_data + rec->data_position);
 		if (rec->data_position + rec_hdr->data_size > mmap_data_size) {
 			index_set_corrupted(index,
@@ -195,7 +192,7 @@
 	return TRUE;
 }
 
-int mail_index_compress_data(MailIndex *index)
+int mail_index_compress_data(struct mail_index *index)
 {
 	const char *temppath, *datapath;
 	int fd, failed;
--- a/src/lib-index/mail-index-data.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index-data.c	Sun Jan 05 15:09:51 2003 +0200
@@ -21,13 +21,13 @@
 #define COMPRESS_PERCENTAGE 20
 
 /* Initial size for the file */
-#define INDEX_DATA_INITIAL_SIZE (sizeof(MailIndexDataHeader) + 10240)
+#define INDEX_DATA_INITIAL_SIZE (sizeof(struct mail_index_data_header) + 10240)
 
 /* When more space is needed, grow the file n% larger than the previous size */
 #define INDEX_DATA_GROW_PERCENTAGE 10
 
-struct _MailIndexData {
-	MailIndex *index;
+struct mail_index_data {
+	struct mail_index *index;
 
 	int fd;
 	char *filepath;
@@ -36,7 +36,7 @@
 	size_t mmap_full_length;
 	size_t mmap_used_length;
 
-	MailIndexDataHeader *header;
+	struct mail_index_data_header *header;
 
 	unsigned int anon_mmap:1;
 	unsigned int dirty_mmap:1;
@@ -44,7 +44,7 @@
 	unsigned int fsynced:1;
 };
 
-int index_data_set_corrupted(MailIndexData *data, const char *fmt, ...)
+int index_data_set_corrupted(struct mail_index_data *data, const char *fmt, ...)
 {
 	va_list va;
 
@@ -61,7 +61,7 @@
 	return FALSE;
 }
 
-static int index_data_set_syscall_error(MailIndexData *data,
+static int index_data_set_syscall_error(struct mail_index_data *data,
 					const char *function)
 {
 	i_assert(function != NULL);
@@ -71,7 +71,7 @@
 	return FALSE;
 }
 
-static void mail_index_data_file_close(MailIndexData *data)
+static void mail_index_data_file_close(struct mail_index_data *data)
 {
 	if (data->anon_mmap) {
 		if (munmap_anon(data->mmap_base, data->mmap_full_length) < 0)
@@ -91,7 +91,7 @@
 	}
 }
 
-static int data_file_reopen(MailIndexData *data)
+static int data_file_reopen(struct mail_index_data *data)
 {
 	int fd;
 
@@ -107,9 +107,9 @@
 	return TRUE;
 }
 
-static int mmap_update(MailIndexData *data, uoff_t pos, size_t size)
+static int mmap_update(struct mail_index_data *data, uoff_t pos, size_t size)
 {
-	MailIndexDataHeader *hdr;
+	struct mail_index_data_header *hdr;
 
 	if (data->header != NULL &&
 	    data->header->indexid != data->index->indexid) {
@@ -170,12 +170,12 @@
 		return index_data_set_syscall_error(data, "mmap()");
 	}
 
-	if (data->mmap_full_length < sizeof(MailIndexDataHeader))
+	if (data->mmap_full_length < sizeof(struct mail_index_data_header))
 		return index_data_set_corrupted(data, "File too small");
 
 	hdr = data->mmap_base;
 
-	if (hdr->used_file_size < sizeof(MailIndexDataHeader)) {
+	if (hdr->used_file_size < sizeof(struct mail_index_data_header)) {
 		index_data_set_corrupted(data, "used_file_size too small ("
 					 "%"PRIuUOFF_T")", hdr->used_file_size);
 		return FALSE;
@@ -195,9 +195,9 @@
 	return TRUE;
 }
 
-int mail_index_data_open(MailIndex *index)
+int mail_index_data_open(struct mail_index *index)
 {
-	MailIndexData *data;
+	struct mail_index_data *data;
 	const char *path;
 	int fd;
 
@@ -211,14 +211,14 @@
 		return index_file_set_syscall_error(index, path, "open()");
 	}
 
-	data = i_new(MailIndexData, 1);
+	data = i_new(struct mail_index_data, 1);
 	data->index = index;
 	data->fd = fd;
 	data->filepath = i_strdup(path);
 
 	index->data = data;
 
-	if (!mmap_update(data, 0, sizeof(MailIndexDataHeader))) {
+	if (!mmap_update(data, 0, sizeof(struct mail_index_data_header))) {
 		mail_index_data_free(data);
 		return FALSE;
 	}
@@ -235,12 +235,13 @@
 	return TRUE;
 }
 
-static const char *init_data_file(MailIndex *index, MailIndexDataHeader *hdr,
+static const char *init_data_file(struct mail_index *index,
+				  struct mail_index_data_header *hdr,
 				  int fd, const char *temppath)
 {
 	const char *realpath;
 
-	if (write_full(fd, hdr, sizeof(MailIndexDataHeader)) < 0) {
+	if (write_full(fd, hdr, sizeof(*hdr)) < 0) {
 		index_file_set_syscall_error(index, temppath, "write_full()");
 		return NULL;
 	}
@@ -263,16 +264,16 @@
 	return realpath;
 }
 
-int mail_index_data_create(MailIndex *index)
+int mail_index_data_create(struct mail_index *index)
 {
-        MailIndexDataHeader hdr;
-	MailIndexData *data;
+        struct mail_index_data_header hdr;
+	struct mail_index_data *data;
 	const char *temppath, *realpath;
 	int fd;
 
-	memset(&hdr, 0, sizeof(MailIndexDataHeader));
+	memset(&hdr, 0, sizeof(struct mail_index_data_header));
 	hdr.indexid = index->indexid;
-	hdr.used_file_size = sizeof(MailIndexDataHeader);
+	hdr.used_file_size = sizeof(struct mail_index_data_header);
 
 	realpath = NULL;
 
@@ -300,13 +301,13 @@
 		}
 	}
 
-	data = i_new(MailIndexData, 1);
+	data = i_new(struct mail_index_data, 1);
 
 	if (fd == -1) {
 		data->mmap_full_length = INDEX_DATA_INITIAL_SIZE;
 		data->mmap_base = mmap_anon(data->mmap_full_length);
 
-		memcpy(data->mmap_base, &hdr, sizeof(MailIndexDataHeader));
+		memcpy(data->mmap_base, &hdr, sizeof(hdr));
 		data->header = data->mmap_base;
 		data->mmap_used_length = data->header->used_file_size;
 
@@ -319,7 +320,7 @@
 	data->index = index;
 	data->fd = fd;
 
-	if (!mmap_update(data, 0, sizeof(MailIndexDataHeader))) {
+	if (!mmap_update(data, 0, sizeof(struct mail_index_data_header))) {
 		mail_index_data_free(data);
 		return FALSE;
 	}
@@ -328,7 +329,7 @@
 	return TRUE;
 }
 
-void mail_index_data_free(MailIndexData *data)
+void mail_index_data_free(struct mail_index_data *data)
 {
 	data->index->data = NULL;
 
@@ -338,16 +339,16 @@
 	i_free(data);
 }
 
-int mail_index_data_reset(MailIndexData *data)
+int mail_index_data_reset(struct mail_index_data *data)
 {
-	MailIndexDataHeader hdr;
+	struct mail_index_data_header hdr;
 
-	memset(&hdr, 0, sizeof(MailIndexDataHeader));
+	memset(&hdr, 0, sizeof(struct mail_index_data_header));
 	hdr.indexid = data->index->indexid;
-	hdr.used_file_size = sizeof(MailIndexDataHeader);
+	hdr.used_file_size = sizeof(struct mail_index_data_header);
 
 	if (data->anon_mmap) {
-		memcpy(data->mmap_base, &hdr, sizeof(MailIndexDataHeader));
+		memcpy(data->mmap_base, &hdr, sizeof(hdr));
 		return TRUE;
 	}
 
@@ -360,7 +361,7 @@
 	if (lseek(data->fd, 0, SEEK_SET) < 0)
 		return index_data_set_syscall_error(data, "lseek()");
 
-	if (write_full(data->fd, &hdr, sizeof(MailIndexDataHeader)) < 0) {
+	if (write_full(data->fd, &hdr, sizeof(hdr)) < 0) {
 		if (errno == ENOSPC)
 			data->index->nodiskspace = TRUE;
 		return index_data_set_syscall_error(data, "write_full()");
@@ -371,25 +372,26 @@
 	return mmap_update(data, 0, 0);
 }
 
-int mail_index_data_mark_file_deleted(MailIndexData *data)
+int mail_index_data_mark_file_deleted(struct mail_index_data *data)
 {
 	if (data->anon_mmap)
 		return TRUE;
 
 	data->header->indexid = 0;
-	if (msync(data->mmap_base, sizeof(MailIndexDataHeader), MS_SYNC) < 0)
+	if (msync(data->mmap_base,
+		  sizeof(struct mail_index_data_header), MS_SYNC) < 0)
 		return index_data_set_syscall_error(data, "msync()");
 
 	data->fsynced = FALSE;
 	return TRUE;
 }
 
-void mail_index_data_mark_modified(MailIndexData *data)
+void mail_index_data_mark_modified(struct mail_index_data *data)
 {
 	data->modified = TRUE;
 }
 
-static int mail_index_data_grow(MailIndexData *data, size_t size)
+static int mail_index_data_grow(struct mail_index_data *data, size_t size)
 {
 	void *base;
 	uoff_t new_fsize;
@@ -427,7 +429,7 @@
 		return TRUE;
 	}
 
-	if (pos < (int)sizeof(MailIndexDataHeader))
+	if (pos < (off_t)sizeof(struct mail_index_data_header))
 		return index_data_set_corrupted(data, "Header is missing");
 
 	if (file_set_size(data->fd, (off_t)new_fsize) < 0) {
@@ -439,7 +441,7 @@
 	return mmap_update(data, 0, 0);
 }
 
-uoff_t mail_index_data_append(MailIndexData *data, const void *buffer,
+uoff_t mail_index_data_append(struct mail_index_data *data, const void *buffer,
 			      size_t size)
 {
 	uoff_t offset;
@@ -447,7 +449,7 @@
 	i_assert((size & (MEM_ALIGN_SIZE-1)) == 0);
 	i_assert(data->index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
-	if (!mmap_update(data, 0, sizeof(MailIndexDataHeader)))
+	if (!mmap_update(data, 0, sizeof(struct mail_index_data_header)))
 		return 0;
 
 	if (size > data->mmap_full_length ||
@@ -466,9 +468,10 @@
 	return offset;
 }
 
-int mail_index_data_delete(MailIndexData *data, MailIndexRecord *index_rec)
+int mail_index_data_delete(struct mail_index_data *data,
+			   struct mail_index_record *index_rec)
 {
-        MailIndexDataRecordHeader *rec_hdr;
+        struct mail_index_data_record_header *rec_hdr;
 	uoff_t max_del_space;
 
 	i_assert(data->index->lock_type == MAIL_LOCK_EXCLUSIVE);
@@ -482,8 +485,8 @@
 
 	/* clear the record data. not really needed, but better not to keep
 	   deleted information lying around.. */
-	memset((char *) rec_hdr + sizeof(MailIndexDataRecordHeader), 0,
-	       rec_hdr->data_size - sizeof(MailIndexDataRecordHeader));
+	memset((char *) rec_hdr + sizeof(*rec_hdr), 0,
+	       rec_hdr->data_size - sizeof(*rec_hdr));
 
 	/* see if we've reached the max. deleted space in file */
 	if (data->header->used_file_size >= COMPRESS_MIN_SIZE &&
@@ -498,7 +501,7 @@
 	return TRUE;
 }
 
-int mail_index_data_sync_file(MailIndexData *data, int *fsync_fd)
+int mail_index_data_sync_file(struct mail_index_data *data, int *fsync_fd)
 {
 	*fsync_fd = -1;
 
@@ -520,8 +523,9 @@
 	return TRUE;
 }
 
-MailIndexDataRecordHeader *
-mail_index_data_lookup_header(MailIndexData *data, MailIndexRecord *index_rec)
+struct mail_index_data_record_header *
+mail_index_data_lookup_header(struct mail_index_data *data,
+			      struct mail_index_record *index_rec)
 {
 	uoff_t pos;
 
@@ -531,14 +535,17 @@
 		return NULL;
 	}
 
-	if (!mmap_update(data, pos, sizeof(MailIndexDataRecordHeader)))
+	if (!mmap_update(data, pos,
+			 sizeof(struct mail_index_data_record_header)))
 		return NULL;
 
-	if (pos + sizeof(MailIndexDataRecordHeader) > data->mmap_used_length) {
+	if (pos + sizeof(struct mail_index_data_record_header) >
+	    data->mmap_used_length) {
 		index_data_set_corrupted(data,
 			"Data position of record %u points outside file "
 			"(%"PRIuUOFF_T" + %"PRIuSIZE_T" > %"PRIuSIZE_T")",
-			index_rec->uid, pos, sizeof(MailIndexDataRecordHeader),
+			index_rec->uid, pos,
+			sizeof(struct mail_index_data_record_header),
 			data->mmap_used_length);
 		return NULL;
 	}
@@ -550,15 +557,17 @@
 		return NULL;
 	}
 
-	return (MailIndexDataRecordHeader *) ((char *) data->mmap_base + pos);
+	return (struct mail_index_data_record_header *)
+		((char *) data->mmap_base + pos);
 }
 
-MailIndexDataRecord *
-mail_index_data_lookup(MailIndexData *data, MailIndexRecord *index_rec,
-		       MailDataField field)
+struct mail_index_data_record *
+mail_index_data_lookup(struct mail_index_data *data,
+		       struct mail_index_record *index_rec,
+		       enum mail_data_field field)
 {
-        MailIndexDataRecordHeader *rec_hdr;
-	MailIndexDataRecord *rec;
+        struct mail_index_data_record_header *rec_hdr;
+	struct mail_index_data_record *rec;
 	uoff_t pos, max_pos;
 
 	index_reset_error(data->index);
@@ -588,12 +597,13 @@
 		return NULL;
 	}
 
-	pos += sizeof(MailIndexDataRecordHeader);
+	pos += sizeof(struct mail_index_data_record_header);
 	do {
-		rec = (MailIndexDataRecord *) ((char *) data->mmap_base + pos);
+		rec = (struct mail_index_data_record *)
+			((char *) data->mmap_base + pos);
 
 		if (rec->full_field_size > max_pos ||
-		    pos + sizeof(MailIndexDataRecord) > max_pos ||
+		    pos + sizeof(struct mail_index_data_record) > max_pos ||
 		    pos + DATA_RECORD_SIZE(rec) > max_pos) {
 			index_data_set_corrupted(data,
 				"Field %d size points outside file "
@@ -626,11 +636,12 @@
 	return NULL;
 }
 
-MailIndexDataRecord *
-mail_index_data_next(MailIndexData *data, MailIndexRecord *index_rec,
-		     MailIndexDataRecord *rec)
+struct mail_index_data_record *
+mail_index_data_next(struct mail_index_data *data,
+		     struct mail_index_record *index_rec,
+		     struct mail_index_data_record *rec)
 {
-        MailIndexDataRecordHeader *rec_hdr;
+        struct mail_index_data_record_header *rec_hdr;
 	uoff_t pos, end_pos, max_pos;
 
 	index_reset_error(data->index);
@@ -638,8 +649,8 @@
 	if (rec == NULL)
 		return NULL;
 
-	rec_hdr = (MailIndexDataRecordHeader *) ((char *) data->mmap_base +
-						 index_rec->data_position);
+	rec_hdr = (struct mail_index_data_record_header *)
+		((char *) data->mmap_base + index_rec->data_position);
 
 	/* get position to next record */
 	pos = DATA_FILE_POSITION(data, rec) + DATA_RECORD_SIZE(rec);
@@ -649,7 +660,8 @@
 	if (pos >= max_pos)
 		return NULL;
 
-	rec = (MailIndexDataRecord *) ((char *) data->mmap_base + pos);
+	rec = (struct mail_index_data_record *)
+		((char *) data->mmap_base + pos);
 	end_pos = pos + DATA_RECORD_SIZE(rec);
 	if (end_pos < pos || end_pos > max_pos) {
 		index_data_set_corrupted(data, "Field size points outside file "
@@ -661,7 +673,8 @@
 	return rec;
 }
 
-int mail_index_data_record_verify(MailIndexData *data, MailIndexDataRecord *rec)
+int mail_index_data_record_verify(struct mail_index_data *data,
+				  struct mail_index_data_record *rec)
 {
 	int i;
 
@@ -687,7 +700,7 @@
 	return FALSE;
 }
 
-void *mail_index_data_get_mmaped(MailIndexData *data, size_t *size)
+void *mail_index_data_get_mmaped(struct mail_index_data *data, size_t *size)
 {
 	if (!mmap_update(data, 0, 0))
 		return NULL;
--- a/src/lib-index/mail-index-data.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index-data.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,57 +3,61 @@
 
 #define DATA_FILE_PREFIX ".data"
 
-int mail_index_data_open(MailIndex *index);
-int mail_index_data_create(MailIndex *index);
-void mail_index_data_free(MailIndexData *data);
+int mail_index_data_open(struct mail_index *index);
+int mail_index_data_create(struct mail_index *index);
+void mail_index_data_free(struct mail_index_data *data);
 
 /* Truncate the data file and update it's indexid */
-int mail_index_data_reset(MailIndexData *data);
+int mail_index_data_reset(struct mail_index_data *data);
 
 /* Set indexid to 0 to notify other processes using this file that they should
    re-open it. */
-int mail_index_data_mark_file_deleted(MailIndexData *data);
+int mail_index_data_mark_file_deleted(struct mail_index_data *data);
 
 /* Mark the file as being modified */
-void mail_index_data_mark_modified(MailIndexData *data);
+void mail_index_data_mark_modified(struct mail_index_data *data);
 
 /* Append new data at the end of the file. Returns the position in file
    where the data begins, or 0 if error occured. */
-uoff_t mail_index_data_append(MailIndexData *data, const void *buffer,
+uoff_t mail_index_data_append(struct mail_index_data *data, const void *buffer,
 			      size_t size);
 
 /* Mark the given record deleted. */
-int mail_index_data_delete(MailIndexData *data, MailIndexRecord *index_rec);
+int mail_index_data_delete(struct mail_index_data *data,
+			   struct mail_index_record *index_rec);
 
 /* Synchronize the data into disk */
-int mail_index_data_sync_file(MailIndexData *data, int *fsync_fd);
+int mail_index_data_sync_file(struct mail_index_data *data, int *fsync_fd);
 
 /* Looks up a record header from data file. Returns NULL if not found or
    if error occured. */
-MailIndexDataRecordHeader *
-mail_index_data_lookup_header(MailIndexData *data, MailIndexRecord *index_rec);
+struct mail_index_data_record_header *
+mail_index_data_lookup_header(struct mail_index_data *data,
+			      struct mail_index_record *index_rec);
 
 /* Looks up a field from data file. If field is 0, returns the first field
    found. Returns NULL if not found or if error occured. */
-MailIndexDataRecord *
-mail_index_data_lookup(MailIndexData *data, MailIndexRecord *index_rec,
-		       MailDataField field);
+struct mail_index_data_record *
+mail_index_data_lookup(struct mail_index_data *data,
+		       struct mail_index_record *index_rec,
+		       enum mail_data_field field);
 
 /* Returns the next record in data file, or NULL if there's no more. */
-MailIndexDataRecord *
-mail_index_data_next(MailIndexData *data, MailIndexRecord *index_rec,
-		     MailIndexDataRecord *rec);
+struct mail_index_data_record *
+mail_index_data_next(struct mail_index_data *data,
+		     struct mail_index_record *index_rec,
+		     struct mail_index_data_record *rec);
 
 /* Returns TRUE if rec->data is a valid \0-terminated string */
-int mail_index_data_record_verify(MailIndexData *data,
-				  MailIndexDataRecord *rec);
+int mail_index_data_record_verify(struct mail_index_data *data,
+				  struct mail_index_data_record *rec);
 
 /* Return the whole data file mmap()ed. */
-void *mail_index_data_get_mmaped(MailIndexData *data, size_t *size);
+void *mail_index_data_get_mmaped(struct mail_index_data *data, size_t *size);
 
 /* "Error in index data file %s: ...". Also marks the index file as
    corrupted. */
-int index_data_set_corrupted(MailIndexData *data, const char *fmt, ...)
+int index_data_set_corrupted(struct mail_index_data *data, const char *fmt, ...)
 	__attr_format__(2, 3);
 
 #endif
--- a/src/lib-index/mail-index-fsck.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index-fsck.c	Sun Jan 05 15:09:51 2003 +0200
@@ -10,9 +10,9 @@
 			  index->filepath, old_hdr->field, new_hdr->field);
 
 
-static void print_differences(MailIndex *index,
-			      MailIndexHeader *old_hdr,
-			      MailIndexHeader *new_hdr)
+static void print_differences(struct mail_index *index,
+			      struct mail_index_header *old_hdr,
+			      struct mail_index_header *new_hdr)
 {
 	if (old_hdr->first_hole_index != new_hdr->first_hole_index) {
 		i_warning("fsck %s: first_hole_position %u != %u",
@@ -46,13 +46,12 @@
 	}
 }
 
-int mail_index_fsck(MailIndex *index)
+int mail_index_fsck(struct mail_index *index)
 {
 	/* we verify only the fields in the header. other problems will be
 	   noticed and fixed while reading the messages. */
-	MailIndexHeader old_hdr;
-	MailIndexHeader *hdr;
-	MailIndexRecord *rec, *end_rec;
+	struct mail_index_header old_hdr, *hdr;
+	struct mail_index_record *rec, *end_rec;
 	unsigned int max_uid, pos;
 
 	i_assert(index->lock_type != MAIL_LOCK_SHARED);
@@ -61,7 +60,7 @@
 		return FALSE;
 
 	hdr = index->header;
-	memcpy(&old_hdr, hdr, sizeof(MailIndexHeader));
+	memcpy(&old_hdr, hdr, sizeof(struct mail_index_header));
 
 	hdr->first_hole_index = 0;
 	hdr->first_hole_records = 0;
@@ -73,10 +72,8 @@
 	hdr->first_unseen_uid_lowwater = 0;
 	hdr->first_deleted_uid_lowwater = 0;
 
-	rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				   sizeof(MailIndexHeader));
-	end_rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				       index->mmap_used_length);
+	rec = INDEX_RECORD_AT(index, 0);
+	end_rec = INDEX_END_RECORD(index);
 
 	max_uid = 0;
 	for (; rec < end_rec; rec++) {
--- a/src/lib-index/mail-index-open.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index-open.c	Sun Jan 05 15:09:51 2003 +0200
@@ -46,14 +46,14 @@
 	return TRUE;
 }
 
-static int read_and_verify_header(int fd, MailIndexHeader *hdr,
+static int read_and_verify_header(int fd, struct mail_index_header *hdr,
 				  int check_version)
 {
 	/* read the header */
 	if (lseek(fd, 0, SEEK_SET) != 0)
 		return FALSE;
 
-	if (read(fd, hdr, sizeof(MailIndexHeader)) != sizeof(MailIndexHeader))
+	if (read(fd, hdr, sizeof(*hdr)) != sizeof(*hdr))
 		return FALSE;
 
 	/* check the compatibility */
@@ -67,9 +67,10 @@
 
 /* Returns TRUE if we're compatible with given index file. May delete the
    file if it's from older version. */
-static int mail_check_compatible_index(MailIndex *index, const char *path)
+static int mail_check_compatible_index(struct mail_index *index,
+				       const char *path)
 {
-        MailIndexHeader hdr;
+        struct mail_index_header hdr;
 	int fd, compatible;
 
 	fd = open(path, O_RDONLY);
@@ -94,7 +95,7 @@
 }
 
 /* Returns a file name of compatible index */
-static const char *mail_find_index(MailIndex *index)
+static const char *mail_find_index(struct mail_index *index)
 {
 	const char *name;
 	char path[PATH_MAX];
@@ -116,9 +117,9 @@
 	return NULL;
 }
 
-static int mail_index_open_init(MailIndex *index, int update_recent)
+static int mail_index_open_init(struct mail_index *index, int update_recent)
 {
-	MailIndexHeader *hdr;
+	struct mail_index_header *hdr;
 
 	hdr = index->header;
 
@@ -155,7 +156,8 @@
 	return TRUE;
 }
 
-static int index_open_and_fix(MailIndex *index, int update_recent, int fast)
+static int index_open_and_fix(struct mail_index *index,
+			      int update_recent, int fast)
 {
 	int rebuild;
 
@@ -247,7 +249,8 @@
 	return TRUE;
 }
 
-static int mail_index_verify_header(MailIndex *index, MailIndexHeader *hdr)
+static int mail_index_verify_header(struct mail_index *index,
+				    struct mail_index_header *hdr)
 {
 	/* if index is being created, we'll wait here until it's finished */
 	if (!mail_index_wait_lock(index, F_RDLCK))
@@ -267,10 +270,10 @@
 	return TRUE;
 }
 
-static int mail_index_open_file(MailIndex *index, const char *path,
+static int mail_index_open_file(struct mail_index *index, const char *path,
 				int update_recent, int fast)
 {
-        MailIndexHeader hdr;
+        struct mail_index_header hdr;
 
 	/* the index file should already be checked that it exists and
 	   we're compatible with it. */
@@ -301,7 +304,8 @@
 	return TRUE;
 }
 
-static int mail_index_init_new_file(MailIndex *index, MailIndexHeader *hdr,
+static int mail_index_init_new_file(struct mail_index *index,
+				    struct mail_index_header *hdr,
 				    const char *temp_path)
 {
 	const char *index_path;
@@ -310,14 +314,14 @@
 	/* set the index's path temporarily */
 	index->filepath = t_strdup_noconst(temp_path);
 
-	if (write_full(index->fd, hdr, sizeof(MailIndexHeader)) < 0) {
+	if (write_full(index->fd, hdr, sizeof(struct mail_index_header)) < 0) {
 		index_set_syscall_error(index, "write_full()");
 		index->filepath = NULL;
 		return FALSE;
 	}
 
-	fsize = sizeof(MailIndexHeader) +
-		INDEX_MIN_RECORDS_COUNT * sizeof(MailIndexRecord);
+	fsize = sizeof(struct mail_index_header) +
+		INDEX_MIN_RECORDS_COUNT * sizeof(struct mail_index_record);
 	if (file_set_size(index->fd, fsize) < 0) {
 		index_set_syscall_error(index, "file_set_size()");
 		index->filepath = NULL;
@@ -371,10 +375,10 @@
 	return TRUE;
 }
 
-static int mail_index_create(MailIndex *index, int *dir_unlocked,
+static int mail_index_create(struct mail_index *index, int *dir_unlocked,
 			     int update_recent)
 {
-	MailIndexHeader hdr;
+	struct mail_index_header hdr;
 	const char *path;
 	int nodiskspace;
 
@@ -477,9 +481,10 @@
 	return FALSE;
 }
 
-void mail_index_init_header(MailIndex *index, MailIndexHeader *hdr)
+void mail_index_init_header(struct mail_index *index,
+			    struct mail_index_header *hdr)
 {
-	memset(hdr, 0, sizeof(MailIndexHeader));
+	memset(hdr, 0, sizeof(struct mail_index_header));
 	hdr->compat_data[0] = MAIL_INDEX_VERSION;
 	hdr->compat_data[1] = MAIL_INDEX_COMPAT_FLAGS;
 	hdr->compat_data[2] = sizeof(unsigned int);
@@ -495,7 +500,7 @@
 	/* set the fields we always want to cache */
 	hdr->cache_fields |= index->default_cache_fields;
 
-	hdr->used_file_size = sizeof(MailIndexHeader);
+	hdr->used_file_size = sizeof(struct mail_index_header);
 	hdr->uid_validity = ioloop_time;
 	hdr->next_uid = 1;
 }
@@ -506,7 +511,7 @@
 			 "temp.", time(NULL) - TEMP_FILE_TIMEOUT);
 }
 
-void mail_index_init(MailIndex *index, const char *dir)
+void mail_index_init(struct mail_index *index, const char *dir)
 {
 	size_t len;
 
@@ -520,7 +525,7 @@
 	index->mail_read_mmaped = getenv("MAIL_READ_MMAPED") != NULL;
 }
 
-int mail_index_open(MailIndex *index, int update_recent, int fast)
+int mail_index_open(struct mail_index *index, int update_recent, int fast)
 {
 	const char *name, *path;
 
@@ -543,7 +548,8 @@
 	return TRUE;
 }
 
-int mail_index_open_or_create(MailIndex *index, int update_recent, int fast)
+int mail_index_open_or_create(struct mail_index *index,
+			      int update_recent, int fast)
 {
 	int failed, dir_unlocked;
 
--- a/src/lib-index/mail-index-update-cache.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index-update-cache.c	Sun Jan 05 15:09:51 2003 +0200
@@ -6,11 +6,11 @@
 
 #include <unistd.h>
 
-static int cache_record(MailIndex *index, MailIndexRecord *rec,
-			MailDataField cache_fields)
+static int cache_record(struct mail_index *index, struct mail_index_record *rec,
+			enum mail_data_field cache_fields)
 {
-	MailIndexUpdate *update;
-	IStream *input;
+	struct mail_index_update *update;
+	struct istream *input;
 	time_t internal_date;
 	int failed, deleted;
 
@@ -30,10 +30,10 @@
 	return !failed;
 }
 
-int mail_index_update_cache(MailIndex *index)
+int mail_index_update_cache(struct mail_index *index)
 {
-	MailIndexRecord *rec;
-	MailDataField cache_fields;
+	struct mail_index_record *rec;
+	enum mail_data_field cache_fields;
 
 	if (!index->set_lock(index, MAIL_LOCK_EXCLUSIVE))
 		return FALSE;
@@ -42,7 +42,8 @@
 
 	rec = index->lookup(index, 1);
 	while (rec != NULL) {
-		if ((rec->data_fields & cache_fields) != cache_fields) {
+		if (((enum mail_data_field)rec->data_fields & cache_fields) !=
+		    cache_fields) {
 			t_push();
 			if (!cache_record(index, rec, cache_fields)) {
 				t_pop();
--- a/src/lib-index/mail-index-update.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index-update.c	Sun Jan 05 15:09:51 2003 +0200
@@ -4,7 +4,7 @@
 #include "buffer.h"
 #include "istream.h"
 #include "ioloop.h"
-#include "rfc822-date.h"
+#include "message-date.h"
 #include "message-parser.h"
 #include "message-part-serialize.h"
 #include "message-size.h"
@@ -14,12 +14,12 @@
 #include "mail-index-data.h"
 #include "mail-index-util.h"
 
-struct _MailIndexUpdate {
-	Pool pool;
+struct mail_index_update {
+	pool_t pool;
 
-	MailIndex *index;
-	MailIndexRecord *rec;
-	MailIndexDataRecordHeader data_hdr;
+	struct mail_index *index;
+	struct mail_index_record *rec;
+	struct mail_index_data_record_header data_hdr;
 
 	unsigned int updated_fields;
 	void *fields[DATA_FIELD_MAX_BITS];
@@ -27,17 +27,18 @@
 	size_t field_extra_sizes[DATA_FIELD_MAX_BITS];
 };
 
-MailIndexUpdate *mail_index_update_begin(MailIndex *index, MailIndexRecord *rec)
+struct mail_index_update *
+mail_index_update_begin(struct mail_index *index, struct mail_index_record *rec)
 {
-	Pool pool;
-	MailIndexUpdate *update;
-	MailIndexDataRecordHeader *data_hdr;
+	pool_t pool;
+	struct mail_index_update *update;
+	struct mail_index_data_record_header *data_hdr;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
-	pool = pool_alloconly_create("MailIndexUpdate", 4096);
+	pool = pool_alloconly_create("mail_index_update", 4096);
 
-	update = p_new(pool, MailIndexUpdate, 1);
+	update = p_new(pool, struct mail_index_update, 1);
 	update->pool = pool;
 	update->index = index;
 	update->rec = rec;
@@ -48,7 +49,7 @@
 	return update;
 }
 
-static int mail_field_get_index(MailDataField field)
+static int mail_field_get_index(enum mail_data_field field)
 {
 	unsigned int i, mask;
 
@@ -60,16 +61,16 @@
 	return -1;
 }
 
-static void get_data_block_sizes(MailIndexUpdate *update,
+static void get_data_block_sizes(struct mail_index_update *update,
 				 size_t *min_size, size_t *max_size,
 				 int *no_grown_fields)
 {
-	MailIndexDataRecord *rec;
-	MailDataField field;
+	struct mail_index_data_record *rec;
+	enum mail_data_field field;
 	unsigned int field_min_size;
 	int i, field_exists;
 
-	*min_size = *max_size = sizeof(MailIndexDataRecordHeader);
+	*min_size = *max_size = sizeof(struct mail_index_data_record_header);
 	*no_grown_fields = TRUE;
 
 	rec = mail_index_data_lookup(update->index->data, update->rec, 0);
@@ -124,13 +125,13 @@
 
 /* extra_size is the amount of data in data_size which can be used for
    field_extra_sizes */
-static void *create_data_block(MailIndexUpdate *update, size_t data_size,
-			       size_t extra_size)
+static void *create_data_block(struct mail_index_update *update,
+			       size_t data_size, size_t extra_size)
 {
-        MailIndexDataRecordHeader *dest_hdr;
-        MailIndexDataRecord *rec, *destrec;
-	MailDataField field;
-	Buffer *buf;
+        struct mail_index_data_record_header *dest_hdr;
+        struct mail_index_data_record *rec, *destrec;
+	enum mail_data_field field;
+	buffer_t *buf;
 	const void *src;
 	size_t src_size;
 	size_t full_field_size;
@@ -184,8 +185,8 @@
 
 /* Append all the data at the end of the data file and update 
    the index's data position */
-static int update_by_append(MailIndexUpdate *update, size_t data_size,
-			    size_t extra_size)
+static int update_by_append(struct mail_index_update *update,
+			    size_t data_size, size_t extra_size)
 {
 	void *mem;
 	uoff_t fpos;
@@ -207,9 +208,10 @@
 }
 
 /* Replace the whole block - assumes there's enough space to do it */
-static void update_by_replace_block(MailIndexUpdate *update, size_t extra_size)
+static void update_by_replace_block(struct mail_index_update *update,
+				    size_t extra_size)
 {
-	MailIndexDataRecordHeader *data_hdr;
+	struct mail_index_data_record_header *data_hdr;
 	size_t data_size;
 	void *mem;
 
@@ -231,10 +233,10 @@
 
 /* Replace the modified fields in the file - assumes there's enough
    space to do it */
-static void update_by_replace_fields(MailIndexUpdate *update)
+static void update_by_replace_fields(struct mail_index_update *update)
 {
-	MailIndexDataRecordHeader *data_hdr;
-	MailIndexDataRecord *rec;
+	struct mail_index_data_record_header *data_hdr;
+	struct mail_index_data_record *rec;
 	size_t field_size;
 	int index;
 
@@ -267,9 +269,9 @@
         mail_index_data_mark_modified(update->index->data);
 }
 
-int mail_index_update_end(MailIndexUpdate *update)
+int mail_index_update_end(struct mail_index_update *update)
 {
-	MailIndexDataRecordHeader *data_hdr;
+	struct mail_index_data_record_header *data_hdr;
 	size_t min_size, max_size, extra_size;
 	int no_grown_fields, failed = FALSE;
 
@@ -304,7 +306,8 @@
 	return !failed;
 }
 
-static void update_field_full(MailIndexUpdate *update, MailDataField field,
+static void update_field_full(struct mail_index_update *update,
+			      enum mail_data_field field,
 			      const void *value, size_t size,
 			      size_t extra_space)
 {
@@ -320,7 +323,8 @@
 	memcpy(update->fields[index], value, size);
 }
 
-static void update_header_field(MailIndexUpdate *update, MailDataField field,
+static void update_header_field(struct mail_index_update *update,
+				enum mail_data_field field,
 				const void *value, size_t size __attr_unused__)
 {
 	switch (field) {
@@ -347,13 +351,15 @@
 	update->updated_fields |= field;
 }
 
-void mail_index_update_field(MailIndexUpdate *update, MailDataField field,
+void mail_index_update_field(struct mail_index_update *update,
+			     enum mail_data_field field,
 			     const char *value, size_t extra_space)
 {
 	update_field_full(update, field, value, strlen(value) + 1, extra_space);
 }
 
-void mail_index_update_field_raw(MailIndexUpdate *update, MailDataField field,
+void mail_index_update_field_raw(struct mail_index_update *update,
+				 enum mail_data_field field,
 				 const void *value, size_t size)
 {
 	if (field >= DATA_FIELD_LAST)
@@ -362,21 +368,21 @@
 		update_field_full(update, field, value, size, 0);
 }
 
-typedef struct {
-	MailIndexUpdate *update;
-	Pool envelope_pool;
-	MessagePartEnvelopeData *envelope;
+struct header_update_context {
+	struct mail_index_update *update;
+	pool_t envelope_pool;
+	struct message_part_envelope_data *envelope;
 
 	MessageHeaderFunc header_func;
 	void *context;
-} HeaderUpdateContext;
+};
 
-static void update_header_func(MessagePart *part,
+static void update_header_func(struct message_part *part,
 			       const unsigned char *name, size_t name_len,
 			       const unsigned char *value, size_t value_len,
 			       void *context)
 {
-	HeaderUpdateContext *ctx = context;
+	struct header_update_context *ctx = context;
 
 	if (part != NULL && part->parent != NULL)
 		return;
@@ -397,15 +403,16 @@
 	}
 }
 
-void mail_index_update_headers(MailIndexUpdate *update, IStream *input,
-                               MailDataField cache_fields,
+void mail_index_update_headers(struct mail_index_update *update,
+			       struct istream *input,
+                               enum mail_data_field cache_fields,
 			       MessageHeaderFunc header_func, void *context)
 {
-	HeaderUpdateContext ctx;
-	MessagePart *part;
-	MessageSize hdr_size, body_size;
-	Pool pool;
-	Buffer *buf;
+	struct header_update_context ctx;
+	struct message_part *part;
+	struct message_size hdr_size, body_size;
+	pool_t pool;
+	buffer_t *buf;
 	const char *value;
 	size_t size;
 	uoff_t start_offset;
--- a/src/lib-index/mail-index-util.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index-util.c	Sun Jan 05 15:09:51 2003 +0200
@@ -12,7 +12,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-int index_set_error(MailIndex *index, const char *fmt, ...)
+int index_set_error(struct mail_index *index, const char *fmt, ...)
 {
 	va_list va;
 
@@ -31,7 +31,7 @@
 	return FALSE;
 }
 
-int index_set_corrupted(MailIndex *index, const char *fmt, ...)
+int index_set_corrupted(struct mail_index *index, const char *fmt, ...)
 {
 	va_list va;
 
@@ -48,7 +48,7 @@
 	return FALSE;
 }
 
-int index_set_syscall_error(MailIndex *index, const char *function)
+int index_set_syscall_error(struct mail_index *index, const char *function)
 {
 	i_assert(function != NULL);
 
@@ -57,7 +57,7 @@
 	return FALSE;
 }
 
-int index_file_set_syscall_error(MailIndex *index, const char *filepath,
+int index_file_set_syscall_error(struct mail_index *index, const char *filepath,
 				 const char *function)
 {
 	i_assert(filepath != NULL);
@@ -69,7 +69,7 @@
 	return FALSE;
 }
 
-void index_reset_error(MailIndex *index)
+void index_reset_error(struct mail_index *index)
 {
 	if (index->error != NULL) {
 		i_free(index->error);
@@ -79,7 +79,7 @@
 	index->nodiskspace = FALSE;
 }
 
-int mail_index_create_temp_file(MailIndex *index, const char **path)
+int mail_index_create_temp_file(struct mail_index *index, const char **path)
 {
 	int fd;
 
@@ -109,7 +109,7 @@
 
 static void mail_index_lock_notify(unsigned int secs_left, void *context)
 {
-	MailIndex *index = context;
+	struct mail_index *index = context;
 
 	if (index->lock_notify_func == NULL)
 		return;
@@ -118,7 +118,7 @@
 				secs_left, index->lock_notify_context);
 }
 
-int mail_index_wait_lock(MailIndex *index, int lock_type)
+int mail_index_wait_lock(struct mail_index *index, int lock_type)
 {
 	int ret;
 
--- a/src/lib-index/mail-index-util.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index-util.h	Sun Jan 05 15:09:51 2003 +0200
@@ -16,28 +16,28 @@
 #endif
 
 /* Set the current error message */
-int index_set_error(MailIndex *index, const char *fmt, ...)
+int index_set_error(struct mail_index *index, const char *fmt, ...)
 	__attr_format__(2, 3);
 
 /* "Error in index file %s: ...". Also marks the index file as corrupted. */
-int index_set_corrupted(MailIndex *index, const char *fmt, ...)
+int index_set_corrupted(struct mail_index *index, const char *fmt, ...)
 	__attr_format__(2, 3);
 
 /* "%s failed with index file %s: %m" */
-int index_set_syscall_error(MailIndex *index, const char *function);
+int index_set_syscall_error(struct mail_index *index, const char *function);
 
 /* "%s failed with file %s: %m" */
-int index_file_set_syscall_error(MailIndex *index, const char *filepath,
+int index_file_set_syscall_error(struct mail_index *index, const char *filepath,
 				 const char *function);
 
 /* Reset the current error */
-void index_reset_error(MailIndex *index);
+void index_reset_error(struct mail_index *index);
 
 /* Create temporary file into index's directory. Returns opened file handle
    and sets *path to the full path of the created file.  */
-int mail_index_create_temp_file(MailIndex *index, const char **path);
+int mail_index_create_temp_file(struct mail_index *index, const char **path);
 
 /* Wrapper to file_set_lock(), also calling index's lock notify callback. */
-int mail_index_wait_lock(MailIndex *index, int lock_type);
+int mail_index_wait_lock(struct mail_index *index, int lock_type);
 
 #endif
--- a/src/lib-index/mail-index.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index.c	Sun Jan 05 15:09:51 2003 +0200
@@ -16,20 +16,20 @@
 #include <fcntl.h>
 #include <utime.h>
 
-static int mmap_verify(MailIndex *index)
+static int mmap_verify(struct mail_index *index)
 {
-	MailIndexHeader *hdr;
+	struct mail_index_header *hdr;
 	unsigned int extra;
 
 	index->mmap_used_length = 0;
 
-	if (index->mmap_full_length < sizeof(MailIndexHeader)) {
+	if (index->mmap_full_length < sizeof(struct mail_index_header)) {
                 index_set_corrupted(index, "File too small");
 		return FALSE;
 	}
 
-	extra = (index->mmap_full_length - sizeof(MailIndexHeader)) %
-		sizeof(MailIndexRecord);
+	extra = (index->mmap_full_length - sizeof(struct mail_index_header)) %
+		sizeof(struct mail_index_record);
 
 	if (extra != 0) {
 		/* partial write or corrupted -
@@ -53,8 +53,8 @@
 		return FALSE;
 	}
 
-	if ((hdr->used_file_size - sizeof(MailIndexHeader)) %
-	    sizeof(MailIndexRecord) != 0) {
+	if ((hdr->used_file_size - sizeof(struct mail_index_header)) %
+	    sizeof(struct mail_index_record) != 0) {
 		index_set_corrupted(index, "Invalid used_file_size in header "
 				    "(%"PRIuUOFF_T")",
 				    hdr->used_file_size);
@@ -80,13 +80,13 @@
 	return TRUE;
 }
 
-int mail_index_mmap_update(MailIndex *index)
+int mail_index_mmap_update(struct mail_index *index)
 {
 	if (index->anon_mmap)
 		return mmap_verify(index);
 
 	if (index->mmap_base != NULL) {
-		index->header = (MailIndexHeader *) index->mmap_base;
+		index->header = (struct mail_index_header *) index->mmap_base;
 
 		/* make sure file size hasn't changed */
 		if (index->header->sync_id == index->sync_id) {
@@ -117,7 +117,7 @@
 	return mmap_verify(index);
 }
 
-void mail_index_close(MailIndex *index)
+void mail_index_close(struct mail_index *index)
 {
 	index->set_flags = 0;
 	index->set_cache_fields = 0;
@@ -175,7 +175,7 @@
 	}
 }
 
-static int mail_index_sync_file(MailIndex *index)
+static int mail_index_sync_file(struct mail_index *index)
 {
 	unsigned int i;
 	int failed, fsync_fds[3];
@@ -215,7 +215,7 @@
 	return !failed;
 }
 
-static void mail_index_update_timestamp(MailIndex *index)
+static void mail_index_update_timestamp(struct mail_index *index)
 {
 	struct utimbuf ut;
 
@@ -226,7 +226,7 @@
 		index_set_syscall_error(index, "utime()");
 }
 
-int mail_index_fmdatasync(MailIndex *index, size_t size)
+int mail_index_fmdatasync(struct mail_index *index, size_t size)
 {
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
@@ -240,7 +240,7 @@
 	return TRUE;
 }
 
-static void mail_index_update_header_changes(MailIndex *index)
+static void mail_index_update_header_changes(struct mail_index *index)
 {
 	if (index->set_flags != 0) {
 		index->header->flags |= index->set_flags;
@@ -253,7 +253,7 @@
 	}
 }
 
-static int mail_index_write_header_changes(MailIndex *index)
+static int mail_index_write_header_changes(struct mail_index *index)
 {
 	int failed;
 
@@ -269,7 +269,8 @@
 
 	mail_index_update_header_changes(index);
 
-	failed = msync(index->mmap_base, sizeof(MailIndexHeader), MS_SYNC) < 0;
+	failed = msync(index->mmap_base,
+		       sizeof(struct mail_index_header), MS_SYNC) < 0;
 	if (failed)
 		index_set_syscall_error(index, "msync()");
 
@@ -283,9 +284,9 @@
 	return !failed;
 }
 
-static int mail_index_lock_remove(MailIndex *index)
+static int mail_index_lock_remove(struct mail_index *index)
 {
-	MailLockType old_lock_type;
+	enum mail_lock_type old_lock_type;
 
 	if (!mail_index_wait_lock(index, F_UNLCK))
 		return FALSE;
@@ -297,7 +298,7 @@
 		/* releasing shared lock. we may need to update some
 		   flags in header. */
 		unsigned int old_flags;
-		MailDataField old_cache;
+		enum mail_data_field old_cache;
 
 		old_flags = index->header->flags;
 		old_cache = index->header->cache_fields;
@@ -311,8 +312,8 @@
 	return TRUE;
 }
 
-static int mail_index_lock_change(MailIndex *index, MailLockType lock_type,
-				  int try_lock)
+static int mail_index_lock_change(struct mail_index *index,
+				  enum mail_lock_type lock_type, int try_lock)
 {
 	int ret, fd_lock_type;
 
@@ -390,7 +391,8 @@
 		   when the lock is released, the FSCK flag will also be
 		   removed. */
 		index->header->flags |= MAIL_INDEX_FLAG_FSCK;
-		if (!mail_index_fmdatasync(index, sizeof(MailIndexHeader))) {
+		if (!mail_index_fmdatasync(index,
+					   sizeof(struct mail_index_header))) {
 			(void)index->set_lock(index, MAIL_LOCK_UNLOCK);
 			return FALSE;
 		}
@@ -399,8 +401,8 @@
 	return TRUE;
 }
 
-static int mail_index_lock_full(MailIndex *index, MailLockType lock_type,
-				int try_lock)
+static int mail_index_lock_full(struct mail_index *index,
+				enum mail_lock_type lock_type, int try_lock)
 {
 	int keep_fsck;
 
@@ -428,7 +430,8 @@
 		/* remove the FSCK flag only after successful fsync() */
 		if (mail_index_sync_file(index) && !keep_fsck) {
 			index->header->flags &= ~MAIL_INDEX_FLAG_FSCK;
-			if (msync(index->mmap_base, sizeof(MailIndexHeader),
+			if (msync(index->mmap_base,
+				  sizeof(struct mail_index_header),
 				  MS_SYNC) < 0) {
 				/* we only failed to remove the fsck flag,
 				   so this isn't fatal. */
@@ -445,27 +448,26 @@
 		return mail_index_lock_change(index, lock_type, try_lock);
 }
 
-int mail_index_set_lock(MailIndex *index, MailLockType lock_type)
+int mail_index_set_lock(struct mail_index *index, enum mail_lock_type lock_type)
 {
 	return mail_index_lock_full(index, lock_type, FALSE);
 }
 
-int mail_index_try_lock(MailIndex *index, MailLockType lock_type)
+int mail_index_try_lock(struct mail_index *index, enum mail_lock_type lock_type)
 {
 	return mail_index_lock_full(index, lock_type, TRUE);
 }
 
-void mail_index_set_lock_notify_callback(MailIndex *index,
-					 MailLockNotifyFunc func,
-					 void *context)
+void mail_index_set_lock_notify_callback(struct mail_index *index,
+					 MailLockNotifyFunc func, void *context)
 {
 	index->lock_notify_func = func;
 	index->lock_notify_context = context;
 }
 
-int mail_index_verify_hole_range(MailIndex *index)
+int mail_index_verify_hole_range(struct mail_index *index)
 {
-	MailIndexHeader *hdr;
+	struct mail_index_header *hdr;
 	unsigned int max_records;
 
 	hdr = index->header;
@@ -489,17 +491,18 @@
 	return TRUE;
 }
 
-MailIndexHeader *mail_index_get_header(MailIndex *index)
+struct mail_index_header *mail_index_get_header(struct mail_index *index)
 {
 	i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
 
 	return index->header;
 }
 
-MailIndexRecord *mail_index_lookup(MailIndex *index, unsigned int seq)
+struct mail_index_record *mail_index_lookup(struct mail_index *index,
+					    unsigned int seq)
 {
-	MailIndexHeader *hdr;
-	MailIndexRecord *rec;
+	struct mail_index_header *hdr;
+	struct mail_index_record *rec;
 	const char *error;
 	unsigned int idx;
 
@@ -547,8 +550,7 @@
 		return NULL;
 	}
 
-	rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				   sizeof(MailIndexHeader)) + idx;
+	rec = INDEX_RECORD_AT(index, idx);
 	if (rec->uid == 0) {
 		index_set_corrupted(index, "%s", error);
 		return NULL;
@@ -557,19 +559,19 @@
 	return rec;
 }
 
-MailIndexRecord *mail_index_next(MailIndex *index, MailIndexRecord *rec)
+struct mail_index_record *mail_index_next(struct mail_index *index,
+					  struct mail_index_record *rec)
 {
-	MailIndexRecord *end_rec;
+	struct mail_index_record *end_rec;
 
 	i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
-	i_assert(rec >= (MailIndexRecord *) index->mmap_base);
+	i_assert(rec >= (struct mail_index_record *) index->mmap_base);
 
 	if (rec == NULL)
 		return NULL;
 
 	/* go to the next non-deleted record */
-	end_rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				       index->mmap_used_length);
+	end_rec = INDEX_END_RECORD(index);
 	while (++rec < end_rec) {
 		if (rec->uid != 0)
 			return rec;
@@ -578,12 +580,11 @@
 	return NULL;
 }
 
-MailIndexRecord *mail_index_lookup_uid_range(MailIndex *index,
-					     unsigned int first_uid,
-					     unsigned int last_uid,
-					     unsigned int *seq_r)
+struct mail_index_record *
+mail_index_lookup_uid_range(struct mail_index *index, unsigned int first_uid,
+			    unsigned int last_uid, unsigned int *seq_r)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 	unsigned int idx;
 
 	i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
@@ -604,8 +605,7 @@
 		return NULL;
 	}
 
-	rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				   sizeof(MailIndexHeader)) + idx;
+	rec = INDEX_RECORD_AT(index, idx);
 	if (rec->uid < first_uid || rec->uid > last_uid) {
 		index_set_error(index, "Corrupted binary tree for index %s: "
 				"lookup returned offset to wrong UID "
@@ -618,10 +618,11 @@
 	return rec;
 }
 
-const char *mail_index_lookup_field(MailIndex *index, MailIndexRecord *rec,
-				    MailDataField field)
+const char *mail_index_lookup_field(struct mail_index *index,
+				    struct mail_index_record *rec,
+				    enum mail_data_field field)
 {
-	MailIndexDataRecord *datarec;
+	struct mail_index_data_record *datarec;
 
 	datarec = (rec->data_fields & field) == 0 ? NULL :
 		mail_index_data_lookup(index->data, rec, field);
@@ -636,11 +637,13 @@
 	return datarec->data;
 }
 
-const void *mail_index_lookup_field_raw(MailIndex *index, MailIndexRecord *rec,
-					MailDataField field, size_t *size)
+const void *mail_index_lookup_field_raw(struct mail_index *index,
+					struct mail_index_record *rec,
+					enum mail_data_field field,
+					size_t *size)
 {
-	MailIndexDataRecordHeader *datahdr;
-	MailIndexDataRecord *datarec;
+	struct mail_index_data_record_header *datahdr;
+	struct mail_index_data_record *datarec;
 
 	if ((rec->data_fields & field) == 0) {
 		*size = 0;
@@ -685,7 +688,8 @@
 	}
 }
 
-void mail_index_cache_fields_later(MailIndex *index, MailDataField field)
+void mail_index_cache_fields_later(struct mail_index *index,
+				   enum mail_data_field field)
 {
 	i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
 
@@ -707,7 +711,8 @@
 	}
 }
 
-time_t mail_get_internal_date(MailIndex *index, MailIndexRecord *rec)
+time_t mail_get_internal_date(struct mail_index *index,
+			      struct mail_index_record *rec)
 {
 	const time_t *date;
 	size_t size;
@@ -722,8 +727,10 @@
 	}
 }
 
-void mail_index_mark_flag_changes(MailIndex *index, MailIndexRecord *rec,
-				  MailFlags old_flags, MailFlags new_flags)
+void mail_index_mark_flag_changes(struct mail_index *index,
+				  struct mail_index_record *rec,
+				  enum mail_flags old_flags,
+				  enum mail_flags new_flags)
 {
 	if ((old_flags & MAIL_SEEN) == 0 && (new_flags & MAIL_SEEN)) {
 		/* unseen -> seen */
@@ -766,28 +773,25 @@
 	}
 }
 
-static void update_first_hole_records(MailIndex *index)
+static void update_first_hole_records(struct mail_index *index)
 {
-        MailIndexRecord *rec, *end_rec;
+        struct mail_index_record *rec, *end_rec;
 
 	/* see if first_hole_records can be grown */
-	rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				   sizeof(MailIndexHeader)) +
-		index->header->first_hole_index +
-		index->header->first_hole_records;
-	end_rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				       index->mmap_used_length);
+	rec = INDEX_RECORD_AT(index, index->header->first_hole_index +
+			      index->header->first_hole_records);
+	end_rec = INDEX_END_RECORD(index);
 	while (rec < end_rec && rec->uid == 0) {
 		index->header->first_hole_records++;
 		rec++;
 	}
 }
 
-static int mail_index_truncate_hole(MailIndex *index)
+static int mail_index_truncate_hole(struct mail_index *index)
 {
-	index->header->used_file_size = sizeof(MailIndexHeader) +
+	index->header->used_file_size = sizeof(struct mail_index_header) +
 		(uoff_t)index->header->first_hole_index *
-		sizeof(MailIndexRecord);
+		sizeof(struct mail_index_record);
 	index->header->first_hole_index = 0;
 	index->header->first_hole_records = 0;
 
@@ -809,10 +813,10 @@
 	 (records) * (100-INDEX_COMPRESS_PERCENTAGE) / 100 > \
 	 	(hdr)->messages_count)
 
-int mail_index_expunge(MailIndex *index, MailIndexRecord *rec,
+int mail_index_expunge(struct mail_index *index, struct mail_index_record *rec,
 		       unsigned int seq, int external_change)
 {
-	MailIndexHeader *hdr;
+	struct mail_index_header *hdr;
 	unsigned int records, uid, idx;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
@@ -891,8 +895,9 @@
 	return TRUE;
 }
 
-int mail_index_update_flags(MailIndex *index, MailIndexRecord *rec,
-			    unsigned int seq, MailFlags flags,
+int mail_index_update_flags(struct mail_index *index,
+			    struct mail_index_record *rec,
+			    unsigned int seq, enum mail_flags flags,
 			    int external_change)
 {
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
@@ -909,7 +914,7 @@
 					 rec->uid, external_change);
 }
 
-static int mail_index_grow(MailIndex *index)
+static int mail_index_grow(struct mail_index *index)
 {
 	uoff_t pos;
 	unsigned int grow_count;
@@ -920,7 +925,8 @@
 	if (grow_count < 16)
 		grow_count = 16;
 
-	pos = index->mmap_full_length + (grow_count * sizeof(MailIndexRecord));
+	pos = index->mmap_full_length +
+		(grow_count * sizeof(struct mail_index_record));
 	i_assert(pos < OFF_T_MAX);
 
 	if (index->anon_mmap) {
@@ -952,9 +958,9 @@
 	return TRUE;
 }
 
-MailIndexRecord *mail_index_append_begin(MailIndex *index)
+struct mail_index_record *mail_index_append_begin(struct mail_index *index)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
@@ -964,20 +970,21 @@
 	}
 
 	i_assert(index->header->used_file_size == index->mmap_used_length);
-	i_assert(index->mmap_used_length + sizeof(MailIndexRecord) <=
+	i_assert(index->mmap_used_length + sizeof(struct mail_index_record) <=
 		 index->mmap_full_length);
 
-	rec = (MailIndexRecord *) ((char *) index->mmap_base +
-				   index->mmap_used_length);
-	memset(rec, 0, sizeof(MailIndexRecord));
+	rec = (struct mail_index_record *) ((char *) index->mmap_base +
+					    index->mmap_used_length);
+	memset(rec, 0, sizeof(struct mail_index_record));
 
-	index->header->used_file_size += sizeof(MailIndexRecord);
-	index->mmap_used_length += sizeof(MailIndexRecord);
+	index->header->used_file_size += sizeof(struct mail_index_record);
+	index->mmap_used_length += sizeof(struct mail_index_record);
 
 	return rec;
 }
 
-int mail_index_append_end(MailIndex *index, MailIndexRecord *rec)
+int mail_index_append_end(struct mail_index *index,
+			  struct mail_index_record *rec)
 {
 	i_assert(rec->uid == 0);
 
@@ -999,7 +1006,7 @@
 	return TRUE;
 }
 
-MailIndexError mail_index_get_last_error(MailIndex *index)
+enum mail_index_error mail_index_get_last_error(struct mail_index *index)
 {
 	if (index->inconsistent)
 		return MAIL_INDEX_ERROR_INCONSISTENT;
@@ -1016,7 +1023,7 @@
 	return MAIL_INDEX_ERROR_NONE;
 }
 
-const char *mail_index_get_last_error_text(MailIndex *index)
+const char *mail_index_get_last_error_text(struct mail_index *index)
 {
 	return index->error;
 }
--- a/src/lib-index/mail-index.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-index.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,15 +4,15 @@
 #include "message-parser.h"
 #include "imap-util.h"
 
-#define MAIL_INDEX_VERSION 1
+#define MAIL_INDEX_VERSION 2
 
 #define INDEX_FILE_PREFIX ".imap.index"
 
-enum {
+enum mail_index_header_compat {
 	MAIL_INDEX_COMPAT_LITTLE_ENDIAN	= 0x01
 };
 
-enum {
+enum mail_index_header_flag {
 	/* Rebuild flag is set while index is being rebuilt or when
 	   some error is noticed in the index file. If this flag is set,
 	   the index shouldn't be used before rebuilding it. */
@@ -26,30 +26,29 @@
 	MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS	= 0x80
 };
 
-/* Use macros instead of enum so highest bit can be used without kludging */
-#define DATA_FIELD_LOCATION		0x00000001
-#define DATA_FIELD_ENVELOPE		0x00000002
-#define DATA_FIELD_BODY			0x00000004
-#define DATA_FIELD_BODYSTRUCTURE	0x00000008
-#define DATA_FIELD_MD5			0x00000010
-#define DATA_FIELD_MESSAGEPART		0x00000020
+enum mail_data_field {
+	DATA_FIELD_LOCATION		= 0x00000001,
+	DATA_FIELD_ENVELOPE		= 0x00000002,
+	DATA_FIELD_BODY			= 0x00000004,
+	DATA_FIELD_BODYSTRUCTURE	= 0x00000008,
+	DATA_FIELD_MD5			= 0x00000010,
+	DATA_FIELD_MESSAGEPART		= 0x00000020,
 
-#define DATA_FIELD_LAST			0x00000040
-#define DATA_FIELD_MAX_BITS		6
+	DATA_FIELD_LAST			= 0x00000040,
+	DATA_FIELD_MAX_BITS		= 6,
 
-/* separate from above, but in same bitmask */
-#define DATA_HDR_INTERNAL_DATE		0x80000000
-#define DATA_HDR_VIRTUAL_SIZE		0x40000000
-#define DATA_HDR_HEADER_SIZE		0x20000000
-#define DATA_HDR_BODY_SIZE		0x10000000
-
-typedef unsigned int MailDataField;
+	/* separate from above, but in same bitmask */
+	DATA_HDR_INTERNAL_DATE		= 0x40000000,
+	DATA_HDR_VIRTUAL_SIZE		= 0x20000000,
+	DATA_HDR_HEADER_SIZE		= 0x10000000,
+	DATA_HDR_BODY_SIZE		= 0x08000000
+};
 
 #define IS_BODYSTRUCTURE_FIELD(field) \
 	(((field) & (DATA_FIELD_BODY | DATA_FIELD_BODYSTRUCTURE | \
 		     DATA_FIELD_MESSAGEPART)) != 0)
 
-typedef enum {
+enum mail_index_mail_flag {
 	/* If binary flags are set, it's not checked whether mail is
 	   missing CRs. So this flag may be set as an optimization for
 	   regular non-binary mails as well if it's known that it contains
@@ -60,24 +59,24 @@
 	/* Currently this means with mbox format that message flags have
 	   been changed in index, but not written into mbox file yet. */
 	INDEX_MAIL_FLAG_DIRTY		= 0x0004
-} MailIndexMailFlags;
+};
 
-typedef enum {
+enum mail_lock_type {
 	MAIL_LOCK_UNLOCK = 0,
 	MAIL_LOCK_SHARED,
 	MAIL_LOCK_EXCLUSIVE
-} MailLockType;
+};
 
-typedef enum {
+enum mail_lock_notify_type {
 	/* Mailbox is locked, will abort in secs_left */
 	MAIL_LOCK_NOTIFY_MAILBOX_ABORT,
 	/* Mailbox lock looks stale, will override in secs_left */
 	MAIL_LOCK_NOTIFY_MAILBOX_OVERRIDE,
 	/* Index is locked, will abort in secs_left */
 	MAIL_LOCK_NOTIFY_INDEX_ABORT
-} MailLockNotifyType;
+};
 
-typedef enum {
+enum mail_index_error {
 	/* No errors */
 	MAIL_INDEX_ERROR_NONE,
 	/* Internal error, see get_error_text() for more information. */
@@ -94,27 +93,12 @@
 	MAIL_INDEX_ERROR_INDEX_LOCK_TIMEOUT,
 	/* Mailbox locking timeouted */
 	MAIL_INDEX_ERROR_MAILBOX_LOCK_TIMEOUT
-} MailIndexError;
+};
 
-typedef void (*MailLockNotifyFunc)(MailLockNotifyType notify_type,
+typedef void (*MailLockNotifyFunc)(enum mail_lock_notify_type notify_type,
 				   unsigned int secs_left, void *context);
 
-typedef struct _MailIndex MailIndex;
-typedef struct _MailIndexData MailIndexData;
-typedef struct _MailTree MailTree;
-typedef struct _MailModifyLog MailModifyLog;
-typedef struct _MailCustomFlags MailCustomFlags;
-
-typedef struct _MailIndexHeader MailIndexHeader;
-typedef struct _MailIndexDataHeader MailIndexDataHeader;
-
-typedef struct _MailIndexRecord MailIndexRecord;
-typedef struct _MailIndexDataRecord MailIndexDataRecord;
-typedef struct _MailIndexDataRecordHeader MailIndexDataRecordHeader;
-
-typedef struct _MailIndexUpdate MailIndexUpdate;
-
-struct _MailIndexHeader {
+struct mail_index_header {
 	unsigned char compat_data[8];
 	/* 0 = version
 	   1 = flags,
@@ -148,7 +132,7 @@
 	unsigned int first_deleted_uid_lowwater;
 };
 
-struct _MailIndexDataHeader {
+struct mail_index_data_header {
 	unsigned int indexid;
 	unsigned int reserved; /* for alignment mostly */
 
@@ -156,17 +140,17 @@
 	uoff_t deleted_space;
 };
 
-struct _MailIndexRecord {
+struct mail_index_record {
 	unsigned int uid;
-	unsigned int msg_flags; /* MailFlags */
+	unsigned int msg_flags; /* enum mail_flags */
 
-	unsigned int index_flags; /* MailIndexMailFlags */
-	unsigned int data_fields; /* MailDataField */
+	unsigned int index_flags; /* enum mail_index_mail_flag */
+	unsigned int data_fields; /* enum mail_data_field */
 
 	uoff_t data_position;
 };
 
-struct _MailIndexDataRecordHeader {
+struct mail_index_data_record_header {
 	unsigned int data_size; /* including this header */
 
 	time_t internal_date;
@@ -176,29 +160,30 @@
 	uoff_t body_size;
 };
 
-struct _MailIndexDataRecord {
-	unsigned int field; /* MailDataField */
+struct mail_index_data_record {
+	unsigned int field; /* enum mail_data_field */
 	unsigned int full_field_size;
 	char data[MEM_ALIGN_SIZE]; /* variable size */
 };
 
 #define SIZEOF_MAIL_INDEX_DATA \
-	(sizeof(MailIndexDataRecord) - MEM_ALIGN_SIZE)
+	(sizeof(struct mail_index_data_record) - MEM_ALIGN_SIZE)
 
 #define DATA_RECORD_SIZE(rec) \
         (SIZEOF_MAIL_INDEX_DATA + (rec)->full_field_size)
 
-struct _MailIndex {
+struct mail_index {
 	/* If fast is TRUE, compressing and cache updates are not performed.
 	   Note that opening same index twice in the same process is a bad
 	   idea since they share the same file locks. As soon one of the
 	   indexes is closed, the locks in second index are dropped which
 	   especially hurts modify log since it keeps locks all the time. */
-	int (*open)(MailIndex *index, int update_recent, int fast);
-	int (*open_or_create)(MailIndex *index, int update_recent, int fast);
+	int (*open)(struct mail_index *index, int update_recent, int fast);
+	int (*open_or_create)(struct mail_index *index,
+			      int update_recent, int fast);
 
 	/* Free index from memory. */
-	void (*free)(MailIndex *index);
+	void (*free)(struct mail_index *index);
 
 	/* Lock/unlock index. May block. Note that unlocking must not
 	   reset error from get_last_error() as unlocking can be done as
@@ -212,16 +197,18 @@
 	   data to be updated later, b) use try_lock() if the update is
 	   preferred but not required, c) unlock + lock again, but make
 	   sure that won't create race conditions. */
-	int (*set_lock)(MailIndex *index, MailLockType lock_type);
+	int (*set_lock)(struct mail_index *index,
+			enum mail_lock_type lock_type);
 
 	/* Try locking the index. Returns TRUE if the lock was got and
 	   FALSE if lock isn't possible to get currently or some other error
 	   occured. Never blocks. */
-	int (*try_lock)(MailIndex *index, MailLockType lock_type);
+	int (*try_lock)(struct mail_index *index,
+			enum mail_lock_type lock_type);
 
 	/* If we have to wait for the lock, the given lock notify function
 	   is called once in a while. */
-	void (*set_lock_notify_callback)(MailIndex *index,
+	void (*set_lock_notify_callback)(struct mail_index *index,
 					 MailLockNotifyFunc func,
 					 void *context);
 
@@ -230,66 +217,74 @@
 	   Index MUST NOT have shared lock, but exclusive lock or no lock at
 	   all is fine. Note that this function may leave the index
 	   exclusively locked, and always sets index->inconsistent = TRUE. */
-	int (*rebuild)(MailIndex *index);
+	int (*rebuild)(struct mail_index *index);
 
 	/* Verify that the index is valid. If anything invalid is found,
 	   index is set inconsistent and to be rebuilt at next open.
 	   Same locking issues as with rebuild(). */
-	int (*fsck)(MailIndex *index);
+	int (*fsck)(struct mail_index *index);
 
 	/* Synchronize the index with the mailbox. Index must not have shared
 	   lock when calling this function. The data_lock_type specifies what
 	   lock should be set to data file (mbox file). This function may
 	   leave the index in ANY locking state. If changes is non-NULL, it's
 	   set to TRUE if any changes were noticed. */
-	int (*sync_and_lock)(MailIndex *index, MailLockType data_lock_type,
-			     int *changes);
+	int (*sync_and_lock)(struct mail_index *index,
+			     enum mail_lock_type data_lock_type, int *changes);
 
 	/* Returns the index header (never fails). The index needs to be
 	   locked before calling this function, and must be kept locked as
 	   long as you keep using the returned structure. */
-	MailIndexHeader *(*get_header)(MailIndex *index);
+	struct mail_index_header *(*get_header)(struct mail_index *index);
 
 	/* sequence -> data lookup. The index needs to be locked before calling
 	   this function, and must be kept locked as long as you keep using
 	   the returned structure. */
-	MailIndexRecord *(*lookup)(MailIndex *index, unsigned int seq);
+	struct mail_index_record *(*lookup)(struct mail_index *index,
+					    unsigned int seq);
 
 	/* Return the next record after specified record, or NULL if it was
 	   last record. The index must be locked all the time between
 	   lookup() and last next() call. */
-	MailIndexRecord *(*next)(MailIndex *index, MailIndexRecord *rec);
+	struct mail_index_record *(*next)(struct mail_index *index,
+					  struct mail_index_record *rec);
 
 	/* Find first existing UID in range. Sequence number is also retrieved
 	   if seq_r is non-NULL. */
-	MailIndexRecord *(*lookup_uid_range)(MailIndex *index,
-					     unsigned int first_uid,
-					     unsigned int last_uid,
-					     unsigned int *seq_r);
+	struct mail_index_record *(*lookup_uid_range)(struct mail_index *index,
+						      unsigned int first_uid,
+						      unsigned int last_uid,
+						      unsigned int *seq_r);
 
 	/* Find field from specified record, or NULL if it's not in index.
 	   Makes sure that the field ends with \0. */
-	const char *(*lookup_field)(MailIndex *index, MailIndexRecord *rec,
-				    MailDataField field);
+	const char *(*lookup_field)(struct mail_index *index,
+				    struct mail_index_record *rec,
+				    enum mail_data_field field);
 
 	/* Find field from specified record, or NULL if it's not in index. */
-	const void *(*lookup_field_raw)(MailIndex *index, MailIndexRecord *rec,
-					MailDataField field, size_t *size);
+	const void *(*lookup_field_raw)(struct mail_index *index,
+					struct mail_index_record *rec,
+					enum mail_data_field field,
+					size_t *size);
 
 	/* Mark the fields to be cached later. If any of them is already
 	   set in hdr->cache_fields, mark the caching to happen next time
 	   index is opened. */
-	void (*cache_fields_later)(MailIndex *index, MailDataField field);
+	void (*cache_fields_later)(struct mail_index *index,
+				   enum mail_data_field field);
 
 	/* Open mail file and return it as mmap()ed IStream. If we fail,
 	   we return NULL and set deleted = TRUE if failure was because the
 	   mail was just deleted (ie. not an error). internal_date is set
 	   if it's non-NULL. */
-	IStream *(*open_mail)(MailIndex *index, MailIndexRecord *rec,
-			      time_t *internal_date, int *deleted);
+	struct istream *(*open_mail)(struct mail_index *index,
+				     struct mail_index_record *rec,
+				     time_t *internal_date, int *deleted);
 
 	/* Returns internal date of message, or (time_t)-1 if error occured. */
-	time_t (*get_internal_date)(MailIndex *index, MailIndexRecord *rec);
+	time_t (*get_internal_date)(struct mail_index *index,
+				    struct mail_index_record *rec);
 
 	/* Expunge a mail from index. Tree and modifylog is also updated. The
 	   index must be exclusively locked before calling this function.
@@ -301,21 +296,23 @@
 	   Note that the sequence numbers also update immediately after this
 	   call, so if you want to delete messages 1..4 just call this
 	   function 4 times with seq being 1. */
-	int (*expunge)(MailIndex *index, MailIndexRecord *rec,
+	int (*expunge)(struct mail_index *index, struct mail_index_record *rec,
 		       unsigned int seq, int external_change);
 
 	/* Update mail flags. The index must be exclusively locked before
 	   calling this function. This shouldn't be called in the middle of
 	   update_begin() as it may modify location field. */
-	int (*update_flags)(MailIndex *index, MailIndexRecord *rec,
-			    unsigned int seq, MailFlags flags,
+	int (*update_flags)(struct mail_index *index,
+			    struct mail_index_record *rec,
+			    unsigned int seq, enum mail_flags flags,
 			    int external_change);
 
 	/* Append a new record to index. The index must be exclusively
 	   locked before calling this function. rec->uid is updated in
 	   append_end(). */
-	MailIndexRecord *(*append_begin)(MailIndex *index);
-	int (*append_end)(MailIndex *index, MailIndexRecord *rec);
+	struct mail_index_record *(*append_begin)(struct mail_index *index);
+	int (*append_end)(struct mail_index *index,
+			  struct mail_index_record *rec);
 
 	/* Updating fields happens by calling update_begin(), one or more
 	   update_field()s and finally update_end() which does the actual
@@ -330,40 +327,43 @@
 
 	   The files may not actually be updated until after you've unlocked
 	   the file. */
-	MailIndexUpdate *(*update_begin)(MailIndex *index,
-					 MailIndexRecord *rec);
-	int (*update_end)(MailIndexUpdate *update);
+	struct mail_index_update *
+		(*update_begin)(struct mail_index *index,
+				struct mail_index_record *rec);
+	int (*update_end)(struct mail_index_update *update);
 
-	void (*update_field)(MailIndexUpdate *update, MailDataField field,
+	void (*update_field)(struct mail_index_update *update,
+			     enum mail_data_field field,
 			     const char *value, size_t extra_space);
 	/* Just remember that full_field_size will be MEM_ALIGNed, so
 	   it may differer from the given size parameter. */
-	void (*update_field_raw)(MailIndexUpdate *update, MailDataField field,
+	void (*update_field_raw)(struct mail_index_update *update,
+				 enum mail_data_field field,
 				 const void *value, size_t size);
 
 	/* Returns the last error code. */
-	MailIndexError (*get_last_error)(MailIndex *index);
+	enum mail_index_error (*get_last_error)(struct mail_index *index);
 
 	/* Returns the full error message for last error. This message may
 	   contain paths etc. so it shouldn't be shown to users. */
-	const char *(*get_last_error_text)(MailIndex *index);
+	const char *(*get_last_error_text)(struct mail_index *index);
 
 /* private: */
-	MailIndexData *data;
-	MailTree *tree;
-	MailModifyLog *modifylog;
-	MailCustomFlags *custom_flags;
+	struct mail_index_data *data;
+	struct mail_tree *tree;
+	struct mail_modify_log *modifylog;
+	struct mail_custom_flags *custom_flags;
 
 	char *dir; /* directory where to place the index files */
 	char *filepath; /* index file path */
 	char *mailbox_path; /* file/directory for mailbox location */
-	MailDataField default_cache_fields, never_cache_fields;
+	enum mail_data_field default_cache_fields, never_cache_fields;
 	unsigned int indexid;
 	unsigned int sync_id;
 
 	int mbox_fd;
-	IStream *mbox_stream;
-	MailLockType mbox_lock_type;
+	struct istream *mbox_stream;
+	enum mail_lock_type mbox_lock_type;
 	dev_t mbox_dotlock_dev;
 	ino_t mbox_dotlock_ino;
 
@@ -384,9 +384,9 @@
 	size_t mmap_used_length;
 	size_t mmap_full_length;
 
-	MailIndexHeader *header;
+	struct mail_index_header *header;
 
-        MailLockType lock_type;
+        enum mail_lock_type lock_type;
 	time_t file_sync_stamp;
 	unsigned int first_recent_uid;
 
@@ -396,7 +396,7 @@
 	/* these fields are OR'ed to the fields in index header once we
 	   get around grabbing exclusive lock */
 	unsigned int set_flags;
-	MailDataField set_cache_fields;
+	enum mail_data_field set_cache_fields;
 
 	unsigned int anon_mmap:1;
 	unsigned int opened:1;
@@ -424,60 +424,78 @@
 #endif
 
 /* defaults - same as above but prefixed with mail_index_. */
-int mail_index_open(MailIndex *index, int update_recent, int fast);
-int mail_index_open_or_create(MailIndex *index, int update_recent, int fast);
-int mail_index_set_lock(MailIndex *index, MailLockType lock_type);
-int mail_index_try_lock(MailIndex *index, MailLockType lock_type);
-void mail_index_set_lock_notify_callback(MailIndex *index,
+int mail_index_open(struct mail_index *index, int update_recent, int fast);
+int mail_index_open_or_create(struct mail_index *index,
+			      int update_recent, int fast);
+int mail_index_set_lock(struct mail_index *index,
+			enum mail_lock_type lock_type);
+int mail_index_try_lock(struct mail_index *index,
+			enum mail_lock_type lock_type);
+void mail_index_set_lock_notify_callback(struct mail_index *index,
 					 MailLockNotifyFunc func,
 					 void *context);
-int mail_index_fsck(MailIndex *index);
-MailIndexHeader *mail_index_get_header(MailIndex *index);
-MailIndexRecord *mail_index_lookup(MailIndex *index, unsigned int seq);
-MailIndexRecord *mail_index_next(MailIndex *index, MailIndexRecord *rec);
-MailIndexRecord *mail_index_lookup_uid_range(MailIndex *index,
-					     unsigned int first_uid,
-					     unsigned int last_uid,
-					     unsigned int *seq_r);
-const char *mail_index_lookup_field(MailIndex *index, MailIndexRecord *rec,
-				    MailDataField field);
-const void *mail_index_lookup_field_raw(MailIndex *index, MailIndexRecord *rec,
-					MailDataField field, size_t *size);
-void mail_index_cache_fields_later(MailIndex *index, MailDataField field);
-int mail_index_expunge(MailIndex *index, MailIndexRecord *rec,
+int mail_index_fsck(struct mail_index *index);
+struct mail_index_header *mail_index_get_header(struct mail_index *index);
+struct mail_index_record *mail_index_lookup(struct mail_index *index,
+					    unsigned int seq);
+struct mail_index_record *mail_index_next(struct mail_index *index,
+					  struct mail_index_record *rec);
+struct mail_index_record *
+mail_index_lookup_uid_range(struct mail_index *index, unsigned int first_uid,
+			    unsigned int last_uid, unsigned int *seq_r);
+const char *mail_index_lookup_field(struct mail_index *index,
+				    struct mail_index_record *rec,
+				    enum mail_data_field field);
+const void *mail_index_lookup_field_raw(struct mail_index *index,
+					struct mail_index_record *rec,
+					enum mail_data_field field,
+					size_t *size);
+void mail_index_cache_fields_later(struct mail_index *index,
+				   enum mail_data_field field);
+int mail_index_expunge(struct mail_index *index, struct mail_index_record *rec,
 		       unsigned int seq, int external_change);
-int mail_index_update_flags(MailIndex *index, MailIndexRecord *rec,
-			    unsigned int seq, MailFlags flags,
+int mail_index_update_flags(struct mail_index *index,
+			    struct mail_index_record *rec,
+			    unsigned int seq, enum mail_flags flags,
 			    int external_change);
-MailIndexRecord *mail_index_append_begin(MailIndex *index);
-int mail_index_append_end(MailIndex *index, MailIndexRecord *rec);
-MailIndexUpdate *mail_index_update_begin(MailIndex *index,
-					 MailIndexRecord *rec);
-int mail_index_update_end(MailIndexUpdate *update);
-void mail_index_update_field(MailIndexUpdate *update, MailDataField field,
+struct mail_index_record *mail_index_append_begin(struct mail_index *index);
+int mail_index_append_end(struct mail_index *index,
+			  struct mail_index_record *rec);
+struct mail_index_update *
+mail_index_update_begin(struct mail_index *index,
+			struct mail_index_record *rec);
+int mail_index_update_end(struct mail_index_update *update);
+void mail_index_update_field(struct mail_index_update *update,
+			     enum mail_data_field field,
 			     const char *value, size_t extra_space);
-void mail_index_update_field_raw(MailIndexUpdate *update, MailDataField field,
+void mail_index_update_field_raw(struct mail_index_update *update,
+				 enum mail_data_field field,
 				 const void *value, size_t size);
-time_t mail_get_internal_date(MailIndex *index, MailIndexRecord *rec);
-MailIndexError mail_index_get_last_error(MailIndex *index);
-const char *mail_index_get_last_error_text(MailIndex *index);
+time_t mail_get_internal_date(struct mail_index *index,
+			      struct mail_index_record *rec);
+enum mail_index_error mail_index_get_last_error(struct mail_index *index);
+const char *mail_index_get_last_error_text(struct mail_index *index);
 
 /* INTERNAL: */
-void mail_index_init(MailIndex *index, const char *dir);
-int mail_index_mmap_update(MailIndex *index);
-void mail_index_init_header(MailIndex *index, MailIndexHeader *hdr);
-void mail_index_close(MailIndex *index);
-int mail_index_fmdatasync(MailIndex *index, size_t size);
-int mail_index_verify_hole_range(MailIndex *index);
-void mail_index_mark_flag_changes(MailIndex *index, MailIndexRecord *rec,
-				  MailFlags old_flags, MailFlags new_flags);
-void mail_index_update_headers(MailIndexUpdate *update, IStream *input,
-                               MailDataField cache_fields,
+void mail_index_init(struct mail_index *index, const char *dir);
+int mail_index_mmap_update(struct mail_index *index);
+void mail_index_init_header(struct mail_index *index,
+			    struct mail_index_header *hdr);
+void mail_index_close(struct mail_index *index);
+int mail_index_fmdatasync(struct mail_index *index, size_t size);
+int mail_index_verify_hole_range(struct mail_index *index);
+void mail_index_mark_flag_changes(struct mail_index *index,
+				  struct mail_index_record *rec,
+				  enum mail_flags old_flags,
+				  enum mail_flags new_flags);
+void mail_index_update_headers(struct mail_index_update *update,
+			       struct istream *input,
+                               enum mail_data_field cache_fields,
 			       MessageHeaderFunc header_func, void *context);
-int mail_index_update_cache(MailIndex *index);
-int mail_index_compress(MailIndex *index);
-int mail_index_compress_data(MailIndex *index);
-int mail_index_truncate(MailIndex *index);
+int mail_index_update_cache(struct mail_index *index);
+int mail_index_compress(struct mail_index *index);
+int mail_index_compress_data(struct mail_index *index);
+int mail_index_truncate(struct mail_index *index);
 
 /* Maximum allowed UID number. */
 #define MAX_ALLOWED_UID 4294967295U /* 2^32 - 1 */
@@ -507,9 +525,20 @@
 #define INDEX_FILE_POSITION(index, ptr) \
 	((uoff_t) ((char *) (ptr) - (char *) ((index)->mmap_base)))
 
+/* record for given index */
+#define INDEX_RECORD_AT(index, idx) \
+	((struct mail_index_record *) \
+	 ((char *) index->mmap_base + sizeof(struct mail_index_header)) + (idx))
+
+/* returns the next record after last one */
+#define INDEX_END_RECORD(index) \
+	((struct mail_index_record *) \
+	 ((char *) (index)->mmap_base + (index)->mmap_used_length))
+
 /* index number for uoff_t position */
 #define INDEX_POSITION_INDEX(pos) \
-	(((pos) - sizeof(MailIndexHeader)) / sizeof(MailIndexRecord))
+	(((pos) - sizeof(struct mail_index_header)) / \
+	 sizeof(struct mail_index_record))
 
 /* index number for given record */
 #define INDEX_RECORD_INDEX(index, ptr) \
@@ -521,15 +550,15 @@
 
 /* get number of records in mmaped index */
 #define MAIL_INDEX_RECORD_COUNT(index) \
-	((index->mmap_used_length - sizeof(MailIndexHeader)) / \
-	 sizeof(MailIndexRecord))
+	((index->mmap_used_length - sizeof(struct mail_index_header)) / \
+	 sizeof(struct mail_index_record))
 
 /* minimum size for index file */
 #define INDEX_FILE_MIN_SIZE \
-	(sizeof(MailIndexHeader) + \
-	 INDEX_MIN_RECORDS_COUNT * sizeof(MailIndexRecord))
+	(sizeof(struct mail_index_header) + \
+	 INDEX_MIN_RECORDS_COUNT * sizeof(struct mail_index_record))
 
-/* MailLockType to fcntl() lock type */
+/* enum mail_lock_type to fcntl() lock type */
 #define MAIL_LOCK_TO_FLOCK(lock_type) \
         ((lock_type) == MAIL_LOCK_EXCLUSIVE ? F_WRLCK : \
 		(lock_type) == MAIL_LOCK_SHARED ? F_RDLCK : F_UNLCK)
--- a/src/lib-index/mail-lockdir.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-lockdir.c	Sun Jan 05 15:09:51 2003 +0200
@@ -51,8 +51,8 @@
 	return FALSE;
 }
 
-static int mail_index_unlock_dir(MailIndex *index, const char *private_path,
-				 const char *lockpath)
+static int mail_index_unlock_dir(struct mail_index *index,
+				 const char *private_path, const char *lockpath)
 {
 	struct stat st, lockst;
 
@@ -92,7 +92,8 @@
 	return TRUE;
 }
 
-int mail_index_lock_dir(MailIndex *index, MailLockType lock_type)
+int mail_index_lock_dir(struct mail_index *index,
+			enum mail_lock_type lock_type)
 {
 	struct stat st;
 	const char *private_path, *lockpath;
--- a/src/lib-index/mail-lockdir.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-lockdir.h	Sun Jan 05 15:09:51 2003 +0200
@@ -2,6 +2,7 @@
 #define __MAIL_LOCKDIR_H
 
 /* Exclusively lock whole directory where index is located. */
-int mail_index_lock_dir(MailIndex *index, MailLockType lock_type);
+int mail_index_lock_dir(struct mail_index *index,
+			enum mail_lock_type lock_type);
 
 #endif
--- a/src/lib-index/mail-modifylog.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-modifylog.c	Sun Jan 05 15:09:51 2003 +0200
@@ -18,9 +18,10 @@
 #define MAX_MODIFYLOG_SIZE (4096*8)
 
 /* How large chunks to use to grow log file */
-#define MODIFYLOG_GROW_SIZE (sizeof(ModifyLogRecord) * 128)
+#define MODIFYLOG_GROW_SIZE (sizeof(struct modify_log_record) * 128)
 
-#define MODIFY_LOG_INITIAL_SIZE (sizeof(ModifyLogHeader) + MODIFYLOG_GROW_SIZE)
+#define MODIFY_LOG_INITIAL_SIZE \
+	(sizeof(struct modify_log_header) + MODIFYLOG_GROW_SIZE)
 
 #define MODIFYLOG_FILE_POSITION(log, ptr) \
 	((size_t) ((char *) (ptr) - (char *) (log)->mmap_base))
@@ -30,10 +31,8 @@
 	((char *) (ptr) >= (char *) (area_ptr) && \
 	 (char *) (ptr) < (char *) (area_ptr) + (area_size))
 
-typedef struct _ModifyLogFile ModifyLogFile;
-
-struct _ModifyLogFile {
-	MailModifyLog *log;
+struct modify_log_file {
+	struct mail_modify_log *log;
 
 	int fd;
 	char *filepath;
@@ -42,10 +41,10 @@
 	size_t mmap_used_length;
 	size_t mmap_full_length;
 
-	ModifyLogRecord *last_expunge, *last_flags;
+	struct modify_log_record *last_expunge, *last_flags;
 	int last_expunge_external, last_flags_external;
 
-	ModifyLogHeader *header;
+	struct modify_log_header *header;
 	uoff_t synced_position;
 	unsigned int synced_id;
 
@@ -54,18 +53,18 @@
 	unsigned int second_log:1;
 };
 
-struct _MailModifyLog {
-	MailIndex *index;
+struct mail_modify_log {
+	struct mail_index *index;
 
-	ModifyLogRecord *iterator_end;
+	struct modify_log_record *iterator_end;
 
-	ModifyLogFile file1, file2;
-	ModifyLogFile *head, *tail;
+	struct modify_log_file file1, file2;
+	struct modify_log_file *head, *tail;
 };
 
-static const ModifyLogExpunge no_expunges = { 0, 0, 0 };
+static const struct modify_log_expunge no_expunges = { 0, 0, 0 };
 
-static int modifylog_set_syscall_error(ModifyLogFile *file,
+static int modifylog_set_syscall_error(struct modify_log_file *file,
 				       const char *function)
 {
 	i_assert(function != NULL);
@@ -76,7 +75,8 @@
 	return FALSE;
 }
 
-static int modifylog_set_corrupted(ModifyLogFile *file, const char *fmt, ...)
+static int modifylog_set_corrupted(struct modify_log_file *file,
+				   const char *fmt, ...)
 {
 	va_list va;
 
@@ -96,7 +96,7 @@
 	return FALSE;
 }
 
-static int modifylog_drop_lock(ModifyLogFile *file)
+static int modifylog_drop_lock(struct modify_log_file *file)
 {
 	int ret;
 
@@ -118,7 +118,8 @@
 	return 1;
 }
 
-static int modifylog_file_have_other_users(ModifyLogFile *file, int keep_lock)
+static int modifylog_file_have_other_users(struct modify_log_file *file,
+					   int keep_lock)
 {
 	int ret;
 
@@ -140,9 +141,10 @@
 }
 
 /* returns 1 = yes, 0 = no, -1 = error */
-static int modifylog_have_other_users(MailModifyLog *log, int keep_lock)
+static int modifylog_have_other_users(struct mail_modify_log *log,
+				      int keep_lock)
 {
-	ModifyLogFile *file;
+	struct modify_log_file *file;
 	int ret;
 
 	ret = modifylog_file_have_other_users(log->head, keep_lock);
@@ -161,9 +163,9 @@
 	return ret;
 }
 
-static int mmap_update(ModifyLogFile *file, int forced)
+static int mmap_update(struct modify_log_file *file, int forced)
 {
-	ModifyLogHeader *hdr;
+	struct modify_log_header *hdr;
 	unsigned int extra;
 
 	if (!forced && file->header != NULL &&
@@ -201,15 +203,15 @@
 		return modifylog_set_syscall_error(file, "mmap()");
 	}
 
-	if (file->mmap_full_length < sizeof(ModifyLogHeader)) {
+	if (file->mmap_full_length < sizeof(struct modify_log_header)) {
 		index_set_error(file->log->index, "Too small modify log %s",
 				file->filepath);
 		(void)unlink(file->filepath);
 		return FALSE;
 	}
 
-	extra = (file->mmap_full_length - sizeof(ModifyLogHeader)) %
-		sizeof(ModifyLogRecord);
+	extra = (file->mmap_full_length - sizeof(struct modify_log_header)) %
+		sizeof(struct modify_log_record);
 
 	if (extra != 0) {
 		/* partial write or corrupted -
@@ -228,8 +230,8 @@
 		return FALSE;
 	}
 
-	if ((hdr->used_file_size - sizeof(ModifyLogHeader)) %
-	    sizeof(ModifyLogRecord) != 0) {
+	if ((hdr->used_file_size - sizeof(struct modify_log_header)) %
+	    sizeof(struct modify_log_record) != 0) {
 		modifylog_set_corrupted(file,
 			"Invalid used_file_size in header (%"PRIuUOFF_T")",
 			hdr->used_file_size);
@@ -243,7 +245,7 @@
 	return TRUE;
 }
 
-static int mmap_init_update(ModifyLogFile *file)
+static int mmap_init_update(struct modify_log_file *file)
 {
 	if (!mmap_update(file, TRUE))
 		return FALSE;
@@ -253,11 +255,11 @@
 	return TRUE;
 }
 
-static MailModifyLog *mail_modifylog_new(MailIndex *index)
+static struct mail_modify_log *mail_modifylog_new(struct mail_index *index)
 {
-	MailModifyLog *log;
+	struct mail_modify_log *log;
 
-	log = i_new(MailModifyLog, 1);
+	log = i_new(struct mail_modify_log, 1);
 	log->index = index;
 
 	log->file1.fd = -1;
@@ -273,7 +275,7 @@
 	return log;
 }
 
-static void modifylog_munmap(ModifyLogFile *file)
+static void modifylog_munmap(struct modify_log_file *file)
 {
 	if (file->anon_mmap) {
 		if (munmap_anon(file->mmap_base, file->mmap_full_length) < 0)
@@ -291,7 +293,7 @@
 	file->last_flags = NULL;
 }
 
-static void modifylog_close_file(ModifyLogFile *file)
+static void modifylog_close_file(struct modify_log_file *file)
 {
 	modifylog_munmap(file);
 
@@ -302,17 +304,18 @@
 	}
 }
 
-static void mail_modifylog_init_header(MailModifyLog *log, ModifyLogHeader *hdr)
+static void mail_modifylog_init_header(struct mail_modify_log *log,
+				       struct modify_log_header *hdr)
 {
-	memset(hdr, 0, sizeof(ModifyLogHeader));
+	memset(hdr, 0, sizeof(struct modify_log_header));
 	hdr->indexid = log->index->indexid;
-	hdr->used_file_size = sizeof(ModifyLogHeader);
+	hdr->used_file_size = sizeof(struct modify_log_header);
 }
 
-static int mail_modifylog_init_fd(ModifyLogFile *file, int fd)
+static int mail_modifylog_init_fd(struct modify_log_file *file, int fd)
 {
-	MailIndex *index = file->log->index;
-        ModifyLogHeader hdr;
+	struct mail_index *index = file->log->index;
+        struct modify_log_header hdr;
 
         mail_modifylog_init_header(file->log, &hdr);
 	if (write_full(fd, &hdr, sizeof(hdr)) < 0) {
@@ -334,18 +337,18 @@
 	return TRUE;
 }
 
-static int modifylog_mark_full(ModifyLogFile *file)
+static int modifylog_mark_full(struct modify_log_file *file)
 {
 	unsigned int sync_id = SYNC_ID_FULL;
 
 	if (file->mmap_base != NULL) {
 		file->header->sync_id = SYNC_ID_FULL;
 
-		if (msync(file->mmap_base, sizeof(ModifyLogHeader),
+		if (msync(file->mmap_base, sizeof(struct modify_log_header),
 			  MS_SYNC) < 0)
 			return modifylog_set_syscall_error(file, "msync()");
 	} else {
-		off_t offset = offsetof(ModifyLogHeader, sync_id);
+		off_t offset = offsetof(struct modify_log_header, sync_id);
 
 		if (lseek(file->fd, offset, SEEK_SET) < 0)
 			return modifylog_set_syscall_error(file, "lseek()");
@@ -360,9 +363,9 @@
 }
 
 /* Returns 1 = ok, 0 = can't lock file, -1 = error */
-static int modifylog_reuse_or_create_file(ModifyLogFile *file)
+static int modifylog_reuse_or_create_file(struct modify_log_file *file)
 {
-	MailIndex *index = file->log->index;
+	struct mail_index *index = file->log->index;
 	int fd, ret;
 
 	if (index->nodiskspace)
@@ -404,10 +407,10 @@
 }
 
 /* Returns 1 = ok, 0 = full, -1 = error */
-static int mail_modifylog_open_and_verify(ModifyLogFile *file)
+static int mail_modifylog_open_and_verify(struct modify_log_file *file)
 {
-	MailIndex *index = file->log->index;
-	ModifyLogHeader hdr;
+	struct mail_index *index = file->log->index;
+	struct modify_log_header hdr;
 	ssize_t ret;
 	int fd;
 
@@ -459,7 +462,7 @@
 	return ret;
 }
 
-static int modifylog_files_open_or_create(MailModifyLog *log)
+static int modifylog_files_open_or_create(struct mail_modify_log *log)
 {
 	int i, ret1, ret2;
 
@@ -513,7 +516,7 @@
 	return FALSE;
 }
 
-static void modifylog_create_anon(ModifyLogFile *file)
+static void modifylog_create_anon(struct modify_log_file *file)
 {
 	file->mmap_full_length = MODIFY_LOG_INITIAL_SIZE;
 	file->mmap_base = mmap_anon(file->mmap_full_length);
@@ -528,9 +531,9 @@
 	file->filepath = i_strdup("(in-memory modify log)");
 }
 
-int mail_modifylog_create(MailIndex *index)
+int mail_modifylog_create(struct mail_index *index)
 {
-	MailModifyLog *log;
+	struct mail_modify_log *log;
 	int ret;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
@@ -558,9 +561,9 @@
 	return TRUE;
 }
 
-int mail_modifylog_open_or_create(MailIndex *index)
+int mail_modifylog_open_or_create(struct mail_index *index)
 {
-	MailModifyLog *log;
+	struct mail_modify_log *log;
 
 	log = mail_modifylog_new(index);
 
@@ -574,7 +577,7 @@
 	return TRUE;
 }
 
-void mail_modifylog_free(MailModifyLog *log)
+void mail_modifylog_free(struct mail_modify_log *log)
 {
 	log->index->modifylog = NULL;
 
@@ -586,9 +589,9 @@
 	i_free(log);
 }
 
-int mail_modifylog_sync_file(MailModifyLog *log, int *fsync_fd)
+int mail_modifylog_sync_file(struct mail_modify_log *log, int *fsync_fd)
 {
-	ModifyLogFile *file = log->head;
+	struct modify_log_file *file = log->head;
 
 	*fsync_fd = -1;
 
@@ -605,16 +608,16 @@
 	return TRUE;
 }
 
-void mail_modifylog_notify_lock_drop(MailModifyLog *log)
+void mail_modifylog_notify_lock_drop(struct mail_modify_log *log)
 {
 	log->head->last_expunge = NULL;
 	log->head->last_flags = NULL;
 }
 
 /* if head file is closed, change it */
-static int modifylog_update_head(MailModifyLog *log)
+static int modifylog_update_head(struct mail_modify_log *log)
 {
-	ModifyLogFile *file;
+	struct modify_log_file *file;
 
 	if (!mmap_update(log->head, FALSE))
 		return FALSE;
@@ -639,12 +642,12 @@
 
 	/* we're non-synced */
 	file->synced_id = 0;
-	file->synced_position = sizeof(ModifyLogHeader);
+	file->synced_position = sizeof(struct modify_log_header);
 	log->head = file;
 	return TRUE;
 }
 
-static int mmap_update_both(MailModifyLog *log)
+static int mmap_update_both(struct mail_modify_log *log)
 {
 	if (!modifylog_update_head(log))
 		return FALSE;
@@ -657,7 +660,7 @@
 	return TRUE;
 }
 
-static int mail_modifylog_grow(ModifyLogFile *file)
+static int mail_modifylog_grow(struct modify_log_file *file)
 {
 	uoff_t new_fsize;
 	void *base;
@@ -692,10 +695,11 @@
 	return TRUE;
 }
 
-static int mail_modifylog_append(ModifyLogFile *file, ModifyLogRecord **rec,
+static int mail_modifylog_append(struct modify_log_file *file,
+				 struct modify_log_record **rec,
 				 int external_change)
 {
-	ModifyLogRecord *destrec;
+	struct modify_log_record *destrec;
 
 	i_assert(file->log->index->lock_type == MAIL_LOCK_EXCLUSIVE);
 	i_assert(file->header->sync_id != SYNC_ID_FULL);
@@ -720,20 +724,20 @@
 	}
 
 	i_assert(file->header->used_file_size == file->mmap_used_length);
-	i_assert(file->mmap_used_length + sizeof(ModifyLogRecord) <=
+	i_assert(file->mmap_used_length + sizeof(struct modify_log_record) <=
 		 file->mmap_full_length);
 
-	destrec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				       file->mmap_used_length);
-	memcpy(destrec, *rec, sizeof(ModifyLogRecord));
+	destrec = (struct modify_log_record *) ((char *) file->mmap_base +
+						file->mmap_used_length);
+	memcpy(destrec, *rec, sizeof(struct modify_log_record));
 
 	if (!external_change && file->header->sync_id == file->synced_id) {
-		file->synced_position += sizeof(ModifyLogRecord);
+		file->synced_position += sizeof(struct modify_log_record);
 		file->synced_id++;
 	}
 
-	file->header->used_file_size += sizeof(ModifyLogRecord);
-	file->mmap_used_length += sizeof(ModifyLogRecord);
+	file->header->used_file_size += sizeof(struct modify_log_record);
+	file->mmap_used_length += sizeof(struct modify_log_record);
 
 	file->header->sync_id++;
 	file->modified = TRUE;
@@ -742,11 +746,11 @@
 	return TRUE;
 }
 
-int mail_modifylog_add_expunge(MailModifyLog *log, unsigned int seq,
+int mail_modifylog_add_expunge(struct mail_modify_log *log, unsigned int seq,
 			       unsigned int uid, int external_change)
 {
-	ModifyLogFile *file;
-	ModifyLogRecord rec, *recp;
+	struct modify_log_file *file;
+	struct modify_log_record rec, *recp;
 
 	if (!modifylog_update_head(log))
 		return FALSE;
@@ -786,11 +790,11 @@
 	return TRUE;
 }
 
-int mail_modifylog_add_flags(MailModifyLog *log, unsigned int seq,
+int mail_modifylog_add_flags(struct mail_modify_log *log, unsigned int seq,
 			     unsigned int uid, int external_change)
 {
-	ModifyLogFile *file;
-	ModifyLogRecord rec, *recp;
+	struct modify_log_file *file;
+	struct modify_log_record rec, *recp;
 
 	if (!modifylog_update_head(log))
 		return FALSE;
@@ -823,26 +827,27 @@
 	return TRUE;
 }
 
-static void mail_modifylog_get_nonsynced_file(ModifyLogFile *file,
-					      const ModifyLogRecord **arr,
-					      unsigned int *count)
+static void
+mail_modifylog_get_nonsynced_file(struct modify_log_file *file,
+				  const struct modify_log_record **arr,
+				  unsigned int *count)
 {
-	ModifyLogRecord *end_rec;
+	struct modify_log_record *end_rec;
 
 	i_assert(file->synced_position <= file->mmap_used_length);
-	i_assert(file->synced_position >= sizeof(ModifyLogHeader));
+	i_assert(file->synced_position >= sizeof(struct modify_log_header));
 
-	*arr = (ModifyLogRecord *) ((char *) file->mmap_base +
-				    file->synced_position);
-	end_rec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				       file->mmap_used_length);
+	*arr = (struct modify_log_record *) ((char *) file->mmap_base +
+					     file->synced_position);
+	end_rec = (struct modify_log_record *) ((char *) file->mmap_base +
+						file->mmap_used_length);
 	*count = (unsigned int) (end_rec - *arr);
 }
 
-int mail_modifylog_get_nonsynced(MailModifyLog *log,
-				 const ModifyLogRecord **arr1,
+int mail_modifylog_get_nonsynced(struct mail_modify_log *log,
+				 const struct modify_log_record **arr1,
 				 unsigned int *count1,
-				 const ModifyLogRecord **arr2,
+				 const struct modify_log_record **arr2,
 				 unsigned int *count2)
 {
 	i_assert(log->index->lock_type != MAIL_LOCK_UNLOCK);
@@ -860,21 +865,22 @@
 	return TRUE;
 }
 
-static int mail_modifylog_try_truncate(ModifyLogFile *file)
+static int mail_modifylog_try_truncate(struct modify_log_file *file)
 {
 	if (modifylog_have_other_users(file->log, TRUE) != 0)
 		return FALSE;
 
 	file->header->sync_id = 0;
-	file->header->used_file_size = sizeof(ModifyLogHeader);
+	file->header->used_file_size = sizeof(struct modify_log_header);
 
-	if (msync(file->mmap_base, sizeof(ModifyLogHeader), MS_SYNC) < 0) {
+	if (msync(file->mmap_base,
+		  sizeof(struct modify_log_header), MS_SYNC) < 0) {
 		modifylog_set_syscall_error(file, "msync()");
 		return FALSE;
 	}
 
 	file->synced_id = 0;
-	file->synced_position = sizeof(ModifyLogHeader);
+	file->synced_position = sizeof(struct modify_log_header);
 
 	if (file_set_size(file->fd, MODIFY_LOG_INITIAL_SIZE) < 0)
 		modifylog_set_syscall_error(file, "file_set_size()");
@@ -883,9 +889,9 @@
 }
 
 /* switches to active modify log, updating our sync mark to end of it */
-static int mail_modifylog_switch_file(MailModifyLog *log)
+static int mail_modifylog_switch_file(struct mail_modify_log *log)
 {
-	ModifyLogFile *file;
+	struct modify_log_file *file;
 
 	(void)mail_modifylog_try_truncate(log->tail);
 
@@ -904,9 +910,9 @@
 	return mmap_init_update(log->head);
 }
 
-static int mail_modifylog_try_switch_file(MailModifyLog *log)
+static int mail_modifylog_try_switch_file(struct mail_modify_log *log)
 {
-	ModifyLogFile *file;
+	struct modify_log_file *file;
 
 	if (log->head->anon_mmap)
 		return TRUE;
@@ -932,7 +938,7 @@
 	return mmap_init_update(log->head);
 }
 
-int mail_modifylog_mark_synced(MailModifyLog *log)
+int mail_modifylog_mark_synced(struct mail_modify_log *log)
 {
 	i_assert(log->index->lock_type != MAIL_LOCK_UNLOCK);
 
@@ -960,29 +966,29 @@
 
 static int compare_expunge(const void *p1, const void *p2)
 {
-	const ModifyLogExpunge *e1 = p1;
-	const ModifyLogExpunge *e2 = p2;
+	const struct modify_log_expunge *e1 = p1;
+	const struct modify_log_expunge *e2 = p2;
 
 	return e1->uid1 < e2->uid1 ? -1 : e1->uid1 > e2->uid1 ? 1 : 0;
 }
 
-static ModifyLogRecord *modifylog_first(MailModifyLog *log)
+static struct modify_log_record *modifylog_first(struct mail_modify_log *log)
 {
-	ModifyLogFile *file;
-        ModifyLogRecord *rec;
+	struct modify_log_file *file;
+        struct modify_log_record *rec;
 
 	file = log->tail;
-	rec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				   file->synced_position);
-	log->iterator_end = (ModifyLogRecord *) ((char *) file->mmap_base +
-						 file->mmap_used_length);
+	rec = (struct modify_log_record *) ((char *) file->mmap_base +
+					    file->synced_position);
+	log->iterator_end = (struct modify_log_record *)
+		((char *) file->mmap_base + file->mmap_used_length);
 	return rec < log->iterator_end ? rec : NULL;
 }
 
-static ModifyLogRecord *modifylog_next(MailModifyLog *log,
-				       ModifyLogRecord *rec)
+static struct modify_log_record *
+modifylog_next(struct mail_modify_log *log, struct modify_log_record *rec)
 {
-	ModifyLogFile *file;
+	struct modify_log_file *file;
 
 	rec++;
 	if (rec < log->iterator_end)
@@ -993,15 +999,16 @@
 		return NULL; /* end of head */
 
 	/* end of tail, jump to beginning of head */
-	rec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				   sizeof(ModifyLogHeader));
-	log->iterator_end = (ModifyLogRecord *) ((char *) file->mmap_base +
-						 file->mmap_used_length);
+	rec = (struct modify_log_record *) ((char *) file->mmap_base +
+					    sizeof(struct modify_log_header));
+	log->iterator_end = (struct modify_log_record *)
+		((char *) file->mmap_base + file->mmap_used_length);
 	return rec < log->iterator_end ? rec : NULL;
 }
 
-static unsigned int modifylog_get_record_count_after(MailModifyLog *log,
-						     ModifyLogRecord *rec)
+static unsigned int
+modifylog_get_record_count_after(struct mail_modify_log *log,
+				 struct modify_log_record *rec)
 {
 	unsigned int count = 0;
 
@@ -1011,33 +1018,33 @@
 		/* only head */
 		count = (log->head->mmap_used_length -
 			 MODIFYLOG_FILE_POSITION(log->head, rec)) /
-			sizeof(ModifyLogRecord);
+			sizeof(struct modify_log_record);
 	} else {
 		/* tail */
 		count = (log->tail->mmap_used_length -
 			 MODIFYLOG_FILE_POSITION(log->tail, rec)) /
-			sizeof(ModifyLogRecord);
+			sizeof(struct modify_log_record);
 
 		if (log->head != log->tail) {
 			/* + head */
 			count += (log->tail->mmap_used_length -
-				  sizeof(ModifyLogHeader)) /
-				sizeof(ModifyLogRecord);
+				  sizeof(struct modify_log_header)) /
+				sizeof(struct modify_log_record);
 		}
 	}
 
 	return count;
 }
 
-const ModifyLogExpunge *
-mail_modifylog_seq_get_expunges(MailModifyLog *log,
+const struct modify_log_expunge *
+mail_modifylog_seq_get_expunges(struct mail_modify_log *log,
 				unsigned int first_seq,
 				unsigned int last_seq,
 				unsigned int *expunges_before)
 {
-	ModifyLogRecord *rec;
-	ModifyLogExpunge *expunge;
-	Buffer *buf;
+	struct modify_log_record *rec;
+	struct modify_log_expunge *expunge;
+	buffer_t *buf;
 	size_t count;
 	unsigned int before, max_records;
 
@@ -1070,9 +1077,10 @@
 	if (max_records > last_seq - first_seq + 1)
 		max_records = last_seq - first_seq + 1;
 
-	i_assert((max_records+1) < SSIZE_T_MAX/sizeof(ModifyLogExpunge));
+	i_assert((max_records+1) <
+		 SSIZE_T_MAX / sizeof(struct modify_log_expunge));
 	buf = buffer_create_static_hard(data_stack_pool, (max_records+1) *
-					sizeof(ModifyLogExpunge));
+					sizeof(struct modify_log_expunge));
 
 	before = 0;
 	for (; rec != NULL; rec = modifylog_next(log, rec)) {
@@ -1124,27 +1132,28 @@
 	memset(expunge, 0, sizeof(*expunge));
 
 	/* extract the array from buffer */
-	count = buffer_get_used_size(buf)/sizeof(ModifyLogExpunge);
+	count = buffer_get_used_size(buf)/sizeof(struct modify_log_expunge);
 	expunge = buffer_free_without_data(buf);
 
 	/* sort the UID array, not including the terminating 0 */
-	qsort(expunge, count-1, sizeof(ModifyLogExpunge), compare_expunge);
+	qsort(expunge, count-1, sizeof(struct modify_log_expunge),
+	      compare_expunge);
 
 	*expunges_before = before;
 	return expunge;
 }
 
-const ModifyLogExpunge *
-mail_modifylog_uid_get_expunges(MailModifyLog *log,
+const struct modify_log_expunge *
+mail_modifylog_uid_get_expunges(struct mail_modify_log *log,
 				unsigned int first_uid,
 				unsigned int last_uid,
 				unsigned int *expunges_before)
 {
 	/* pretty much copy&pasted from sequence code above ..
 	   kind of annoying */
-	ModifyLogRecord *rec;
-	ModifyLogExpunge *expunge;
-	Buffer *buf;
+	struct modify_log_record *rec;
+	struct modify_log_expunge *expunge;
+	buffer_t *buf;
 	size_t count;
 	unsigned int before, max_records;
 
@@ -1177,9 +1186,10 @@
 	if (max_records > last_uid - first_uid + 1)
 		max_records = last_uid - first_uid + 1;
 
-	i_assert((max_records+1) < SSIZE_T_MAX/sizeof(ModifyLogExpunge));
+	i_assert((max_records+1) <
+		 SSIZE_T_MAX / sizeof(struct modify_log_expunge));
 	buf = buffer_create_static_hard(data_stack_pool, (max_records+1) *
-					sizeof(ModifyLogExpunge));
+					sizeof(struct modify_log_expunge));
 
 	before = 0;
 	for (; rec != NULL; rec = modifylog_next(log, rec)) {
@@ -1212,26 +1222,28 @@
 	memset(expunge, 0, sizeof(*expunge));
 
 	/* extract the array from buffer */
-	count = buffer_get_used_size(buf)/sizeof(ModifyLogExpunge);
+	count = buffer_get_used_size(buf) / sizeof(struct modify_log_expunge);
 	expunge = buffer_free_without_data(buf);
 
 	/* sort the UID array, not including the terminating 0 */
-	qsort(expunge, count-1, sizeof(ModifyLogExpunge), compare_expunge);
+	qsort(expunge, count-1, sizeof(struct modify_log_expunge),
+	      compare_expunge);
 
 	*expunges_before = before;
 	return expunge;
 }
 
-static unsigned int modifylog_file_get_expunge_count(ModifyLogFile *file)
+static unsigned int
+modifylog_file_get_expunge_count(struct modify_log_file *file)
 {
-	ModifyLogRecord *rec, *end_rec;
+	struct modify_log_record *rec, *end_rec;
 	unsigned int expunges;
 
 	/* find the first expunged message that affects our range */
-	rec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				   file->synced_position);
-	end_rec = (ModifyLogRecord *) ((char *) file->mmap_base +
-				       file->mmap_used_length);
+	rec = (struct modify_log_record *) ((char *) file->mmap_base +
+					    file->synced_position);
+	end_rec = (struct modify_log_record *) ((char *) file->mmap_base +
+						file->mmap_used_length);
 
 	expunges = 0;
 	while (rec < end_rec) {
@@ -1243,7 +1255,7 @@
 	return expunges;
 }
 
-unsigned int mail_modifylog_get_expunge_count(MailModifyLog *log)
+unsigned int mail_modifylog_get_expunge_count(struct mail_modify_log *log)
 {
 	unsigned int expunges;
 
--- a/src/lib-index/mail-modifylog.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-modifylog.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,67 +1,63 @@
 #ifndef __MAIL_MODIFYLOG_H
 #define __MAIL_MODIFYLOG_H
 
-typedef enum {
+enum modify_log_record_type {
 	RECORD_TYPE_EXPUNGE,
 	RECORD_TYPE_FLAGS_CHANGED
-} ModifyLogRecordType;
-
-typedef struct _ModifyLogHeader ModifyLogHeader;
-typedef struct _ModifyLogRecord ModifyLogRecord;
-typedef struct _ModifyLogExpunge ModifyLogExpunge;
+};
 
 /* if sync_id has this value, the log file is full and should be
    deleted or reused. */
 #define SYNC_ID_FULL ((unsigned int)-1)
 
-struct _ModifyLogHeader {
+struct modify_log_header {
 	unsigned int indexid;
 	unsigned int sync_id;
 	uoff_t used_file_size;
 };
 
-struct _ModifyLogRecord {
+struct modify_log_record {
 	unsigned int type;
 	unsigned int seq1, seq2;
 	unsigned int uid1, uid2;
 };
 
 /* for mail_modifylog_*_get_expunges() */
-struct _ModifyLogExpunge {
+struct modify_log_expunge {
 	unsigned int uid1, uid2; /* NOTE: may be outside wanted range */
 	unsigned int seq_count;
 };
 
 /* NOTE: All these functions require the index file to be locked. */
 
-int mail_modifylog_create(MailIndex *index);
-int mail_modifylog_open_or_create(MailIndex *index);
-void mail_modifylog_free(MailModifyLog *log);
+int mail_modifylog_create(struct mail_index *index);
+int mail_modifylog_open_or_create(struct mail_index *index);
+void mail_modifylog_free(struct mail_modify_log *log);
 
 /* Append EXPUGE or FLAGS entry to modify log. Index must be exclusively
    locked before calling these functions, and modifylog must have been
    marked synced within the same lock. */
-int mail_modifylog_add_expunge(MailModifyLog *log, unsigned int seq,
+int mail_modifylog_add_expunge(struct mail_modify_log *log, unsigned int seq,
 			       unsigned int uid, int external_change);
-int mail_modifylog_add_flags(MailModifyLog *log, unsigned int seq,
+int mail_modifylog_add_flags(struct mail_modify_log *log, unsigned int seq,
 			     unsigned int uid, int external_change);
 
 /* Synchronize the data into disk */
-int mail_modifylog_sync_file(MailModifyLog *log, int *fsync_fd);
+int mail_modifylog_sync_file(struct mail_modify_log *log, int *fsync_fd);
 
 /* Must be called when exclusive lock is dropped from index. */
-void mail_modifylog_notify_lock_drop(MailModifyLog *log);
+void mail_modifylog_notify_lock_drop(struct mail_modify_log *log);
 
 /* Updates arr and count parameters to list nonsynced log entries.
    Returns TRUE if successful. */
-int mail_modifylog_get_nonsynced(MailModifyLog *log,
-				 const ModifyLogRecord **arr1,
+int mail_modifylog_get_nonsynced(struct mail_modify_log *log,
+				 const struct modify_log_record **arr1,
 				 unsigned int *count1,
-				 const ModifyLogRecord **arr2,
+				 const struct modify_log_record **arr2,
 				 unsigned int *count2);
 
 /* Marks the modify log as being synced with in-memory state. */
-int mail_modifylog_mark_synced(MailModifyLog *log);
+int mail_modifylog_mark_synced(struct mail_modify_log *log);
 
 /* Finds expunged messages for the given sequence range, and number of
    expunged messages before the range. Returns 0,0 terminated list of
@@ -74,8 +70,8 @@
 
    Also the last expunge record's both uid and seq_count ranges may go
    past last_seq */
-const ModifyLogExpunge *
-mail_modifylog_seq_get_expunges(MailModifyLog *log,
+const struct modify_log_expunge *
+mail_modifylog_seq_get_expunges(struct mail_modify_log *log,
 				unsigned int first_seq,
 				unsigned int last_seq,
 				unsigned int *expunges_before);
@@ -87,13 +83,13 @@
    expunges_before=0, {uid1=1, uid2=9, seq_count=9} if only message 10
    exists. This is because we have no idea how many messages there are
    between UIDs since they're not guaranteed to be contiguous. */
-const ModifyLogExpunge *
-mail_modifylog_uid_get_expunges(MailModifyLog *log,
+const struct modify_log_expunge *
+mail_modifylog_uid_get_expunges(struct mail_modify_log *log,
 				unsigned int first_uid,
 				unsigned int last_uid,
 				unsigned int *expunges_before);
 
 /* Get number of non-synced expunges in modify log. */
-unsigned int mail_modifylog_get_expunge_count(MailModifyLog *log);
+unsigned int mail_modifylog_get_expunge_count(struct mail_modify_log *log);
 
 #endif
--- a/src/lib-index/mail-tree-redblack.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-tree-redblack.c	Sun Jan 05 15:09:51 2003 +0200
@@ -84,7 +84,7 @@
 */
 
 static unsigned int
-rb_alloc(MailTree *tree)
+rb_alloc(struct mail_tree *tree)
 {
 	unsigned int x;
 
@@ -94,23 +94,23 @@
 	}
 
 	i_assert(tree->header->used_file_size == tree->mmap_used_length);
-	i_assert(tree->mmap_used_length + sizeof(MailTreeNode) <=
+	i_assert(tree->mmap_used_length + sizeof(struct mail_tree_node) <=
 		 tree->mmap_full_length);
 
-	x = (tree->mmap_used_length - sizeof(MailTreeHeader)) /
-		sizeof(MailTreeNode);
+	x = (tree->mmap_used_length - sizeof(struct mail_tree_header)) /
+		sizeof(struct mail_tree_node);
 
-	tree->header->used_file_size += sizeof(MailTreeNode);
-	tree->mmap_used_length += sizeof(MailTreeNode);
+	tree->header->used_file_size += sizeof(struct mail_tree_node);
+	tree->mmap_used_length += sizeof(struct mail_tree_node);
 
-	memset(&tree->node_base[x], 0, sizeof(MailTreeNode));
+	memset(&tree->node_base[x], 0, sizeof(struct mail_tree_node));
 	return x;
 }
 
 static void
-rb_move(MailTree *tree, unsigned int src, unsigned int dest)
+rb_move(struct mail_tree *tree, unsigned int src, unsigned int dest)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 
 	/* update parent */
 	if (node[src].up != RBNULL) {
@@ -130,21 +130,22 @@
 	if (tree->header->root == src)
 		tree->header->root = dest;
 
-	memcpy(&node[dest], &node[src], sizeof(MailTreeNode));
-	memset(&node[src], 0, sizeof(MailTreeNode));
+	memcpy(&node[dest], &node[src], sizeof(struct mail_tree_node));
+	memset(&node[src], 0, sizeof(struct mail_tree_node));
 }
 
 static void
-rb_free(MailTree *tree, unsigned int x)
+rb_free(struct mail_tree *tree, unsigned int x)
 {
 	unsigned int last;
 
 	i_assert(tree->mmap_used_length >=
-		 sizeof(MailTreeHeader) + sizeof(MailTreeNode));
+		 sizeof(struct mail_tree_header) +
+		 sizeof(struct mail_tree_node));
 
 	/* get index to last used record */
-	last = (tree->mmap_used_length - sizeof(MailTreeHeader)) /
-		sizeof(MailTreeNode) - 1;
+	last = (tree->mmap_used_length - sizeof(struct mail_tree_header)) /
+		sizeof(struct mail_tree_node) - 1;
 
 	if (last != x) {
 		/* move it over the one we want free'd */
@@ -152,8 +153,8 @@
 	}
 
 	/* mark the moved node unused */
-	tree->mmap_used_length -= sizeof(MailTreeNode);
-	tree->header->used_file_size -= sizeof(MailTreeNode);
+	tree->mmap_used_length -= sizeof(struct mail_tree_node);
+	tree->header->used_file_size -= sizeof(struct mail_tree_node);
 
 	_mail_tree_truncate(tree);
 }
@@ -177,9 +178,9 @@
 */
 
 static void
-rb_left_rotate(MailTree *tree, unsigned int x)
+rb_left_rotate(struct mail_tree *tree, unsigned int x)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 	unsigned int y, a_nodes, c_nodes;
 
 	i_assert(x != RBNULL);
@@ -222,9 +223,9 @@
 }
 
 static void
-rb_right_rotate(MailTree *tree, unsigned int y)
+rb_right_rotate(struct mail_tree *tree, unsigned int y)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 	unsigned int x, a_nodes, c_nodes;
 
 	i_assert(y != RBNULL);
@@ -269,9 +270,9 @@
 /* Return index to the smallest key greater than x
 */
 static unsigned int 
-rb_successor(MailTree *tree, unsigned int x)
+rb_successor(struct mail_tree *tree, unsigned int x)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 	unsigned int y;
 
 	if (node[x].right != RBNULL) {
@@ -299,9 +300,9 @@
 
 /* Restore the reb-black properties after insert */
 static int
-rb_insert_fix(MailTree *tree, unsigned int z)
+rb_insert_fix(struct mail_tree *tree, unsigned int z)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 	unsigned int x, y, x_up_up;
 
 	/* color this new node red */
@@ -380,9 +381,9 @@
 
 /* Restore the reb-black properties after a delete */
 static void
-rb_delete_fix(MailTree *tree, unsigned int x)
+rb_delete_fix(struct mail_tree *tree, unsigned int x)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
 	unsigned int w;
 
 	while (x != tree->header->root && IS_NODE_BLACK(node[x])) {
@@ -490,9 +491,9 @@
 /* Delete the node z, and free up the space
 */
 static void
-rb_delete(MailTree *tree, unsigned int z)
+rb_delete(struct mail_tree *tree, unsigned int z)
 {
-	MailTreeNode *node = tree->node_base;
+	struct mail_tree_node *node = tree->node_base;
         unsigned int x, y, b;
 
 	if (node[z].left == RBNULL || node[z].right == RBNULL) {
@@ -550,9 +551,9 @@
 
 #ifdef DEBUG_TREE
 int
-rb_check1(MailTree *tree, unsigned int x)
+rb_check1(struct mail_tree *tree, unsigned int x)
 {
-        MailTreeNode *node = tree->node_base;
+        struct mail_tree_node *node = tree->node_base;
 
 	if (IS_NODE_RED(node[x])) {
 		if (!IS_NODE_BLACK(node[node[x].left]) ||
@@ -585,9 +586,9 @@
 	return 0;
 }
 
-int count_black(MailTree *tree, unsigned int x)
+int count_black(struct mail_tree *tree, unsigned int x)
 {
-        MailTreeNode *node = tree->node_base;
+        struct mail_tree_node *node = tree->node_base;
 	int nleft, nright;
 
 	if (x == RBNULL)
@@ -610,9 +611,9 @@
 	return nleft;
 }
 
-int count_nodes(MailTree *tree, unsigned int x)
+int count_nodes(struct mail_tree *tree, unsigned int x)
 {
-        MailTreeNode *node = tree->node_base;
+        struct mail_tree_node *node = tree->node_base;
 	int nleft, nright;
 
 	if (x == RBNULL)
@@ -633,9 +634,9 @@
 	return nleft+nright+1;
 }
 
-void dumptree(MailTree *tree, unsigned int x, int n)
+void dumptree(struct mail_tree *tree, unsigned int x, int n)
 {
-        MailTreeNode *node = tree->node_base;
+        struct mail_tree_node *node = tree->node_base;
 
 	if (x != RBNULL) {
 		n++;
@@ -651,9 +652,9 @@
 }
 
 int
-rb_check(MailTree *tree)
+rb_check(struct mail_tree *tree)
 {
-        MailTreeNode *node = tree->node_base;
+        struct mail_tree_node *node = tree->node_base;
 	unsigned int root;
 
 	root = tree->header->root;
@@ -685,11 +686,12 @@
 }
 #endif
 
-unsigned int mail_tree_lookup_uid_range(MailTree *tree, unsigned int *seq_r,
+unsigned int mail_tree_lookup_uid_range(struct mail_tree *tree,
+					unsigned int *seq_r,
 					unsigned int first_uid,
 					unsigned int last_uid)
 {
-	MailTreeNode *node;
+	struct mail_tree_node *node;
 	unsigned int x, y, seq;
 
 	i_assert(first_uid > 0 && last_uid > 0);
@@ -746,9 +748,9 @@
 	return x == RBNULL ? (unsigned int)-1 : node[x].value;
 }
 
-unsigned int mail_tree_lookup_sequence(MailTree *tree, unsigned int seq)
+unsigned int mail_tree_lookup_sequence(struct mail_tree *tree, unsigned int seq)
 {
-        MailTreeNode *node;
+        struct mail_tree_node *node;
 	unsigned int x, upleft_nodes, left_nodes;
 
 	i_assert(seq != 0);
@@ -782,9 +784,10 @@
 	return (unsigned int)-1;
 }
 
-int mail_tree_insert(MailTree *tree, unsigned int uid, unsigned int index)
+int mail_tree_insert(struct mail_tree *tree,
+		     unsigned int uid, unsigned int index)
 {
-        MailTreeNode *node;
+        struct mail_tree_node *node;
 	unsigned int x, z;
 
 	i_assert(uid != 0);
@@ -841,9 +844,10 @@
 	return TRUE;
 }
 
-int mail_tree_update(MailTree *tree, unsigned int uid, unsigned int index)
+int mail_tree_update(struct mail_tree *tree,
+		     unsigned int uid, unsigned int index)
 {
-	MailTreeNode *node;
+	struct mail_tree_node *node;
 	unsigned int x;
 
 	i_assert(uid != 0);
@@ -875,9 +879,9 @@
 	return FALSE;
 }
 
-void mail_tree_delete(MailTree *tree, unsigned int uid)
+void mail_tree_delete(struct mail_tree *tree, unsigned int uid)
 {
-	MailTreeNode *node;
+	struct mail_tree_node *node;
 	unsigned int x;
 
 	i_assert(uid != 0);
--- a/src/lib-index/mail-tree.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-tree.c	Sun Jan 05 15:09:51 2003 +0200
@@ -12,10 +12,10 @@
 #include <fcntl.h>
 
 #define MAIL_TREE_MIN_SIZE \
-	(sizeof(MailTreeHeader) + \
-	 INDEX_MIN_RECORDS_COUNT * sizeof(MailTreeNode))
+	(sizeof(struct mail_tree_header) + \
+	 INDEX_MIN_RECORDS_COUNT * sizeof(struct mail_tree_node))
 
-static int tree_set_syscall_error(MailTree *tree, const char *function)
+static int tree_set_syscall_error(struct mail_tree *tree, const char *function)
 {
 	i_assert(function != NULL);
 
@@ -24,7 +24,7 @@
 	return FALSE;
 }
 
-int _mail_tree_set_corrupted(MailTree *tree, const char *fmt, ...)
+int _mail_tree_set_corrupted(struct mail_tree *tree, const char *fmt, ...)
 {
 	va_list va;
 
@@ -44,7 +44,7 @@
 	return FALSE;
 }
 
-static int mmap_update(MailTree *tree)
+static int mmap_update(struct mail_tree *tree)
 {
 	i_assert(!tree->anon_mmap);
 
@@ -73,21 +73,21 @@
 	return TRUE;
 }
 
-static int mmap_verify(MailTree *tree)
+static int mmap_verify(struct mail_tree *tree)
 {
-	MailTreeHeader *hdr;
+	struct mail_tree_header *hdr;
 	unsigned int extra;
 
 	if (tree->mmap_full_length <
-	    sizeof(MailTreeHeader) + sizeof(MailTreeNode)) {
+	    sizeof(struct mail_tree_header) + sizeof(struct mail_tree_node)) {
 		index_set_error(tree->index, "Too small binary tree file %s",
 				tree->filepath);
 		(void)unlink(tree->filepath);
 		return FALSE;
 	}
 
-	extra = (tree->mmap_full_length - sizeof(MailTreeHeader)) %
-		sizeof(MailTreeNode);
+	extra = (tree->mmap_full_length - sizeof(struct mail_tree_header)) %
+		sizeof(struct mail_tree_node);
 
 	if (extra != 0) {
 		/* partial write or corrupted -
@@ -106,8 +106,8 @@
 		return FALSE;
 	}
 
-	if ((hdr->used_file_size - sizeof(MailTreeHeader)) %
-	    sizeof(MailTreeNode) != 0) {
+	if ((hdr->used_file_size - sizeof(struct mail_tree_header)) %
+	    sizeof(struct mail_tree_node) != 0) {
 		_mail_tree_set_corrupted(tree,
 			"Invalid used_file_size in header (%"PRIuUOFF_T")",
 			hdr->used_file_size);
@@ -115,15 +115,15 @@
 	}
 
 	tree->header = tree->mmap_base;
-	tree->node_base = (MailTreeNode *) ((char *) tree->mmap_base +
-					    sizeof(MailTreeHeader));
+	tree->node_base = (struct mail_tree_node *)
+		((char *) tree->mmap_base + sizeof(struct mail_tree_header));
 	tree->sync_id = hdr->sync_id;
 	tree->mmap_used_length = hdr->used_file_size;
 	tree->mmap_highwater = tree->mmap_used_length;
 	return TRUE;
 }
 
-int _mail_tree_mmap_update(MailTree *tree, int forced)
+int _mail_tree_mmap_update(struct mail_tree *tree, int forced)
 {
 	debug_mprotect(tree->mmap_base, tree->mmap_full_length,
 		       tree->index);
@@ -143,9 +143,9 @@
 	return mmap_update(tree) && mmap_verify(tree);
 }
 
-static MailTree *mail_tree_open(MailIndex *index)
+static struct mail_tree *mail_tree_open(struct mail_index *index)
 {
-	MailTree *tree;
+	struct mail_tree *tree;
 	const char *path;
 	int fd;
 
@@ -159,7 +159,7 @@
 		return NULL;
 	}
 
-	tree = i_new(MailTree, 1);
+	tree = i_new(struct mail_tree, 1);
 	tree->fd = fd;
 	tree->index = index;
 	tree->filepath = i_strdup(path);
@@ -168,11 +168,11 @@
 	return tree;
 }
 
-static MailTree *mail_tree_create_anon(MailIndex *index)
+static struct mail_tree *mail_tree_create_anon(struct mail_index *index)
 {
-	MailTree *tree;
+	struct mail_tree *tree;
 
-	tree = i_new(MailTree, 1);
+	tree = i_new(struct mail_tree, 1);
 	tree->anon_mmap = TRUE;
 	tree->fd = -1;
 	tree->index = index;
@@ -182,9 +182,9 @@
 	return tree;
 }
 
-int mail_tree_create(MailIndex *index)
+int mail_tree_create(struct mail_index *index)
 {
-	MailTree *tree;
+	struct mail_tree *tree;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
@@ -201,7 +201,7 @@
 	return TRUE;
 }
 
-static int mail_tree_open_init(MailTree *tree)
+static int mail_tree_open_init(struct mail_tree *tree)
 {
 	if (!mmap_update(tree))
 		return FALSE;
@@ -227,9 +227,9 @@
 	return TRUE;
 }
 
-int mail_tree_open_or_create(MailIndex *index)
+int mail_tree_open_or_create(struct mail_index *index)
 {
-	MailTree *tree;
+	struct mail_tree *tree;
 
 	tree = mail_tree_open(index);
 	if (tree == NULL)
@@ -254,7 +254,7 @@
 	return TRUE;
 }
 
-static void mail_tree_close(MailTree *tree)
+static void mail_tree_close(struct mail_tree *tree)
 {
 	if (tree->anon_mmap) {
 		if (munmap_anon(tree->mmap_base, tree->mmap_full_length) < 0)
@@ -277,7 +277,7 @@
 	i_free(tree->filepath);
 }
 
-void mail_tree_free(MailTree *tree)
+void mail_tree_free(struct mail_tree *tree)
 {
 	tree->index->tree = NULL;
 
@@ -285,19 +285,20 @@
 	i_free(tree);
 }
 
-static int mail_tree_init(MailTree *tree)
+static int mail_tree_init(struct mail_tree *tree)
 {
-        MailTreeHeader hdr;
+        struct mail_tree_header hdr;
 
 	/* first node is always used, and is the RBNULL node */
-	memset(&hdr, 0, sizeof(MailTreeHeader));
+	memset(&hdr, 0, sizeof(struct mail_tree_header));
 	hdr.indexid = tree->index->indexid;
-	hdr.used_file_size = sizeof(MailTreeHeader) + sizeof(MailTreeNode);
+	hdr.used_file_size = sizeof(struct mail_tree_header) +
+		sizeof(struct mail_tree_node);
 
 	if (tree->anon_mmap) {
 		tree->mmap_full_length = MAIL_TREE_MIN_SIZE;
 		tree->mmap_base = mmap_anon(tree->mmap_full_length);
-		memcpy(tree->mmap_base, &hdr, sizeof(MailTreeHeader));
+		memcpy(tree->mmap_base, &hdr, sizeof(struct mail_tree_header));
 		return mmap_verify(tree);
 	}
 
@@ -321,9 +322,9 @@
 	return TRUE;
 }
 
-int mail_tree_rebuild(MailTree *tree)
+int mail_tree_rebuild(struct mail_tree *tree)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 
 	if (!tree->index->set_lock(tree->index, MAIL_LOCK_EXCLUSIVE))
 		return FALSE;
@@ -349,7 +350,7 @@
 	return TRUE;
 }
 
-int mail_tree_sync_file(MailTree *tree, int *fsync_fd)
+int mail_tree_sync_file(struct mail_tree *tree, int *fsync_fd)
 {
 	*fsync_fd = -1;
 
@@ -368,7 +369,7 @@
 	return TRUE;
 }
 
-int _mail_tree_grow(MailTree *tree)
+int _mail_tree_grow(struct mail_tree *tree)
 {
 	uoff_t new_fsize;
 	unsigned int grow_count;
@@ -380,7 +381,7 @@
 		grow_count = 16;
 
 	new_fsize = (uoff_t)tree->mmap_full_length +
-		(grow_count * sizeof(MailTreeNode));
+		(grow_count * sizeof(struct mail_tree_node));
 	i_assert(new_fsize < OFF_T_MAX);
 
 	if (tree->anon_mmap) {
@@ -413,7 +414,7 @@
 	return TRUE;
 }
 
-void _mail_tree_truncate(MailTree *tree)
+void _mail_tree_truncate(struct mail_tree *tree)
 {
 	/* pretty much copy&pasted from mail_index_compress() */
 	uoff_t empty_space, truncate_threshold;
@@ -433,9 +434,9 @@
 			(empty_space * INDEX_TRUNCATE_KEEP_PERCENTAGE / 100);
 
 		/* keep the size record-aligned */
-		tree->mmap_full_length -=
-			(tree->mmap_full_length - sizeof(MailTreeHeader)) %
-			sizeof(MailTreeNode);
+		tree->mmap_full_length -= (tree->mmap_full_length -
+					   sizeof(struct mail_tree_header)) %
+			sizeof(struct mail_tree_node);
 
 		if (tree->mmap_full_length < MAIL_TREE_MIN_SIZE)
 			tree->mmap_full_length = MAIL_TREE_MIN_SIZE;
--- a/src/lib-index/mail-tree.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mail-tree.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,29 +1,26 @@
 #ifndef __MAIL_TREE_H
 #define __MAIL_TREE_H
 
-typedef struct _MailTreeHeader MailTreeHeader;
-typedef struct _MailTreeNode MailTreeNode;
-
-struct _MailTree {
-	MailIndex *index;
+struct mail_tree {
+	struct mail_index *index;
 
 	int fd;
 	char *filepath;
 
 	void *mmap_base;
-	MailTreeNode *node_base;
+	struct mail_tree_node *node_base;
 	size_t mmap_used_length;
 	size_t mmap_full_length;
 	size_t mmap_highwater; /* for msync()ing */
 
-        MailTreeHeader *header;
+        struct mail_tree_header *header;
 	unsigned int sync_id;
 
 	unsigned int anon_mmap:1;
 	unsigned int modified:1;
 };
 
-struct _MailTreeHeader {
+struct mail_tree_header {
 	unsigned int indexid;
 	unsigned int sync_id;
 
@@ -32,7 +29,7 @@
 	unsigned int root;
 };
 
-struct _MailTreeNode {
+struct mail_tree_node {
 	unsigned int left;
 	unsigned int right;
 	unsigned int up;
@@ -46,35 +43,39 @@
 	unsigned int value;
 };
 
-int mail_tree_create(MailIndex *index);
-int mail_tree_open_or_create(MailIndex *index);
-void mail_tree_free(MailTree *tree);
+int mail_tree_create(struct mail_index *index);
+int mail_tree_open_or_create(struct mail_index *index);
+void mail_tree_free(struct mail_tree *tree);
 
-int mail_tree_rebuild(MailTree *tree);
-int mail_tree_sync_file(MailTree *tree, int *fsync_fd);
+int mail_tree_rebuild(struct mail_tree *tree);
+int mail_tree_sync_file(struct mail_tree *tree, int *fsync_fd);
 
 /* Find first existing UID in range. Returns (unsigned int)-1 if not found. */
-unsigned int mail_tree_lookup_uid_range(MailTree *tree, unsigned int *seq_r,
+unsigned int mail_tree_lookup_uid_range(struct mail_tree *tree,
+					unsigned int *seq_r,
 					unsigned int first_uid,
 					unsigned int last_uid);
 
 /* Find message by sequence number. Returns (unsigned int)-1 if not found. */
-unsigned int mail_tree_lookup_sequence(MailTree *tree, unsigned int seq);
+unsigned int mail_tree_lookup_sequence(struct mail_tree *tree,
+				       unsigned int seq);
 
 /* Insert a new record in tree. */
-int mail_tree_insert(MailTree *tree, unsigned int uid, unsigned int index);
+int mail_tree_insert(struct mail_tree *tree,
+		     unsigned int uid, unsigned int index);
 
 /* Update existing record in tree. */
-int mail_tree_update(MailTree *tree, unsigned int uid, unsigned int index);
+int mail_tree_update(struct mail_tree *tree,
+		     unsigned int uid, unsigned int index);
 
 /* Delete record from tree. */
-void mail_tree_delete(MailTree *tree, unsigned int uid);
+void mail_tree_delete(struct mail_tree *tree, unsigned int uid);
 
 /* private: */
-int _mail_tree_set_corrupted(MailTree *tree, const char *fmt, ...)
+int _mail_tree_set_corrupted(struct mail_tree *tree, const char *fmt, ...)
 	__attr_format__(2, 3);
-int _mail_tree_mmap_update(MailTree *tree, int forced);
-int _mail_tree_grow(MailTree *tree);
-void _mail_tree_truncate(MailTree *tree);
+int _mail_tree_mmap_update(struct mail_tree *tree, int forced);
+int _mail_tree_grow(struct mail_tree *tree);
+void _mail_tree_truncate(struct mail_tree *tree);
 
 #endif
--- a/src/lib-index/maildir/maildir-build.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/maildir/maildir-build.c	Sun Jan 05 15:09:51 2003 +0200
@@ -11,10 +11,11 @@
 #include <dirent.h>
 #include <sys/stat.h>
 
-static int maildir_index_append_fd(MailIndex *index, int fd, const char *fname)
+static int maildir_index_append_fd(struct mail_index *index,
+				   int fd, const char *fname)
 {
-	MailIndexRecord *rec;
-	MailIndexUpdate *update;
+	struct mail_index_record *rec;
+	struct mail_index_update *update;
 	struct stat st;
 	uoff_t virtual_size;
 	const char *p;
@@ -71,7 +72,7 @@
 	return index->append_end(index, rec);
 }
 
-int maildir_index_append_file(MailIndex *index, const char *dir,
+int maildir_index_append_file(struct mail_index *index, const char *dir,
 			      const char *fname)
 {
 	const char *path;
@@ -100,7 +101,7 @@
 	return ret;
 }
 
-int maildir_index_build_dir(MailIndex *index, const char *source_dir,
+int maildir_index_build_dir(struct mail_index *index, const char *source_dir,
 			    const char *dest_dir)
 {
 	DIR *dirp;
--- a/src/lib-index/maildir/maildir-index.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/maildir/maildir-index.c	Sun Jan 05 15:09:51 2003 +0200
@@ -9,12 +9,13 @@
 #include <stdio.h>
 #include <sys/stat.h>
 
-extern MailIndex maildir_index;
+extern struct mail_index maildir_index;
 
-MailFlags maildir_filename_get_flags(const char *fname, MailFlags default_flags)
+enum mail_flags maildir_filename_get_flags(const char *fname,
+					   enum mail_flags default_flags)
 {
 	const char *info;
-	MailFlags flags;
+	enum mail_flags flags;
 
 	info = strchr(fname, ':');
 	if (info == NULL || info[1] != '2' || info[2] != ',')
@@ -54,9 +55,9 @@
 	return flags;
 }
 
-const char *maildir_filename_set_flags(const char *fname, MailFlags flags)
+const char *maildir_filename_set_flags(const char *fname, enum mail_flags flags)
 {
-	String *flags_str;
+	string_t *flags_str;
 	const char *info, *oldflags;
 	int i, nextflag;
 
@@ -133,22 +134,22 @@
 	return str_c(flags_str);
 }
 
-MailIndex *maildir_index_alloc(const char *dir, const char *maildir)
+struct mail_index *maildir_index_alloc(const char *dir, const char *maildir)
 {
-	MailIndex *index;
+	struct mail_index *index;
 
 	i_assert(dir != NULL);
 	i_assert(maildir != NULL);
 
-	index = i_new(MailIndex, 1);
-	memcpy(index, &maildir_index, sizeof(MailIndex));
+	index = i_new(struct mail_index, 1);
+	memcpy(index, &maildir_index, sizeof(struct mail_index));
 
 	index->mailbox_path = i_strdup(maildir);
 	mail_index_init(index, dir);
 	return index;
 }
 
-static void maildir_index_free(MailIndex *index)
+static void maildir_index_free(struct mail_index *index)
 {
 	mail_index_close(index);
 	i_free(index->dir);
@@ -156,7 +157,8 @@
 	i_free(index);
 }
 
-static time_t maildir_get_internal_date(MailIndex *index, MailIndexRecord *rec)
+static time_t maildir_get_internal_date(struct mail_index *index,
+					struct mail_index_record *rec)
 {
 	struct stat st;
 	const char *fname;
@@ -183,11 +185,12 @@
 	return st.st_mtime;
 }
 
-static int maildir_index_update_flags(MailIndex *index, MailIndexRecord *rec,
-				      unsigned int seq, MailFlags flags,
+static int maildir_index_update_flags(struct mail_index *index,
+				      struct mail_index_record *rec,
+				      unsigned int seq, enum mail_flags flags,
 				      int external_change)
 {
-	MailIndexUpdate *update;
+	struct mail_index_update *update;
 	const char *old_fname, *new_fname;
 	const char *old_path, *new_path;
 
@@ -232,7 +235,7 @@
 	return TRUE;
 }
 
-MailIndex maildir_index = {
+struct mail_index maildir_index = {
 	mail_index_open,
 	mail_index_open_or_create,
 	maildir_index_free,
--- a/src/lib-index/maildir/maildir-index.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/maildir/maildir-index.h	Sun Jan 05 15:09:51 2003 +0200
@@ -6,23 +6,27 @@
 /* ":2,DFRST" - leave the 2 extra for other clients' additions */
 #define MAILDIR_LOCATION_EXTRA_SPACE 10
 
-MailIndex *maildir_index_alloc(const char *dir, const char *maildir);
+struct mail_index *maildir_index_alloc(const char *dir, const char *maildir);
 
-MailFlags maildir_filename_get_flags(const char *fname,
-				     MailFlags default_flags);
-const char *maildir_filename_set_flags(const char *fname, MailFlags flags);
+enum mail_flags maildir_filename_get_flags(const char *fname,
+					   enum mail_flags default_flags);
+const char *maildir_filename_set_flags(const char *fname,
+				       enum mail_flags flags);
 
-int maildir_index_rebuild(MailIndex *index);
-int maildir_index_sync(MailIndex *index, MailLockType lock_type, int *changes);
+int maildir_index_rebuild(struct mail_index *index);
+int maildir_index_sync(struct mail_index *index,
+		       enum mail_lock_type lock_type, int *changes);
 
-int maildir_index_append_file(MailIndex *index, const char *dir,
+int maildir_index_append_file(struct mail_index *index, const char *dir,
 			      const char *fname);
-int maildir_index_build_dir(MailIndex *index, const char *source_dir,
+int maildir_index_build_dir(struct mail_index *index, const char *source_dir,
 			    const char *dest_dir);
 
-IStream *maildir_open_mail(MailIndex *index, MailIndexRecord *rec,
-			   time_t *internal_date, int *deleted);
+struct istream *maildir_open_mail(struct mail_index *index,
+				  struct mail_index_record *rec,
+				  time_t *internal_date, int *deleted);
 
-int maildir_record_update(MailIndex *index, MailIndexUpdate *update, int fd);
+int maildir_record_update(struct mail_index *index,
+			  struct mail_index_update *update, int fd);
 
 #endif
--- a/src/lib-index/maildir/maildir-open.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/maildir/maildir-open.c	Sun Jan 05 15:09:51 2003 +0200
@@ -10,8 +10,9 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 
-IStream *maildir_open_mail(MailIndex *index, MailIndexRecord *rec,
-			   time_t *internal_date, int *deleted)
+struct istream *maildir_open_mail(struct mail_index *index,
+				  struct mail_index_record *rec,
+				  time_t *internal_date, int *deleted)
 {
 	struct stat st;
 	const char *fname, *path;
--- a/src/lib-index/maildir/maildir-rebuild.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/maildir/maildir-rebuild.c	Sun Jan 05 15:09:51 2003 +0200
@@ -9,7 +9,7 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 
-int maildir_index_rebuild(MailIndex *index)
+int maildir_index_rebuild(struct mail_index *index)
 {
 	struct stat st;
 	const char *cur_dir, *new_dir;
@@ -31,7 +31,8 @@
 	index->indexid = index->header->indexid;
 	index->inconsistent = TRUE;
 
-	if (msync(index->mmap_base, sizeof(MailIndexHeader), MS_SYNC) < 0)
+	if (msync(index->mmap_base,
+		  sizeof(struct mail_index_header), MS_SYNC) < 0)
 		return FALSE;
 
 	/* reset data file */
--- a/src/lib-index/maildir/maildir-sync.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/maildir/maildir-sync.c	Sun Jan 05 15:09:51 2003 +0200
@@ -14,12 +14,13 @@
 #include <utime.h>
 #include <sys/stat.h>
 
-static int maildir_index_sync_file(MailIndex *index, MailIndexRecord *rec,
+static int maildir_index_sync_file(struct mail_index *index,
+				   struct mail_index_record *rec,
 				   unsigned int seq, const char *fname,
 				   const char *path, int fname_changed)
 {
-	MailIndexUpdate *update;
-	MailFlags flags;
+	struct mail_index_update *update;
+	enum mail_flags flags;
 	int failed;
 
 	i_assert(fname != NULL);
@@ -48,11 +49,12 @@
 	return !failed;
 }
 
-static int maildir_index_sync_files(MailIndex *index, const char *dir,
-				    HashTable *files, int check_content_changes)
+static int maildir_index_sync_files(struct mail_index *index, const char *dir,
+				    struct hash_table *files,
+				    int check_content_changes)
 {
-	MailIndexRecord *rec;
-	MailIndexDataRecordHeader *data_hdr;
+	struct mail_index_record *rec;
+	struct mail_index_data_record_header *data_hdr;
 	struct stat st;
 	const char *fname, *base_fname, *value;
 	char path[PATH_MAX];
@@ -144,16 +146,16 @@
 	return TRUE;
 }
 
-typedef struct {
-	MailIndex *index;
+struct hash_append_context {
+	struct mail_index *index;
 	const char *dir;
 	int failed;
-} HashAppendContext;
+};
 
 static void maildir_index_hash_append_file(void *key __attr_unused__,
 					   void *value, void *context)
 {
-	HashAppendContext *ctx = context;
+	struct hash_append_context *ctx = context;
 
 	t_push();
 	if (!maildir_index_append_file(ctx->index, ctx->dir, value)) {
@@ -163,10 +165,10 @@
 	t_pop();
 }
 
-static int maildir_index_append_files(MailIndex *index, const char *dir,
-				      HashTable *files)
+static int maildir_index_append_files(struct mail_index *index, const char *dir,
+				      struct hash_table *files)
 {
-	HashAppendContext ctx;
+	struct hash_append_context ctx;
 
 	ctx.failed = FALSE;
 	ctx.index = index;
@@ -176,10 +178,10 @@
 	return !ctx.failed;
 }
 
-static int maildir_index_sync_dir(MailIndex *index, const char *dir)
+static int maildir_index_sync_dir(struct mail_index *index, const char *dir)
 {
-	Pool pool;
-	HashTable *files;
+	pool_t pool;
+	struct hash_table *files;
 	DIR *dirp;
 	struct dirent *d;
 	char *key, *value, *p;
@@ -250,8 +252,8 @@
 	return !failed;
 }
 
-int maildir_index_sync(MailIndex *index,
-		       MailLockType data_lock_type __attr_unused__,
+int maildir_index_sync(struct mail_index *index,
+		       enum mail_lock_type data_lock_type __attr_unused__,
 		       int *changes)
 {
 	struct stat sti, std;
--- a/src/lib-index/maildir/maildir-update.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/maildir/maildir-update.c	Sun Jan 05 15:09:51 2003 +0200
@@ -4,10 +4,11 @@
 #include "istream.h"
 #include "maildir-index.h"
 
-int maildir_record_update(MailIndex *index, MailIndexUpdate *update, int fd)
+int maildir_record_update(struct mail_index *index,
+			  struct mail_index_update *update, int fd)
 {
-	IStream *input;
-        MailDataField cache_fields;
+	struct istream *input;
+        enum mail_data_field cache_fields;
 
 	/* don't even bother opening the file if we're not going to do
 	   anything */
--- a/src/lib-index/mbox/mbox-append.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-append.c	Sun Jan 05 15:09:51 2003 +0200
@@ -8,11 +8,12 @@
 #include "mbox-index.h"
 #include "mail-index-util.h"
 
-static int mbox_index_append_next(MailIndex *index, IStream *input)
+static int mbox_index_append_next(struct mail_index *index,
+				  struct istream *input)
 {
-	MailIndexRecord *rec;
-	MailIndexUpdate *update;
-        MboxHeaderContext ctx;
+	struct mail_index_record *rec;
+	struct mail_index_update *update;
+        struct mbox_header_context ctx;
 	time_t internal_date;
 	uoff_t abs_start_offset, eoh_offset;
 	const unsigned char *data;
@@ -110,7 +111,7 @@
 	return !failed;
 }
 
-int mbox_index_append(MailIndex *index, IStream *input)
+int mbox_index_append(struct mail_index *index, struct istream *input)
 {
 	int ret;
 
--- a/src/lib-index/mbox/mbox-from.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-from.c	Sun Jan 05 15:09:51 2003 +0200
@@ -94,7 +94,7 @@
 
 const char *mbox_from_create(const char *sender, time_t time)
 {
-	String *str;
+	string_t *str;
 	struct tm *tm;
 	int year;
 
--- a/src/lib-index/mbox/mbox-index.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-index.c	Sun Jan 05 15:09:51 2003 +0200
@@ -16,9 +16,9 @@
 /* Don't try reading more custom flags than this. */
 #define MAX_CUSTOM_FLAGS 1024
 
-extern MailIndex mbox_index;
+extern struct mail_index mbox_index;
 
-int mbox_set_syscall_error(MailIndex *index, const char *function)
+int mbox_set_syscall_error(struct mail_index *index, const char *function)
 {
 	i_assert(function != NULL);
 
@@ -27,7 +27,7 @@
 	return FALSE;
 }
 
-int mbox_file_open(MailIndex *index)
+int mbox_file_open(struct mail_index *index)
 {
 	struct stat st;
 	int fd;
@@ -52,8 +52,8 @@
 	return TRUE;
 }
 
-IStream *mbox_get_stream(MailIndex *index, uoff_t offset,
-			 MailLockType lock_type)
+struct istream *mbox_get_stream(struct mail_index *index, uoff_t offset,
+				enum mail_lock_type lock_type)
 {
 	i_assert(offset < OFF_T_MAX);
 
@@ -104,7 +104,7 @@
 	return index->mbox_stream;
 }
 
-void mbox_file_close_stream(MailIndex *index)
+void mbox_file_close_stream(struct mail_index *index)
 {
 	if (index->mbox_stream != NULL) {
 		i_stream_close(index->mbox_stream);
@@ -113,7 +113,7 @@
 	}
 }
 
-void mbox_file_close_fd(MailIndex *index)
+void mbox_file_close_fd(struct mail_index *index)
 {
 	mbox_file_close_stream(index);
 
@@ -124,10 +124,11 @@
 	}
 }
 
-void mbox_header_init_context(MboxHeaderContext *ctx, MailIndex *index,
-			      IStream *input)
+void mbox_header_init_context(struct mbox_header_context *ctx,
+			      struct mail_index *index,
+			      struct istream *input)
 {
-	memset(ctx, 0, sizeof(MboxHeaderContext));
+	memset(ctx, 0, sizeof(struct mbox_header_context));
 	md5_init(&ctx->md5);
 
 	ctx->index = index;
@@ -135,13 +136,14 @@
 	ctx->custom_flags = mail_custom_flags_list_get(index->custom_flags);
 }
 
-void mbox_header_free_context(MboxHeaderContext *ctx __attr_unused__)
+void mbox_header_free_context(struct mbox_header_context *ctx __attr_unused__)
 {
 }
 
-static MailFlags mbox_get_status_flags(const unsigned char *value, size_t len)
+static enum mail_flags
+mbox_get_status_flags(const unsigned char *value, size_t len)
 {
-	MailFlags flags;
+	enum mail_flags flags;
 	size_t i;
 
 	flags = 0;
@@ -172,17 +174,17 @@
 				     size_t len __attr_unused__,
 				     int index, void *context)
 {
-	MailFlags *flags = context;
+	enum mail_flags *flags = context;
 
 	if (index >= 0)
 		*flags |= 1 << (index + MAIL_CUSTOM_FLAG_1_BIT);
 }
 
-static MailFlags
+static enum mail_flags
 mbox_get_keyword_flags(const unsigned char *value, size_t len,
 		       const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT])
 {
-	MailFlags flags;
+	enum mail_flags flags;
 
 	flags = 0;
 	mbox_keywords_parse(value, len, custom_flags,
@@ -191,12 +193,12 @@
 }
 
 static int mbox_parse_imapbase(const unsigned char *value, size_t len,
-			       MboxHeaderContext *ctx)
+			       struct mbox_header_context *ctx)
 {
 	const char **flag;
-	Buffer *buf;
+	buffer_t *buf;
 	size_t pos, start;
-	MailFlags flags;
+	enum mail_flags flags;
 	unsigned int count;
 	int ret, spaces;
 
@@ -246,12 +248,12 @@
 	return ret > 0;
 }
 
-void mbox_header_func(MessagePart *part __attr_unused__,
+void mbox_header_func(struct message_part *part __attr_unused__,
 		      const unsigned char *name, size_t name_len,
 		      const unsigned char *value, size_t value_len,
 		      void *context)
 {
-	MboxHeaderContext *ctx = context;
+	struct mbox_header_context *ctx = context;
 	uoff_t start_offset, end_offset;
 	size_t i;
 	int fixed = FALSE;
@@ -425,7 +427,7 @@
 	}
 }
 
-int mbox_skip_crlf(IStream *input)
+int mbox_skip_crlf(struct istream *input)
 {
 	const unsigned char *data;
 	size_t size, pos;
@@ -456,7 +458,7 @@
 	return TRUE;
 }
 
-void mbox_skip_empty_lines(IStream *input)
+void mbox_skip_empty_lines(struct istream *input)
 {
 	const unsigned char *data;
 	size_t i, size;
@@ -475,7 +477,7 @@
 	}
 }
 
-static int mbox_is_valid_from(IStream *input, size_t startpos)
+static int mbox_is_valid_from(struct istream *input, size_t startpos)
 {
 	const unsigned char *msg;
 	size_t i, size;
@@ -495,7 +497,7 @@
 	return FALSE;
 }
 
-static void mbox_skip_forward(IStream *input, int header)
+static void mbox_skip_forward(struct istream *input, int header)
 {
 	const unsigned char *msg;
 	size_t i, size, startpos, eoh;
@@ -614,17 +616,17 @@
 	i_stream_skip(input, startpos);
 }
 
-void mbox_skip_header(IStream *input)
+void mbox_skip_header(struct istream *input)
 {
 	mbox_skip_forward(input, TRUE);
 }
 
-void mbox_skip_message(IStream *input)
+void mbox_skip_message(struct istream *input)
 {
 	mbox_skip_forward(input, FALSE);
 }
 
-int mbox_verify_end_of_body(IStream *input, uoff_t end_offset)
+int mbox_verify_end_of_body(struct istream *input, uoff_t end_offset)
 {
 	const unsigned char *data;
 	size_t size;
@@ -662,10 +664,11 @@
 		(size >= 5 && strncmp((const char *) data, "From ", 5) == 0);
 }
 
-int mbox_mail_get_location(MailIndex *index, MailIndexRecord *rec,
+int mbox_mail_get_location(struct mail_index *index,
+			   struct mail_index_record *rec,
 			   uoff_t *offset, uoff_t *hdr_size, uoff_t *body_size)
 {
-	MailIndexDataRecordHeader *data_hdr;
+	struct mail_index_data_record_header *data_hdr;
 	const uoff_t *location;
 	size_t size;
 
@@ -716,14 +719,14 @@
 	return TRUE;
 }
 
-MailIndex *mbox_index_alloc(const char *dir, const char *mbox_path)
+struct mail_index *mbox_index_alloc(const char *dir, const char *mbox_path)
 {
-	MailIndex *index;
+	struct mail_index *index;
 
 	i_assert(dir != NULL);
 
-	index = i_new(MailIndex, 1);
-	memcpy(index, &mbox_index, sizeof(MailIndex));
+	index = i_new(struct mail_index, 1);
+	memcpy(index, &mbox_index, sizeof(struct mail_index));
 
 	index->mbox_fd = -1;
 	index->mbox_sync_counter = (unsigned int)-1;
@@ -733,7 +736,7 @@
 	return index;
 }
 
-static void mbox_index_free(MailIndex *index)
+static void mbox_index_free(struct mail_index *index)
 {
         mbox_file_close_fd(index);
 	mail_index_close(index);
@@ -742,21 +745,24 @@
 	i_free(index);
 }
 
-static int mbox_index_set_lock(MailIndex *index, MailLockType lock_type)
+static int mbox_index_set_lock(struct mail_index *index,
+			       enum mail_lock_type lock_type)
 {
 	if (lock_type == MAIL_LOCK_UNLOCK)
 		(void)mbox_unlock(index);
 	return mail_index_set_lock(index, lock_type);
 }
 
-static int mbox_index_try_lock(MailIndex *index, MailLockType lock_type)
+static int mbox_index_try_lock(struct mail_index *index,
+			       enum mail_lock_type lock_type)
 {
 	if (lock_type == MAIL_LOCK_UNLOCK)
 		(void)mbox_unlock(index);
 	return mail_index_try_lock(index, lock_type);
 }
 
-static int mbox_index_expunge(MailIndex *index, MailIndexRecord *rec,
+static int mbox_index_expunge(struct mail_index *index,
+			      struct mail_index_record *rec,
 			      unsigned int seq, int external_change)
 {
 	if (!mail_index_expunge(index, rec, seq, external_change))
@@ -771,8 +777,9 @@
 	return TRUE;
 }
 
-static int mbox_index_update_flags(MailIndex *index, MailIndexRecord *rec,
-				   unsigned int seq, MailFlags flags,
+static int mbox_index_update_flags(struct mail_index *index,
+				   struct mail_index_record *rec,
+				   unsigned int seq, enum mail_flags flags,
 				   int external_change)
 {
 	if (!mail_index_update_flags(index, rec, seq, flags, external_change))
@@ -785,7 +792,7 @@
 	return TRUE;
 }
 
-MailIndex mbox_index = {
+struct mail_index mbox_index = {
 	mail_index_open,
 	mail_index_open_or_create,
 	mbox_index_free,
--- a/src/lib-index/mbox/mbox-index.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-index.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,33 +4,34 @@
 #include "md5.h"
 #include "mail-index.h"
 
-typedef struct {
-	MailIndex *index;
-	MailFlags flags;
+struct mbox_header_context {
+	struct mail_index *index;
+	enum mail_flags flags;
 	const char **custom_flags;
-	MD5Context md5;
+	struct md5_context md5;
 	int received;
 
-	IStream *input;
+	struct istream *input;
 	uoff_t content_length;
 	int set_read_limit;
-} MboxHeaderContext;
+};
 
-int mbox_set_syscall_error(MailIndex *index, const char *function);
+int mbox_set_syscall_error(struct mail_index *index, const char *function);
 
 /* Make sure the mbox is opened. If reopen is TRUE, the file is closed first,
    which is useful when you want to be sure you're not accessing a deleted
    mbox file. */
-int mbox_file_open(MailIndex *index);
-IStream *mbox_get_stream(MailIndex *index, uoff_t offset,
-			 MailLockType lock_type);
-void mbox_file_close_stream(MailIndex *index);
-void mbox_file_close_fd(MailIndex *index);
+int mbox_file_open(struct mail_index *index);
+struct istream *mbox_get_stream(struct mail_index *index, uoff_t offset,
+				enum mail_lock_type lock_type);
+void mbox_file_close_stream(struct mail_index *index);
+void mbox_file_close_fd(struct mail_index *index);
 
-void mbox_header_init_context(MboxHeaderContext *ctx, MailIndex *index,
-			      IStream *input);
-void mbox_header_free_context(MboxHeaderContext *ctx);
-void mbox_header_func(MessagePart *part __attr_unused__,
+void mbox_header_init_context(struct mbox_header_context *ctx,
+			      struct mail_index *index,
+			      struct istream *input);
+void mbox_header_free_context(struct mbox_header_context *ctx);
+void mbox_header_func(struct message_part *part __attr_unused__,
 		      const unsigned char *name, size_t name_len,
 		      const unsigned char *value, size_t value_len,
 		      void *context);
@@ -39,26 +40,29 @@
 			 void (*func)(const unsigned char *, size_t,
 				      int, void *),
 			 void *context);
-int mbox_skip_crlf(IStream *input);
-void mbox_skip_empty_lines(IStream *input);
-void mbox_skip_header(IStream *input);
-void mbox_skip_message(IStream *input);
-int mbox_verify_end_of_body(IStream *input, uoff_t end_offset);
-int mbox_mail_get_location(MailIndex *index, MailIndexRecord *rec,
+int mbox_skip_crlf(struct istream *input);
+void mbox_skip_empty_lines(struct istream *input);
+void mbox_skip_header(struct istream *input);
+void mbox_skip_message(struct istream *input);
+int mbox_verify_end_of_body(struct istream *input, uoff_t end_offset);
+int mbox_mail_get_location(struct mail_index *index,
+			   struct mail_index_record *rec,
 			   uoff_t *offset, uoff_t *hdr_size, uoff_t *body_size);
 
-MailIndex *mbox_index_alloc(const char *dir, const char *mbox_path);
-int mbox_index_rebuild(MailIndex *index);
-int mbox_index_sync(MailIndex *index, MailLockType lock_type, int *changes);
-int mbox_sync_full(MailIndex *index);
-IStream *mbox_open_mail(MailIndex *index, MailIndexRecord *rec,
-			time_t *internal_date, int *deleted);
+struct mail_index *mbox_index_alloc(const char *dir, const char *mbox_path);
+int mbox_index_rebuild(struct mail_index *index);
+int mbox_index_sync(struct mail_index *index,
+		    enum mail_lock_type lock_type, int *changes);
+int mbox_sync_full(struct mail_index *index);
+struct istream *mbox_open_mail(struct mail_index *index,
+			       struct mail_index_record *rec,
+			       time_t *internal_date, int *deleted);
 
-int mbox_index_append(MailIndex *index, IStream *input);
+int mbox_index_append(struct mail_index *index, struct istream *input);
 
 time_t mbox_from_parse_date(const unsigned char *msg, size_t size);
 const char *mbox_from_create(const char *sender, time_t time);
 
-int mbox_index_rewrite(MailIndex *index);
+int mbox_index_rewrite(struct mail_index *index);
 
 #endif
--- a/src/lib-index/mbox/mbox-lock.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-lock.c	Sun Jan 05 15:09:51 2003 +0200
@@ -63,8 +63,8 @@
 }
 
 #ifdef HAVE_FLOCK
-static int mbox_lock_flock(MailIndex *index, MailLockType lock_type,
-			   time_t max_wait_time)
+static int mbox_lock_flock(struct mail_index *index,
+			   enum mail_lock_type lock_type, time_t max_wait_time)
 {
 	time_t now, last_notify;
 
@@ -105,8 +105,8 @@
 }
 #endif
 
-static int mbox_lock_fcntl(MailIndex *index, MailLockType lock_type,
-			   time_t max_wait_time)
+static int mbox_lock_fcntl(struct mail_index *index,
+			   enum mail_lock_type lock_type, time_t max_wait_time)
 {
 	struct flock fl;
 	time_t now;
@@ -141,7 +141,7 @@
 	return TRUE;
 }
 
-static int mbox_lock_dotlock(MailIndex *index, const char *path,
+static int mbox_lock_dotlock(struct mail_index *index, const char *path,
 			     time_t max_wait_time, int checkonly)
 {
 	struct stat st;
@@ -250,7 +250,7 @@
 	return FALSE;
 }
 
-static int mbox_unlock_dotlock(MailIndex *index, const char *path)
+static int mbox_unlock_dotlock(struct mail_index *index, const char *path)
 {
 	struct stat st;
 	dev_t old_dev;
@@ -286,7 +286,7 @@
 	return TRUE;
 }
 
-static int mbox_file_locks(MailIndex *index, time_t max_wait_time)
+static int mbox_file_locks(struct mail_index *index, time_t max_wait_time)
 {
 	if (use_fcntl_lock && fcntl_before_flock) {
 		if (!mbox_lock_fcntl(index, index->mbox_lock_type,
@@ -308,7 +308,7 @@
 	return TRUE;
 }
 
-int mbox_lock(MailIndex *index, MailLockType lock_type)
+int mbox_lock(struct mail_index *index, enum mail_lock_type lock_type)
 {
 	struct stat st;
 	time_t max_wait_time;
@@ -362,7 +362,7 @@
 	return TRUE;
 }
 
-int mbox_unlock(MailIndex *index)
+int mbox_unlock(struct mail_index *index)
 {
 	int failed;
 
--- a/src/lib-index/mbox/mbox-lock.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-lock.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 
 /* NOTE: if mbox file is not open, it's opened. if it is open but file has
    been overwritten (ie. inode has changed), it's reopened. */
-int mbox_lock(MailIndex *index, MailLockType lock_type);
-int mbox_unlock(MailIndex *index);
+int mbox_lock(struct mail_index *index, enum mail_lock_type lock_type);
+int mbox_unlock(struct mail_index *index);
 
 #endif
--- a/src/lib-index/mbox/mbox-open.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-open.c	Sun Jan 05 15:09:51 2003 +0200
@@ -10,10 +10,11 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-IStream *mbox_open_mail(MailIndex *index, MailIndexRecord *rec,
-			time_t *internal_date, int *deleted)
+struct istream *mbox_open_mail(struct mail_index *index,
+			       struct mail_index_record *rec,
+			       time_t *internal_date, int *deleted)
 {
-	IStream *input;
+	struct istream *input;
 	uoff_t offset, hdr_size, body_size;
 
 	i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
--- a/src/lib-index/mbox/mbox-rebuild.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-rebuild.c	Sun Jan 05 15:09:51 2003 +0200
@@ -12,9 +12,9 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 
-int mbox_index_rebuild(MailIndex *index)
+int mbox_index_rebuild(struct mail_index *index)
 {
-	IStream *input;
+	struct istream *input;
 	struct stat st;
 	int failed;
 
@@ -36,7 +36,8 @@
 	index->indexid = index->header->indexid;
 	index->inconsistent = TRUE;
 
-	if (msync(index->mmap_base, sizeof(MailIndexHeader), MS_SYNC) < 0)
+	if (msync(index->mmap_base,
+		  sizeof(struct mail_index_header), MS_SYNC) < 0)
 		return index_set_syscall_error(index, "msync()");
 
 	/* reset data file */
--- a/src/lib-index/mbox/mbox-rewrite.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-rewrite.c	Sun Jan 05 15:09:51 2003 +0200
@@ -16,8 +16,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-typedef struct {
-	OStream *output;
+struct mbox_rewrite_context {
+	struct ostream *output;
 	int failed;
 
 	uoff_t content_length;
@@ -33,12 +33,12 @@
 	unsigned int status_found:1;
 	unsigned int xstatus_found:1;
 	unsigned int content_length_found:1;
-} MboxRewriteContext;
+};
 
 /* Remove dirty flag from all messages */
-static void reset_dirty_flags(MailIndex *index)
+static void reset_dirty_flags(struct mail_index *index)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 
 	rec = index->lookup(index, 1);
 	while (rec != NULL) {
@@ -50,8 +50,8 @@
 				  MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS);
 }
 
-static int mbox_write(MailIndex *index, IStream *input, OStream *output,
-		      uoff_t end_offset)
+static int mbox_write(struct mail_index *index, struct istream *input,
+		      struct ostream *output, uoff_t end_offset)
 {
 	uoff_t old_limit;
 	int failed;
@@ -78,7 +78,7 @@
 	return !failed;
 }
 
-static int mbox_write_ximapbase(MboxRewriteContext *ctx)
+static int mbox_write_ximapbase(struct mbox_rewrite_context *ctx)
 {
 	const char *str;
 	int i;
@@ -105,7 +105,8 @@
 	return TRUE;
 }
 
-static int mbox_write_xkeywords(MboxRewriteContext *ctx, const char *x_keywords)
+static int mbox_write_xkeywords(struct mbox_rewrite_context *ctx,
+				const char *x_keywords)
 {
 	unsigned int field;
 	int i;
@@ -144,7 +145,8 @@
 	return TRUE;
 }
 
-static int mbox_write_status(MboxRewriteContext *ctx, const char *status)
+static int mbox_write_status(struct mbox_rewrite_context *ctx,
+			     const char *status)
 {
 	const char *str;
 
@@ -160,7 +162,8 @@
 	return TRUE;
 }
 
-static int mbox_write_xstatus(MboxRewriteContext *ctx, const char *x_status)
+static int mbox_write_xstatus(struct mbox_rewrite_context *ctx,
+			      const char *x_status)
 {
 	const char *str;
 
@@ -184,7 +187,7 @@
 	return TRUE;
 }
 
-static int mbox_write_content_length(MboxRewriteContext *ctx)
+static int mbox_write_content_length(struct mbox_rewrite_context *ctx)
 {
 	char str[MAX_INT_STRLEN+30];
 
@@ -219,7 +222,7 @@
 static void update_stripped_custom_flags(const unsigned char *value, size_t len,
 					 int index, void *context)
 {
-	String *str = context;
+	string_t *str = context;
 
 	if (index < 0) {
 		/* not found, keep it */
@@ -230,9 +233,9 @@
 }
 
 static const char *strip_custom_flags(const unsigned char *value, size_t len,
-				      MboxRewriteContext *ctx)
+				      struct mbox_rewrite_context *ctx)
 {
-	String *str;
+	string_t *str;
 
 	str = t_str_new(len+1);
 	mbox_keywords_parse(value, len, ctx->custom_flags,
@@ -240,12 +243,12 @@
 	return str_len(str) == 0 ? NULL : str_c(str);
 }
 
-static void header_func(MessagePart *part __attr_unused__,
+static void header_func(struct message_part *part __attr_unused__,
 			const unsigned char *name, size_t name_len,
 			const unsigned char *value, size_t value_len,
 			void *context)
 {
-	MboxRewriteContext *ctx = context;
+	struct mbox_rewrite_context *ctx = context;
 	const char *str;
 	char *end;
 
@@ -296,9 +299,10 @@
 		ctx->failed = TRUE;
 }
 
-static int mbox_write_header(MailIndex *index,
-			     MailIndexRecord *rec, unsigned int seq,
-			     IStream *input, OStream *output, uoff_t end_offset,
+static int mbox_write_header(struct mail_index *index,
+			     struct mail_index_record *rec, unsigned int seq,
+			     struct istream *input, struct ostream *output,
+			     uoff_t end_offset,
 			     uoff_t hdr_size, uoff_t body_size)
 {
 	/* We need to update fields that define message flags. Standard fields
@@ -312,8 +316,8 @@
 	   validity is always kept different from our internal UID validity.
 	   Last used UID is also not updated, and set to 0 initially.
 	*/
-	MboxRewriteContext ctx;
-	MessageSize hdr_parsed_size;
+	struct mbox_rewrite_context ctx;
+	struct message_size hdr_parsed_size;
 
 	if (input->v_offset >= end_offset) {
 		/* fsck should have noticed it.. */
@@ -364,8 +368,8 @@
 
 static int fd_copy(int in_fd, int out_fd, uoff_t out_offset)
 {
-	IStream *input;
-	OStream *output;
+	struct istream *input;
+	struct ostream *output;
 	int ret;
 
 	i_assert(out_offset <= OFF_T_MAX);
@@ -399,15 +403,15 @@
 #define INDEX_DIRTY_FLAGS \
         (MAIL_INDEX_FLAG_DIRTY_MESSAGES | MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS)
 
-int mbox_index_rewrite(MailIndex *index)
+int mbox_index_rewrite(struct mail_index *index)
 {
 	/* Write messages beginning from the first dirty one to temp file,
 	   then copy it over the mbox file. This may create data loss if
 	   interrupted (see below). This rewriting relies quite a lot on
 	   valid header/body sizes which fsck() should have ensured. */
-	MailIndexRecord *rec;
-	IStream *input;
-	OStream *output;
+	struct mail_index_record *rec;
+	struct istream *input;
+	struct ostream *output;
 	uoff_t offset, hdr_size, body_size, dirty_offset;
 	const char *path;
 	unsigned int seq;
--- a/src/lib-index/mbox/mbox-sync-full.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-sync-full.c	Sun Jan 05 15:09:51 2003 +0200
@@ -12,7 +12,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-static void skip_line(IStream *input)
+static void skip_line(struct istream *input)
 {
 	const unsigned char *msg;
 	size_t i, size;
@@ -29,7 +29,8 @@
 	}
 }
 
-static int verify_header_md5sum(MailIndex *index, MailIndexRecord *rec,
+static int verify_header_md5sum(struct mail_index *index,
+				struct mail_index_record *rec,
 				unsigned char current_digest[16])
 {
 	const unsigned char *old_digest;
@@ -41,9 +42,10 @@
                 memcmp(old_digest, current_digest, 16) == 0;
 }
 
-static int mail_update_header_size(MailIndex *index, MailIndexRecord *rec,
-				   MailIndexUpdate *update,
-				   MessageSize *hdr_size)
+static int mail_update_header_size(struct mail_index *index,
+				   struct mail_index_record *rec,
+				   struct mail_index_update *update,
+				   struct message_size *hdr_size)
 {
 	const void *part_data;
 	void *part_data_copy;
@@ -89,13 +91,14 @@
 	return TRUE;
 }
 
-static int match_next_record(MailIndex *index, MailIndexRecord *rec,
-			     unsigned int seq, IStream *input,
-			     MailIndexRecord **next_rec, int *dirty)
+static int match_next_record(struct mail_index *index,
+			     struct mail_index_record *rec,
+			     unsigned int seq, struct istream *input,
+			     struct mail_index_record **next_rec, int *dirty)
 {
-        MailIndexUpdate *update;
-	MessageSize hdr_parsed_size;
-	MboxHeaderContext ctx;
+        struct mail_index_update *update;
+	struct message_size hdr_parsed_size;
+	struct mbox_header_context ctx;
 	uoff_t header_offset, body_offset, offset;
 	uoff_t hdr_size, body_size;
 	unsigned char current_digest[16];
@@ -189,9 +192,10 @@
 	return TRUE;
 }
 
-static int mbox_sync_from_stream(MailIndex *index, IStream *input)
+static int mbox_sync_from_stream(struct mail_index *index,
+				 struct istream *input)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 	uoff_t from_offset;
 	const unsigned char *data;
 	size_t size;
@@ -271,9 +275,9 @@
 		return mbox_index_append(index, input);
 }
 
-int mbox_sync_full(MailIndex *index)
+int mbox_sync_full(struct mail_index *index)
 {
-	IStream *input;
+	struct istream *input;
 	int failed;
 
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
--- a/src/lib-index/mbox/mbox-sync.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-index/mbox/mbox-sync.c	Sun Jan 05 15:09:51 2003 +0200
@@ -10,9 +10,9 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 
-static uoff_t get_indexed_mbox_size(MailIndex *index)
+static uoff_t get_indexed_mbox_size(struct mail_index *index)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 	uoff_t offset, hdr_size, body_size;
 
 	if (index->lock_type == MAIL_LOCK_UNLOCK) {
@@ -41,10 +41,10 @@
 	return offset + 1; /* +1 for trailing \n */
 }
 
-static int mbox_lock_and_sync_full(MailIndex *index,
-				   MailLockType data_lock_type)
+static int mbox_lock_and_sync_full(struct mail_index *index,
+				   enum mail_lock_type data_lock_type)
 {
-        MailLockType lock_type;
+        enum mail_lock_type lock_type;
 
 	/* syncing needs exclusive index lock and shared
 	   mbox lock, but if we'd want exclusive mbox lock
@@ -65,8 +65,8 @@
 	return mbox_sync_full(index);
 }
 
-int mbox_index_sync(MailIndex *index, MailLockType data_lock_type,
-		    int *changes)
+int mbox_index_sync(struct mail_index *index,
+		    enum mail_lock_type data_lock_type, int *changes)
 {
 	struct stat st;
 	time_t index_mtime;
--- a/src/lib-mail/Makefile.am	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/Makefile.am	Sun Jan 05 15:09:51 2003 +0200
@@ -5,29 +5,29 @@
 	-I$(top_srcdir)/src/lib-charset
 
 libmail_a_SOURCES = \
+	message-address.c \
 	message-body-search.c \
 	message-content-parser.c \
+	message-date.c \
 	message-header-decode.c \
 	message-header-search.c \
 	message-parser.c \
 	message-part-serialize.c \
 	message-send.c \
 	message-size.c \
-	rfc822-address.c \
-	rfc822-date.c \
-	rfc822-tokenize.c \
+	message-tokenize.c \
 	quoted-printable.c
 
 noinst_HEADERS = \
+	message-address.h \
 	message-body-search.h \
 	message-content-parser.h \
+	message-date.h \
 	message-header-decode.h \
 	message-header-search.h \
 	message-parser.h \
 	message-part-serialize.h \
 	message-send.h \
 	message-size.h \
-	rfc822-address.h \
-	rfc822-date.h \
-	rfc822-tokenize.h \
+	message-tokenize.h \
 	quoted-printable.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-mail/message-address.c	Sun Jan 05 15:09:51 2003 +0200
@@ -0,0 +1,212 @@
+/* Copyright (C) 2002 Timo Sirainen */
+
+#include "lib.h"
+#include "str.h"
+#include "message-tokenize.h"
+#include "message-address.h"
+
+static struct message_address *
+new_address(pool_t pool, struct message_address ***next_addr)
+{
+	struct message_address *addr;
+
+	addr = p_new(pool, struct message_address, 1);
+
+	**next_addr = addr;
+	*next_addr = &addr->next;
+
+	return addr;
+}
+
+struct message_address *
+message_address_parse(pool_t pool, const unsigned char *data, size_t size)
+{
+	static const enum message_token stop_tokens_init[] =
+		{ ',', '@', '<', ':', TOKEN_LAST };
+	static const enum message_token stop_tokens_group[] =
+		{ ',', '@', '<', ';', TOKEN_LAST };
+	static const enum message_token stop_tokens_domain[] =
+		{ ',', '<', TOKEN_LAST };
+	static const enum message_token stop_tokens_domain_group[] =
+		{ ',', '<', ';', TOKEN_LAST };
+	static const enum message_token stop_tokens_post_addr[] =
+		{ ',', TOKEN_LAST };
+	static const enum message_token stop_tokens_post_addr_group[] =
+		{ ',', ';', TOKEN_LAST };
+	static const enum message_token stop_tokens_addr_route[] =
+		{ ':', '>', TOKEN_LAST };
+	static const enum message_token stop_tokens_addr_mailbox[] =
+		{ '@', '>', TOKEN_LAST };
+	static const enum message_token stop_tokens_addr_domain[] =
+		{ '>', TOKEN_LAST };
+
+	struct message_address *first_addr, **next_addr, *addr;
+	struct message_tokenizer *tok;
+	const enum message_token *stop_tokens;
+	enum message_token token;
+	string_t *mailbox, *domain, *route, *name, *comment, *next_phrase;
+	size_t len;
+	int ingroup, stop;
+
+	if (size == 0)
+		return NULL;
+
+	first_addr = NULL;
+	next_addr = &first_addr;
+
+	/* 1) name <@route:mailbox@domain>, ...
+	   2) mailbox@domain (name), ...
+	   3) group: name <box@domain>, box2@domain2 (name2), ... ;, ...
+
+	   ENVELOPE wants groups to be stored like (NIL, NIL, group, NIL),
+	   ..., (NIL, NIL, NIL, NIL)
+	*/
+	tok = message_tokenize_init(data, size, NULL, NULL);
+	message_tokenize_skip_comments(tok, FALSE);
+
+	t_push();
+	mailbox = t_str_new(128);
+	domain = t_str_new(256);
+	route = t_str_new(128);
+	name = t_str_new(256);
+	comment = t_str_new(256);
+
+	ingroup = FALSE; len = 0;
+	stop_tokens = stop_tokens_init;
+
+	next_phrase = mailbox; stop = FALSE;
+	while (!stop) {
+		if (next_phrase == name && str_len(name) > 0) {
+			/* continuing previously started name,
+			   separate it from us with space */
+			str_append_c(name, ' ');
+			len = str_len(name);
+		} else {
+			len = 0;
+		}
+		message_tokenize_get_string(tok, next_phrase, comment,
+					    stop_tokens);
+
+		if (next_phrase == name && len > 0 && len == str_len(name)) {
+			/* nothing appeneded, remove the space */
+			str_truncate(name, len-1);
+		}
+
+		token = message_tokenize_get(tok);
+		switch (token) {
+		case TOKEN_LAST:
+		case ',':
+		case ';':
+			/* end of address */
+			if (str_len(mailbox) > 0 || str_len(domain) > 0 ||
+			    str_len(route) > 0 || str_len(name) > 0) {
+				addr = new_address(pool, &next_addr);
+				addr->mailbox = p_strdup(pool, str_c(mailbox));
+				addr->domain = str_len(domain) == 0 ? NULL :
+					p_strdup(pool, str_c(domain));
+				addr->route = str_len(route) == 0 ? NULL :
+					p_strdup(pool, str_c(route));
+				addr->name = next_phrase == name ?
+					p_strdup(pool, str_c(name)) :
+					p_strdup(pool, str_c(comment));
+			}
+
+			if (ingroup && token == ';') {
+				/* end of group - add end of group marker */
+				ingroup = FALSE;
+				(void)new_address(pool, &next_addr);
+			}
+
+			if (token == TOKEN_LAST) {
+				stop = TRUE;
+				break;
+			}
+
+			stop_tokens = ingroup ? stop_tokens_group :
+				stop_tokens_init;
+
+			str_truncate(mailbox, 0);
+			str_truncate(domain, 0);
+			str_truncate(route, 0);
+			str_truncate(name, 0);
+			str_truncate(comment, 0);
+
+			next_phrase = mailbox;
+			break;
+		case '@':
+			/* domain part comes next */
+			next_phrase = domain;
+			stop_tokens = ingroup ? stop_tokens_domain_group :
+				stop_tokens_domain;
+			break;
+		case '<':
+			/* route-addr */
+
+			/* mailbox/domain name so far has actually
+			   been the real name */
+			str_append_str(name, mailbox);
+			str_truncate(mailbox, 0);
+
+			if (str_len(domain) > 0) {
+                                str_append_c(name, '@');
+				str_append_str(name, domain);
+				str_truncate(domain, 0);
+			}
+
+			/* mailbox */
+			message_tokenize_get_string(tok, mailbox, NULL,
+						    stop_tokens_addr_mailbox);
+
+			if (message_tokenize_get(tok) == '@' &&
+			    str_len(mailbox) == 0) {
+				/* route is given */
+				message_tokenize_get_string(tok,
+					route, NULL, stop_tokens_addr_route);
+
+				if (message_tokenize_get(tok) == ':') {
+					/* mailbox comes next */
+					message_tokenize_get_string(tok,
+						mailbox, NULL,
+						stop_tokens_addr_mailbox);
+				}
+			}
+
+			if (message_tokenize_get(tok) == '@') {
+				/* domain */
+				message_tokenize_get_string(tok,
+					domain, NULL, stop_tokens_addr_domain);
+			}
+
+			token = message_tokenize_get(tok);
+			i_assert(token == '>' || token == TOKEN_LAST);
+
+			next_phrase = name;
+			stop_tokens = ingroup ? stop_tokens_post_addr_group :
+				stop_tokens_post_addr;
+			break;
+		case ':':
+			/* beginning of group */
+			addr = new_address(pool, &next_addr);
+			addr->name = p_strdup(pool, str_c(mailbox));
+
+			str_truncate(mailbox, 0);
+			str_truncate(comment, 0);
+
+			ingroup = TRUE;
+			stop_tokens = stop_tokens_group;
+			break;
+		default:
+			i_unreached();
+			break;
+		}
+	}
+
+	if (ingroup)
+		(void)new_address(pool, &next_addr);
+
+	t_pop();
+	message_tokenize_deinit(tok);
+
+	return first_addr;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-mail/message-address.h	Sun Jan 05 15:09:51 2003 +0200
@@ -0,0 +1,13 @@
+#ifndef __MESSAGE_ADDRESS_H
+#define __MESSAGE_ADDRESS_H
+
+struct message_address {
+	struct message_address *next;
+
+	const char *name, *route, *mailbox, *domain;
+};
+
+struct message_address *
+message_address_parse(pool_t pool, const unsigned char *data, size_t size);
+
+#endif
--- a/src/lib-mail/message-body-search.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-body-search.c	Sun Jan 05 15:09:51 2003 +0200
@@ -14,8 +14,8 @@
 
 #define DECODE_BLOCK_SIZE 8192
 
-typedef struct {
-	Pool pool;
+struct body_search_context {
+	pool_t pool;
 
 	const char *key;
 	size_t key_len;
@@ -23,16 +23,16 @@
 	const char *charset;
 	unsigned int unknown_charset:1;
 	unsigned int search_header:1;
-} BodySearchContext;
+};
 
-typedef struct {
-	BodySearchContext *body_ctx;
+struct part_search_context {
+	struct body_search_context *body_ctx;
 
-	HeaderSearchContext *hdr_search_ctx;
-	CharsetTranslation *translation;
+	struct header_search_context *hdr_search_ctx;
+	struct charset_translation *translation;
 
-	Buffer *decode_buf;
-	Buffer *match_buf;
+	buffer_t *decode_buf;
+	buffer_t *match_buf;
 
 	char *content_type;
 	char *content_charset;
@@ -43,12 +43,12 @@
 	unsigned int content_type_text:1; /* text/any or message/any */
 	unsigned int ignore_header:1;
 	unsigned int found:1;
-} PartSearchContext;
+};
 
 static void parse_content_type(const unsigned char *value, size_t value_len,
 			       void *context)
 {
-	PartSearchContext *ctx = context;
+	struct part_search_context *ctx = context;
 
 	if (ctx->content_type != NULL) {
 		ctx->content_type = i_strndup(value, value_len);
@@ -63,7 +63,7 @@
 			 const unsigned char *value, size_t value_len,
 			 int value_quoted, void *context)
 {
-	PartSearchContext *ctx = context;
+	struct part_search_context *ctx = context;
 
 	if (name_len == 7 && memcasecmp(name, "charset", 7) == 0 &&
 	    ctx->content_charset == NULL) {
@@ -75,7 +75,7 @@
 static void parse_content_encoding(const unsigned char *value, size_t value_len,
 				   void *context)
 {
-	PartSearchContext *ctx = context;
+	struct part_search_context *ctx = context;
 
 	switch (value_len) {
 	case 4:
@@ -101,12 +101,12 @@
 	}
 }
 
-static void header_find(MessagePart *part __attr_unused__,
+static void header_find(struct message_part *part __attr_unused__,
 			const unsigned char *name, size_t name_len,
 			const unsigned char *value, size_t value_len,
 			void *context)
 {
-	PartSearchContext *ctx = context;
+	struct part_search_context *ctx = context;
 
 	if (ctx->found)
 		return;
@@ -129,7 +129,8 @@
 	}
 }
 
-static int message_search_header(PartSearchContext *ctx, IStream *input)
+static int message_search_header(struct part_search_context *ctx,
+				 struct istream *input)
 {
 	ctx->hdr_search_ctx = message_header_search_init(data_stack_pool,
 							 ctx->body_ctx->key,
@@ -143,7 +144,8 @@
 	return ctx->found;
 }
 
-static int message_search_decoded_block(PartSearchContext *ctx, Buffer *block)
+static int message_search_decoded_block(struct part_search_context *ctx,
+					buffer_t *block)
 {
 	const unsigned char *p, *end, *key;
 	size_t key_len, block_size, *matches, match_count, value;
@@ -191,11 +193,12 @@
 }
 
 /* returns 1 = found, 0 = not found, -1 = error in input data */
-static int message_search_body_block(PartSearchContext *ctx, Buffer *block)
+static int message_search_body_block(struct part_search_context *ctx,
+				     buffer_t *block)
 {
 	const unsigned char *inbuf;
-	Buffer *outbuf;
-        CharsetResult result;
+	buffer_t *outbuf;
+        enum charset_result result;
 	size_t block_pos, inbuf_size, inbuf_left, ret;
 
 	outbuf = buffer_create_static(data_stack_pool, DECODE_BLOCK_SIZE);
@@ -250,11 +253,12 @@
 	return 0;
 }
 
-static int message_search_body(PartSearchContext *ctx, IStream *input,
-			       MessagePart *part)
+static int message_search_body(struct part_search_context *ctx,
+			       struct istream *input,
+			       struct message_part *part)
 {
 	const unsigned char *data;
-	Buffer *decodebuf;
+	buffer_t *decodebuf;
 	size_t data_size, pos;
 	uoff_t old_limit;
 	ssize_t ret;
@@ -336,13 +340,13 @@
 	return found;
 }
 
-static int message_body_search_init(BodySearchContext *ctx, const char *key,
-				    const char *charset, int *unknown_charset,
-				    int search_header)
+static int message_body_search_init(struct body_search_context *ctx,
+				    const char *key, const char *charset,
+				    int *unknown_charset, int search_header)
 {
 	size_t key_len;
 
-	memset(ctx, 0, sizeof(BodySearchContext));
+	memset(ctx, 0, sizeof(struct body_search_context));
 
 	/* get the key uppercased */
 	key = charset_to_ucase_utf8_string(charset, unknown_charset,
@@ -362,10 +366,11 @@
 	return TRUE;
 }
 
-static int message_body_search_ctx(BodySearchContext *ctx, IStream *input,
-				   MessagePart *part)
+static int message_body_search_ctx(struct body_search_context *ctx,
+				   struct istream *input,
+				   struct message_part *part)
 {
-	PartSearchContext part_ctx;
+	struct part_search_context part_ctx;
 	int found;
 
 	found = FALSE;
@@ -404,10 +409,10 @@
 }
 
 int message_body_search(const char *key, const char *charset,
-			int *unknown_charset, IStream *input,
-			MessagePart *part, int search_header)
+			int *unknown_charset, struct istream *input,
+			struct message_part *part, int search_header)
 {
-        BodySearchContext ctx;
+        struct body_search_context ctx;
 
 	if (!message_body_search_init(&ctx, key, charset, unknown_charset,
 				      search_header))
--- a/src/lib-mail/message-body-search.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-body-search.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,12 +1,14 @@
 #ifndef __MESSAGE_BODY_SEARCH_H
 #define __MESSAGE_BODY_SEARCH_H
 
+struct message_part;
+
 /* Returns 1 if key is found from input buffer, 0 if not and -1 if error.
    There's two possible errors: either the charset is unknown or the key
    is invalid. If charset is NULL, the key isn't assumed to be in any
    specific charset but is compared to message data without any translation. */
 int message_body_search(const char *key, const char *charset,
-			int *unknown_charset, IStream *input,
-			MessagePart *part, int search_header);
+			int *unknown_charset, struct istream *input,
+			struct message_part *part, int search_header);
 
 #endif
--- a/src/lib-mail/message-content-parser.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-content-parser.c	Sun Jan 05 15:09:51 2003 +0200
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "str.h"
-#include "rfc822-tokenize.h"
+#include "message-tokenize.h"
 #include "message-content-parser.h"
 
 void message_content_parse_header(const unsigned char *data, size_t size,
@@ -10,48 +10,48 @@
 				  ParseContentParamFunc param_func,
 				  void *context)
 {
-	static const Rfc822Token stop_tokens[] = { ';', TOKEN_LAST };
-	Rfc822TokenizeContext *ctx;
-	Rfc822Token token;
-	String *str;
+	static const enum message_token stop_tokens[] = { ';', TOKEN_LAST };
+	struct message_tokenizer *tok;
+	enum message_token token;
+	string_t *str;
 	const unsigned char *key, *value;
 	size_t key_len, value_len;
 
-	ctx = rfc822_tokenize_init(data, size, NULL, NULL);
-        rfc822_tokenize_dot_token(ctx, FALSE);
+	tok = message_tokenize_init(data, size, NULL, NULL);
+        message_tokenize_dot_token(tok, FALSE);
 
 	t_push();
 	str = t_str_new(256);
 
         /* first ';' separates the parameters */
-	rfc822_tokenize_get_string(ctx, str, NULL, stop_tokens);
+	message_tokenize_get_string(tok, str, NULL, stop_tokens);
 
 	if (func != NULL)
 		func(str_data(str), str_len(str), context);
 
 	t_pop();
 
-	if (param_func != NULL && rfc822_tokenize_get(ctx) == ';') {
+	if (param_func != NULL && message_tokenize_get(tok) == ';') {
 		/* parse the parameters */
-		while ((token = rfc822_tokenize_next(ctx)) != TOKEN_LAST) {
+		while ((token = message_tokenize_next(tok)) != TOKEN_LAST) {
 			/* <token> "=" <token> | <quoted-string> */
 			if (token != TOKEN_ATOM)
 				continue;
 
-			key = rfc822_tokenize_get_value(ctx, &key_len);
+			key = message_tokenize_get_value(tok, &key_len);
 
-			if (rfc822_tokenize_next(ctx) != '=')
+			if (message_tokenize_next(tok) != '=')
 				continue;
 
-			token = rfc822_tokenize_next(ctx);
+			token = message_tokenize_next(tok);
 			if (token != TOKEN_ATOM && token != TOKEN_QSTRING)
 				continue;
 
-			value = rfc822_tokenize_get_value(ctx, &value_len);
+			value = message_tokenize_get_value(tok, &value_len);
 			param_func(key, key_len, value, value_len,
 				   token == TOKEN_QSTRING, context);
 		}
 	}
 
-	rfc822_tokenize_deinit(ctx);
+	message_tokenize_deinit(tok);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-mail/message-date.c	Sun Jan 05 15:09:51 2003 +0200
@@ -0,0 +1,247 @@
+/* Copyright (C) 2002 Timo Sirainen */
+
+#include "lib.h"
+#include "utc-offset.h"
+#include "utc-mktime.h"
+#include "message-tokenize.h"
+#include "message-date.h"
+
+#include <ctype.h>
+
+static const char *month_names[] = {
+	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
+	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+static const char *weekday_names[] = {
+	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+};
+
+static int parse_timezone(const unsigned char *str, size_t len)
+{
+	int offset;
+	char chr;
+
+	if (len == 5 && (*str == '+' || *str == '-')) {
+		/* numeric offset */
+		if (!i_isdigit(str[1]) || !i_isdigit(str[2]) ||
+		    !i_isdigit(str[3]) || !i_isdigit(str[4]))
+			return FALSE;
+
+		offset = (str[1]-'0') * 1000 + (str[2]-'0') * 100 +
+			(str[3]-'0') * 10 + (str[4]-'0');
+		return *str == '+' ? offset : -offset;
+	}
+
+	if (len == 1) {
+		/* military zone - handle them the correct way, not as
+		   RFC822 says. RFC2822 though suggests that they'd be
+		   considered as unspecified.. */
+		chr = i_toupper(*str);
+		if (chr < 'J')
+			return (*str-'A'+1) * 60;
+		if (chr == 'J')
+			return 0;
+		if (chr <= 'M')
+			return (*str-'A') * 60;
+		if (chr < 'Z')
+			return ('M'-*str) * 60;
+		return 0;
+	}
+
+	if (len == 2 && i_toupper(str[0]) == 'U' && i_toupper(str[1]) == 'T') {
+		/* UT - Universal Time */
+		return 0;
+	}
+
+	if (len == 3) {
+		/* GMT | [ECMP][DS]T */
+		if (str[2] != 'T')
+			return 0;
+
+		switch (i_toupper(*str)) {
+		case 'E':
+			offset = -5 * 60;
+			break;
+		case 'C':
+			offset = -6 * 60;
+			break;
+		case 'M':
+			offset = -7 * 60;
+			break;
+		case 'P':
+			offset = -8 * 60;
+			break;
+		default:
+			/* GMT and others */
+			return 0;
+		}
+
+		if (i_toupper(str[1]) == 'D')
+			return offset + 60;
+		if (i_toupper(str[1]) == 'S')
+			return offset;
+	}
+
+	return 0;
+}
+
+static enum message_token next_token(struct message_tokenizer *ctx,
+				     const unsigned char **value,
+				     size_t *value_len)
+{
+	enum message_token token;
+
+	token = message_tokenize_next(ctx);
+	if (token == 'A')
+		*value = message_tokenize_get_value(ctx, value_len);
+	return token;
+}
+
+static int mail_date_parse_tokens(struct message_tokenizer *ctx, time_t *time,
+				  int *timezone_offset)
+{
+	struct tm tm;
+	enum message_token token;
+	const unsigned char *value;
+	size_t i, len;
+
+	/* [weekday_name "," ] dd month_name [yy]yy hh:mi[:ss] timezone */
+	memset(&tm, 0, sizeof(tm));
+
+	/* skip the optional weekday */
+	token = next_token(ctx, &value, &len);
+	if (token == 'A' && len == 3) {
+		token = next_token(ctx, &value, &len);
+		if (token != ',')
+			return FALSE;
+
+		token = next_token(ctx, &value, &len);
+	}
+
+	/* dd */
+	if (token != 'A' || len > 2 || !i_isdigit(value[0]))
+		return FALSE;
+
+	tm.tm_mday = value[0]-'0';
+	if (len == 2) {
+		if (!i_isdigit(value[1]))
+			return FALSE;
+		tm.tm_mday = (tm.tm_mday * 10) + (value[1]-'0');
+	}
+
+	/* month name */
+	token = next_token(ctx, &value, &len);
+	if (token != 'A' || len != 3)
+		return FALSE;
+
+	for (i = 0; i < 12; i++) {
+		if (memcasecmp(month_names[i], value, 3) == 0) {
+			tm.tm_mon = i;
+			break;
+		}
+	}
+	if (i == 12)
+		return FALSE;
+
+	/* [yy]yy */
+	token = next_token(ctx, &value, &len);
+	if (token != 'A' || (len != 2 && len != 4))
+		return FALSE;
+
+	for (i = 0; i < len; i++) {
+		if (!i_isdigit(value[i]))
+			return FALSE;
+		tm.tm_year = tm.tm_year * 10 + (value[i]-'0');
+	}
+
+	if (len == 2) {
+		/* two digit year, assume 1970+ */
+		if (tm.tm_year < 70)
+			tm.tm_year += 100;
+	} else {
+		if (tm.tm_year < 1900)
+			return FALSE;
+		tm.tm_year -= 1900;
+	}
+
+	/* hh */
+	token = next_token(ctx, &value, &len);
+	if (token != 'A' || len != 2 ||
+	    !i_isdigit(value[0]) || !i_isdigit(value[1]))
+		return FALSE;
+	tm.tm_hour = (value[0]-'0') * 10 + (value[1]-'0');
+
+	/* :mm */
+	token = next_token(ctx, &value, &len);
+	if (token != ':')
+		return FALSE;
+	token = next_token(ctx, &value, &len);
+	if (token != 'A' || len != 2 ||
+	    !i_isdigit(value[0]) || !i_isdigit(value[1]))
+		return FALSE;
+	tm.tm_min = (value[0]-'0') * 10 + (value[1]-'0');
+
+	/* [:ss] */
+	token = next_token(ctx, &value, &len);
+	if (token == ':') {
+		token = next_token(ctx, &value, &len);
+		if (token != 'A' || len != 2 ||
+		    !i_isdigit(value[0]) || !i_isdigit(value[1]))
+			return FALSE;
+		tm.tm_sec = (value[0]-'0') * 10 + (value[1]-'0');
+	}
+
+	/* timezone */
+	if (token != 'A')
+		return FALSE;
+	*timezone_offset = parse_timezone(value, len);
+
+	tm.tm_isdst = -1;
+	*time = utc_mktime(&tm);
+	if (*time == (time_t)-1)
+		return FALSE;
+
+	*time -= *timezone_offset;
+
+	return TRUE;
+}
+
+int message_date_parse(const char *data, time_t *time, int *timezone_offset)
+{
+	struct message_tokenizer *ctx;
+	int ret;
+
+	if (data == NULL || *data == '\0')
+		return FALSE;
+
+	ctx = message_tokenize_init((const unsigned char *) data, (size_t)-1,
+				    NULL, NULL);
+	ret = mail_date_parse_tokens(ctx, time, timezone_offset);
+	message_tokenize_deinit(ctx);
+
+	return ret;
+}
+
+const char *message_date_create(time_t time)
+{
+	struct tm *tm;
+	int offset, negative;
+
+	tm = localtime(&time);
+	offset = utc_offset(tm, time);
+	if (offset >= 0)
+		negative = 0;
+	else {
+		negative = 1;
+		offset = -offset;
+	}
+
+	return t_strdup_printf("%s, %02d %s %04d %02d:%02d:%02d %c%02d%02d",
+			       weekday_names[tm->tm_wday],
+			       tm->tm_mday,
+			       month_names[tm->tm_mon],
+			       tm->tm_year+1900,
+			       tm->tm_hour, tm->tm_min, tm->tm_sec,
+			       negative ? '-' : '+', offset / 60, offset % 60);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-mail/message-date.h	Sun Jan 05 15:09:51 2003 +0200
@@ -0,0 +1,11 @@
+#ifndef __MESSAGE_DATE
+#define __MESSAGE_DATE