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
+
+/* Parses RFC2822 date/time string. timezone_offset is filled with the
+   timezone's difference to UTC in minutes. */
+int message_date_parse(const char *data, time_t *time, int *timezone_offset);
+
+/* Create RFC2822 date/time string from given time in local timezone. */
+const char *message_date_create(time_t time);
+
+#endif
--- a/src/lib-mail/message-header-decode.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-header-decode.c	Sun Jan 05 15:09:51 2003 +0200
@@ -50,7 +50,7 @@
 {
 	const unsigned char *text;
 	const char *charset, *encoding;
-	Buffer *decodebuf;
+	buffer_t *decodebuf;
 	size_t text_size;
 	int ret;
 
--- a/src/lib-mail/message-header-search.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-header-search.c	Sun Jan 05 15:09:51 2003 +0200
@@ -11,14 +11,14 @@
 
 #include <ctype.h>
 
-struct _HeaderSearchContext {
-	Pool pool;
+struct header_search_context {
+	pool_t pool;
 
 	unsigned char *key;
 	size_t key_len;
 	char *key_charset;
 
-	Buffer *match_buf;
+	buffer_t *match_buf;
 
 	unsigned int found:1;
 	unsigned int last_newline:1;
@@ -28,17 +28,17 @@
 };
 
 static void search_loop(const unsigned char *data, size_t size,
-			HeaderSearchContext *ctx);
+			struct header_search_context *ctx);
 
-HeaderSearchContext *
-message_header_search_init(Pool pool, const char *key, const char *charset,
+struct header_search_context *
+message_header_search_init(pool_t pool, const char *key, const char *charset,
 			   int *unknown_charset)
 {
-	HeaderSearchContext *ctx;
+	struct header_search_context *ctx;
 	size_t key_len;
 	const unsigned char *p;
 
-	ctx = p_new(pool, HeaderSearchContext, 1);
+	ctx = p_new(pool, struct header_search_context, 1);
 	ctx->pool = pool;
 
 	/* get the key uppercased */
@@ -70,9 +70,9 @@
 	return ctx;
 }
 
-void message_header_search_free(HeaderSearchContext *ctx)
+void message_header_search_free(struct header_search_context *ctx)
 {
-	Pool pool;
+	pool_t pool;
 
 	buffer_free(ctx->match_buf);
 
@@ -83,7 +83,8 @@
 }
 
 static void search_with_charset(const unsigned char *data, size_t size,
-				const char *charset, HeaderSearchContext *ctx)
+				const char *charset,
+				struct header_search_context *ctx)
 {
 	const char *utf8_data;
 	size_t utf8_size;
@@ -111,7 +112,7 @@
 }
 
 static void search_loop(const unsigned char *data, size_t size,
-			HeaderSearchContext *ctx)
+			struct header_search_context *ctx)
 {
 	size_t pos, *matches, match_count, value;
 	ssize_t i;
@@ -186,7 +187,7 @@
 static int search_block(const unsigned char *data, size_t size,
 			const char *charset, void *context)
 {
-	HeaderSearchContext *ctx = context;
+	struct header_search_context *ctx = context;
 
 	t_push();
 	if (charset != NULL) {
@@ -201,14 +202,14 @@
 }
 
 int message_header_search(const unsigned char *header_block, size_t size,
-			  HeaderSearchContext *ctx)
+			  struct header_search_context *ctx)
 {
 	if (!ctx->found)
 		message_header_decode(header_block, size, search_block, ctx);
 	return ctx->found;
 }
 
-void message_header_search_reset(HeaderSearchContext *ctx)
+void message_header_search_reset(struct header_search_context *ctx)
 {
 	buffer_set_used_size(ctx->match_buf, 0);
 	ctx->found = FALSE;
--- a/src/lib-mail/message-header-search.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-header-search.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,24 +1,24 @@
 #ifndef __MESSAGE_HEADER_SEARCH_H
 #define __MESSAGE_HEADER_SEARCH_H
 
-typedef struct _HeaderSearchContext HeaderSearchContext;
+struct header_search_context;
 
 /* Initialize new search. Returns NULL if charset is unknown or key is not
    valid in specified charset. */
-HeaderSearchContext *
-message_header_search_init(Pool pool, const char *key, const char *charset,
+struct header_search_context *
+message_header_search_init(pool_t pool, const char *key, const char *charset,
 			   int *unknown_charset);
 
 /* Free search context. Not needed if you just destroy the pool. */
-void message_header_search_free(HeaderSearchContext *ctx);
+void message_header_search_free(struct header_search_context *ctx);
 
 /* Returns TRUE if key is found from header. This function may be called
    multiple times with partial header blocks, but the blocks must contain only
    full lines so RFC2047 parsing can be done. */
 int message_header_search(const unsigned char *header_block, size_t size,
-			  HeaderSearchContext *ctx);
+			  struct header_search_context *ctx);
 
 /* Next call to message_header_search() will begin a new header. */
-void message_header_search_reset(HeaderSearchContext *ctx);
+void message_header_search_reset(struct header_search_context *ctx);
 
 #endif
--- a/src/lib-mail/message-parser.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-parser.c	Sun Jan 05 15:09:51 2003 +0200
@@ -7,36 +7,41 @@
 #include "message-parser.h"
 #include "message-size.h"
 
-typedef struct _MessageBoundary {
-	struct _MessageBoundary *next;
+struct message_boundary {
+	struct message_boundary *next;
 
-	MessagePart *part;
+	struct message_part *part;
 	const char *boundary;
 	size_t len;
-} MessageBoundary;
+};
 
-typedef struct {
-	Pool pool;
-	MessagePart *part;
+struct parser_context {
+	pool_t pool;
+	struct message_part *part;
 
 	char *last_boundary;
 	char *last_content_type;
-	MessageBoundary *boundaries;
+	struct message_boundary *boundaries;
 
 	MessageHeaderFunc func;
 	void *context;
-} MessageParseContext;
+};
+
+static struct message_part *
+message_parse_part(struct istream *input,
+		   struct parser_context *parser_ctx);
 
-static MessagePart *message_parse_part(IStream *input,
-				       MessageParseContext *parse_ctx);
-static MessagePart *message_parse_body(IStream *input,
-				       MessageBoundary *boundaries,
-				       MessageSize *body_size);
-static MessagePart *message_skip_boundary(IStream *input,
-					  MessageBoundary *boundaries,
-					  MessageSize *boundary_size);
+static struct message_part *
+message_parse_body(struct istream *input, struct message_boundary *boundaries,
+		   struct message_size *body_size);
 
-static void message_size_add_part(MessageSize *dest, MessagePart *part)
+static struct message_part *
+message_skip_boundary(struct istream *input,
+		      struct message_boundary *boundaries,
+		      struct message_size *boundary_size);
+
+static void message_size_add_part(struct message_size *dest,
+				  struct message_part *part)
 {
 	dest->physical_size +=
 		part->header_size.physical_size +
@@ -47,11 +52,12 @@
 	dest->lines += part->header_size.lines + part->body_size.lines;
 }
 
-static MessagePart *message_part_append(Pool pool, MessagePart *parent)
+static struct message_part *
+message_part_append(pool_t pool, struct message_part *parent)
 {
-	MessagePart *part, **list;
+	struct message_part *part, **list;
 
-	part = p_new(pool, MessagePart, 1);
+	part = p_new(pool, struct message_part, 1);
 	part->parent = parent;
 
 	/* set child position */
@@ -71,24 +77,24 @@
 static void parse_content_type(const unsigned char *value, size_t value_len,
 			       void *context)
 {
-	MessageParseContext *parse_ctx = context;
+	struct parser_context *parser_ctx = context;
 	const char *str;
 
-	if (parse_ctx->last_content_type != NULL || value_len == 0)
+	if (parser_ctx->last_content_type != NULL || value_len == 0)
 		return;
 
-	str = parse_ctx->last_content_type =
-		p_strndup(parse_ctx->pool, value, value_len);
+	str = parser_ctx->last_content_type =
+		p_strndup(parser_ctx->pool, value, value_len);
 
 	if (strcasecmp(str, "message/rfc822") == 0)
-		parse_ctx->part->flags |= MESSAGE_PART_FLAG_MESSAGE_RFC822;
+		parser_ctx->part->flags |= MESSAGE_PART_FLAG_MESSAGE_RFC822;
 	else if (strncasecmp(str, "text/", 5) == 0)
-		parse_ctx->part->flags |= MESSAGE_PART_FLAG_TEXT;
+		parser_ctx->part->flags |= MESSAGE_PART_FLAG_TEXT;
 	else if (strncasecmp(str, "multipart/", 10) == 0) {
-		parse_ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART;
+		parser_ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART;
 
 		if (strcasecmp(str+10, "digest") == 0) {
-			parse_ctx->part->flags |=
+			parser_ctx->part->flags |=
 				MESSAGE_PART_FLAG_MULTIPART_DIGEST;
 		}
 	}
@@ -99,31 +105,31 @@
 			 const unsigned char *value, size_t value_len,
 			 int value_quoted, void *context)
 {
-	MessageParseContext *parse_ctx = context;
+	struct parser_context *parser_ctx = context;
 
-	if ((parse_ctx->part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0 ||
+	if ((parser_ctx->part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0 ||
 	    name_len != 8 || memcasecmp(name, "boundary", 8) != 0)
 		return;
 
-	if (parse_ctx->last_boundary == NULL) {
-		parse_ctx->last_boundary =
-			p_strndup(parse_ctx->pool, value, value_len);
+	if (parser_ctx->last_boundary == NULL) {
+		parser_ctx->last_boundary =
+			p_strndup(parser_ctx->pool, value, value_len);
 		if (value_quoted)
-			str_unescape(parse_ctx->last_boundary);
+			str_unescape(parser_ctx->last_boundary);
 	}
 }
 
-static void parse_header_field(MessagePart *part,
+static void parse_header_field(struct message_part *part,
 			       const unsigned char *name, size_t name_len,
 			       const unsigned char *value, size_t value_len,
 			       void *context)
 {
-	MessageParseContext *parse_ctx = context;
+	struct parser_context *parser_ctx = context;
 
 	/* call the user-defined header parser */
-	if (parse_ctx->func != NULL) {
-		parse_ctx->func(part, name, name_len, value, value_len,
-				parse_ctx->context);
+	if (parser_ctx->func != NULL) {
+		parser_ctx->func(part, name, name_len, value, value_len,
+				 parser_ctx->context);
 	}
 
 	if (name_len == 12 && memcasecmp(name, "Content-Type", 12) == 0) {
@@ -131,41 +137,42 @@
 		message_content_parse_header(value, value_len,
 					     parse_content_type,
 					     parse_content_type_param,
-					     parse_ctx);
+					     parser_ctx);
 	}
 }
 
-static MessagePart *message_parse_multipart(IStream *input,
-					    MessageParseContext *parse_ctx)
+static struct message_part *
+message_parse_multipart(struct istream *input,
+			struct parser_context *parser_ctx)
 {
-	MessagePart *parent_part, *next_part, *part;
-	MessageBoundary *b;
+	struct message_part *parent_part, *next_part, *part;
+	struct message_boundary *b;
 
 	/* multipart message. add new boundary */
-	b = t_new(MessageBoundary, 1);
-	b->part = parse_ctx->part;
-	b->boundary = parse_ctx->last_boundary;
+	b = t_new(struct message_boundary, 1);
+	b->part = parser_ctx->part;
+	b->boundary = parser_ctx->last_boundary;
 	b->len = strlen(b->boundary);
 
-	b->next = parse_ctx->boundaries;
-	parse_ctx->boundaries = b;
+	b->next = parser_ctx->boundaries;
+	parser_ctx->boundaries = b;
 
 	/* reset fields */
-	parse_ctx->last_boundary = NULL;
-	parse_ctx->last_content_type = NULL;
+	parser_ctx->last_boundary = NULL;
+	parser_ctx->last_content_type = NULL;
 
 	/* skip the data before the first boundary */
-	parent_part = parse_ctx->part;
-	next_part = message_skip_boundary(input, parse_ctx->boundaries,
+	parent_part = parser_ctx->part;
+	next_part = message_skip_boundary(input, parser_ctx->boundaries,
 					  &parent_part->body_size);
 
 	/* now, parse the parts */
 	while (next_part == parent_part) {
 		/* new child */
-		part = message_part_append(parse_ctx->pool, parent_part);
+		part = message_part_append(parser_ctx->pool, parent_part);
 
-                parse_ctx->part = part;
-		next_part = message_parse_part(input, parse_ctx);
+                parser_ctx->part = part;
+		next_part = message_parse_part(input, parser_ctx);
 
 		/* update our size */
 		message_size_add_part(&parent_part->body_size, part);
@@ -174,95 +181,96 @@
 			break;
 
 		/* skip the boundary */
-		next_part = message_skip_boundary(input, parse_ctx->boundaries,
+		next_part = message_skip_boundary(input, parser_ctx->boundaries,
 						  &parent_part->body_size);
 	}
 
 	/* remove boundary */
-	i_assert(parse_ctx->boundaries == b);
-	parse_ctx->boundaries = b->next;
+	i_assert(parser_ctx->boundaries == b);
+	parser_ctx->boundaries = b->next;
 	return next_part;
 }
 
 #define MUTEX_FLAGS \
 	(MESSAGE_PART_FLAG_MESSAGE_RFC822 | MESSAGE_PART_FLAG_MULTIPART)
 
-static MessagePart *message_parse_part(IStream *input,
-				       MessageParseContext *parse_ctx)
+static struct message_part *
+message_parse_part(struct istream *input, struct parser_context *parser_ctx)
 {
-	MessagePart *next_part, *part;
+	struct message_part *next_part, *part;
 	uoff_t hdr_size;
 
-	message_parse_header(parse_ctx->part, input,
-			     &parse_ctx->part->header_size,
-			     parse_header_field, parse_ctx);
+	message_parse_header(parser_ctx->part, input,
+			     &parser_ctx->part->header_size,
+			     parse_header_field, parser_ctx);
 
-	i_assert((parse_ctx->part->flags & MUTEX_FLAGS) != MUTEX_FLAGS);
+	i_assert((parser_ctx->part->flags & MUTEX_FLAGS) != MUTEX_FLAGS);
 
 	/* update message position/size */
-	hdr_size = parse_ctx->part->header_size.physical_size;
+	hdr_size = parser_ctx->part->header_size.physical_size;
 
-	if (parse_ctx->last_boundary != NULL)
-		return message_parse_multipart(input, parse_ctx);
+	if (parser_ctx->last_boundary != NULL)
+		return message_parse_multipart(input, parser_ctx);
 
-	if (parse_ctx->last_content_type == NULL) {
-		if (parse_ctx->part->parent != NULL &&
-		    (parse_ctx->part->parent->flags &
+	if (parser_ctx->last_content_type == NULL) {
+		if (parser_ctx->part->parent != NULL &&
+		    (parser_ctx->part->parent->flags &
 		     MESSAGE_PART_FLAG_MULTIPART_DIGEST)) {
 			/* when there's no content-type specified and we're
 			   below multipart/digest, the assume message/rfc822
 			   content-type */
-			parse_ctx->part->flags |=
+			parser_ctx->part->flags |=
 				MESSAGE_PART_FLAG_MESSAGE_RFC822;
 		} else {
 			/* otherwise we default to text/plain */
-			parse_ctx->part->flags |= MESSAGE_PART_FLAG_TEXT;
+			parser_ctx->part->flags |= MESSAGE_PART_FLAG_TEXT;
 		}
 	}
 
-	parse_ctx->last_boundary = NULL;
-        parse_ctx->last_content_type = NULL;
+	parser_ctx->last_boundary = NULL;
+        parser_ctx->last_content_type = NULL;
 
-	if (parse_ctx->part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) {
+	if (parser_ctx->part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) {
 		/* message/rfc822 part - the message body begins with
 		   headers again, this works pretty much the same as
 		   a single multipart/mixed item */
-		part = message_part_append(parse_ctx->pool, parse_ctx->part);
+		part = message_part_append(parser_ctx->pool, parser_ctx->part);
 
-		parse_ctx->part = part;
-		next_part = message_parse_part(input, parse_ctx);
-		parse_ctx->part = part->parent;
+		parser_ctx->part = part;
+		next_part = message_parse_part(input, parser_ctx);
+		parser_ctx->part = part->parent;
 
 		/* our body size is the size of header+body in message/rfc822 */
 		message_size_add_part(&part->parent->body_size, part);
 	} else {
 		/* normal message, read until the next boundary */
-		part = parse_ctx->part;
-		next_part = message_parse_body(input, parse_ctx->boundaries,
+		part = parser_ctx->part;
+		next_part = message_parse_body(input, parser_ctx->boundaries,
 					       &part->body_size);
 	}
 
 	return next_part;
 }
 
-MessagePart *message_parse(Pool pool, IStream *input,
-			   MessageHeaderFunc func, void *context)
+struct message_part *message_parse(pool_t pool, struct istream *input,
+				   MessageHeaderFunc func, void *context)
 {
-	MessagePart *part;
-	MessageParseContext parse_ctx;
+	struct message_part *part;
+	struct parser_context parser_ctx;
 
-	memset(&parse_ctx, 0, sizeof(parse_ctx));
-	parse_ctx.pool = pool;
-	parse_ctx.func = func;
-	parse_ctx.context = context;
-	parse_ctx.part = part = p_new(pool, MessagePart, 1);
+	memset(&parser_ctx, 0, sizeof(parser_ctx));
+	parser_ctx.pool = pool;
+	parser_ctx.func = func;
+	parser_ctx.context = context;
+	parser_ctx.part = part = p_new(pool, struct message_part, 1);
 
-	message_parse_part(input, &parse_ctx);
+	message_parse_part(input, &parser_ctx);
 	return part;
 }
 
 /* skip over to next line increasing message size */
-static void message_skip_line(IStream *input, MessageSize *msg_size)
+static void message_skip_line(struct istream *input,
+			      struct message_size *msg_size)
 {
 	const unsigned char *msg;
 	size_t i, size, startpos;
@@ -304,8 +312,8 @@
 	}
 }
 
-void message_parse_header(MessagePart *part, IStream *input,
-			  MessageSize *hdr_size,
+void message_parse_header(struct message_part *part, struct istream *input,
+			  struct message_size *hdr_size,
 			  MessageHeaderFunc func, void *context)
 {
 	const unsigned char *msg;
@@ -314,7 +322,7 @@
 	int ret;
 
 	if (hdr_size != NULL)
-		memset(hdr_size, 0, sizeof(MessageSize));
+		memset(hdr_size, 0, sizeof(struct message_size));
 
 	missing_cr_count = startpos = line_start = 0;
 	colon_pos = UINT_MAX;
@@ -433,8 +441,9 @@
 	}
 }
 
-static MessageBoundary *boundary_find(MessageBoundary *boundaries,
-				      const unsigned char *msg, size_t len)
+static struct message_boundary *
+boundary_find(struct message_boundary *boundaries,
+	      const unsigned char *msg, size_t len)
 {
 	while (boundaries != NULL) {
 		if (boundaries->len <= len &&
@@ -450,11 +459,12 @@
 /* read until next boundary is found. if skip_over = FALSE, stop at the
    [\r]\n before the boundary, otherwise leave it right after the known
    boundary so the ending "--" can be checked. */
-static MessageBoundary *
-message_find_boundary(IStream *input, MessageBoundary *boundaries,
-		      MessageSize *msg_size, int skip_over)
+static struct message_boundary *
+message_find_boundary(struct istream *input,
+		      struct message_boundary *boundaries,
+		      struct message_size *msg_size, int skip_over)
 {
-	MessageBoundary *boundary;
+	struct message_boundary *boundary;
 	const unsigned char *msg;
 	size_t i, size, startpos, line_start, missing_cr_count;
 
@@ -544,11 +554,11 @@
 	return boundary;
 }
 
-static MessagePart *message_parse_body(IStream *input,
-				       MessageBoundary *boundaries,
-				       MessageSize *body_size)
+static struct message_part *
+message_parse_body(struct istream *input, struct message_boundary *boundaries,
+		   struct message_size *body_size)
 {
-	MessageBoundary *boundary;
+	struct message_boundary *boundary;
 
 	if (boundaries == NULL) {
 		message_get_body_size(input, body_size, (uoff_t)-1, NULL);
@@ -562,11 +572,12 @@
 
 /* skip data until next boundary is found. if it's end boundary,
    skip the footer as well. */
-static MessagePart *message_skip_boundary(IStream *input,
-					  MessageBoundary *boundaries,
-					  MessageSize *boundary_size)
+static struct message_part *
+message_skip_boundary(struct istream *input,
+		      struct message_boundary *boundaries,
+		      struct message_size *boundary_size)
 {
-	MessageBoundary *boundary;
+	struct message_boundary *boundary;
 	const unsigned char *msg;
 	size_t size;
 	int end_boundary;
--- a/src/lib-mail/message-parser.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-parser.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,11 +4,7 @@
 #define IS_LWSP(c) \
 	((c) == ' ' || (c) == '\t')
 
-typedef struct _MessagePart MessagePart;
-typedef struct _MessagePosition MessagePosition;
-typedef struct _MessageSize MessageSize;
-
-typedef enum {
+enum message_part_flags {
 	MESSAGE_PART_FLAG_MULTIPART		= 0x01,
 	MESSAGE_PART_FLAG_MULTIPART_DIGEST	= 0x02,
 	MESSAGE_PART_FLAG_MESSAGE_RFC822	= 0x04,
@@ -18,45 +14,45 @@
 
 	/* content-transfer-encoding: binary */
 	MESSAGE_PART_FLAG_BINARY		= 0x10
-} MessagePartFlags;
+};
 
-struct _MessageSize {
+struct message_size {
 	uoff_t physical_size;
 	uoff_t virtual_size;
 	unsigned int lines;
 };
 
-struct _MessagePart {
-	MessagePart *parent;
-	MessagePart *next;
-	MessagePart *children;
+struct message_part {
+	struct message_part *parent;
+	struct message_part *next;
+	struct message_part *children;
 
 	uoff_t physical_pos; /* absolute position from beginning of message */
-	MessageSize header_size;
-	MessageSize body_size;
+	struct message_size header_size;
+	struct message_size body_size;
 
-	MessagePartFlags flags;
+	enum message_part_flags flags;
 	void *context;
 };
 
 /* NOTE: name and value aren't \0-terminated. Also called once at end of
    headers with name_len = value_len = 0. */
-typedef void (*MessageHeaderFunc)(MessagePart *part,
+typedef void (*MessageHeaderFunc)(struct message_part *part,
 				  const unsigned char *name, size_t name_len,
 				  const unsigned char *value, size_t value_len,
 				  void *context);
 
 /* func is called for each field in message header. */
-MessagePart *message_parse(Pool pool, IStream *input,
-			   MessageHeaderFunc func, void *context);
+struct message_part *message_parse(pool_t pool, struct istream *input,
+				   MessageHeaderFunc func, void *context);
 
 /* Call func for each field in message header. Fills the hdr_size.
    part can be NULL, just make sure your header function works with it.
    This function doesn't use data stack so your header function may save
    values to it. When finished, input will point to beginning of message
    body. */
-void message_parse_header(MessagePart *part, IStream *input,
-			  MessageSize *hdr_size,
+void message_parse_header(struct message_part *part, struct istream *input,
+			  struct message_size *hdr_size,
 			  MessageHeaderFunc func, void *context);
 
 #endif
--- a/src/lib-mail/message-part-serialize.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-part-serialize.c	Sun Jan 05 15:09:51 2003 +0200
@@ -17,7 +17,7 @@
 */
 
 /* struct is 8 byte aligned */
-typedef struct {
+struct serialized_message_part {
 	uoff_t physical_pos;
   
 	uoff_t header_physical_size;
@@ -31,18 +31,18 @@
 
 	unsigned int children_count;
 	unsigned int flags;
-} SerializedMessagePart;
+};
 
-static unsigned int _message_part_serialize(MessagePart *part, Buffer *dest)
+static unsigned int
+_message_part_serialize(struct message_part *part, buffer_t *dest)
 {
-	SerializedMessagePart *spart;
+	struct serialized_message_part *spart;
 	unsigned int count = 1;
 
 	while (part != NULL) {
 		/* create serialized part */
-		spart = buffer_append_space(dest,
-					    sizeof(SerializedMessagePart));
-		memset(spart, 0, sizeof(SerializedMessagePart));
+		spart = buffer_append_space(dest, sizeof(*spart));
+		memset(spart, 0, sizeof(*spart));
 
 		spart->physical_pos = part->physical_pos;
 
@@ -69,18 +69,18 @@
 	return count;
 }
 
-void message_part_serialize(MessagePart *part, Buffer *dest)
+void message_part_serialize(struct message_part *part, buffer_t *dest)
 {
 	_message_part_serialize(part, dest);
 }
 
-static MessagePart *
-message_part_deserialize_part(Pool pool, MessagePart *parent,
-			      const SerializedMessagePart **spart_pos,
+static struct message_part *
+message_part_deserialize_part(pool_t pool, struct message_part *parent,
+			      const struct serialized_message_part **spart_pos,
 			      size_t *count, unsigned int child_count)
 {
-        const SerializedMessagePart *spart;
-	MessagePart *part, *first_part, **next_part;
+        const struct serialized_message_part *spart;
+	struct message_part *part, *first_part, **next_part;
 	unsigned int i;
 
 	first_part = NULL;
@@ -90,7 +90,7 @@
 		(*spart_pos)++;
 		(*count)--;
 
-		part = p_new(pool, MessagePart, 1);
+		part = p_new(pool, struct message_part, 1);
 		part->physical_pos = spart->physical_pos;
 
 		part->header_size.physical_size = spart->header_physical_size;
@@ -118,18 +118,18 @@
 	return first_part;
 }
 
-MessagePart *message_part_deserialize(Pool pool, const void *data,
-				      size_t size)
+struct message_part *message_part_deserialize(pool_t pool, const void *data,
+					      size_t size)
 {
-        const SerializedMessagePart *spart;
+        const struct serialized_message_part *spart;
 	size_t count;
 
 	/* make sure it looks valid */
-	if (size < sizeof(SerializedMessagePart))
+	if (size < sizeof(struct serialized_message_part))
 		return NULL;
 
 	spart = data;
-	count = size / sizeof(SerializedMessagePart);
+	count = size / sizeof(struct serialized_message_part);
 	if (count > UINT_MAX)
 		return NULL;
 
@@ -138,15 +138,15 @@
 }
 
 int message_part_serialize_update_header(void *data, size_t size,
-					 MessageSize *hdr_size)
+					 struct message_size *hdr_size)
 {
-	SerializedMessagePart *spart = data;
+	struct serialized_message_part *spart = data;
 	uoff_t first_pos;
 	off_t pos_diff;
 	size_t i, count;
 
 	/* make sure it looks valid */
-	if (size < sizeof(SerializedMessagePart))
+	if (size < sizeof(struct serialized_message_part))
 		return FALSE;
 
 	if (hdr_size->physical_size >= OFF_T_MAX ||
@@ -163,7 +163,7 @@
 
 	if (pos_diff != 0) {
 		/* have to update all positions, but skip the first one */
-		count = (size / sizeof(SerializedMessagePart))-1;
+		count = (size / sizeof(struct serialized_message_part))-1;
 		spart++;
 
 		for (i = 0; i < count; i++, spart++) {
@@ -179,13 +179,13 @@
 }
 
 int message_part_deserialize_size(const void *data, size_t size,
-				  MessageSize *hdr_size,
-				  MessageSize *body_size)
+				  struct message_size *hdr_size,
+				  struct message_size *body_size)
 {
-        const SerializedMessagePart *spart = data;
+        const struct serialized_message_part *spart = data;
 
 	/* make sure it looks valid */
-	if (size < sizeof(SerializedMessagePart))
+	if (size < sizeof(struct serialized_message_part))
 		return FALSE;
 
 	hdr_size->physical_size = spart->header_physical_size;
--- a/src/lib-mail/message-part-serialize.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-part-serialize.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,19 +1,23 @@
 #ifndef __MESSAGE_PART_SERIALIZE_H
 #define __MESSAGE_PART_SERIALIZE_H
 
-/* Serialize message part. */
-void message_part_serialize(MessagePart *part, Buffer *dest);
+struct message_part;
+struct message_size;
 
-/* Generate MessagePart from serialized data. */
-MessagePart *message_part_deserialize(Pool pool, const void *data, size_t size);
+/* Serialize message part. */
+void message_part_serialize(struct message_part *part, buffer_t *dest);
 
-/* Update header size in serialized MessagePart. */
-int message_part_serialize_update_header(void *data, size_t size,
-					 MessageSize *hdr_size);
+/* Generate struct message_part from serialized data. */
+struct message_part *message_part_deserialize(pool_t pool, const void *data,
+					      size_t size);
 
-/* Get message size from serialized MessagePart data. */
+/* Update header size in serialized struct message_part. */
+int message_part_serialize_update_header(void *data, size_t size,
+					 struct message_size *hdr_size);
+
+/* Get message size from serialized struct message_part data. */
 int message_part_deserialize_size(const void *data, size_t size,
-				  MessageSize *hdr_size,
-				  MessageSize *body_size);
+				  struct message_size *hdr_size,
+				  struct message_size *body_size);
 
 #endif
--- a/src/lib-mail/message-send.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-send.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,10 +3,12 @@
 #include "lib.h"
 #include "istream.h"
 #include "ostream.h"
+#include "message-parser.h"
 #include "message-send.h"
 #include "message-size.h"
 
-int message_send(OStream *output, IStream *input, MessageSize *msg_size,
+int message_send(struct ostream *output, struct istream *input,
+		 struct message_size *msg_size,
 		 uoff_t virtual_skip, uoff_t max_virtual_size)
 {
 	const unsigned char *msg;
--- a/src/lib-mail/message-send.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-send.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,13 +1,14 @@
 #ifndef __MESSAGE_SEND_H
 #define __MESSAGE_SEND_H
 
-#include "message-parser.h"
+struct message_size;
 
 /* Send message to client inserting CRs if needed. Only max_virtual_size
    bytes if sent (relative to virtual_skip), if you want it unlimited,
    use (uoff_t)-1. Remember that if input begins with LF, CR is inserted
    before it unless virtual_skip = 1. Returns TRUE if successful. */
-int message_send(OStream *output, IStream *input, MessageSize *msg_size,
+int message_send(struct ostream *output, struct istream *input,
+		 struct message_size *msg_size,
 		 uoff_t virtual_skip, uoff_t max_virtual_size);
 
 #endif
--- a/src/lib-mail/message-size.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-size.c	Sun Jan 05 15:09:51 2003 +0200
@@ -5,12 +5,12 @@
 #include "message-parser.h"
 #include "message-size.h"
 
-void message_get_header_size(IStream *input, MessageSize *hdr)
+void message_get_header_size(struct istream *input, struct message_size *hdr)
 {
 	const unsigned char *msg;
 	size_t i, size, startpos, missing_cr_count;
 
-	memset(hdr, 0, sizeof(MessageSize));
+	memset(hdr, 0, sizeof(struct message_size));
 
 	missing_cr_count = 0; startpos = 0;
 	while (i_stream_read_data(input, &msg, &size, startpos) > 0) {
@@ -55,14 +55,14 @@
 	i_assert(hdr->virtual_size >= hdr->physical_size);
 }
 
-void message_get_body_size(IStream *input, MessageSize *body,
+void message_get_body_size(struct istream *input, struct message_size *body,
 			   uoff_t max_virtual_size, int *last_cr)
 {
 	const unsigned char *msg;
 	size_t i, size, startpos, missing_cr_count;
 	int cr;
 
-	memset(body, 0, sizeof(MessageSize));
+	memset(body, 0, sizeof(struct message_size));
 
 	cr = 0;
 	missing_cr_count = 0; startpos = 0;
@@ -110,8 +110,8 @@
 		*last_cr = cr;
 }
 
-void message_skip_virtual(IStream *input, uoff_t virtual_skip,
-			  MessageSize *msg_size, int *cr_skipped)
+void message_skip_virtual(struct istream *input, uoff_t virtual_skip,
+			  struct message_size *msg_size, int *cr_skipped)
 {
 	const unsigned char *msg;
 	size_t i, size, startpos;
@@ -168,7 +168,8 @@
 	}
 }
 
-void message_size_add(MessageSize *dest, const MessageSize *src)
+void message_size_add(struct message_size *dest,
+		      const struct message_size *src)
 {
 	dest->virtual_size += src->virtual_size;
 	dest->physical_size += src->physical_size;
--- a/src/lib-mail/message-size.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/message-size.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,24 +1,25 @@
 #ifndef __MESSAGE_SIZE_H
 #define __MESSAGE_SIZE_H
 
-#include "message-parser.h"
+struct message_size;
 
 /* Calculate size of message header. Leave the input point to first
    character in body. */
-void message_get_header_size(IStream *input, MessageSize *hdr);
+void message_get_header_size(struct istream *input, struct message_size *hdr);
 /* Calculate size of message body. Read only max_virtual_size virtual bytes,
    if you want it unlimited, use (uoff_t)-1. If last_cr is not NULL, it's set
    to 1 if last character is CR, 2 if it's virtual CR. */
-void message_get_body_size(IStream *input, MessageSize *body,
+void message_get_body_size(struct istream *input, struct message_size *body,
 			   uoff_t max_virtual_size, int *last_cr);
 
 /* Skip number of virtual bytes from putfer. If first character is \n, and
    cr_skipped is FALSE, \r must be sent before it. msg_size is updated if
    it's not NULL. */
-void message_skip_virtual(IStream *input, uoff_t virtual_skip,
-			  MessageSize *msg_size, int *cr_skipped);
+void message_skip_virtual(struct istream *input, uoff_t virtual_skip,
+			  struct message_size *msg_size, int *cr_skipped);
 
 /* Sum contents of src into dest. */
-void message_size_add(MessageSize *dest, const MessageSize *src);
+void message_size_add(struct message_size *dest,
+		      const struct message_size *src);
 
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-mail/message-tokenize.c	Sun Jan 05 15:09:51 2003 +0200
@@ -0,0 +1,344 @@
+/* Copyright (C) 2002 Timo Sirainen */
+
+#include "lib.h"
+#include "str.h"
+#include "strescape.h"
+#include "message-tokenize.h"
+
+struct message_tokenizer {
+	const unsigned char *data;
+	size_t size;
+
+	MessageTokenizeErrorFunc error_func;
+	void *error_context;
+
+	int token;
+	size_t token_pos, token_len;
+	size_t parse_pos;
+
+	unsigned int skip_comments:1;
+	unsigned int dot_token:1;
+
+	unsigned int in_bracket:1;
+};
+
+#define PARSE_ERROR() \
+	STMT_START { \
+	if (tok->error_func != NULL && \
+	    !tok->error_func(data, i, '\0', tok->error_context)) { \
+		tok->token = TOKEN_LAST; \
+		return TOKEN_LAST; \
+	} \
+	} STMT_END
+
+#define PARSE_ERROR_MISSING(c) \
+	STMT_START { \
+	if (tok->error_func != NULL && \
+	    !tok->error_func(data, i, c, tok->error_context)) { \
+		tok->token = TOKEN_LAST; \
+		return TOKEN_LAST; \
+	} \
+	} STMT_END
+
+
+struct message_tokenizer *
+message_tokenize_init(const unsigned char *data, size_t size,
+		      MessageTokenizeErrorFunc error_func, void *error_context)
+{
+	struct message_tokenizer *tok;
+
+	tok = i_new(struct message_tokenizer, 1);
+	tok->data = data;
+	tok->size = size;
+
+	tok->error_func = error_func;
+	tok->error_context = error_context;
+
+	tok->skip_comments = TRUE;
+	tok->dot_token = TRUE;
+
+	tok->token = -1;
+	return tok;
+}
+
+void message_tokenize_deinit(struct message_tokenizer *tok)
+{
+	i_free(tok);
+}
+
+void message_tokenize_skip_comments(struct message_tokenizer *tok, int set)
+{
+	tok->skip_comments = set;
+}
+
+void message_tokenize_dot_token(struct message_tokenizer *tok, int set)
+{
+	tok->dot_token = set;
+}
+
+enum message_token message_tokenize_next(struct message_tokenizer *tok)
+{
+	int token, level, last_atom;
+	const unsigned char *data;
+	size_t i, size;
+
+	if (tok->token == TOKEN_LAST)
+		return TOKEN_LAST;
+
+	data = tok->data;
+	size = tok->size;
+
+	tok->token = TOKEN_LAST;
+
+	last_atom = FALSE;
+	for (i = tok->parse_pos; i < size && data[i] != '\0'; i++) {
+		token = -1;
+		switch (data[i]) {
+		case ' ':
+		case '\t':
+		case '\r':
+		case '\n':
+			/* skip whitespace */
+			break;
+
+		case '(':
+			/* (comment) - nesting is allowed */
+			if (last_atom)
+				break;
+
+			token = '(';
+			tok->token_pos = ++i;
+
+			level = 1;
+			for (; i < size && data[i] != '\0'; i++) {
+				if (data[i] == '\\' &&
+				    i+1 < size && data[i+1] != '\0')
+					i++;
+				else if (data[i] == '(')
+					level++;
+				else if (data[i] == ')') {
+					if (--level == 0)
+						break;
+				}
+			}
+
+			if (level > 0)
+				PARSE_ERROR_MISSING(')');
+
+			tok->token_len = (size_t) (i - tok->token_pos);
+			break;
+
+		case '[':
+			/* domain literal - nesting isn't allowed */
+			if (last_atom)
+				break;
+
+			token = '[';
+			tok->token_pos = ++i;
+
+			while (i < size && data[i] != '\0' && data[i] != ']') {
+				if (data[i] == '\\' &&
+				    i+1 < size && data[i+1] != '\0')
+					i++;
+				else if (data[i] == '[') {
+					/* nesting not allowed, but
+					   continue anyway */
+					PARSE_ERROR();
+				}
+
+				i++;
+			}
+
+			if (i == size || data[i] == '\0')
+				PARSE_ERROR_MISSING(']');
+
+			tok->token_len = (size_t) (i - tok->token_pos);
+			break;
+
+		case '"':
+			/* quoted string */
+			if (last_atom)
+				break;
+
+			token = '"';
+			tok->token_pos = ++i;
+
+			while (i < size && data[i] != '\0' && data[i] != '"') {
+				if (data[i] == '\\' &&
+				    i+1 < size && data[i+1] != '\0')
+					i++;
+				i++;
+			}
+
+			if (i == size || data[i] == '\0')
+				PARSE_ERROR_MISSING('"');
+
+			tok->token_len = (size_t) (i - tok->token_pos);
+			break;
+
+		case '<':
+			if (last_atom)
+				break;
+
+			if (tok->in_bracket) {
+				/* '<' cannot be nested */
+				PARSE_ERROR();
+			}
+
+			token = '<';
+			tok->in_bracket = TRUE;
+			break;
+		case '>':
+			if (last_atom)
+				break;
+
+			if (!tok->in_bracket) {
+				/* missing '<' */
+                                PARSE_ERROR();
+			}
+
+			token = '>';
+			tok->in_bracket = FALSE;
+			break;
+
+		case ')':
+		case ']':
+		case '\\':
+			PARSE_ERROR();
+			/* fall through */
+
+		/* RFC822 specials: */
+		case '@':
+		case ',':
+		case ';':
+		case ':':
+		case '.':
+		/* RFC 2045 specials: */
+		case '/':
+		case '?':
+		case '=':
+			token = tok->data[i];
+			if (token != '.' || tok->dot_token)
+				break;
+			/* fall through */
+		default:
+			/* atom */
+			token = 'A';
+			if (!last_atom) {
+				tok->token = token;
+				tok->token_pos = i;
+				last_atom = TRUE;
+			}
+			break;
+		}
+
+		if (last_atom) {
+			if (token != 'A') {
+				/* end of atom */
+				tok->token_len = (size_t) (i - tok->token_pos);
+				last_atom = FALSE;
+				break;
+			}
+		} else {
+			if (token != -1) {
+				tok->token = token;
+				if (i < tok->size && data[i] != '\0')
+					i++;
+				break;
+			}
+		}
+
+		if (i == tok->size || data[i] == '\0') {
+			/* unexpected eol */
+			break;
+		}
+	}
+
+	if (last_atom) {
+		/* end of atom */
+		tok->token_len = (size_t) (i - tok->token_pos);
+	}
+
+	tok->parse_pos = i;
+
+	if (tok->token == TOKEN_LAST && tok->in_bracket &&
+	    tok->error_func != NULL) {
+		if (tok->error_func(data, i, '>', tok->error_context))
+			tok->token = TOKEN_LAST;
+	}
+
+	return tok->token;
+}
+
+enum message_token message_tokenize_get(const struct message_tokenizer *tok)
+{
+	return tok->token;
+}
+
+const unsigned char *
+message_tokenize_get_value(const struct message_tokenizer *tok, size_t *len)
+{
+	i_assert(IS_TOKEN_STRING(tok->token));
+
+	*len = tok->token_len;
+	return tok->data + tok->token_pos;
+}
+
+void message_tokenize_get_string(struct message_tokenizer *tok,
+				 string_t *str, string_t *comments,
+				 const enum message_token *stop_tokens)
+{
+	enum message_token token;
+	const unsigned char *value;
+	size_t len;
+	int i, token_str, last_str;
+
+	last_str = FALSE;
+	while ((token = message_tokenize_next(tok)) != TOKEN_LAST) {
+		for (i = 0; stop_tokens[i] != TOKEN_LAST; i++)
+			if (token == stop_tokens[i])
+				return;
+
+		if (token == TOKEN_COMMENT) {
+			/* handle comment specially */
+			if (comments != NULL) {
+				if (str_len(comments) > 0)
+					str_append_c(comments, ' ');
+
+				value = message_tokenize_get_value(tok, &len);
+				str_append_unescaped(comments, value, len);
+			}
+			continue;
+		}
+
+		token_str = token == TOKEN_ATOM || token == TOKEN_QSTRING ||
+			token == TOKEN_DLITERAL || token == TOKEN_COMMENT;
+
+		if (!token_str)
+			str_append_c(str, token);
+		else if (token == TOKEN_QSTRING) {
+			/* unescape only quoted strings, since we're removing
+			   the quotes. for domain literals I don't see much
+			   point in unescaping if [] is still kept.. */
+			if (last_str)
+				str_append_c(str, ' ');
+
+			value = message_tokenize_get_value(tok, &len);
+			str_append_unescaped(str, value, len);
+		} else {
+			if (last_str)
+				str_append_c(str, ' ');
+
+			if (token == TOKEN_DLITERAL)
+				str_append_c(str, '[');
+
+			value = message_tokenize_get_value(tok, &len);
+			str_append_n(str, value, len);
+
+			if (token == TOKEN_DLITERAL)
+				str_append_c(str, ']');
+		}
+
+		last_str = token_str;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-mail/message-tokenize.h	Sun Jan 05 15:09:51 2003 +0200
@@ -0,0 +1,66 @@
+#ifndef __MESSAGE_TOKENIZE_H
+#define __MESSAGE_TOKENIZE_H
+
+#define IS_TOKEN_STRING(token) \
+	((token) == TOKEN_ATOM || (token) == TOKEN_QSTRING || \
+	 (token) == TOKEN_COMMENT || (token) == TOKEN_DLITERAL)
+
+enum message_token {
+	TOKEN_ATOM	= 'A',
+	TOKEN_QSTRING	= '"',
+	TOKEN_COMMENT	= '(',
+	TOKEN_DLITERAL	= '[',
+
+	/* RFC822 specials:
+
+	   '<', '>', '@', ',', ';', ':', '\'
+	   '.' (not included in RFC2045 -> optional)
+
+	   RFC2045 tspecials:
+
+	   '/', '?', '=' */
+
+	TOKEN_LAST	= 0
+};
+
+struct message_tokenizer;
+
+/* Parsing is aborted if returns FALSE. There's two kinds of errors:
+
+   missing_char == '\0': unexpected character at str[pos]
+   missing_char != '\0': missing character */
+typedef int (*MessageTokenizeErrorFunc)(const unsigned char *str, size_t pos,
+					char missing_char, void *context);
+
+/* Tokenize the string. Returns NULL if string is empty. Memory for
+   returned array is allocated from data stack. You don't have to use
+   the tokens_count, since last token is always 0. */
+struct message_tokenizer *
+message_tokenize_init(const unsigned char *data, size_t size,
+		      MessageTokenizeErrorFunc error_func, void *error_context);
+void message_tokenize_deinit(struct message_tokenizer *tok);
+
+/* Specify whether comments should be silently skipped (default yes). */
+void message_tokenize_skip_comments(struct message_tokenizer *tok, int set);
+/* Specify whether '.' should be treated as a separate token (default yes). */
+void message_tokenize_dot_token(struct message_tokenizer *tok, int set);
+
+/* Parse the next token and return it. */
+enum message_token message_tokenize_next(struct message_tokenizer *tok);
+
+/* Return the current token. */
+enum message_token message_tokenize_get(const struct message_tokenizer *tok);
+
+/* - not including enclosing "", () or []
+   - '\' isn't expanded
+   - [CR+]LF+LWSP (continued header) isn't removed */
+const unsigned char *
+message_tokenize_get_value(const struct message_tokenizer *tok, size_t *len);
+
+/* Read tokens as a string, all quoted strings will be unquoted.
+   Reads until stop_token is found. */
+void message_tokenize_get_string(struct message_tokenizer *tok,
+				 string_t *str, string_t *comments,
+				 const enum message_token *stop_tokens);
+
+#endif
--- a/src/lib-mail/quoted-printable.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/quoted-printable.c	Sun Jan 05 15:09:51 2003 +0200
@@ -6,7 +6,7 @@
 #include "quoted-printable.h"
 
 void quoted_printable_decode(const unsigned char *src, size_t src_size,
-			     size_t *src_pos_r, Buffer *dest)
+			     size_t *src_pos_r, buffer_t *dest)
 {
 	char hexbuf[3];
 	size_t src_pos, next;
--- a/src/lib-mail/quoted-printable.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-mail/quoted-printable.h	Sun Jan 05 15:09:51 2003 +0200
@@ -8,6 +8,6 @@
    If src_pos is non-NULL, it's updated to first non-translated character in
    src. */
 void quoted_printable_decode(const unsigned char *src, size_t src_size,
-			     size_t *src_pos_r, Buffer *dest);
+			     size_t *src_pos_r, buffer_t *dest);
 
 #endif
--- a/src/lib-mail/rfc822-address.c	Sun Jan 05 11:23:13 2003 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,211 +0,0 @@
-/* Copyright (C) 2002 Timo Sirainen */
-
-#include "lib.h"
-#include "str.h"
-#include "rfc822-tokenize.h"
-#include "rfc822-address.h"
-
-static Rfc822Address *new_address(Pool pool, Rfc822Address ***next_addr)
-{
-	Rfc822Address *addr;
-
-	addr = p_new(pool, Rfc822Address, 1);
-
-	**next_addr = addr;
-	*next_addr = &addr->next;
-
-	return addr;
-}
-
-Rfc822Address *rfc822_address_parse(Pool pool, const unsigned char *data,
-				    size_t size)
-{
-	static const Rfc822Token stop_tokens_init[] =
-		{ ',', '@', '<', ':', TOKEN_LAST };
-	static const Rfc822Token stop_tokens_group[] =
-		{ ',', '@', '<', ';', TOKEN_LAST };
-	static const Rfc822Token stop_tokens_domain[] =
-		{ ',', '<', TOKEN_LAST };
-	static const Rfc822Token stop_tokens_domain_group[] =
-		{ ',', '<', ';', TOKEN_LAST };
-	static const Rfc822Token stop_tokens_post_addr[] =
-		{ ',', TOKEN_LAST };
-	static const Rfc822Token stop_tokens_post_addr_group[] =
-		{ ',', ';', TOKEN_LAST };
-	static const Rfc822Token stop_tokens_addr_route[] =
-		{ ':', '>', TOKEN_LAST };
-	static const Rfc822Token stop_tokens_addr_mailbox[] =
-		{ '@', '>', TOKEN_LAST };
-	static const Rfc822Token stop_tokens_addr_domain[] =
-		{ '>', TOKEN_LAST };
-
-	Rfc822Address *first_addr, **next_addr, *addr;
-	Rfc822TokenizeContext *ctx;
-	const Rfc822Token *stop_tokens;
-	Rfc822Token token;
-	String *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)
-	*/
-	ctx = rfc822_tokenize_init(data, size, NULL, NULL);
-	rfc822_tokenize_skip_comments(ctx, 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;
-		}
-		rfc822_tokenize_get_string(ctx, 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 = rfc822_tokenize_get(ctx);
-		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 */
-			rfc822_tokenize_get_string(ctx, mailbox, NULL,
-						   stop_tokens_addr_mailbox);
-
-			if (rfc822_tokenize_get(ctx) == '@' &&
-			    str_len(mailbox) == 0) {
-				/* route is given */
-				rfc822_tokenize_get_string(ctx,
-					route, NULL, stop_tokens_addr_route);
-
-				if (rfc822_tokenize_get(ctx) == ':') {
-					/* mailbox comes next */
-					rfc822_tokenize_get_string(ctx,
-						mailbox, NULL,
-						stop_tokens_addr_mailbox);
-				}
-			}
-
-			if (rfc822_tokenize_get(ctx) == '@') {
-				/* domain */
-				rfc822_tokenize_get_string(ctx,
-					domain, NULL, stop_tokens_addr_domain);
-			}
-
-			token = rfc822_tokenize_get(ctx);
-			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();
-	rfc822_tokenize_deinit(ctx);
-
-	return first_addr;
-}
-
--- a/src/lib-mail/rfc822-address.h	Sun Jan 05 11:23:13 2003 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#ifndef __RFC822_ADDRLIST_H
-#define __RFC822_ADDRLIST_H
-
-typedef struct _Rfc822Address Rfc822Address;
-
-struct _Rfc822Address {
-	Rfc822Address *next;
-
-	char *name, *route, *mailbox, *domain;
-};
-
-Rfc822Address *rfc822_address_parse(Pool pool, const unsigned char *data,
-				    size_t size);
-
-#endif
--- a/src/lib-mail/rfc822-date.c	Sun Jan 05 11:23:13 2003 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,246 +0,0 @@
-/* Copyright (C) 2002 Timo Sirainen */
-
-#include "lib.h"
-#include "utc-offset.h"
-#include "utc-mktime.h"
-#include "rfc822-date.h"
-#include "rfc822-tokenize.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 Rfc822Token next_token(Rfc822TokenizeContext *ctx,
-			      const unsigned char **value, size_t *value_len)
-{
-	Rfc822Token token;
-
-	token = rfc822_tokenize_next(ctx);
-	if (token == 'A')
-		*value = rfc822_tokenize_get_value(ctx, value_len);
-	return token;
-}
-
-static int rfc822_parse_date_tokens(Rfc822TokenizeContext *ctx, time_t *time,
-				    int *timezone_offset)
-{
-	struct tm tm;
-	Rfc822Token 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 rfc822_parse_date(const char *data, time_t *time, int *timezone_offset)
-{
-	Rfc822TokenizeContext *ctx;
-	int ret;
-
-	if (data == NULL || *data == '\0')
-		return FALSE;
-
-	ctx = rfc822_tokenize_init((const unsigned char *) data, (size_t)-1,
-				   NULL, NULL);
-	ret = rfc822_parse_date_tokens(ctx, time, timezone_offset);
-	rfc822_tokenize_deinit(ctx);
-
-	return ret;
-}
-
-const char *rfc822_to_date(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);
-}
--- a/src/lib-mail/rfc822-date.h	Sun Jan 05 11:23:13 2003 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-#ifndef __RFC822_DATE
-#define __RFC822_DATE
-
-/* Parses RFC822 date/time string. timezone_offset is filled with the
-   timezone's difference to UTC in minutes. */
-int rfc822_parse_date(const char *data, time_t *time, int *timezone_offset);
-
-/* Create RFC822 date/time string from given time in local timezone. */
-const char *rfc822_to_date(time_t time);
-
-#endif
--- a/src/lib-mail/rfc822-tokenize.c	Sun Jan 05 11:23:13 2003 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,344 +0,0 @@
-/* Copyright (C) 2002 Timo Sirainen */
-
-#include "lib.h"
-#include "str.h"
-#include "strescape.h"
-#include "rfc822-tokenize.h"
-
-struct _Rfc822TokenizeContext {
-	const unsigned char *data;
-	size_t size;
-
-	Rfc822TokenizeErrorFunc error_func;
-	void *error_context;
-
-	int token;
-	size_t token_pos, token_len;
-	size_t parse_pos;
-
-	unsigned int skip_comments:1;
-	unsigned int dot_token:1;
-
-	unsigned int in_bracket:1;
-};
-
-#define PARSE_ERROR() \
-	STMT_START { \
-	if (ctx->error_func != NULL && \
-	    !ctx->error_func(data, i, '\0', ctx->error_context)) { \
-		ctx->token = TOKEN_LAST; \
-		return TOKEN_LAST; \
-	} \
-	} STMT_END
-
-#define PARSE_ERROR_MISSING(c) \
-	STMT_START { \
-	if (ctx->error_func != NULL && \
-	    !ctx->error_func(data, i, c, ctx->error_context)) { \
-		ctx->token = TOKEN_LAST; \
-		return TOKEN_LAST; \
-	} \
-	} STMT_END
-
-
-Rfc822TokenizeContext *
-rfc822_tokenize_init(const unsigned char *data, size_t size,
-		     Rfc822TokenizeErrorFunc error_func, void *error_context)
-{
-	Rfc822TokenizeContext *ctx;
-
-	ctx = i_new(Rfc822TokenizeContext, 1);
-	ctx->data = data;
-	ctx->size = size;
-
-	ctx->error_func = error_func;
-	ctx->error_context = error_context;
-
-	ctx->skip_comments = TRUE;
-	ctx->dot_token = TRUE;
-
-	ctx->token = -1;
-	return ctx;
-}
-
-void rfc822_tokenize_deinit(Rfc822TokenizeContext *ctx)
-{
-	i_free(ctx);
-}
-
-void rfc822_tokenize_skip_comments(Rfc822TokenizeContext *ctx, int set)
-{
-	ctx->skip_comments = set;
-}
-
-void rfc822_tokenize_dot_token(Rfc822TokenizeContext *ctx, int set)
-{
-	ctx->dot_token = set;
-}
-
-Rfc822Token rfc822_tokenize_next(Rfc822TokenizeContext *ctx)
-{
-	int token, level, last_atom;
-	const unsigned char *data;
-	size_t i, size;
-
-	if (ctx->token == TOKEN_LAST)
-		return TOKEN_LAST;
-
-	data = ctx->data;
-	size = ctx->size;
-
-	ctx->token = TOKEN_LAST;
-
-	last_atom = FALSE;
-	for (i = ctx->parse_pos; i < size && data[i] != '\0'; i++) {
-		token = -1;
-		switch (data[i]) {
-		case ' ':
-		case '\t':
-		case '\r':
-		case '\n':
-			/* skip whitespace */
-			break;
-
-		case '(':
-			/* (comment) - nesting is allowed */
-			if (last_atom)
-				break;
-
-			token = '(';
-			ctx->token_pos = ++i;
-
-			level = 1;
-			for (; i < size && data[i] != '\0'; i++) {
-				if (data[i] == '\\' &&
-				    i+1 < size && data[i+1] != '\0')
-					i++;
-				else if (data[i] == '(')
-					level++;
-				else if (data[i] == ')') {
-					if (--level == 0)
-						break;
-				}
-			}
-
-			if (level > 0)
-				PARSE_ERROR_MISSING(')');
-
-			ctx->token_len = (size_t) (i - ctx->token_pos);
-			break;
-
-		case '[':
-			/* domain literal - nesting isn't allowed */
-			if (last_atom)
-				break;
-
-			token = '[';
-			ctx->token_pos = ++i;
-
-			while (i < size && data[i] != '\0' && data[i] != ']') {
-				if (data[i] == '\\' &&
-				    i+1 < size && data[i+1] != '\0')
-					i++;
-				else if (data[i] == '[') {
-					/* nesting not allowed, but
-					   continue anyway */
-					PARSE_ERROR();
-				}
-
-				i++;
-			}
-
-			if (i == size || data[i] == '\0')
-				PARSE_ERROR_MISSING(']');
-
-			ctx->token_len = (size_t) (i - ctx->token_pos);
-			break;
-
-		case '"':
-			/* quoted string */
-			if (last_atom)
-				break;
-
-			token = '"';
-			ctx->token_pos = ++i;
-
-			while (i < size && data[i] != '\0' && data[i] != '"') {
-				if (data[i] == '\\' &&
-				    i+1 < size && data[i+1] != '\0')
-					i++;
-				i++;
-			}
-
-			if (i == size || data[i] == '\0')
-				PARSE_ERROR_MISSING('"');
-
-			ctx->token_len = (size_t) (i - ctx->token_pos);
-			break;
-
-		case '<':
-			if (last_atom)
-				break;
-
-			if (ctx->in_bracket) {
-				/* '<' cannot be nested */
-				PARSE_ERROR();
-			}
-
-			token = '<';
-			ctx->in_bracket = TRUE;
-			break;
-		case '>':
-			if (last_atom)
-				break;
-
-			if (!ctx->in_bracket) {
-				/* missing '<' */
-                                PARSE_ERROR();
-			}
-
-			token = '>';
-			ctx->in_bracket = FALSE;
-			break;
-
-		case ')':
-		case ']':
-		case '\\':
-			PARSE_ERROR();
-			/* fall through */
-
-		/* RFC822 specials: */
-		case '@':
-		case ',':
-		case ';':
-		case ':':
-		case '.':
-		/* RFC 2045 specials: */
-		case '/':
-		case '?':
-		case '=':
-			token = ctx->data[i];
-			if (token != '.' || ctx->dot_token)
-				break;
-			/* fall through */
-		default:
-			/* atom */
-			token = 'A';
-			if (!last_atom) {
-				ctx->token = token;
-				ctx->token_pos = i;
-				last_atom = TRUE;
-			}
-			break;
-		}
-
-		if (last_atom) {
-			if (token != 'A') {
-				/* end of atom */
-				ctx->token_len = (size_t) (i - ctx->token_pos);
-				last_atom = FALSE;
-				break;
-			}
-		} else {
-			if (token != -1) {
-				ctx->token = token;
-				if (i < ctx->size && data[i] != '\0')
-					i++;
-				break;
-			}
-		}
-
-		if (i == ctx->size || data[i] == '\0') {
-			/* unexpected eol */
-			break;
-		}
-	}
-
-	if (last_atom) {
-		/* end of atom */
-		ctx->token_len = (size_t) (i - ctx->token_pos);
-	}
-
-	ctx->parse_pos = i;
-
-	if (ctx->token == TOKEN_LAST && ctx->in_bracket &&
-	    ctx->error_func != NULL) {
-		if (ctx->error_func(data, i, '>', ctx->error_context))
-			ctx->token = TOKEN_LAST;
-	}
-
-	return ctx->token;
-}
-
-Rfc822Token rfc822_tokenize_get(const Rfc822TokenizeContext *ctx)
-{
-	return ctx->token;
-}
-
-const unsigned char *
-rfc822_tokenize_get_value(const Rfc822TokenizeContext *ctx, size_t *len)
-{
-	i_assert(IS_TOKEN_STRING(ctx->token));
-
-	*len = ctx->token_len;
-	return ctx->data + ctx->token_pos;
-}
-
-void rfc822_tokenize_get_string(Rfc822TokenizeContext *ctx,
-				String *str, String *comments,
-				const Rfc822Token *stop_tokens)
-{
-	Rfc822Token token;
-	const unsigned char *value;
-	size_t len;
-	int i, token_str, last_str;
-
-	last_str = FALSE;
-	while ((token = rfc822_tokenize_next(ctx)) != TOKEN_LAST) {
-		for (i = 0; stop_tokens[i] != TOKEN_LAST; i++)
-			if (token == stop_tokens[i])
-				return;
-
-		if (token == TOKEN_COMMENT) {
-			/* handle comment specially */
-			if (comments != NULL) {
-				if (str_len(comments) > 0)
-					str_append_c(comments, ' ');
-
-				value = rfc822_tokenize_get_value(ctx, &len);
-				str_append_unescaped(comments, value, len);
-			}
-			continue;
-		}
-
-		token_str = token == TOKEN_ATOM || token == TOKEN_QSTRING ||
-			token == TOKEN_DLITERAL || token == TOKEN_COMMENT;
-
-		if (!token_str)
-			str_append_c(str, token);
-		else if (token == TOKEN_QSTRING) {
-			/* unescape only quoted strings, since we're removing
-			   the quotes. for domain literals I don't see much
-			   point in unescaping if [] is still kept.. */
-			if (last_str)
-				str_append_c(str, ' ');
-
-			value = rfc822_tokenize_get_value(ctx, &len);
-			str_append_unescaped(str, value, len);
-		} else {
-			if (last_str)
-				str_append_c(str, ' ');
-
-			if (token == TOKEN_DLITERAL)
-				str_append_c(str, '[');
-
-			value = rfc822_tokenize_get_value(ctx, &len);
-			str_append_n(str, value, len);
-
-			if (token == TOKEN_DLITERAL)
-				str_append_c(str, ']');
-		}
-
-		last_str = token_str;
-	}
-}
--- a/src/lib-mail/rfc822-tokenize.h	Sun Jan 05 11:23:13 2003 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-#ifndef __RFC822_TOKENIZE_H
-#define __RFC822_TOKENIZE_H
-
-#define IS_TOKEN_STRING(token) \
-	((token) == TOKEN_ATOM || (token) == TOKEN_QSTRING || \
-	 (token) == TOKEN_COMMENT || (token) == TOKEN_DLITERAL)
-
-typedef enum {
-	TOKEN_ATOM	= 'A',
-	TOKEN_QSTRING	= '"',
-	TOKEN_COMMENT	= '(',
-	TOKEN_DLITERAL	= '[',
-
-	/* RFC822 specials:
-
-	   '<', '>', '@', ',', ';', ':', '\'
-	   '.' (optional)
-
-	   RFC2045 tspecials:
-
-	   '/', '?', '=' */
-
-	TOKEN_LAST	= 0
-} Rfc822Token;
-
-typedef struct _Rfc822TokenizeContext Rfc822TokenizeContext;
-
-/* Parsing is aborted if returns FALSE. There's two kinds of errors:
-
-   missing_char == '\0': unexpected character at str[pos]
-   missing_char != '\0': missing character */
-typedef int (*Rfc822TokenizeErrorFunc)(const unsigned char *str, size_t pos,
-				       char missing_char, void *context);
-
-/* Tokenize the string. Returns NULL if string is empty. Memory for
-   returned array is allocated from data stack. You don't have to use
-   the tokens_count, since last token is always 0. */
-Rfc822TokenizeContext *
-rfc822_tokenize_init(const unsigned char *data, size_t size,
-		     Rfc822TokenizeErrorFunc error_func, void *error_context);
-void rfc822_tokenize_deinit(Rfc822TokenizeContext *ctx);
-
-/* Specify whether comments should be silently skipped (default yes). */
-void rfc822_tokenize_skip_comments(Rfc822TokenizeContext *ctx, int set);
-/* Specify whether '.' should be treated as a separate token (default yes). */
-void rfc822_tokenize_dot_token(Rfc822TokenizeContext *ctx, int set);
-
-/* Parse the next token and return it. */
-Rfc822Token rfc822_tokenize_next(Rfc822TokenizeContext *ctx);
-
-/* Return the current token. */
-Rfc822Token rfc822_tokenize_get(const Rfc822TokenizeContext *ctx);
-
-/* - not including enclosing "", () or []
-   - '\' isn't expanded
-   - [CR+]LF+LWSP (continued header) isn't removed */
-const unsigned char *
-rfc822_tokenize_get_value(const Rfc822TokenizeContext *ctx, size_t *len);
-
-/* Read tokens as a string, all quoted strings will be unquoted.
-   Reads until stop_token is found. */
-void rfc822_tokenize_get_string(Rfc822TokenizeContext *ctx,
-				String *str, String *comments,
-				const Rfc822Token *stop_tokens);
-
-#endif
--- a/src/lib-storage/index/index-copy.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-copy.c	Sun Jan 05 15:09:51 2003 +0200
@@ -8,19 +8,19 @@
 
 #include <unistd.h>
 
-typedef struct {
-	Mailbox *dest;
+struct copy_context {
+	struct mailbox *dest;
 	const char **custom_flags;
 	int copy_inside_mailbox;
-} CopyContext;
+};
 
-static int copy_func(MailIndex *index, MailIndexRecord *rec,
+static int copy_func(struct mail_index *index, struct mail_index_record *rec,
 		     unsigned int client_seq __attr_unused__,
 		     unsigned int idx_seq __attr_unused__, void *context)
 {
-	CopyContext *ctx = context;
-	IndexMailbox *dest_ibox = NULL;
-	IStream *input;
+	struct copy_context *ctx = context;
+	struct index_mailbox *dest_ibox = NULL;
+	struct istream *input;
 	time_t internal_date;
 	int failed, deleted;
 
@@ -30,7 +30,7 @@
 
 	if (ctx->copy_inside_mailbox) {
                 /* kludgy.. */
-		dest_ibox = (IndexMailbox *) ctx->dest;
+		dest_ibox = (struct index_mailbox *) ctx->dest;
 		dest_ibox->delay_save_unlocking = TRUE;
 	}
 
@@ -46,12 +46,12 @@
 	return !failed;
 }
 
-int index_storage_copy(Mailbox *box, Mailbox *destbox,
+int index_storage_copy(struct mailbox *box, struct mailbox *destbox,
 		       const char *messageset, int uidset)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
-        CopyContext ctx;
-	MailLockType lock_type;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
+        struct copy_context ctx;
+	enum mail_lock_type lock_type;
 	int failed;
 
 	if (destbox->readonly) {
--- a/src/lib-storage/index/index-expunge.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-expunge.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,10 +3,10 @@
 #include "lib.h"
 #include "index-storage.h"
 
-int index_expunge_seek_first(IndexMailbox *ibox, unsigned int *seq,
-			     MailIndexRecord **rec)
+int index_expunge_seek_first(struct index_mailbox *ibox, unsigned int *seq,
+			     struct mail_index_record **rec)
 {
-	MailIndexHeader *hdr;
+	struct mail_index_header *hdr;
 
 	i_assert(ibox->index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
@@ -43,7 +43,8 @@
 	return TRUE;
 }
 
-int index_expunge_mail(IndexMailbox *ibox, MailIndexRecord *rec,
+int index_expunge_mail(struct index_mailbox *ibox,
+		       struct mail_index_record *rec,
 		       unsigned int seq, int notify)
 {
 	if (!ibox->index->expunge(ibox->index, rec, seq, FALSE))
@@ -51,7 +52,7 @@
 
 	if (seq <= ibox->synced_messages_count) {
 		if (notify) {
-			MailStorage *storage = ibox->box.storage;
+			struct mail_storage *storage = ibox->box.storage;
 			storage->callbacks->expunge(&ibox->box, seq,
 						    storage->callback_context);
 		}
@@ -61,9 +62,9 @@
 	return TRUE;
 }
 
-int index_storage_expunge(Mailbox *box, int notify)
+int index_storage_expunge(struct mailbox *box, int notify)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
 	int failed;
 
 	if (box->readonly) {
--- a/src/lib-storage/index/index-fetch-section.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-fetch-section.c	Sun Jan 05 15:09:51 2003 +0200
@@ -11,15 +11,15 @@
 #include <ctype.h>
 #include <unistd.h>
 
-typedef struct {
-	String *dest;
-	OStream *output;
+struct fetch_header_field_context {
+	string_t *dest;
+	struct ostream *output;
 	uoff_t dest_size;
 
 	uoff_t skip, max_size;
 	const char *const *fields;
 	int (*match_func) (const char *const *, const unsigned char *, size_t);
-} FetchHeaderFieldContext;
+};
 
 /* For FETCH[HEADER.FIELDS*] we need to modify the header data before sending
    it. We can either save it in memory and then send it, or we can parse it
@@ -30,7 +30,7 @@
 
 #define UNSIGNED_CRLF (const unsigned char *) "\r\n"
 
-ImapCacheField index_fetch_body_get_cache(const char *section)
+enum imap_cache_field index_fetch_body_get_cache(const char *section)
 {
 	if (*section >= '0' && *section <= '9')
 		return IMAP_CACHE_MESSAGE_PART | IMAP_CACHE_MESSAGE_OPEN;
@@ -50,11 +50,13 @@
 }
 
 /* fetch BODY[] or BODY[TEXT] */
-static int fetch_body(MailIndexRecord *rec, MailFetchBodyData *sect,
-		      FetchContext *ctx, const char *prefix, int fetch_header)
+static int fetch_body(struct mail_index_record *rec,
+		      struct mail_fetch_body_data *sect,
+		      struct fetch_context *ctx,
+		      const char *prefix, int fetch_header)
 {
-	MessageSize size;
-	IStream *input;
+	struct message_size size;
+	struct istream *input;
 	const char *str;
 	int cr_skipped;
 
@@ -151,7 +153,7 @@
 	return FALSE;
 }
 
-static int fetch_header_append(FetchHeaderFieldContext *ctx,
+static int fetch_header_append(struct fetch_header_field_context *ctx,
 			       const unsigned char *str, size_t size)
 {
 	if (ctx->skip > 0) {
@@ -181,13 +183,13 @@
 	return ctx->dest_size < ctx->max_size;
 }
 
-static void fetch_header_field(MessagePart *part __attr_unused__,
+static void fetch_header_field(struct message_part *part __attr_unused__,
 			       const unsigned char *name, size_t name_len,
 			       const unsigned char *value __attr_unused__,
 			       size_t value_len __attr_unused__,
 			       void *context)
 {
-	FetchHeaderFieldContext *ctx = context;
+	struct fetch_header_field_context *ctx = context;
 	const unsigned char *field_start, *field_end, *cr, *p;
 
 	/* see if we want this field. */
@@ -225,8 +227,8 @@
 	(void)fetch_header_append(ctx, UNSIGNED_CRLF, 2);
 }
 
-static int fetch_header_fields(IStream *input, const char *section,
-			       FetchHeaderFieldContext *ctx)
+static int fetch_header_fields(struct istream *input, const char *section,
+			       struct fetch_header_field_context *ctx)
 {
 	if (strncasecmp(section, "HEADER.FIELDS ", 14) == 0) {
 		ctx->fields = get_fields_array(section + 14);
@@ -257,11 +259,12 @@
 }
 
 /* fetch wanted headers from given data */
-static int fetch_header_from(IStream *input, OStream *output,
-			     const char *prefix, MessageSize *size,
-			     const char *section, MailFetchBodyData *sect)
+static int fetch_header_from(struct istream *input, struct ostream *output,
+			     const char *prefix, struct message_size *size,
+			     const char *section,
+			     struct mail_fetch_body_data *sect)
 {
-	FetchHeaderFieldContext ctx;
+	struct fetch_header_field_context ctx;
 	const char *str;
 	uoff_t start_offset;
 	int failed;
@@ -337,11 +340,11 @@
 }
 
 /* fetch BODY[HEADER...] */
-static int fetch_header(MailFetchBodyData *sect, FetchContext *ctx,
-			const char *prefix)
+static int fetch_header(struct mail_fetch_body_data *sect,
+			struct fetch_context *ctx, const char *prefix)
 {
-	MessageSize hdr_size;
-	IStream *input;
+	struct message_size hdr_size;
+	struct istream *input;
 
 	if (!imap_msgcache_get_rfc822(ctx->cache, &input, &hdr_size, NULL))
 		return FALSE;
@@ -350,11 +353,12 @@
 				 sect->section, sect);
 }
 
-/* Find MessagePart for section (eg. 1.3.4) */
-static MessagePart *part_find(MailFetchBodyData *sect, FetchContext *ctx,
-			      const char **section)
+/* Find message_part for section (eg. 1.3.4) */
+static struct message_part *
+part_find(struct mail_fetch_body_data *sect, struct fetch_context *ctx,
+	  const char **section)
 {
-	MessagePart *part;
+	struct message_part *part;
 	const char *path;
 	unsigned int num;
 
@@ -397,10 +401,11 @@
 }
 
 /* fetch BODY[1.2] or BODY[1.2.TEXT] */
-static int fetch_part_body(MessagePart *part, MailFetchBodyData *sect,
-			   FetchContext *ctx, const char *prefix)
+static int fetch_part_body(struct message_part *part,
+			   struct mail_fetch_body_data *sect,
+			   struct fetch_context *ctx, const char *prefix)
 {
-	IStream *input;
+	struct istream *input;
 	const char *str;
 	uoff_t skip_pos;
 
@@ -423,11 +428,11 @@
 }
 
 /* fetch BODY[1.2.MIME|HEADER...] */
-static int fetch_part_header(MessagePart *part, const char *section,
-			     MailFetchBodyData *sect, FetchContext *ctx,
-			     const char *prefix)
+static int fetch_part_header(struct message_part *part, const char *section,
+			     struct mail_fetch_body_data *sect,
+			     struct fetch_context *ctx, const char *prefix)
 {
-	IStream *input;
+	struct istream *input;
 
 	if (!imap_msgcache_get_data(ctx->cache, &input))
 		return FALSE;
@@ -437,10 +442,10 @@
 				 section, sect);
 }
 
-static int fetch_part(MailFetchBodyData *sect, FetchContext *ctx,
-		      const char *prefix)
+static int fetch_part(struct mail_fetch_body_data *sect,
+		      struct fetch_context *ctx, const char *prefix)
 {
-	MessagePart *part;
+	struct message_part *part;
 	const char *section;
 
 	part = part_find(sect, ctx, &section);
@@ -458,8 +463,9 @@
 	return FALSE;
 }
 
-int index_fetch_body_section(MailIndexRecord *rec, MailFetchBodyData *sect,
-			     FetchContext *ctx)
+int index_fetch_body_section(struct mail_index_record *rec,
+			     struct mail_fetch_body_data *sect,
+			     struct fetch_context *ctx)
 {
 	const char *prefix;
 
--- a/src/lib-storage/index/index-fetch.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-fetch.c	Sun Jan 05 15:09:51 2003 +0200
@@ -14,7 +14,8 @@
 
 #include <unistd.h>
 
-static int index_fetch_internaldate(MailIndexRecord *rec, FetchContext *ctx)
+static int index_fetch_internaldate(struct mail_index_record *rec,
+				    struct fetch_context *ctx)
 {
 	time_t date;
 
@@ -31,7 +32,8 @@
 	}
 }
 
-static int index_fetch_body(MailIndexRecord *rec, FetchContext *ctx)
+static int index_fetch_body(struct mail_index_record *rec,
+			    struct fetch_context *ctx)
 {
 	const char *body;
 
@@ -47,7 +49,8 @@
 	}
 }
 
-static int index_fetch_bodystructure(MailIndexRecord *rec, FetchContext *ctx)
+static int index_fetch_bodystructure(struct mail_index_record *rec,
+				     struct fetch_context *ctx)
 {
 	const char *bodystructure;
 
@@ -63,7 +66,8 @@
 	}
 }
 
-static int index_fetch_envelope(MailIndexRecord *rec, FetchContext *ctx)
+static int index_fetch_envelope(struct mail_index_record *rec,
+				struct fetch_context *ctx)
 {
 	const char *envelope;
 
@@ -79,7 +83,8 @@
 	}
 }
 
-static int index_fetch_rfc822_size(MailIndexRecord *rec, FetchContext *ctx)
+static int index_fetch_rfc822_size(struct mail_index_record *rec,
+				   struct fetch_context *ctx)
 {
 	uoff_t size;
 
@@ -95,9 +100,10 @@
 	return TRUE;
 }
 
-static void index_fetch_flags(MailIndexRecord *rec, FetchContext *ctx)
+static void index_fetch_flags(struct mail_index_record *rec,
+			      struct fetch_context *ctx)
 {
-	MailFlags flags;
+	enum mail_flags flags;
 
 	flags = rec->msg_flags;
 	if (rec->uid >= ctx->index->first_recent_uid)
@@ -110,15 +116,17 @@
 				     ctx->custom_flags_count));
 }
 
-static void index_fetch_uid(MailIndexRecord *rec, FetchContext *ctx)
+static void index_fetch_uid(struct mail_index_record *rec,
+			    struct fetch_context *ctx)
 {
 	str_printfa(ctx->str, "UID %u ", rec->uid);
 }
 
-static int index_fetch_send_rfc822(MailIndexRecord *rec, FetchContext *ctx)
+static int index_fetch_send_rfc822(struct mail_index_record *rec,
+				   struct fetch_context *ctx)
 {
-	MessageSize hdr_size, body_size;
-	IStream *input;
+	struct message_size hdr_size, body_size;
+	struct istream *input;
 	const char *str;
 
 	if (!imap_msgcache_get_rfc822(ctx->cache, &input,
@@ -142,11 +150,11 @@
 	return message_send(ctx->output, input, &body_size, 0, (uoff_t)-1);
 }
 
-static int index_fetch_send_rfc822_header(MailIndexRecord *rec,
-					  FetchContext *ctx)
+static int index_fetch_send_rfc822_header(struct mail_index_record *rec,
+					  struct fetch_context *ctx)
 {
-	MessageSize hdr_size;
-	IStream *input;
+	struct message_size hdr_size;
+	struct istream *input;
 	const char *str;
 
 	if (!imap_msgcache_get_rfc822(ctx->cache, &input, &hdr_size, NULL)) {
@@ -167,10 +175,11 @@
 	return message_send(ctx->output, input, &hdr_size, 0, (uoff_t)-1);
 }
 
-static int index_fetch_send_rfc822_text(MailIndexRecord *rec, FetchContext *ctx)
+static int index_fetch_send_rfc822_text(struct mail_index_record *rec,
+					struct fetch_context *ctx)
 {
-	MessageSize body_size;
-	IStream *input;
+	struct message_size body_size;
+	struct istream *input;
 	const char *str;
 
 	if (!imap_msgcache_get_rfc822(ctx->cache, &input, NULL, &body_size)) {
@@ -191,10 +200,10 @@
 	return message_send(ctx->output, input, &body_size, 0, (uoff_t)-1);
 }
 
-static ImapCacheField index_get_cache(MailFetchData *fetch_data)
+static enum imap_cache_field index_get_cache(struct mail_fetch_data *fetch_data)
 {
-	MailFetchBodyData *sect;
-	ImapCacheField field;
+	struct mail_fetch_body_data *sect;
+	enum imap_cache_field field;
 
 	field = 0;
 	if (fetch_data->body)
@@ -224,9 +233,10 @@
 	return field;
 }
 
-static int fetch_msgcache_open(FetchContext *ctx, MailIndexRecord *rec)
+static int fetch_msgcache_open(struct fetch_context *ctx,
+			       struct mail_index_record *rec)
 {
-	ImapCacheField fields;
+	enum imap_cache_field fields;
 
 	fields = index_get_cache(ctx->fetch_data);
 	if (fields == 0)
@@ -235,14 +245,13 @@
 	return index_msgcache_open(ctx->cache, ctx->index, rec, fields);
 }
 
-static int index_fetch_mail(MailIndex *index __attr_unused__,
-			    MailIndexRecord *rec,
-			    unsigned int client_seq,
-			    unsigned int idx_seq,
+static int index_fetch_mail(struct mail_index *index __attr_unused__,
+			    struct mail_index_record *rec,
+			    unsigned int client_seq, unsigned int idx_seq,
 			    void *context)
 {
-	FetchContext *ctx = context;
-	MailFetchBodyData *sect;
+	struct fetch_context *ctx = context;
+	struct mail_fetch_body_data *sect;
 	size_t len, orig_len;
 	int failed, data_written, fetch_flags;
 
@@ -339,12 +348,12 @@
 	return !failed;
 }
 
-int index_storage_fetch(Mailbox *box, MailFetchData *fetch_data,
-			OStream *output, int *all_found)
+int index_storage_fetch(struct mailbox *box, struct mail_fetch_data *fetch_data,
+			struct ostream *output, int *all_found)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
-	FetchContext ctx;
-	MailFetchBodyData *sect;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
+	struct fetch_context ctx;
+	struct mail_fetch_body_data *sect;
 	int ret;
 
 	memset(&ctx, 0, sizeof(ctx));
--- a/src/lib-storage/index/index-fetch.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-fetch.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,24 +1,25 @@
 #ifndef __INDEX_FETCH_H
 #define __INDEX_FETCH_H
 
-typedef struct {
-	Mailbox *box;
-	MailStorage *storage;
-	ImapMessageCache *cache;
-	MailIndex *index;
+struct fetch_context {
+	struct mailbox *box;
+	struct mail_storage *storage;
+	struct imap_message_cache *cache;
+	struct mail_index *index;
 
 	const char **custom_flags;
 	unsigned int custom_flags_count;
 
-	MailFetchData *fetch_data;
-	OStream *output;
-	String *str;
+	struct mail_fetch_data *fetch_data;
+	struct ostream *output;
+	string_t *str;
 	int update_seen, failed;
 	int first;
-} FetchContext;
+};
 
-ImapCacheField index_fetch_body_get_cache(const char *section);
-int index_fetch_body_section(MailIndexRecord *rec, MailFetchBodyData *sect,
-			     FetchContext *ctx);
+enum imap_cache_field index_fetch_body_get_cache(const char *section);
+int index_fetch_body_section(struct mail_index_record *rec,
+			     struct mail_fetch_body_data *sect,
+			     struct fetch_context *ctx);
 
 #endif
--- a/src/lib-storage/index/index-mailbox-check.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-mailbox-check.c	Sun Jan 05 15:09:51 2003 +0200
@@ -9,9 +9,10 @@
 
 static int check_interval = -1;
 
-static void check_timeout(void *context, Timeout timeout __attr_unused__)
+static void check_timeout(void *context,
+			  struct timeout *timeout __attr_unused__)
 {
-	IndexMailbox *ibox = context;
+	struct index_mailbox *ibox = context;
 	struct stat st;
 
 	if (ioloop_time - ibox->last_check < check_interval)
@@ -25,7 +26,7 @@
 	}
 }
 
-void index_mailbox_check_add(IndexMailbox *ibox, const char *path)
+void index_mailbox_check_add(struct index_mailbox *ibox, const char *path)
 {
 	const char *str;
 	struct stat st;
@@ -45,7 +46,7 @@
 	ibox->check_to = timeout_add(1000, check_timeout, ibox);
 }
 
-void index_mailbox_check_remove(IndexMailbox *ibox)
+void index_mailbox_check_remove(struct index_mailbox *ibox)
 {
 	if (ibox->check_to != NULL)
 		timeout_remove(ibox->check_to);
--- a/src/lib-storage/index/index-messageset.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-messageset.c	Sun Jan 05 15:09:51 2003 +0200
@@ -22,12 +22,12 @@
 	return num;
 }
 
-static int mail_index_foreach(MailIndex *index,
+static int mail_index_foreach(struct mail_index *index,
 			      unsigned int seq, unsigned int seq2,
 			      MsgsetForeachFunc func, void *context)
 {
-	MailIndexRecord *rec;
-	const ModifyLogExpunge *expunges;
+	struct mail_index_record *rec;
+	const struct modify_log_expunge *expunges;
 	unsigned int idx_seq, expunges_before, temp;
 	int expunges_found;
 
@@ -90,7 +90,7 @@
 	return !expunges_found && seq > seq2 ? 1 : 2;
 }
 
-static int mail_index_messageset_foreach(MailIndex *index,
+static int mail_index_messageset_foreach(struct mail_index *index,
 					 const char *messageset,
 					 unsigned int messages_count,
 					 MsgsetForeachFunc func, void *context,
@@ -175,12 +175,12 @@
 	return all_found ? 1 : 2;
 }
 
-static int mail_index_uid_foreach(MailIndex *index,
+static int mail_index_uid_foreach(struct mail_index *index,
 				  unsigned int uid, unsigned int uid2,
 				  MsgsetForeachFunc func, void *context)
 {
-	MailIndexRecord *rec;
-	const ModifyLogExpunge *expunges;
+	struct mail_index_record *rec;
+	const struct modify_log_expunge *expunges;
 	unsigned int client_seq, idx_seq, expunges_before, temp;
 	int expunges_found;
 
@@ -234,12 +234,13 @@
 	return expunges_found ? 2 : 1;
 }
 
-static int mail_index_uidset_foreach(MailIndex *index, const char *uidset,
+static int mail_index_uidset_foreach(struct mail_index *index,
+				     const char *uidset,
 				     unsigned int messages_count,
 				     MsgsetForeachFunc func, void *context,
 				     const char **error)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 	const char *input;
 	unsigned int uid, uid2;
 	int ret, all_found;
@@ -309,7 +310,7 @@
 	return all_found ? 1 : 2;
 }
 
-int index_messageset_foreach(IndexMailbox *ibox,
+int index_messageset_foreach(struct index_mailbox *ibox,
 			     const char *messageset, int uidset,
 			     MsgsetForeachFunc func, void *context)
 {
--- a/src/lib-storage/index/index-messageset.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-messageset.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,14 +4,15 @@
 #include "index-storage.h"
 
 /* If FALSE is returned, the loop is stopped. */
-typedef int (*MsgsetForeachFunc)(MailIndex *index, MailIndexRecord *rec,
+typedef int (*MsgsetForeachFunc)(struct mail_index *index,
+				 struct mail_index_record *rec,
 				 unsigned int client_seq, unsigned int idx_seq,
 				 void *context);
 
 /* Returns 1 if all were found, 2 if some messages were deleted,
    0 func returned FALSE, -1 if internal error occured or -2 if messageset
    was invalid. */
-int index_messageset_foreach(IndexMailbox *ibox,
+int index_messageset_foreach(struct index_mailbox *ibox,
 			     const char *messageset, int uidset,
 			     MsgsetForeachFunc func, void *context);
 
--- a/src/lib-storage/index/index-msgcache.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-msgcache.c	Sun Jan 05 15:09:51 2003 +0200
@@ -11,21 +11,22 @@
 
 #include <unistd.h>
 
-typedef struct {
-	MailIndex *index;
-	MailIndexRecord *rec;
+struct index_msgcache_context {
+	struct mail_index *index;
+	struct mail_index_record *rec;
 	time_t internal_date;
-} IndexMsgcacheContext;
+};
 
-int index_msgcache_open(ImapMessageCache *cache, MailIndex *index,
-			MailIndexRecord *rec, ImapCacheField fields)
+int index_msgcache_open(struct imap_message_cache *cache,
+			struct mail_index *index, struct mail_index_record *rec,
+			enum imap_cache_field fields)
 {
-	IndexMsgcacheContext *ctx;
+	struct index_msgcache_context *ctx;
 	uoff_t vp_header_size, vp_body_size, full_virtual_size;
 	const uoff_t *uoff_p;
 	size_t size;
 
-	ctx = t_new(IndexMsgcacheContext, 1);
+	ctx = t_new(struct index_msgcache_context, 1);
 	ctx->index = index;
 	ctx->rec = rec;
 	ctx->internal_date = (time_t)-1;
@@ -71,27 +72,28 @@
 				  full_virtual_size, ctx);
 }
 
-static IStream *index_msgcache_open_mail(void *context)
+static struct istream *index_msgcache_open_mail(void *context)
 {
-	IndexMsgcacheContext *ctx = context;
+	struct index_msgcache_context *ctx = context;
 	int deleted;
 
 	return ctx->index->open_mail(ctx->index, ctx->rec,
 				     &ctx->internal_date, &deleted);
 }
 
-static IStream *index_msgcache_stream_rewind(IStream *input,
-					     void *context __attr_unused__)
+static struct istream *
+index_msgcache_stream_rewind(struct istream *input,
+			     void *context __attr_unused__)
 {
 	i_stream_seek(input, 0);
 	return input;
 }
 
-static const char *index_msgcache_get_cached_field(ImapCacheField field,
-						   void *context)
+static const char *
+index_msgcache_get_cached_field(enum imap_cache_field field, void *context)
 {
-	IndexMsgcacheContext *ctx = context;
-	MailDataField data_field;
+	struct index_msgcache_context *ctx = context;
+	enum mail_data_field data_field;
 	const time_t *time_p;
 	const char *ret;
 	size_t size;
@@ -131,10 +133,11 @@
 	return ret;
 }
 
-static MessagePart *index_msgcache_get_cached_parts(Pool pool, void *context)
+static struct message_part *
+index_msgcache_get_cached_parts(pool_t pool, void *context)
 {
-	IndexMsgcacheContext *ctx = context;
-	MessagePart *part;
+	struct index_msgcache_context *ctx = context;
+	struct message_part *part;
 	const void *part_data;
 	size_t part_size;
 
@@ -150,7 +153,7 @@
 	part = message_part_deserialize(pool, part_data, part_size);
 	if (part == NULL) {
 		index_set_corrupted(ctx->index,
-				    "Corrupted cached MessagePart data");
+				    "Corrupted cached message_part data");
 		return NULL;
 	}
 
@@ -159,7 +162,7 @@
 
 static time_t index_msgcache_get_internal_date(void *context)
 {
-	IndexMsgcacheContext *ctx = context;
+	struct index_msgcache_context *ctx = context;
 
 	if (ctx->internal_date != (time_t)-1)
 		return ctx->internal_date;
@@ -167,7 +170,7 @@
 	return ctx->index->get_internal_date(ctx->index, ctx->rec);
 }
 
-ImapMessageCacheIface index_msgcache_iface = {
+struct imap_message_cache_iface index_msgcache_iface = {
 	index_msgcache_open_mail,
 	index_msgcache_stream_rewind,
 	index_msgcache_get_cached_field,
--- a/src/lib-storage/index/index-save.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-save.c	Sun Jan 05 15:09:51 2003 +0200
@@ -9,7 +9,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-static int write_with_crlf(OStream *output, const unsigned char *data,
+static int write_with_crlf(struct ostream *output, const unsigned char *data,
 			   size_t size)
 {
 	size_t i, start;
@@ -40,7 +40,7 @@
 	return size;
 }
 
-static int write_with_lf(OStream *output, const unsigned char *data,
+static int write_with_lf(struct ostream *output, const unsigned char *data,
 			 size_t size)
 {
 	size_t i, start;
@@ -70,10 +70,11 @@
 	return size;
 }
 
-int index_storage_save(MailStorage *storage, const char *path,
-		       IStream *input, OStream *output, uoff_t data_size)
+int index_storage_save(struct mail_storage *storage, const char *path,
+		       struct istream *input, struct ostream *output,
+		       uoff_t data_size)
 {
-	int (*write_func)(OStream *, const unsigned char *, size_t);
+	int (*write_func)(struct ostream *, const unsigned char *, size_t);
 	const unsigned char *data;
 	size_t size;
 	ssize_t ret;
--- a/src/lib-storage/index/index-search.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-search.c	Sun Jan 05 15:09:51 2003 +0200
@@ -4,7 +4,7 @@
 #include "istream.h"
 #include "ostream.h"
 #include "mmap-util.h"
-#include "rfc822-date.h"
+#include "message-date.h"
 #include "message-size.h"
 #include "message-body-search.h"
 #include "message-header-search.h"
@@ -28,32 +28,32 @@
 #define TXT_UNKNOWN_CHARSET "[BADCHARSET] Unknown charset"
 #define TXT_INVALID_SEARCH_KEY "Invalid search key"
 
-typedef struct {
-	Pool hdr_pool;
-	IndexMailbox *ibox;
-	MailIndexRecord *rec;
+struct search_index_context {
+	pool_t hdr_pool;
+	struct index_mailbox *ibox;
+	struct mail_index_record *rec;
 	unsigned int client_seq;
 	int cached;
 	const char *charset;
 	const char *error;
-} SearchIndexContext;
+};
 
-typedef struct {
-        SearchIndexContext *index_context;
-	MailSearchArg *args;
+struct search_header_context {
+        struct search_index_context *index_context;
+	struct mail_search_arg *args;
 	int custom_header;
 
 	const unsigned char *name, *value;
 	size_t name_len, value_len;
-} SearchHeaderContext;
+};
 
-typedef struct {
-        SearchIndexContext *index_ctx;
-	IStream *input;
-	MessagePart *part;
-} SearchBodyContext;
+struct search_body_context {
+        struct search_index_context *index_ctx;
+	struct istream *input;
+	struct message_part *part;
+};
 
-static MailSortType sort_unsorted[] = { MAIL_SORT_END };
+static enum mail_sort_type sort_unsorted[] = { MAIL_SORT_END };
 
 static int msgset_contains(const char *set, unsigned int match_num,
 			   unsigned int max_num)
@@ -122,8 +122,8 @@
 	return num;
 }
 
-static int search_keyword(MailIndex *index, MailIndexRecord *rec,
-			  const char *value)
+static int search_keyword(struct mail_index *index,
+			  struct mail_index_record *rec, const char *value)
 {
 	const char **custom_flags;
 	int i;
@@ -144,9 +144,11 @@
 }
 
 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
-static int search_arg_match_index(IndexMailbox *ibox, MailIndexRecord *rec,
+static int search_arg_match_index(struct index_mailbox *ibox,
+				  struct mail_index_record *rec,
 				  unsigned int client_seq,
-				  MailSearchArgType type, const char *value)
+				  enum mail_search_arg_type type,
+				  const char *value)
 {
 	switch (type) {
 	case SEARCH_ALL:
@@ -179,9 +181,9 @@
 	}
 }
 
-static void search_index_arg(MailSearchArg *arg, void *context)
+static void search_index_arg(struct mail_search_arg *arg, void *context)
 {
-	SearchIndexContext *ctx = context;
+	struct search_index_context *ctx = context;
 
 	switch (search_arg_match_index(ctx->ibox, ctx->rec, ctx->client_seq,
 				       arg->type, arg->value.str)) {
@@ -197,7 +199,8 @@
 	}
 }
 
-static ImapMessageCache *search_open_cache(SearchIndexContext *ctx)
+static struct imap_message_cache *
+search_open_cache(struct search_index_context *ctx)
 {
 	if (!ctx->cached) {
 		(void)index_msgcache_open(ctx->ibox->cache,
@@ -208,8 +211,9 @@
 }
 
 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
-static int search_arg_match_cached(SearchIndexContext *ctx,
-				   MailSearchArgType type, const char *value)
+static int search_arg_match_cached(struct search_index_context *ctx,
+				   enum mail_search_arg_type type,
+				   const char *value)
 {
 	time_t internal_date, search_time;
 	uoff_t virtual_size, search_size;
@@ -259,9 +263,9 @@
 	}
 }
 
-static void search_cached_arg(MailSearchArg *arg, void *context)
+static void search_cached_arg(struct mail_search_arg *arg, void *context)
 {
-	SearchIndexContext *ctx = context;
+	struct search_index_context *ctx = context;
 
 	switch (search_arg_match_cached(ctx, arg->type,
 					arg->value.str)) {
@@ -277,7 +281,7 @@
 	}
 }
 
-static int search_sent(MailSearchArgType type, const char *search_value,
+static int search_sent(enum mail_search_arg_type type, const char *search_value,
 		       const char *sent_value)
 {
 	time_t search_time, sent_time;
@@ -291,7 +295,7 @@
 
 	/* NOTE: Latest IMAP4rev1 draft specifies that timezone is ignored
 	   in searches. */
-	if (!rfc822_parse_date(sent_value, &sent_time, &timezone_offset))
+	if (!message_date_parse(sent_value, &sent_time, &timezone_offset))
 		return 0;
 
 	switch (type) {
@@ -307,8 +311,9 @@
 	}
 }
 
-static HeaderSearchContext *search_header_context(SearchIndexContext *ctx,
-						  MailSearchArg *arg)
+static struct header_search_context *
+search_header_context(struct search_index_context *ctx,
+		      struct mail_search_arg *arg)
 {
 	int unknown_charset;
 
@@ -334,12 +339,12 @@
 }
 
 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
-static int search_arg_match_envelope(SearchIndexContext *ctx,
-				     MailSearchArg *arg)
+static int search_arg_match_envelope(struct search_index_context *ctx,
+				     struct mail_search_arg *arg)
 {
-	MailIndex *index = ctx->ibox->index;
-	ImapEnvelopeField env_field;
-        HeaderSearchContext *hdr_search_ctx;
+	struct mail_index *index = ctx->ibox->index;
+	enum imap_envelope_field env_field;
+        struct header_search_context *hdr_search_ctx;
 	const char *envelope, *field;
 	int ret;
 
@@ -382,7 +387,7 @@
 	envelope = index->lookup_field(index, ctx->rec, DATA_FIELD_ENVELOPE);
 	if (envelope != NULL) {
 		ret = imap_envelope_parse(envelope, env_field,
-					  IMAP_ENVELOPE_RESULT_STRING,
+					  IMAP_ENVELOPE_RESULT_TYPE_STRING,
 					  &field) ? 1 : -1;
 	} else {
 		index->cache_fields_later(index, DATA_FIELD_ENVELOPE);
@@ -426,9 +431,9 @@
 	return ret;
 }
 
-static void search_envelope_arg(MailSearchArg *arg, void *context)
+static void search_envelope_arg(struct mail_search_arg *arg, void *context)
 {
-	SearchIndexContext *ctx = context;
+	struct search_index_context *ctx = context;
 
 	switch (search_arg_match_envelope(ctx, arg)) {
 	case -1:
@@ -443,10 +448,10 @@
 	}
 }
 
-static void search_header_arg(MailSearchArg *arg, void *context)
+static void search_header_arg(struct mail_search_arg *arg, void *context)
 {
-	SearchHeaderContext *ctx = context;
-        HeaderSearchContext *hdr_search_ctx;
+	struct search_header_context *ctx = context;
+        struct header_search_context *hdr_search_ctx;
 	size_t len;
 	int ret;
 
@@ -520,12 +525,12 @@
         ARG_SET_RESULT(arg, ret);
 }
 
-static void search_header(MessagePart *part __attr_unused__,
+static void search_header(struct message_part *part __attr_unused__,
 			  const unsigned char *name, size_t name_len,
 			  const unsigned char *value, size_t value_len,
 			  void *context)
 {
-	SearchHeaderContext *ctx = context;
+	struct search_header_context *ctx = context;
 
 	if ((name_len > 0 && ctx->custom_header) ||
 	    (name_len == 4 && memcasecmp(name, "Date", 4) == 0) ||
@@ -544,9 +549,9 @@
 	}
 }
 
-static void search_body(MailSearchArg *arg, void *context)
+static void search_body(struct mail_search_arg *arg, void *context)
 {
-	SearchBodyContext *ctx = context;
+	struct search_body_context *ctx = context;
 	int ret, unknown_charset;
 
 	if (ctx->index_ctx->error != NULL)
@@ -568,9 +573,10 @@
 	}
 }
 
-static int search_arg_match_text(MailSearchArg *args, SearchIndexContext *ctx)
+static int search_arg_match_text(struct mail_search_arg *args,
+				 struct search_index_context *ctx)
 {
-	IStream *input;
+	struct istream *input;
 	int have_headers, have_body, have_text;
 
 	/* first check what we need to use */
@@ -579,7 +585,7 @@
 		return TRUE;
 
 	if (have_headers || have_text) {
-		SearchHeaderContext hdr_ctx;
+		struct search_header_context hdr_ctx;
 
 		if (!imap_msgcache_get_data(search_open_cache(ctx), &input))
 			return FALSE;
@@ -598,7 +604,7 @@
 	}
 
 	if (have_text || have_body) {
-		SearchBodyContext body_ctx;
+		struct search_body_context body_ctx;
 
 		memset(&body_ctx, 0, sizeof(body_ctx));
 		body_ctx.index_ctx = ctx;
@@ -638,7 +644,8 @@
 	}
 }
 
-static void search_get_sequid(IndexMailbox *ibox, MailSearchArg *args,
+static void search_get_sequid(struct index_mailbox *ibox,
+			      struct mail_search_arg *args,
 			      unsigned int *first_seq, unsigned int *last_seq,
 			      unsigned int *first_uid, unsigned int *last_uid)
 {
@@ -662,11 +669,12 @@
 	}
 }
 
-static int search_limit_by_flags(IndexMailbox *ibox, MailSearchArg *args,
+static int search_limit_by_flags(struct index_mailbox *ibox,
+				 struct mail_search_arg *args,
 				 unsigned int *first_uid,
 				 unsigned int *last_uid)
 {
-	MailIndexHeader *hdr;
+	struct mail_index_header *hdr;
 	unsigned int uid;
 
 	hdr = ibox->index->header;
@@ -715,9 +723,10 @@
 	return *first_uid <= *last_uid;
 }
 
-static unsigned int client_seq_to_uid(MailIndex *index, unsigned int seq)
+static unsigned int client_seq_to_uid(struct mail_index *index,
+				      unsigned int seq)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 	unsigned int expunges_before;
 
 	(void)mail_modifylog_seq_get_expunges(index->modifylog, seq, seq,
@@ -728,7 +737,8 @@
 	return rec == NULL ? 0 : rec->uid;
 }
 
-static int search_get_uid_range(IndexMailbox *ibox, MailSearchArg *args,
+static int search_get_uid_range(struct index_mailbox *ibox,
+				struct mail_search_arg *args,
 				unsigned int *first_uid,
 				unsigned int *last_uid)
 {
@@ -775,14 +785,15 @@
 	return TRUE;
 }
 
-static int search_messages(IndexMailbox *ibox, const char *charset,
-			   MailSearchArg *args, MailSortContext *sort_ctx,
-			   OStream *output, int uid_result)
+static int search_messages(struct index_mailbox *ibox, const char *charset,
+			   struct mail_search_arg *args,
+			   struct mail_sort_context *sort_ctx,
+			   struct ostream *output, int uid_result)
 {
-	SearchIndexContext ctx;
-	MailIndexRecord *rec;
-        MailSearchArg *arg;
-	const ModifyLogExpunge *expunges;
+	struct search_index_context ctx;
+	struct mail_index_record *rec;
+        struct mail_search_arg *arg;
+	const struct modify_log_expunge *expunges;
 	unsigned int first_uid, last_uid, client_seq, expunges_before;
 	const char *str;
 	int found, failed;
@@ -870,12 +881,14 @@
 	return ctx.error == NULL;
 }
 
-int index_storage_search(Mailbox *box, const char *charset, MailSearchArg *args,
-			 MailSortType *sorting, OStream *output, int uid_result)
+int index_storage_search(struct mailbox *box, const char *charset,
+			 struct mail_search_arg *args,
+			 enum mail_sort_type *sorting,
+			 struct ostream *output, int uid_result)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
-	MailSortContext *sort_ctx;
-	IndexSortContext index_sort_ctx;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
+	struct mail_sort_context *sort_ctx;
+	struct index_sort_context index_sort_ctx;
 	int failed;
 
 	if (!index_storage_sync_and_lock(ibox, TRUE, MAIL_LOCK_SHARED))
--- a/src/lib-storage/index/index-sort.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-sort.c	Sun Jan 05 15:09:51 2003 +0200
@@ -2,15 +2,15 @@
 
 #include "lib.h"
 #include "ostream.h"
-#include "rfc822-date.h"
+#include "message-date.h"
 #include "imap-envelope.h"
 #include "imap-message-cache.h"
 #include "mail-index.h"
 #include "index-storage.h"
 #include "index-sort.h"
 
-static ImapMessageCache *search_open_cache(IndexSortContext *ctx,
-					   unsigned int uid)
+static struct imap_message_cache *
+search_open_cache(struct index_sort_context *ctx, unsigned int uid)
 {
 	if (ctx->last_uid != uid) {
 		ctx->cached = FALSE;
@@ -33,10 +33,11 @@
 	return ctx->ibox->cache;
 }
 
-static uoff_t _input_uofft(MailSortType type, unsigned int id, void *context)
+static uoff_t _input_uofft(enum mail_sort_type type,
+			   unsigned int id, void *context)
 {
-	IndexSortContext *ctx = context;
-        ImapMessageCache *cache;
+	struct index_sort_context *ctx = context;
+        struct imap_message_cache *cache;
 
 	if (type != MAIL_SORT_SIZE) {
 		i_unreached();
@@ -47,11 +48,11 @@
 	return cache == NULL ? 0 : imap_msgcache_get_virtual_size(cache);
 }
 
-static const char *_input_mailbox(MailSortType type, unsigned int id,
+static const char *_input_mailbox(enum mail_sort_type type, unsigned int id,
 				  void *context)
 {
-	IndexSortContext *ctx = context;
-	ImapEnvelopeField env_field;
+	struct index_sort_context *ctx = context;
+	enum imap_envelope_field env_field;
 	const char *envelope, *str;
 
 	switch (type) {
@@ -76,16 +77,17 @@
 		return NULL;
 
 	if (!imap_envelope_parse(envelope, env_field,
-				 IMAP_ENVELOPE_RESULT_FIRST_MAILBOX, &str))
+				 IMAP_ENVELOPE_RESULT_TYPE_FIRST_MAILBOX, &str))
 		return NULL;
 
 	return str;
 }
 
-static const char *_input_str(MailSortType type, unsigned int id, void *context)
+static const char *_input_str(enum mail_sort_type type,
+			      unsigned int id, void *context)
 {
-	IndexSortContext *ctx = context;
-	ImapEnvelopeField env_field;
+	struct index_sort_context *ctx = context;
+	enum imap_envelope_field env_field;
 	const char *envelope, *str;
 
 	switch (type) {
@@ -107,16 +109,17 @@
 		return NULL;
 
 	if (!imap_envelope_parse(envelope, env_field,
-				 IMAP_ENVELOPE_RESULT_STRING, &str))
+				 IMAP_ENVELOPE_RESULT_TYPE_STRING, &str))
 		return NULL;
 
 	return str;
 }
 
-static time_t _input_time(MailSortType type, unsigned int id, void *context)
+static time_t _input_time(enum mail_sort_type type,
+			  unsigned int id, void *context)
 {
-	IndexSortContext *ctx = context;
-        ImapMessageCache *cache;
+	struct index_sort_context *ctx = context;
+        struct imap_message_cache *cache;
 	const char *str;
 	time_t time;
 	int timezone_offset;
@@ -131,7 +134,7 @@
 		if (str == NULL)
 			return 0;
 
-		if (!rfc822_parse_date(str, &time, &timezone_offset))
+		if (!message_date_parse(str, &time, &timezone_offset))
 			return 0;
 
 		return time - timezone_offset*60;
@@ -143,14 +146,14 @@
 
 static void _input_reset(void *context)
 {
-	IndexSortContext *ctx = context;
+	struct index_sort_context *ctx = context;
 
 	ctx->cached = FALSE;
 }
 
 static void _output(unsigned int *data, size_t count, void *context)
 {
-	IndexSortContext *ctx = context;
+	struct index_sort_context *ctx = context;
 	size_t i;
 
 	for (i = 0; i < count; i++) {
@@ -161,7 +164,7 @@
 	}
 }
 
-MailSortFuncs index_sort_funcs = {
+struct mail_sort_funcs index_sort_funcs = {
 	_input_time,
 	_input_uofft,
 	_input_mailbox,
--- a/src/lib-storage/index/index-sort.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-sort.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,16 +4,16 @@
 #include "mail-storage.h"
 #include "mail-sort.h"
 
-typedef struct {
-	IndexMailbox *ibox;
-	OStream *output;
+struct index_sort_context {
+	struct index_mailbox *ibox;
+	struct ostream *output;
 
 	unsigned int last_uid;
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 
 	unsigned int cached:1;
-} IndexSortContext;
+};
 
-extern MailSortFuncs index_sort_funcs;
+extern struct mail_sort_funcs index_sort_funcs;
 
 #endif
--- a/src/lib-storage/index/index-status.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-status.c	Sun Jan 05 15:09:51 2003 +0200
@@ -5,10 +5,10 @@
 #include "mail-index-util.h"
 #include "index-storage.h"
 
-static unsigned int get_first_unseen_seq(MailIndex *index)
+static unsigned int get_first_unseen_seq(struct mail_index *index)
 {
-	MailIndexHeader *hdr;
-	MailIndexRecord *rec;
+	struct mail_index_header *hdr;
+	struct mail_index_record *rec;
 	unsigned int seq, lowwater_uid;
 
 	hdr = mail_index_get_header(index);
@@ -56,7 +56,7 @@
 }
 
 static void
-get_custom_flags(MailCustomFlags *mcf, MailboxStatus *status)
+get_custom_flags(struct mail_custom_flags *mcf, struct mailbox_status *status)
 {
 	const char **flags;
 	unsigned int i;
@@ -69,13 +69,14 @@
 		status->custom_flags[i] = t_strdup(flags[i]);
 }
 
-int index_storage_get_status(Mailbox *box, MailboxStatusItems items,
-			     MailboxStatus *status)
+int index_storage_get_status(struct mailbox *box,
+			     enum mailbox_status_items items,
+			     struct mailbox_status *status)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
-	MailIndexHeader *hdr;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
+	struct mail_index_header *hdr;
 
-	memset(status, 0, sizeof(MailboxStatus));
+	memset(status, 0, sizeof(struct mailbox_status));
 
 	/* if we're doing STATUS for selected mailbox, we have to sync it
 	   first or STATUS reply may give different data */
--- a/src/lib-storage/index/index-storage.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-storage.c	Sun Jan 05 15:09:51 2003 +0200
@@ -13,22 +13,20 @@
 
 #define LOCK_NOTIFY_INTERVAL 30
 
-typedef struct _IndexList IndexList;
+struct index_list {
+	struct index_list *next;
 
-struct _IndexList {
-	IndexList *next;
-
-	MailIndex *index;
+	struct mail_index *index;
 	int refcount;
 };
 
-static IndexList *indexes = NULL;
+static struct index_list *indexes = NULL;
 
-void index_storage_add(MailIndex *index)
+void index_storage_add(struct mail_index *index)
 {
-	IndexList *list;
+	struct index_list *list;
 
-	list = i_new(IndexList, 1);
+	list = i_new(struct index_list, 1);
 	list->refcount = 1;
 	list->index = index;
 
@@ -36,9 +34,9 @@
 	indexes = list;
 }
 
-MailIndex *index_storage_lookup_ref(const char *path)
+struct mail_index *index_storage_lookup_ref(const char *path)
 {
-	IndexList *list;
+	struct index_list *list;
 	struct stat st1, st2;
 
 	if (stat(path, &st1) < 0)
@@ -58,9 +56,9 @@
 	return NULL;
 }
 
-void index_storage_unref(MailIndex *index)
+void index_storage_unref(struct mail_index *index)
 {
-	IndexList **list, *rec;
+	struct index_list **list, *rec;
 
 	for (list = &indexes; *list != NULL; list = &(*list)->next) {
 		rec = *list;
@@ -78,7 +76,7 @@
 	i_unreached();
 }
 
-static MailDataField get_data_fields(const char *fields)
+static enum mail_data_field get_data_fields(const char *fields)
 {
 	static const char *field_names[] = {
 		"Location",
@@ -91,7 +89,7 @@
 	};
 
 	const char *const *arr;
-	MailDataField ret;
+	enum mail_data_field ret;
 	int i;
 
 	if (fields == NULL || *fields == '\0')
@@ -117,9 +115,9 @@
 	return ret;
 }
 
-static MailDataField get_default_cache_fields(void)
+static enum mail_data_field get_default_cache_fields(void)
 {
-	static MailDataField ret = 0;
+	static enum mail_data_field ret = 0;
 	static int ret_set = FALSE;
 
 	if (ret_set)
@@ -130,9 +128,9 @@
 	return ret;
 }
 
-static MailDataField get_never_cache_fields(void)
+static enum mail_data_field get_never_cache_fields(void)
 {
-	static MailDataField ret = 0;
+	static enum mail_data_field ret = 0;
 	static int ret_set = FALSE;
 
 	if (ret_set)
@@ -143,11 +141,11 @@
 	return ret;
 }
 
-static void lock_notify(MailLockNotifyType notify_type,
+static void lock_notify(enum mail_lock_notify_type notify_type,
 			unsigned int secs_left, void *context)
 {
-	IndexMailbox *ibox = context;
-	MailStorage *storage = ibox->box.storage;
+	struct index_mailbox *ibox = context;
+	struct mail_storage *storage = ibox->box.storage;
 	const char *str;
 	time_t now;
 
@@ -187,7 +185,8 @@
 	}
 }
 
-int index_storage_lock(IndexMailbox *ibox, MailLockType lock_type)
+int index_storage_lock(struct index_mailbox *ibox,
+		       enum mail_lock_type lock_type)
 {
 	int ret;
 
@@ -205,16 +204,17 @@
 	return TRUE;
 }
 
-IndexMailbox *index_storage_init(MailStorage *storage, Mailbox *box,
-				 MailIndex *index, const char *name,
-				 int readonly, int fast)
+struct index_mailbox *
+index_storage_init(struct mail_storage *storage, struct mailbox *box,
+		   struct mail_index *index, const char *name,
+		   int readonly, int fast)
 {
-	IndexMailbox *ibox;
+	struct index_mailbox *ibox;
 
 	i_assert(name != NULL);
 
 	do {
-		ibox = i_new(IndexMailbox, 1);
+		ibox = i_new(struct index_mailbox, 1);
 		ibox->box = *box;
 
 		ibox->box.storage = storage;
@@ -257,9 +257,9 @@
 	return NULL;
 }
 
-int index_storage_close(Mailbox *box)
+int index_storage_close(struct mailbox *box)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
 
 	index_mailbox_check_remove(ibox);
 	imap_msgcache_free(ibox->cache);
@@ -272,15 +272,16 @@
 	return TRUE;
 }
 
-void index_storage_set_callbacks(MailStorage *storage,
-				 MailStorageCallbacks *callbacks,
+void index_storage_set_callbacks(struct mail_storage *storage,
+				 struct mail_storage_callbacks *callbacks,
 				 void *context)
 {
-	memcpy(storage->callbacks, callbacks, sizeof(MailStorageCallbacks));
+	memcpy(storage->callbacks, callbacks,
+	       sizeof(struct mail_storage_callbacks));
 	storage->callback_context = context;
 }
 
-int mail_storage_set_index_error(IndexMailbox *ibox)
+int mail_storage_set_index_error(struct index_mailbox *ibox)
 {
 	switch (ibox->index->get_last_error(ibox->index)) {
 	case MAIL_INDEX_ERROR_NONE:
@@ -309,7 +310,8 @@
 	return FALSE;
 }
 
-int index_mailbox_fix_custom_flags(IndexMailbox *ibox, MailFlags *flags,
+int index_mailbox_fix_custom_flags(struct index_mailbox *ibox,
+				   enum mail_flags *flags,
                                    const char *custom_flags[])
 {
 	int ret;
@@ -329,10 +331,10 @@
 	}
 }
 
-unsigned int index_storage_get_recent_count(MailIndex *index)
+unsigned int index_storage_get_recent_count(struct mail_index *index)
 {
-	MailIndexHeader *hdr;
-	MailIndexRecord *rec;
+	struct mail_index_header *hdr;
+	struct mail_index_record *rec;
 	unsigned int seq;
 
 	hdr = mail_index_get_header(index);
--- a/src/lib-storage/index/index-storage.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-storage.h	Sun Jan 05 15:09:51 2003 +0200
@@ -5,20 +5,18 @@
 #include "mail-index.h"
 #include "imap-message-cache.h"
 
-typedef struct _IndexMailbox IndexMailbox;
-
-struct _IndexMailbox {
-	Mailbox box;
+struct index_mailbox {
+	struct mailbox box;
 
 	/* expunge messages marked as deleted, requires index to be
 	   exclusively locked */
-	int (*expunge_locked)(IndexMailbox *ibox, int notify);
+	int (*expunge_locked)(struct index_mailbox *ibox, int notify);
 
-	MailIndex *index;
-	ImapMessageCache *cache;
+	struct mail_index *index;
+	struct imap_message_cache *cache;
 
 	char *check_path;
-	Timeout check_to;
+	struct timeout *check_to;
 	time_t check_file_stamp;
 	time_t last_check;
 
@@ -30,61 +28,70 @@
 	unsigned int delay_save_unlocking:1; /* For COPYing inside mailbox */
 };
 
-extern ImapMessageCacheIface index_msgcache_iface;
+extern struct imap_message_cache_iface index_msgcache_iface;
 
-int mail_storage_set_index_error(IndexMailbox *ibox);
-int index_storage_lock(IndexMailbox *ibox, MailLockType lock_type);
+int mail_storage_set_index_error(struct index_mailbox *ibox);
+int index_storage_lock(struct index_mailbox *ibox,
+		       enum mail_lock_type lock_type);
 
-void index_storage_add(MailIndex *index);
-MailIndex *index_storage_lookup_ref(const char *path);
-void index_storage_unref(MailIndex *index);
+void index_storage_add(struct mail_index *index);
+struct mail_index *index_storage_lookup_ref(const char *path);
+void index_storage_unref(struct mail_index *index);
 
-IndexMailbox *index_storage_init(MailStorage *storage, Mailbox *box,
-				 MailIndex *index, const char *name,
-				 int readonly, int fast);
-int index_storage_close(Mailbox *box);
+struct index_mailbox *
+index_storage_init(struct mail_storage *storage, struct mailbox *box,
+		   struct mail_index *index, const char *name,
+		   int readonly, int fast);
+int index_storage_close(struct mailbox *box);
 
-int index_storage_sync_and_lock(IndexMailbox *ibox, int sync_size,
-				MailLockType data_lock_type);
-int index_storage_sync_modifylog(IndexMailbox *ibox, int hide_deleted);
+int index_storage_sync_and_lock(struct index_mailbox *ibox, int sync_size,
+				enum mail_lock_type data_lock_type);
+int index_storage_sync_modifylog(struct index_mailbox *ibox, int hide_deleted);
 
-int index_mailbox_fix_custom_flags(IndexMailbox *ibox, MailFlags *flags,
+int index_mailbox_fix_custom_flags(struct index_mailbox *ibox,
+				   enum mail_flags *flags,
                                    const char *custom_flags[]);
 
-unsigned int index_storage_get_recent_count(MailIndex *index);
+unsigned int index_storage_get_recent_count(struct mail_index *index);
 
-int index_expunge_seek_first(IndexMailbox *ibox, unsigned int *seq,
-			     MailIndexRecord **rec);
-int index_expunge_mail(IndexMailbox *ibox, MailIndexRecord *rec,
+int index_expunge_seek_first(struct index_mailbox *ibox, unsigned int *seq,
+			     struct mail_index_record **rec);
+int index_expunge_mail(struct index_mailbox *ibox,
+		       struct mail_index_record *rec,
 		       unsigned int seq, int notify);
 
-int index_storage_save(MailStorage *storage, const char *path,
-		       IStream *input, OStream *output, uoff_t data_size);
-
-int index_msgcache_open(ImapMessageCache *cache, MailIndex *index,
-			MailIndexRecord *rec, ImapCacheField fields);
+int index_storage_save(struct mail_storage *storage, const char *path,
+		       struct istream *input, struct ostream *output,
+		       uoff_t data_size);
 
-void index_mailbox_check_add(IndexMailbox *ibox, const char *path);
-void index_mailbox_check_remove(IndexMailbox *ibox);
+int index_msgcache_open(struct imap_message_cache *cache,
+			struct mail_index *index, struct mail_index_record *rec,
+			enum imap_cache_field fields);
 
-/* Mailbox methods: */
-void index_storage_set_callbacks(MailStorage *storage,
-				 MailStorageCallbacks *callbacks,
+void index_mailbox_check_add(struct index_mailbox *ibox, const char *path);
+void index_mailbox_check_remove(struct index_mailbox *ibox);
+
+/* mailbox methods: */
+void index_storage_set_callbacks(struct mail_storage *storage,
+				 struct mail_storage_callbacks *callbacks,
 				 void *context);
-int index_storage_copy(Mailbox *box, Mailbox *destbox,
+int index_storage_copy(struct mailbox *box, struct mailbox *destbox,
 		       const char *messageset, int uidset);
-int index_storage_expunge(Mailbox *box, int notify);
-int index_storage_get_status(Mailbox *box, MailboxStatusItems items,
-			     MailboxStatus *status);
-int index_storage_sync(Mailbox *box, int sync_expunges);
-int index_storage_update_flags(Mailbox *box, const char *messageset, int uidset,
-			       MailFlags flags, const char *custom_flags[],
-			       ModifyType modify_type, int notify,
+int index_storage_expunge(struct mailbox *box, int notify);
+int index_storage_get_status(struct mailbox *box,
+			     enum mailbox_status_items items,
+			     struct mailbox_status *status);
+int index_storage_sync(struct mailbox *box, int sync_expunges);
+int index_storage_update_flags(struct mailbox *box, const char *messageset,
+			       int uidset, enum mail_flags flags,
+			       const char *custom_flags[],
+			       enum modify_type modify_type, int notify,
 			       int *all_found);
-int index_storage_fetch(Mailbox *box, MailFetchData *fetch_data,
-			OStream *output, int *all_found);
-int index_storage_search(Mailbox *box, const char *charset, MailSearchArg *args,
-			 MailSortType *sorting, OStream *output,
-			 int uid_result);
+int index_storage_fetch(struct mailbox *box, struct mail_fetch_data *fetch_data,
+			struct ostream *output, int *all_found);
+int index_storage_search(struct mailbox *box, const char *charset,
+			 struct mail_search_arg *args,
+			 enum mail_sort_type *sorting,
+			 struct ostream *output, int uid_result);
 
 #endif
--- a/src/lib-storage/index/index-sync.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-sync.c	Sun Jan 05 15:09:51 2003 +0200
@@ -7,9 +7,9 @@
 #include "mail-modifylog.h"
 #include "mail-custom-flags.h"
 
-static void index_storage_sync_size(IndexMailbox *ibox)
+static void index_storage_sync_size(struct index_mailbox *ibox)
 {
-	MailStorage *storage = ibox->box.storage;
+	struct mail_storage *storage = ibox->box.storage;
 	unsigned int messages, recent;
 
 	if (storage->callbacks->new_messages == NULL)
@@ -29,11 +29,11 @@
 	}
 }
 
-int index_storage_sync_and_lock(IndexMailbox *ibox, int sync_size,
-				MailLockType data_lock_type)
+int index_storage_sync_and_lock(struct index_mailbox *ibox, int sync_size,
+				enum mail_lock_type data_lock_type)
 {
-	MailStorage *storage = ibox->box.storage;
-	MailIndex *index = ibox->index;
+	struct mail_storage *storage = ibox->box.storage;
+	struct mail_index *index = ibox->index;
 	int changes, set_shared_lock;
 
         set_shared_lock = ibox->index->lock_type != MAIL_LOCK_EXCLUSIVE;
@@ -86,12 +86,12 @@
 	return TRUE;
 }
 
-int index_storage_sync_modifylog(IndexMailbox *ibox, int hide_deleted)
+int index_storage_sync_modifylog(struct index_mailbox *ibox, int hide_deleted)
 {
-	const ModifyLogRecord *log1, *log2, *log, *first_flag_log;
-	MailIndexRecord *rec;
-	MailFlags flags;
-        MailStorageCallbacks *sc;
+	const struct modify_log_record *log1, *log2, *log, *first_flag_log;
+	struct mail_index_record *rec;
+	enum mail_flags flags;
+        struct mail_storage_callbacks *sc;
 	void *sc_context;
 	const char **custom_flags;
 	unsigned int count1, count2, total_count, seq, seq_count, i, messages;
@@ -205,9 +205,9 @@
 	return TRUE;
 }
 
-int index_storage_sync(Mailbox *box, int sync_expunges)
+int index_storage_sync(struct mailbox *box, int sync_expunges)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
 	int ret;
 
 	ibox->last_check = ioloop_time;
--- a/src/lib-storage/index/index-update-flags.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/index-update-flags.c	Sun Jan 05 15:09:51 2003 +0200
@@ -5,20 +5,20 @@
 #include "index-messageset.h"
 #include "mail-custom-flags.h"
 
-typedef struct {
-	IndexMailbox *ibox;
-	MailFlags flags;
-	ModifyType modify_type;
+struct update_context {
+	struct index_mailbox *ibox;
+	enum mail_flags flags;
+	enum modify_type modify_type;
 	int notify;
-} UpdateContext;
+};
 
-static int update_func(MailIndex *index, MailIndexRecord *rec,
+static int update_func(struct mail_index *index, struct mail_index_record *rec,
 		       unsigned int client_seq, unsigned int idx_seq,
 		       void *context)
 {
-	UpdateContext *ctx = context;
-	MailStorage *storage;
-	MailFlags flags;
+	struct update_context *ctx = context;
+	struct mail_storage *storage;
+	enum mail_flags flags;
 	const char **custom_flags;
 
 	switch (ctx->modify_type) {
@@ -60,13 +60,15 @@
 	return TRUE;
 }
 
-int index_storage_update_flags(Mailbox *box, const char *messageset, int uidset,
-			       MailFlags flags, const char *custom_flags[],
-			       ModifyType modify_type, int notify,
+int index_storage_update_flags(struct mailbox *box,
+			       const char *messageset, int uidset,
+			       enum mail_flags flags,
+			       const char *custom_flags[],
+			       enum modify_type modify_type, int notify,
 			       int *all_found)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
-        UpdateContext ctx;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
+        struct update_context ctx;
 	int ret;
 
 	if (box->readonly) {
--- a/src/lib-storage/index/maildir/maildir-copy.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/maildir/maildir-copy.c	Sun Jan 05 15:09:51 2003 +0200
@@ -9,19 +9,20 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-typedef struct {
-	MailStorage *storage;
-	IndexMailbox *dest;
+struct copy_hard_context {
+	struct mail_storage *storage;
+	struct index_mailbox *dest;
 	int error;
 	const char **custom_flags;
-} CopyHardContext;
+};
 
-static int copy_hard_func(MailIndex *index, MailIndexRecord *rec,
+static int copy_hard_func(struct mail_index *index,
+			  struct mail_index_record *rec,
 			  unsigned int client_seq __attr_unused__,
 			  unsigned int idx_seq __attr_unused__, void *context)
 {
-	CopyHardContext *ctx = context;
-	MailFlags flags;
+	struct copy_hard_context *ctx = context;
+	enum mail_flags flags;
 	const char *fname;
 	char src[PATH_MAX], dest[PATH_MAX];
 
@@ -60,11 +61,11 @@
 	}
 }
 
-static int maildir_copy_with_hardlinks(IndexMailbox *src,
-				       IndexMailbox *dest,
+static int maildir_copy_with_hardlinks(struct index_mailbox *src,
+				       struct index_mailbox *dest,
 				       const char *messageset, int uidset)
 {
-	CopyHardContext ctx;
+	struct copy_hard_context ctx;
 	int ret;
 
 	if (!index_storage_sync_and_lock(src, TRUE, MAIL_LOCK_SHARED))
@@ -83,10 +84,10 @@
 	return ctx.error ? -1 : ret;
 }
 
-int maildir_storage_copy(Mailbox *box, Mailbox *destbox,
+int maildir_storage_copy(struct mailbox *box, struct mailbox *destbox,
 			 const char *messageset, int uidset)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
 
 	if (destbox->readonly) {
 		mail_storage_set_error(box->storage,
@@ -99,7 +100,7 @@
 		/* both source and destination mailbox are in maildirs and
 		   copy_with_hardlinks option is on, do it */
 		switch (maildir_copy_with_hardlinks(ibox,
-			(IndexMailbox *) destbox, messageset, uidset)) {
+			(struct index_mailbox *) destbox, messageset, uidset)) {
 		case 1:
 			return TRUE;
 		case 0:
--- a/src/lib-storage/index/maildir/maildir-expunge.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/maildir/maildir-expunge.c	Sun Jan 05 15:09:51 2003 +0200
@@ -5,7 +5,8 @@
 
 #include <unistd.h>
 
-static int expunge_msg(IndexMailbox *ibox, MailIndexRecord *rec)
+static int expunge_msg(struct index_mailbox *ibox,
+		       struct mail_index_record *rec)
 {
 	const char *fname;
 	char path[PATH_MAX];
@@ -34,9 +35,9 @@
 	return TRUE;
 }
 
-int maildir_expunge_locked(IndexMailbox *ibox, int notify)
+int maildir_expunge_locked(struct index_mailbox *ibox, int notify)
 {
-	MailIndexRecord *rec;
+	struct mail_index_record *rec;
 	unsigned int seq;
 
 	if (!index_expunge_seek_first(ibox, &seq, &rec))
--- a/src/lib-storage/index/maildir/maildir-list.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/maildir/maildir-list.c	Sun Jan 05 15:09:51 2003 +0200
@@ -11,12 +11,12 @@
 #include <dirent.h>
 #include <sys/stat.h>
 
-typedef struct {
+struct find_subscribed_context {
 	MailboxFunc func;
 	void *context;
-} FindSubscribedContext;
+};
 
-static MailboxFlags
+static enum mailbox_flags
 maildir_get_marked_flags_from(const char *dir, time_t index_stamp)
 {
 	struct stat st;
@@ -44,8 +44,8 @@
 	return st.st_mtime <= cur_stamp ? MAILBOX_UNMARKED : MAILBOX_MARKED;
 }
 
-static MailboxFlags
-maildir_get_marked_flags(MailStorage *storage, const char *dir)
+static enum mailbox_flags
+maildir_get_marked_flags(struct mail_storage *storage, const char *dir)
 {
 	const char *path;
 	struct stat st;
@@ -71,14 +71,14 @@
 	return maildir_get_marked_flags_from(dir, st.st_mtime);
 }
 
-int maildir_find_mailboxes(MailStorage *storage, const char *mask,
+int maildir_find_mailboxes(struct mail_storage *storage, const char *mask,
 			   MailboxFunc func, void *context)
 {
-        ImapMatchGlob *glob;
+        struct imap_match_glob *glob;
 	DIR *dirp;
 	struct dirent *d;
 	struct stat st;
-        MailboxFlags flags;
+        enum mailbox_flags flags;
 	char path[PATH_MAX];
 	int failed, found_inbox;
 
@@ -155,11 +155,11 @@
 	return !failed;
 }
 
-static int maildir_subs_func(MailStorage *storage, const char *name,
+static int maildir_subs_func(struct mail_storage *storage, const char *name,
 			     void *context)
 {
-	FindSubscribedContext *ctx = context;
-	MailboxFlags flags;
+	struct find_subscribed_context *ctx = context;
+	enum mailbox_flags flags;
 	struct stat st;
 	char path[PATH_MAX];
 
@@ -176,10 +176,10 @@
 	return TRUE;
 }
 
-int maildir_find_subscribed(MailStorage *storage, const char *mask,
+int maildir_find_subscribed(struct mail_storage *storage, const char *mask,
 			    MailboxFunc func, void *context)
 {
-	FindSubscribedContext ctx;
+	struct find_subscribed_context ctx;
 
 	ctx.func = func;
 	ctx.context = context;
--- a/src/lib-storage/index/maildir/maildir-save.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/maildir/maildir-save.c	Sun Jan 05 15:09:51 2003 +0200
@@ -22,7 +22,7 @@
 			       my_pid, create_count++, my_hostname);
 }
 
-static int maildir_create_tmp(MailStorage *storage, const char *dir,
+static int maildir_create_tmp(struct mail_storage *storage, const char *dir,
 			      const char **fname)
 {
 	const char *path;
@@ -47,11 +47,12 @@
 	return fd;
 }
 
-static const char *maildir_read_into_tmp(MailStorage *storage, const char *dir,
-					 IStream *input, uoff_t data_size)
+static const char *
+maildir_read_into_tmp(struct mail_storage *storage, const char *dir,
+		      struct istream *input, uoff_t data_size)
 {
 	const char *fname, *path;
-	OStream *output;
+	struct ostream *output;
 	int fd;
 
 	fd = maildir_create_tmp(storage, dir, &fname);
@@ -77,12 +78,12 @@
 	return fname;
 }
 
-int maildir_storage_save(Mailbox *box, MailFlags flags,
+int maildir_storage_save(struct mailbox *box, enum mail_flags flags,
 			 const char *custom_flags[], time_t internal_date,
 			 int timezone_offset __attr_unused__,
-			 IStream *data, uoff_t data_size)
+			 struct istream *data, uoff_t data_size)
 {
-        IndexMailbox *ibox = (IndexMailbox *) box;
+        struct index_mailbox *ibox = (struct index_mailbox *) box;
         struct utimbuf buf;
 	const char *tmpdir, *fname, *tmp_path, *new_path;
 	int failed;
--- a/src/lib-storage/index/maildir/maildir-storage.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Sun Jan 05 15:09:51 2003 +0200
@@ -13,20 +13,20 @@
 
 #define CREATE_MODE 0770 /* umask() should limit it more */
 
-typedef struct {
+struct rename_context {
 	int found;
 	size_t oldnamelen;
 	const char *newname;
-} RenameContext;
+};
 
-extern MailStorage maildir_storage;
-extern Mailbox maildir_mailbox;
+extern struct mail_storage maildir_storage;
+extern struct mailbox maildir_mailbox;
 
 static const char *maildirs[] = { "cur", "new", "tmp", NULL  };
 
-static MailStorage *maildir_create(const char *data, const char *user)
+static struct mail_storage *maildir_create(const char *data, const char *user)
 {
-	MailStorage *storage;
+	struct mail_storage *storage;
 	const char *home, *path, *root_dir, *index_dir, *p;
 
 	root_dir = index_dir = NULL;
@@ -65,17 +65,17 @@
 	if (index_dir == NULL)
 		index_dir = root_dir;
 
-	storage = i_new(MailStorage, 1);
-	memcpy(storage, &maildir_storage, sizeof(MailStorage));
+	storage = i_new(struct mail_storage, 1);
+	memcpy(storage, &maildir_storage, sizeof(struct mail_storage));
 
 	storage->dir = i_strdup(root_dir);
 	storage->index_dir = i_strdup(index_dir);
 	storage->user = i_strdup(user);
-	storage->callbacks = i_new(MailStorageCallbacks, 1);
+	storage->callbacks = i_new(struct mail_storage_callbacks, 1);
 	return storage;
 }
 
-static void maildir_free(MailStorage *storage)
+static void maildir_free(struct mail_storage *storage)
 {
 	i_free(storage->dir);
 	i_free(storage->index_dir);
@@ -93,7 +93,7 @@
 		S_ISDIR(st.st_mode);
 }
 
-static int maildir_is_valid_name(MailStorage *storage, const char *name)
+static int maildir_is_valid_name(struct mail_storage *storage, const char *name)
 {
 	return name[0] != '\0' && name[0] != storage->hierarchy_sep &&
 		name[strlen(name)-1] != storage->hierarchy_sep &&
@@ -101,7 +101,8 @@
 		strchr(name, '*') == NULL && strchr(name, '%') == NULL;
 }
 
-static const char *maildir_get_path(MailStorage *storage, const char *name)
+static const char *maildir_get_path(struct mail_storage *storage,
+				    const char *name)
 {
 	return t_strconcat(storage->dir, "/.", name, NULL);
 }
@@ -125,7 +126,7 @@
 	return TRUE;
 }
 
-static int create_index_dir(MailStorage *storage, const char *name)
+static int create_index_dir(struct mail_storage *storage, const char *name)
 {
 	const char *dir;
 
@@ -142,7 +143,7 @@
 	return TRUE;
 }
 
-static int verify_inbox(MailStorage *storage)
+static int verify_inbox(struct mail_storage *storage)
 {
 	const char **tmp, *src, *dest, *inbox;
 
@@ -173,11 +174,12 @@
 	return create_index_dir(storage, "INBOX");
 }
 
-static Mailbox *maildir_open(MailStorage *storage, const char *name,
-			     int readonly, int fast)
+static struct mailbox *
+maildir_open(struct mail_storage *storage, const char *name,
+	     int readonly, int fast)
 {
-	IndexMailbox *ibox;
-	MailIndex *index;
+	struct index_mailbox *ibox;
+	struct mail_index *index;
 	const char *path, *index_dir;
 
 	path = t_strconcat(storage->dir, "/.", name, NULL);
@@ -195,10 +197,11 @@
 		ibox->expunge_locked = maildir_expunge_locked;
 		index_mailbox_check_add(ibox, t_strconcat(path, "/new", NULL));
 	}
-	return (Mailbox *) ibox;
+	return (struct mailbox *) ibox;
 }
 
-static const char *inbox_fix_case(MailStorage *storage, const char *name)
+static const char *inbox_fix_case(struct mail_storage *storage,
+				  const char *name)
 {
         if (strncasecmp(name, "INBOX", 5) == 0 &&
 	    (name[5] == '\0' || name[5] == storage->hierarchy_sep)) {
@@ -210,8 +213,9 @@
 	return name;
 }
 
-static Mailbox *maildir_open_mailbox(MailStorage *storage, const char *name,
-				     int readonly, int fast)
+static struct mailbox *
+maildir_open_mailbox(struct mail_storage *storage,
+		     const char *name, int readonly, int fast)
 {
 	const char *path;
 	struct stat st;
@@ -250,7 +254,8 @@
 	}
 }
 
-static int maildir_create_mailbox(MailStorage *storage, const char *name)
+static int maildir_create_mailbox(struct mail_storage *storage,
+				  const char *name)
 {
 	const char *path;
 
@@ -275,7 +280,8 @@
 	}
 }
 
-static int maildir_delete_mailbox(MailStorage *storage, const char *name)
+static int maildir_delete_mailbox(struct mail_storage *storage,
+				  const char *name)
 {
 	struct stat st;
 	const char *src, *dest, *index_dir;
@@ -343,7 +349,7 @@
 	return TRUE;
 }
 
-static int move_inbox_data(MailStorage *storage, const char *newdir)
+static int move_inbox_data(struct mail_storage *storage, const char *newdir)
 {
 	const char **tmp, *oldpath, *newpath;
 
@@ -374,7 +380,7 @@
 	return TRUE;
 }
 
-static int rename_indexes(MailStorage *storage,
+static int rename_indexes(struct mail_storage *storage,
 			  const char *oldname, const char *newname)
 {
 	const char *oldpath, *newpath;
@@ -395,10 +401,11 @@
 	return TRUE;
 }
 
-static void rename_subfolder(MailStorage *storage, const char *name,
-			     MailboxFlags flags __attr_unused__, void *context)
+static void rename_subfolder(struct mail_storage *storage, const char *name,
+			     enum mailbox_flags flags __attr_unused__,
+			     void *context)
 {
-	RenameContext *ctx = context;
+	struct rename_context *ctx = context;
 	const char *newname, *oldpath, *newpath;
 
 	i_assert(ctx->oldnamelen <= strlen(name));
@@ -425,10 +432,10 @@
 	(void)rename_indexes(storage, name, newname);
 }
 
-static int maildir_rename_mailbox(MailStorage *storage, const char *oldname,
-				  const char *newname)
+static int maildir_rename_mailbox(struct mail_storage *storage,
+				  const char *oldname, const char *newname)
 {
-	RenameContext ctx;
+	struct rename_context ctx;
 	const char *oldpath, *newpath;
 	int ret;
 
@@ -485,9 +492,9 @@
 	}
 }
 
-static int maildir_get_mailbox_name_status(MailStorage *storage,
+static int maildir_get_mailbox_name_status(struct mail_storage *storage,
 					   const char *name,
-					   MailboxNameStatus *status)
+					   enum mailbox_name_status *status)
 {
 	struct stat st;
 	const char *path;
@@ -514,7 +521,7 @@
 	}
 }
 
-MailStorage maildir_storage = {
+struct mail_storage maildir_storage = {
 	"maildir", /* name */
 
 	'.', /* hierarchy_sep - can't be changed */
@@ -543,7 +550,7 @@
 	0
 };
 
-Mailbox maildir_mailbox = {
+struct mailbox maildir_mailbox = {
 	NULL, /* name */
 	NULL, /* storage */
 
--- a/src/lib-storage/index/maildir/maildir-storage.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/maildir/maildir-storage.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,19 +3,19 @@
 
 #include "index-storage.h"
 
-int maildir_storage_copy(Mailbox *box, Mailbox *destbox,
+int maildir_storage_copy(struct mailbox *box, struct mailbox *destbox,
 			 const char *messageset, int uidset);
-int maildir_storage_save(Mailbox *box, MailFlags flags,
+int maildir_storage_save(struct mailbox *box, enum mail_flags flags,
 			 const char *custom_flags[],
 			 time_t internal_date, int timezone_offset,
-			 IStream *data, uoff_t data_size);
+			 struct istream *data, uoff_t data_size);
 
-int maildir_find_mailboxes(MailStorage *storage, const char *mask,
+int maildir_find_mailboxes(struct mail_storage *storage, const char *mask,
 			   MailboxFunc func, void *context);
-int maildir_find_subscribed(MailStorage *storage, const char *mask,
+int maildir_find_subscribed(struct mail_storage *storage, const char *mask,
 			    MailboxFunc func, void *context);
 
-int maildir_expunge_locked(IndexMailbox *ibox, int notify);
+int maildir_expunge_locked(struct index_mailbox *ibox, int notify);
 
 /* Return new filename base to save into tmp/ */
 const char *maildir_generate_tmp_filename(void);
--- a/src/lib-storage/index/mbox/mbox-expunge.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/mbox/mbox-expunge.c	Sun Jan 05 15:09:51 2003 +0200
@@ -10,8 +10,9 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-static int expunge_real(IndexMailbox *ibox, MailIndexRecord *rec,
-			unsigned int seq, IStream *input, OStream *output,
+static int expunge_real(struct index_mailbox *ibox,
+			struct mail_index_record *rec, unsigned int seq,
+			struct istream *input, struct ostream *output,
 			int notify)
 {
 	uoff_t offset, hdr_size, body_size;
@@ -101,11 +102,11 @@
 	return o_stream_send_istream(output, input) >= 0;
 }
 
-int mbox_expunge_locked(IndexMailbox *ibox, int notify)
+int mbox_expunge_locked(struct index_mailbox *ibox, int notify)
 {
-	MailIndexRecord *rec;
-	IStream *input;
-	OStream *output;
+	struct mail_index_record *rec;
+	struct istream *input;
+	struct ostream *output;
 	unsigned int seq;
 	int failed;
 
@@ -118,7 +119,7 @@
 	}
 
 	/* mbox must be already opened, synced and locked at this point.
-	   we just want the IStream. */
+	   we just want the istream. */
 	input = mbox_get_stream(ibox->index, 0, MAIL_LOCK_EXCLUSIVE);
 	if (input == NULL)
 		return FALSE;
--- a/src/lib-storage/index/mbox/mbox-list.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/mbox/mbox-list.c	Sun Jan 05 15:09:51 2003 +0200
@@ -10,12 +10,13 @@
 #include <dirent.h>
 #include <sys/stat.h>
 
-typedef struct {
+struct find_subscribed_context {
 	MailboxFunc func;
 	void *context;
-} FindSubscribedContext;
+};
 
-static int mbox_find_path(MailStorage *storage, ImapMatchGlob *glob,
+static int mbox_find_path(struct mail_storage *storage,
+			  struct imap_match_glob *glob,
 			  MailboxFunc func, void *context,
 			  const char *relative_dir)
 {
@@ -146,10 +147,10 @@
 	return last_dir != NULL ? t_strdup_until(mask, last_dir) : NULL;
 }
 
-int mbox_find_mailboxes(MailStorage *storage, const char *mask,
+int mbox_find_mailboxes(struct mail_storage *storage, const char *mask,
 			MailboxFunc func, void *context)
 {
-	ImapMatchGlob *glob;
+	struct imap_match_glob *glob;
 	const char *relative_dir;
 
 	/* check that we're not trying to do any "../../" lists */
@@ -176,11 +177,11 @@
 	return TRUE;
 }
 
-static int mbox_subs_func(MailStorage *storage, const char *name,
+static int mbox_subs_func(struct mail_storage *storage, const char *name,
 			  void *context)
 {
-	FindSubscribedContext *ctx = context;
-	MailboxFlags flags;
+	struct find_subscribed_context *ctx = context;
+	enum mailbox_flags flags;
 	struct stat st;
 	char path[PATH_MAX];
 
@@ -198,10 +199,10 @@
 	return TRUE;
 }
 
-int mbox_find_subscribed(MailStorage *storage, const char *mask,
+int mbox_find_subscribed(struct mail_storage *storage, const char *mask,
 			 MailboxFunc func, void *context)
 {
-	FindSubscribedContext ctx;
+	struct find_subscribed_context ctx;
 
 	ctx.func = func;
 	ctx.context = context;
--- a/src/lib-storage/index/mbox/mbox-save.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/mbox/mbox-save.c	Sun Jan 05 15:09:51 2003 +0200
@@ -16,7 +16,7 @@
 
 static char my_hostdomain[256] = "";
 
-static int write_error(MailStorage *storage, const char *mbox_path)
+static int write_error(struct mail_storage *storage, const char *mbox_path)
 {
 	if (errno == ENOSPC)
 		mail_storage_set_error(storage, "Not enough disk space");
@@ -28,7 +28,7 @@
 	return FALSE;
 }
 
-static int mbox_seek_to_end(MailStorage *storage, int fd,
+static int mbox_seek_to_end(struct mail_storage *storage, int fd,
 			    const char *mbox_path, off_t *pos)
 {
 	struct stat st;
@@ -65,7 +65,7 @@
 	return TRUE;
 }
 
-static int mbox_append_lf(MailStorage *storage, OStream *output,
+static int mbox_append_lf(struct mail_storage *storage, struct ostream *output,
 			  const char *mbox_path)
 {
 	if (o_stream_send(output, "\n", 1) < 0)
@@ -74,7 +74,7 @@
 	return TRUE;
 }
 
-static int write_from_line(MailStorage *storage, OStream *output,
+static int write_from_line(struct mail_storage *storage, struct ostream *output,
 			   const char *mbox_path, time_t internal_date)
 {
 	const char *sender, *line, *name;
@@ -105,9 +105,9 @@
 	return TRUE;
 }
 
-static int write_flags(MailStorage *storage, OStream *output,
+static int write_flags(struct mail_storage *storage, struct ostream *output,
 		       const char *mbox_path,
-		       MailFlags flags, const char *custom_flags[])
+		       enum mail_flags flags, const char *custom_flags[])
 {
 	const char *str;
 	unsigned int field;
@@ -156,15 +156,16 @@
 	return TRUE;
 }
 
-int mbox_storage_save(Mailbox *box, MailFlags flags, const char *custom_flags[],
-		      time_t internal_date, int timezone_offset __attr_unused__,
-		      IStream *data, uoff_t data_size)
+int mbox_storage_save(struct mailbox *box, enum mail_flags flags,
+		      const char *custom_flags[], time_t internal_date,
+		      int timezone_offset __attr_unused__,
+		      struct istream *data, uoff_t data_size)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
-	MailIndex *index;
-	MailFlags real_flags;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
+	struct mail_index *index;
+	enum mail_flags real_flags;
 	const char *mbox_path;
-	OStream *output;
+	struct ostream *output;
 	int failed;
 	off_t pos;
 
--- a/src/lib-storage/index/mbox/mbox-storage.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Sun Jan 05 15:09:51 2003 +0200
@@ -16,8 +16,8 @@
 
 #define CREATE_MODE 0770 /* umask() should limit it more */
 
-extern MailStorage mbox_storage;
-extern Mailbox mbox_mailbox;
+extern struct mail_storage mbox_storage;
+extern struct mailbox mbox_mailbox;
 
 static int mkdir_parents(const char *path)
 {
@@ -98,9 +98,9 @@
 	return NULL;
 }
 
-static MailStorage *mbox_create(const char *data, const char *user)
+static struct mail_storage *mbox_create(const char *data, const char *user)
 {
-	MailStorage *storage;
+	struct mail_storage *storage;
 	const char *root_dir, *inbox_file, *index_dir, *p;
 	struct stat st;
 
@@ -148,18 +148,18 @@
 	if (index_dir == NULL)
 		index_dir = root_dir;
 
-	storage = i_new(MailStorage, 1);
-	memcpy(storage, &mbox_storage, sizeof(MailStorage));
+	storage = i_new(struct mail_storage, 1);
+	memcpy(storage, &mbox_storage, sizeof(struct mail_storage));
 
 	storage->dir = i_strdup(root_dir);
 	storage->inbox_file = i_strdup(inbox_file);
 	storage->index_dir = i_strdup(index_dir);
 	storage->user = i_strdup(user);
-	storage->callbacks = i_new(MailStorageCallbacks, 1);
+	storage->callbacks = i_new(struct mail_storage_callbacks, 1);
 	return storage;
 }
 
-static void mbox_free(MailStorage *storage)
+static void mbox_free(struct mail_storage *storage)
 {
 	i_free(storage->dir);
 	i_free(storage->inbox_file);
@@ -187,7 +187,7 @@
 	return TRUE;
 }
 
-static int mbox_is_valid_name(MailStorage *storage, const char *name)
+static int mbox_is_valid_name(struct mail_storage *storage, const char *name)
 {
 	return name[0] != '\0' && name[0] != storage->hierarchy_sep &&
 		name[strlen(name)-1] != storage->hierarchy_sep &&
@@ -195,7 +195,8 @@
 		mbox_is_valid_mask(name);
 }
 
-static const char *mbox_get_index_dir(MailStorage *storage, const char *name)
+static const char *mbox_get_index_dir(struct mail_storage *storage,
+				      const char *name)
 {
 	const char *p;
 
@@ -208,8 +209,8 @@
 	}
 }
 
-static int create_mbox_index_dirs(MailStorage *storage, const char *name,
-				  int verify)
+static int create_mbox_index_dirs(struct mail_storage *storage,
+				  const char *name, int verify)
 {
 	const char *index_dir, *imap_dir;
 
@@ -224,7 +225,7 @@
 	return TRUE;
 }
 
-static void verify_inbox(MailStorage *storage)
+static void verify_inbox(struct mail_storage *storage)
 {
 	int fd;
 
@@ -237,7 +238,7 @@
 	(void)create_mbox_index_dirs(storage, "INBOX", TRUE);
 }
 
-static const char *mbox_get_path(MailStorage *storage, const char *name)
+static const char *mbox_get_path(struct mail_storage *storage, const char *name)
 {
 	if (strcasecmp(name, "INBOX") == 0)
 		return storage->inbox_file;
@@ -245,11 +246,11 @@
 		return t_strconcat(storage->dir, "/", name, NULL);
 }
 
-static Mailbox *mbox_open(MailStorage *storage, const char *name,
-			  int readonly, int fast)
+static struct mailbox *mbox_open(struct mail_storage *storage, const char *name,
+				 int readonly, int fast)
 {
-	IndexMailbox *ibox;
-	MailIndex *index;
+	struct index_mailbox *ibox;
+	struct mail_index *index;
 	const char *path, *index_dir;
 
 	if (strcasecmp(name, "INBOX") == 0) {
@@ -278,11 +279,12 @@
 		ibox->expunge_locked = mbox_expunge_locked;
 		index_mailbox_check_add(ibox, index->mailbox_path);
 	}
-	return (Mailbox *) ibox;
+	return (struct mailbox *) ibox;
 }
 
-static Mailbox *mbox_open_mailbox(MailStorage *storage, const char *name,
-				  int readonly, int fast)
+static struct mailbox *
+mbox_open_mailbox(struct mail_storage *storage,
+		  const char *name, int readonly, int fast)
 {
 	const char *path;
 	struct stat st;
@@ -324,7 +326,7 @@
 	}
 }
 
-static int mbox_create_mailbox(MailStorage *storage, const char *name)
+static int mbox_create_mailbox(struct mail_storage *storage, const char *name)
 {
 	const char *path, *p;
 	struct stat st;
@@ -364,8 +366,8 @@
 	if (p != NULL) {
 		if (mkdir_parents(t_strdup_until(path, p)) < 0) {
 			mail_storage_set_critical(storage,
-						  "mkdir_parents() failed for mbox path "
-						  "%s: %m", path);
+				"mkdir_parents() failed for mbox path %s: %m",
+				path);
 			return FALSE;
 		}
 	}
@@ -386,7 +388,7 @@
 	}
 }
 
-static int mbox_delete_mailbox(MailStorage *storage, const char *name)
+static int mbox_delete_mailbox(struct mail_storage *storage, const char *name)
 {
 	const char *index_dir, *path;
 	struct stat st;
@@ -456,8 +458,8 @@
 	return TRUE;
 }
 
-static int mbox_rename_mailbox(MailStorage *storage, const char *oldname,
-			       const char *newname)
+static int mbox_rename_mailbox(struct mail_storage *storage,
+			       const char *oldname, const char *newname)
 {
 	const char *oldpath, *newpath, *old_indexdir, *new_indexdir, *p;
 
@@ -508,8 +510,9 @@
 	return TRUE;
 }
 
-static int mbox_get_mailbox_name_status(MailStorage *storage, const char *name,
-					MailboxNameStatus *status)
+static int mbox_get_mailbox_name_status(struct mail_storage *storage,
+					const char *name,
+					enum mailbox_name_status *status)
 {
 	struct stat st;
 	const char *path;
@@ -541,9 +544,9 @@
 	}
 }
 
-static int mbox_storage_close(Mailbox *box)
+static int mbox_storage_close(struct mailbox *box)
 {
-	IndexMailbox *ibox = (IndexMailbox *) box;
+	struct index_mailbox *ibox = (struct index_mailbox *) box;
 	int failed = FALSE;
 
 	/* update flags by rewrite mbox file */
@@ -555,7 +558,7 @@
 	return index_storage_close(box) && !failed;
 }
 
-MailStorage mbox_storage = {
+struct mail_storage mbox_storage = {
 	"mbox", /* name */
 
 	'/', /* hierarchy_sep - can't be changed */
@@ -584,7 +587,7 @@
 	0
 };
 
-Mailbox mbox_mailbox = {
+struct mailbox mbox_mailbox = {
 	NULL, /* name */
 	NULL, /* storage */
 
--- a/src/lib-storage/index/mbox/mbox-storage.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/index/mbox/mbox-storage.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,18 +3,19 @@
 
 #include "index-storage.h"
 
-int mbox_storage_copy(Mailbox *box, Mailbox *destbox,
+int mbox_storage_copy(struct mailbox *box, struct mailbox *destbox,
 		      const char *messageset, int uidset);
-int mbox_storage_save(Mailbox *box, MailFlags flags, const char *custom_flags[],
-		      time_t internal_date, int timezone_offset,
-		      IStream *data, uoff_t data_size);
+int mbox_storage_save(struct mailbox *box, enum mail_flags flags,
+		      const char *custom_flags[], time_t internal_date,
+		      int timezone_offset,
+		      struct istream *data, uoff_t data_size);
 
-int mbox_find_mailboxes(MailStorage *storage, const char *mask,
+int mbox_find_mailboxes(struct mail_storage *storage, const char *mask,
 			MailboxFunc func, void *context);
-int mbox_find_subscribed(MailStorage *storage, const char *mask,
+int mbox_find_subscribed(struct mail_storage *storage, const char *mask,
 			 MailboxFunc func, void *context);
 
-int mbox_expunge_locked(IndexMailbox *ibox, int notify);
+int mbox_expunge_locked(struct index_mailbox *ibox, int notify);
 
 int mbox_is_valid_mask(const char *mask);
 
--- a/src/lib-storage/mail-search.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/mail-search.c	Sun Jan 05 15:09:51 2003 +0200
@@ -3,16 +3,17 @@
 #include "lib.h"
 #include "mail-search.h"
 
-typedef struct {
-	Pool pool;
+struct search_build_data {
+	pool_t pool;
 	const char *error;
-} SearchBuildData;
+};
 
-static MailSearchArg *search_arg_new(Pool pool, MailSearchArgType type)
+static struct mail_search_arg *
+search_arg_new(pool_t pool, enum mail_search_arg_type type)
 {
-	MailSearchArg *arg;
+	struct mail_search_arg *arg;
 
-	arg = p_new(pool, MailSearchArg, 1);
+	arg = p_new(pool, struct mail_search_arg, 1);
 	arg->type = type;
 
 	return arg;
@@ -21,10 +22,11 @@
 #define ARG_NEW(type, value) \
 	arg_new(data, args, next_sarg, type, value)
 
-static int arg_new(SearchBuildData *data, ImapArg **args,
-		   MailSearchArg **next_sarg, MailSearchArgType type, int value)
+static int arg_new(struct search_build_data *data, struct imap_arg **args,
+		   struct mail_search_arg **next_sarg,
+		   enum mail_search_arg_type type, int value)
 {
-	MailSearchArg *sarg;
+	struct mail_search_arg *sarg;
 
 	*next_sarg = sarg = search_arg_new(data->pool, type);
 	if (value == 0)
@@ -66,11 +68,12 @@
 	return TRUE;
 }
 
-static int search_arg_build(SearchBuildData *data, ImapArg **args,
-			    MailSearchArg **next_sarg)
+static int search_arg_build(struct search_build_data *data,
+			    struct imap_arg **args,
+			    struct mail_search_arg **next_sarg)
 {
-	MailSearchArg **subargs;
-	ImapArg *arg;
+	struct mail_search_arg **subargs;
+	struct imap_arg *arg;
 	char *str;
 
 	if ((*args)->type == IMAP_ARG_EOL) {
@@ -87,7 +90,7 @@
 	}
 
 	if (arg->type == IMAP_ARG_LIST) {
-		ImapArg *listargs = IMAP_ARG_LIST(arg)->args;
+		struct imap_arg *listargs = IMAP_ARG_LIST(arg)->args;
 
 		*next_sarg = search_arg_new(data->pool, SEARCH_SUB);
 		subargs = &(*next_sarg)->value.subargs;
@@ -348,11 +351,11 @@
 	return FALSE;
 }
 
-MailSearchArg *mail_search_args_build(Pool pool, ImapArg *args,
-				      const char **error)
+struct mail_search_arg *
+mail_search_args_build(pool_t pool, struct imap_arg *args, const char **error)
 {
-        SearchBuildData data;
-	MailSearchArg *first_sarg, **sargs;
+        struct search_build_data data;
+	struct mail_search_arg *first_sarg, **sargs;
 
 	data.pool = pool;
 	data.error = NULL;
@@ -371,7 +374,7 @@
 	return first_sarg;
 }
 
-void mail_search_args_reset(MailSearchArg *args)
+void mail_search_args_reset(struct mail_search_arg *args)
 {
 	while (args != NULL) {
 		if (args->type == SEARCH_OR || args->type == SEARCH_SUB)
@@ -382,10 +385,10 @@
 	}
 }
 
-static void search_arg_foreach(MailSearchArg *arg, MailSearchForeachFunc func,
-			       void *context)
+static void search_arg_foreach(struct mail_search_arg *arg,
+			       MailSearchForeachFunc func, void *context)
 {
-	MailSearchArg *subarg;
+	struct mail_search_arg *subarg;
 
 	if (arg->result != 0)
 		return;
@@ -438,8 +441,8 @@
 	}
 }
 
-int mail_search_args_foreach(MailSearchArg *args, MailSearchForeachFunc func,
-			     void *context)
+int mail_search_args_foreach(struct mail_search_arg *args,
+			     MailSearchForeachFunc func, void *context)
 {
 	int result;
 
@@ -459,10 +462,10 @@
 	return result;
 }
 
-static void search_arg_analyze(MailSearchArg *arg, int *have_headers,
+static void search_arg_analyze(struct mail_search_arg *arg, int *have_headers,
 			       int *have_body, int *have_text)
 {
-	MailSearchArg *subarg;
+	struct mail_search_arg *subarg;
 
 	if (arg->result != 0)
 		return;
@@ -504,7 +507,7 @@
 	}
 }
 
-void mail_search_args_analyze(MailSearchArg *args, int *have_headers,
+void mail_search_args_analyze(struct mail_search_arg *args, int *have_headers,
 			      int *have_body, int *have_text)
 {
 	*have_headers = *have_body = *have_text = FALSE;
--- a/src/lib-storage/mail-search.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/mail-search.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,7 +4,7 @@
 #include "imap-parser.h"
 #include "mail-storage.h"
 
-typedef enum {
+enum mail_search_arg_type {
 	SEARCH_OR,
 	SEARCH_SUB,
 
@@ -49,14 +49,14 @@
 	/* our shortcuts for headers */
         SEARCH_IN_REPLY_TO,
         SEARCH_MESSAGE_ID
-} MailSearchArgType;
+};
 
-struct _MailSearchArg {
-	MailSearchArg *next;
+struct mail_search_arg {
+	struct mail_search_arg *next;
 
-	MailSearchArgType type;
+	enum mail_search_arg_type type;
 	union {
-		MailSearchArg *subargs;
+		struct mail_search_arg *subargs;
 		const char *str;
 	} value;
 
@@ -67,23 +67,24 @@
 	int result;
 };
 
-typedef void (*MailSearchForeachFunc)(MailSearchArg *arg, void *context);
+typedef void (*MailSearchForeachFunc)(struct mail_search_arg *arg,
+				      void *context);
 
 /* Builds search arguments based on IMAP arguments. */
-MailSearchArg *mail_search_args_build(Pool pool, ImapArg *args,
-				      const char **error);
+struct mail_search_arg *
+mail_search_args_build(pool_t pool, struct imap_arg *args, const char **error);
 
 /* Reset the results in search arguments */
-void mail_search_args_reset(MailSearchArg *args);
+void mail_search_args_reset(struct mail_search_arg *args);
 
 /* goes through arguments in list that don't have a result yet.
    Returns 1 = search matched, -1 = search unmatched, 0 = don't know yet */
-int mail_search_args_foreach(MailSearchArg *args, MailSearchForeachFunc func,
-			     void *context);
+int mail_search_args_foreach(struct mail_search_arg *args,
+			     MailSearchForeachFunc func, void *context);
 
 /* Fills have_headers, have_body and have_text based on if such search
    argument exists that needs to be checked. */
-void mail_search_args_analyze(MailSearchArg *args, int *have_headers,
+void mail_search_args_analyze(struct mail_search_arg *args, int *have_headers,
 			      int *have_body, int *have_text);
 
 #endif
--- a/src/lib-storage/mail-sort.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/mail-sort.c	Sun Jan 05 15:09:51 2003 +0200
@@ -10,27 +10,27 @@
 
 #include <stdlib.h>
 
-struct _MailSortContext {
-	MailSortType output[MAX_SORT_PROGRAM_SIZE];
-	MailSortType common_mask;
+struct mail_sort_context {
+	enum mail_sort_type output[MAX_SORT_PROGRAM_SIZE];
+	enum mail_sort_type common_mask;
 
-	MailSortFuncs funcs;
+	struct mail_sort_funcs funcs;
 	void *func_context;
 
-	Buffer *sort_buffer;
-	Pool temp_pool;
+	buffer_t *sort_buffer;
+	pool_t temp_pool;
 
 	time_t last_arrival, last_date;
 	uoff_t last_size;
 	char *last_cc, *last_from, *last_subject, *last_to;
 };
 
-static void mail_sort_flush(MailSortContext *ctx);
+static void mail_sort_flush(struct mail_sort_context *ctx);
 
-static MailSortType
-mail_sort_normalize(const MailSortType *input, Buffer *output)
+static enum mail_sort_type
+mail_sort_normalize(const enum mail_sort_type *input, buffer_t *output)
 {
-        MailSortType type, mask = 0;
+        enum mail_sort_type type, mask = 0;
 	int pos, reverse;
 
 	reverse = FALSE;
@@ -59,11 +59,11 @@
 	return mask;
 }
 
-static MailSortType
-mail_sort_get_common_mask(const MailSortType *input,
-			  MailSortType **output)
+static enum mail_sort_type
+mail_sort_get_common_mask(const enum mail_sort_type *input,
+			  enum mail_sort_type **output)
 {
-	MailSortType mask = 0;
+	enum mail_sort_type mask = 0;
 
 	while (*input == **output && *input != MAIL_SORT_END) {
 		if (*input != MAIL_SORT_REVERSE)
@@ -74,16 +74,17 @@
 	return mask;
 }
 
-MailSortContext *mail_sort_init(const MailSortType *input, MailSortType *output,
-				MailSortFuncs funcs, void *context)
+struct mail_sort_context *
+mail_sort_init(const enum mail_sort_type *input, enum mail_sort_type *output,
+	       struct mail_sort_funcs funcs, void *context)
 {
-	MailSortContext *ctx;
-	MailSortType norm_input[MAX_SORT_PROGRAM_SIZE];
-	MailSortType norm_output[MAX_SORT_PROGRAM_SIZE];
-	Buffer *buf;
+	struct mail_sort_context *ctx;
+	enum mail_sort_type norm_input[MAX_SORT_PROGRAM_SIZE];
+	enum mail_sort_type norm_output[MAX_SORT_PROGRAM_SIZE];
+	buffer_t *buf;
 	int i;
 
-	ctx = i_new(MailSortContext, 1);
+	ctx = i_new(struct mail_sort_context, 1);
 
 	t_push();
 	buf = buffer_create_data(data_stack_pool,
@@ -114,7 +115,7 @@
 	return ctx;
 }
 
-void mail_sort_deinit(MailSortContext *ctx)
+void mail_sort_deinit(struct mail_sort_context *ctx)
 {
 	mail_sort_flush(ctx);
 	buffer_free(ctx->sort_buffer);
@@ -140,7 +141,7 @@
 	return strcasecmp(s1, s2);
 }
 
-static int subject_cmp(Pool pool, const char *s1, const char *s2)
+static int subject_cmp(pool_t pool, const char *s1, const char *s2)
 {
 	int ret;
 
@@ -155,7 +156,8 @@
 	return ret;
 }
 
-static void mail_sort_check_flush(MailSortContext *ctx, unsigned int id)
+static void mail_sort_check_flush(struct mail_sort_context *ctx,
+				  unsigned int id)
 {
 	const char *str;
 	time_t t;
@@ -233,7 +235,7 @@
 		mail_sort_flush(ctx);
 }
 
-void mail_sort_input(MailSortContext *ctx, unsigned int id)
+void mail_sort_input(struct mail_sort_context *ctx, unsigned int id)
 {
 	if (ctx->common_mask != 0)
 		mail_sort_check_flush(ctx, id);
@@ -241,14 +243,14 @@
 	buffer_append(ctx->sort_buffer, &id, sizeof(id));
 }
 
-static MailSortContext *mail_sort_qsort_context;
+static struct mail_sort_context *mail_sort_qsort_context;
 
 static int mail_sort_qsort_func(const void *p1, const void *p2)
 {
 	const unsigned int *i1 = p1;
 	const unsigned int *i2 = p2;
-	MailSortType *output = mail_sort_qsort_context->output;
-        MailSortFuncs *funcs = &mail_sort_qsort_context->funcs;
+	enum mail_sort_type *output = mail_sort_qsort_context->output;
+        struct mail_sort_funcs *funcs = &mail_sort_qsort_context->funcs;
 	void *ctx = mail_sort_qsort_context->func_context;
 	int ret, reverse = FALSE;
 
@@ -315,7 +317,7 @@
 	return ret != 0 ? ret : (*i1 < *i2 ? -1 : 1);
 }
 
-static void mail_sort_flush(MailSortContext *ctx)
+static void mail_sort_flush(struct mail_sort_context *ctx)
 {
 	unsigned int *arr;
 	size_t count;
--- a/src/lib-storage/mail-sort.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/mail-sort.h	Sun Jan 05 15:09:51 2003 +0200
@@ -6,7 +6,7 @@
 /* Maximum size for sort program, 2x for reverse + END */
 #define MAX_SORT_PROGRAM_SIZE (2*7 + 1)
 
-enum _MailSortType {
+enum mail_sort_type {
 	MAIL_SORT_ARRIVAL	= 0x0010,
 	MAIL_SORT_CC		= 0x0020,
 	MAIL_SORT_DATE		= 0x0040,
@@ -20,20 +20,18 @@
 	MAIL_SORT_END		= 0x0000 /* ends sort program */
 };
 
-typedef struct _MailSortContext MailSortContext;
-
-typedef struct {
+struct mail_sort_funcs {
 	/* arrival, date */
-	time_t (*input_time)(MailSortType type, unsigned int id,
+	time_t (*input_time)(enum mail_sort_type type, unsigned int id,
 			     void *context);
 	/* size */
-	uoff_t (*input_uofft)(MailSortType type, unsigned int id,
+	uoff_t (*input_uofft)(enum mail_sort_type type, unsigned int id,
 			      void *context);
 	/* cc, from, to. Return the mailbox of the first address. */
-	const char *(*input_mailbox)(MailSortType type, unsigned int id,
+	const char *(*input_mailbox)(enum mail_sort_type type, unsigned int id,
 				     void *context);
 	/* subject */
-	const char *(*input_str)(MailSortType type, unsigned int id,
+	const char *(*input_str)(enum mail_sort_type type, unsigned int id,
 				 void *context);
 
 	/* done parsing this message, free all resources */
@@ -41,18 +39,19 @@
 
 	/* result callback */
 	void (*output)(unsigned int *data, size_t count, void *context);
-} MailSortFuncs;
+};
 
 /* input and output are arrays of sort programs ending with MAIL_SORT_END.
    input specifies the order in which the messages are arriving to sorting.
    It may be just MAIL_SORT_END if the order is random. The better the ordering
    is known, the less memory is used. */
-MailSortContext *mail_sort_init(const MailSortType *input, MailSortType *output,
-				MailSortFuncs funcs, void *context);
-void mail_sort_deinit(MailSortContext *ctx);
+struct mail_sort_context *
+mail_sort_init(const enum mail_sort_type *input, enum mail_sort_type *output,
+	       struct mail_sort_funcs funcs, void *context);
+void mail_sort_deinit(struct mail_sort_context *ctx);
 
 /* id is either UID or sequence number of message, whichever is preferred
    in MailSortFuncs parameters. */
-void mail_sort_input(MailSortContext *ctx, unsigned int id);
+void mail_sort_input(struct mail_sort_context *ctx, unsigned int id);
 
 #endif
--- a/src/lib-storage/mail-storage.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/mail-storage.c	Sun Jan 05 15:09:51 2003 +0200
@@ -10,20 +10,18 @@
 /* Message to show to users when critical error occurs */
 #define CRITICAL_MSG "Internal error [%Y-%m-%d %H:%M:%S]"
 
-typedef struct _MailStorageList MailStorageList;
-
-struct _MailStorageList {
-	MailStorageList *next;
-	MailStorage *storage;
+struct mail_storage_list {
+	struct mail_storage_list *next;
+	struct mail_storage *storage;
 };
 
-static MailStorageList *storages = NULL;
+static struct mail_storage_list *storages = NULL;
 
-void mail_storage_class_register(MailStorage *storage_class)
+void mail_storage_class_register(struct mail_storage *storage_class)
 {
-	MailStorageList *list, **pos;
+	struct mail_storage_list *list, **pos;
 
-	list = i_new(MailStorageList, 1);
+	list = i_new(struct mail_storage_list, 1);
 	list->storage = storage_class;
 
 	/* append it after the list, so the autodetection order is correct */
@@ -33,9 +31,9 @@
 	*pos = list;
 }
 
-void mail_storage_class_unregister(MailStorage *storage_class)
+void mail_storage_class_unregister(struct mail_storage *storage_class)
 {
-	MailStorageList **list, *next;
+	struct mail_storage_list **list, *next;
 
 	for (list = &storages; *list != NULL; list = &(*list)->next) {
 		if ((*list)->storage == storage_class) {
@@ -49,10 +47,10 @@
 	}
 }
 
-MailStorage *mail_storage_create(const char *name, const char *data,
-				 const char *user)
+struct mail_storage *mail_storage_create(const char *name, const char *data,
+					 const char *user)
 {
-	MailStorageList *list;
+	struct mail_storage_list *list;
 
 	i_assert(name != NULL);
 
@@ -64,10 +62,10 @@
 	return NULL;
 }
 
-MailStorage *mail_storage_create_default(const char *user)
+struct mail_storage *mail_storage_create_default(const char *user)
 {
-	MailStorageList *list;
-	MailStorage *storage;
+	struct mail_storage_list *list;
+	struct mail_storage *storage;
 
 	for (list = storages; list != NULL; list = list->next) {
 		storage = list->storage->create(NULL, user);
@@ -78,9 +76,9 @@
 	return NULL;
 }
 
-static MailStorage *mail_storage_autodetect(const char *data)
+static struct mail_storage *mail_storage_autodetect(const char *data)
 {
-	MailStorageList *list;
+	struct mail_storage_list *list;
 
 	for (list = storages; list != NULL; list = list->next) {
 		if (list->storage->autodetect(data))
@@ -90,9 +88,10 @@
 	return NULL;
 }
 
-MailStorage *mail_storage_create_with_data(const char *data, const char *user)
+struct mail_storage *mail_storage_create_with_data(const char *data,
+						   const char *user)
 {
-	MailStorage *storage;
+	struct mail_storage *storage;
 	const char *p, *name;
 
 	if (data == NULL || *data == '\0')
@@ -115,7 +114,7 @@
 	return storage;
 }
 
-void mail_storage_destroy(MailStorage *storage)
+void mail_storage_destroy(struct mail_storage *storage)
 {
 	i_assert(storage != NULL);
 
@@ -123,7 +122,7 @@
 	i_free(storage);
 }
 
-void mail_storage_clear_error(MailStorage *storage)
+void mail_storage_clear_error(struct mail_storage *storage)
 {
 	i_free(storage->error);
 	storage->error = NULL;
@@ -131,7 +130,7 @@
 	storage->syntax_error = FALSE;
 }
 
-void mail_storage_set_error(MailStorage *storage, const char *fmt, ...)
+void mail_storage_set_error(struct mail_storage *storage, const char *fmt, ...)
 {
 	va_list va;
 
@@ -147,7 +146,8 @@
 	}
 }
 
-void mail_storage_set_syntax_error(MailStorage *storage, const char *fmt, ...)
+void mail_storage_set_syntax_error(struct mail_storage *storage,
+				   const char *fmt, ...)
 {
 	va_list va;
 
@@ -163,7 +163,7 @@
 	}
 }
 
-void mail_storage_set_internal_error(MailStorage *storage)
+void mail_storage_set_internal_error(struct mail_storage *storage)
 {
 	struct tm *tm;
 	char str[256];
@@ -175,7 +175,8 @@
 	storage->syntax_error = FALSE;
 }
 
-void mail_storage_set_critical(MailStorage *storage, const char *fmt, ...)
+void mail_storage_set_critical(struct mail_storage *storage,
+			       const char *fmt, ...)
 {
 	va_list va;
 
@@ -194,14 +195,15 @@
 	}
 }
 
-const char *mail_storage_get_last_error(MailStorage *storage, int *syntax)
+const char *mail_storage_get_last_error(struct mail_storage *storage,
+					int *syntax)
 {
 	if (syntax != NULL)
 		*syntax = storage->syntax_error;
 	return storage->error;
 }
 
-int mail_storage_is_inconsistency_error(Mailbox *box)
+int mail_storage_is_inconsistency_error(struct mailbox *box)
 {
 	return box->inconsistent;
 }
--- a/src/lib-storage/mail-storage.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/mail-storage.h	Sun Jan 05 15:09:51 2003 +0200
@@ -2,9 +2,8 @@
 #define __MAIL_STORAGE_H
 
 #include "imap-util.h"
-#include "imap-parser.h"
 
-typedef enum {
+enum mailbox_flags {
 	MAILBOX_NOSELECT	= 0x01,
 	MAILBOX_CHILDREN	= 0x02,
 	MAILBOX_NOCHILDREN	= 0x04,
@@ -13,9 +12,9 @@
 	MAILBOX_UNMARKED	= 0x20,
 
 	MAILBOX_READONLY	= 0x40
-} MailboxFlags;
+};
 
-typedef enum {
+enum mailbox_status_items {
 	STATUS_MESSAGES		= 0x01,
 	STATUS_RECENT		= 0x02,
 	STATUS_UIDNEXT		= 0x04,
@@ -23,52 +22,51 @@
 	STATUS_UNSEEN		= 0x10,
 	STATUS_FIRST_UNSEEN_SEQ	= 0x20,
 	STATUS_CUSTOM_FLAGS	= 0x40
-} MailboxStatusItems;
+};
 
-typedef enum {
+enum mailbox_name_status {
 	MAILBOX_NAME_EXISTS,
 	MAILBOX_NAME_VALID,
 	MAILBOX_NAME_INVALID,
 	MAILBOX_NAME_NOINFERIORS
-} MailboxNameStatus;
+};
 
-typedef enum {
+enum modify_type {
 	MODIFY_ADD,
 	MODIFY_REMOVE,
 	MODIFY_REPLACE
-} ModifyType;
+};
 
-typedef struct _MailStorage MailStorage;
-typedef struct _Mailbox Mailbox;
-typedef struct _MailboxStatus MailboxStatus;
-typedef struct _MailStorageCallbacks MailStorageCallbacks;
-typedef struct _MailFetchData MailFetchData;
-typedef struct _MailFetchBodyData MailFetchBodyData;
-typedef struct _MailSearchArg MailSearchArg;
-typedef enum _MailSortType MailSortType;
+struct mail_storage;
+struct mail_storage_callbacks;
+struct mailbox_status;
+struct mail_fetch_data;
+struct mail_search_arg;
+enum mail_sort_type;
 
-typedef void (*MailboxFunc)(MailStorage *storage, const char *name,
-			    MailboxFlags flags, void *context);
+typedef void (*MailboxFunc)(struct mail_storage *storage, const char *name,
+			    enum mailbox_flags flags, void *context);
 
 /* All methods returning int return either TRUE or FALSE. */
-struct _MailStorage {
+struct mail_storage {
 	char *name;
 
 	char hierarchy_sep;
 
 	/* Create new instance */
-	MailStorage *(*create)(const char *data, const char *user);
+	struct mail_storage *(*create)(const char *data, const char *user);
 
 	/* Free this instance */
-	void (*free)(MailStorage *storage);
+	void (*free)(struct mail_storage *storage);
 
 	/* Returns TRUE if this storage would accept the given data
 	   as a valid parameter to create(). */
 	int (*autodetect)(const char *data);
 
 	/* Set storage callback functions to use. */
-	void (*set_callbacks)(MailStorage *storage,
-			      MailStorageCallbacks *callbacks, void *context);
+	void (*set_callbacks)(struct mail_storage *storage,
+			      struct mail_storage_callbacks *callbacks,
+			      void *context);
 
 	/* Open a mailbox. If readonly is TRUE, mailbox must not be
 	   modified in any way even when it's asked. If fast is TRUE,
@@ -77,15 +75,16 @@
 
 	   Note that append and copy may open the selected mailbox again
 	   with possibly different readonly-state. */
-	Mailbox *(*open_mailbox)(MailStorage *storage, const char *name,
-				 int readonly, int fast);
+	struct mailbox *(*open_mailbox)(struct mail_storage *storage,
+					const char *name,
+					int readonly, int fast);
 
 	/* name is allowed to contain multiple new hierarchy levels. */
-	int (*create_mailbox)(MailStorage *storage, const char *name);
+	int (*create_mailbox)(struct mail_storage *storage, const char *name);
 
 	/* Only the specified mailbox is deleted, ie. folders under the
 	   specified mailbox must not be deleted. */
-	int (*delete_mailbox)(MailStorage *storage, const char *name);
+	int (*delete_mailbox)(struct mail_storage *storage, const char *name);
 
 	/* If the name has inferior hierarchical names, then the inferior
 	   hierarchical names MUST also be renamed (ie. foo -> bar renames
@@ -94,29 +93,32 @@
 
 	   If oldname is case-insensitively "INBOX", the mails are moved
 	   into new folder but the INBOX folder must not be deleted. */
-	int (*rename_mailbox)(MailStorage *storage, const char *oldname,
+	int (*rename_mailbox)(struct mail_storage *storage, const char *oldname,
 			      const char *newname);
 
 	/* Execute specified function for all mailboxes matching given
 	   mask. The mask is in RFC2060 LIST format. */
-	int (*find_mailboxes)(MailStorage *storage, const char *mask,
+	int (*find_mailboxes)(struct mail_storage *storage, const char *mask,
 			      MailboxFunc func, void *context);
 
 	/* Subscribe/unsubscribe mailbox. There should be no error when
 	   subscribing to already subscribed mailbox. Subscribing to
 	   unexisting mailboxes is optional. */
-	int (*set_subscribed)(MailStorage *storage, const char *name, int set);
+	int (*set_subscribed)(struct mail_storage *storage,
+			      const char *name, int set);
 
 	/* Exactly like find_mailboxes(), but list only subscribed mailboxes. */
-	int (*find_subscribed)(MailStorage *storage, const char *mask,
+	int (*find_subscribed)(struct mail_storage *storage, const char *mask,
 			       MailboxFunc func, void *context);
 
 	/* Returns mailbox name status */
-	int (*get_mailbox_name_status)(MailStorage *storage, const char *name,
-				       MailboxNameStatus *status);
+	int (*get_mailbox_name_status)(struct mail_storage *storage,
+				       const char *name,
+				       enum mailbox_name_status *status);
 
 	/* Returns the error message of last occured error. */
-	const char *(*get_last_error)(MailStorage *storage, int *syntax_error);
+	const char *(*get_last_error)(struct mail_storage *storage,
+				      int *syntax_error);
 
 /* private: */
 	char *dir; /* root directory */
@@ -126,67 +128,72 @@
 	char *user; /* name of user accessing the storage */
 	char *error;
 
-	MailStorageCallbacks *callbacks;
+	struct mail_storage_callbacks *callbacks;
 	void *callback_context;
 
 	unsigned int syntax_error:1; /* Give a BAD reply instead of NO */
 };
 
-struct _Mailbox {
+struct mailbox {
 	char *name;
 
-	MailStorage *storage;
+	struct mail_storage *storage;
 
 	/* Close the box. Returns FALSE if some cleanup errors occured, but
 	   the mailbox was closed anyway. */
-	int (*close)(Mailbox *box);
+	int (*close)(struct mailbox *box);
 
 	/* Gets the mailbox status information. */
-	int (*get_status)(Mailbox *box, MailboxStatusItems items,
-			  MailboxStatus *status);
+	int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
+			  struct mailbox_status *status);
 
 	/* Synchronize the mailbox. If sync_expunges is FALSE, everything
 	   but expunges are synced. */
-	int (*sync)(Mailbox *box, int sync_expunges);
+	int (*sync)(struct mailbox *box, int sync_expunges);
 
 	/* Expunge all mails with \Deleted flag. If notify is TRUE, call
 	   expunge callbacks. Also always does full syncing. */
-	int (*expunge)(Mailbox *box, int notify);
+	int (*expunge)(struct mailbox *box, int notify);
 
 	/* Update mail flags, calling update_flags callbacks. */
-	int (*update_flags)(Mailbox *box, const char *messageset, int uidset,
-			    MailFlags flags, const char *custom_flags[],
-			    ModifyType modify_type, int notify, int *all_found);
+	int (*update_flags)(struct mailbox *box,
+			    const char *messageset, int uidset,
+			    enum mail_flags flags, const char *custom_flags[],
+			    enum modify_type modify_type, int notify,
+			    int *all_found);
 
 	/* Copy mails to another mailbox. */
-	int (*copy)(Mailbox *box, Mailbox *destbox,
+	int (*copy)(struct mailbox *box, struct mailbox *destbox,
 		    const char *messageset, int uidset);
 
 	/* Fetch wanted mail data. The results are written into output stream
 	   in RFC2060 FETCH format. */
-	int (*fetch)(Mailbox *box, MailFetchData *fetch_data,
-		     OStream *output, int *all_found);
+	int (*fetch)(struct mailbox *box, struct mail_fetch_data *fetch_data,
+		     struct ostream *output, int *all_found);
 
 	/* Search wanted mail data. args contains the search criteria.
 	   Results are written into output stream in RFC2060 SEARCH format.
 	   If charset is NULL, the given search strings are matched without
 	   any conversion. */
-	int (*search)(Mailbox *box, const char *charset, MailSearchArg *args,
-		      MailSortType *sorting, OStream *output, int uid_result);
+	int (*search)(struct mailbox *box, const char *charset,
+		      struct mail_search_arg *args,
+		      enum mail_sort_type *sorting,
+		      struct ostream *output, int uid_result);
 
 	/* Save a new mail into mailbox. timezone_offset specifies the
 	   timezone in minutes which internal_date was originally given
 	   with. */
-	int (*save)(Mailbox *box, MailFlags flags, const char *custom_flags[],
+	int (*save)(struct mailbox *box, enum mail_flags flags,
+		    const char *custom_flags[],
 		    time_t internal_date, int timezone_offset,
-		    IStream *data, uoff_t data_size);
+		    struct istream *data, uoff_t data_size);
 
 	/* Returns TRUE if mailbox is now in inconsistent state, meaning that
 	   the message IDs etc. may have changed - only way to recover this
 	   would be to fully close the mailbox and reopen it. With IMAP
 	   connection this would mean a forced disconnection since we can't
 	   do forced CLOSE. */
-	int (*is_inconsistency_error)(Mailbox *box);
+	int (*is_inconsistency_error)(struct mailbox *box);
 
 /* public: */
 	unsigned int readonly:1;
@@ -195,7 +202,7 @@
 	unsigned int inconsistent:1;
 };
 
-struct _MailboxStatus {
+struct mailbox_status {
 	unsigned int messages;
 	unsigned int recent;
 	unsigned int unseen;
@@ -212,33 +219,38 @@
 	const char **custom_flags;
 };
 
-struct _MailStorageCallbacks {
+struct mail_storage_callbacks {
 	/* Alert: Not enough disk space */
-	void (*alert_no_diskspace)(Mailbox *mailbox, void *context);
+	void (*alert_no_diskspace)(struct mailbox *mailbox, void *context);
 	/* "* OK <text>" */
-	void (*notify_ok)(Mailbox *mailbox, const char *text, void *context);
+	void (*notify_ok)(struct mailbox *mailbox, const char *text,
+			  void *context);
 	/* "* NO <text>" */
-	void (*notify_no)(Mailbox *mailbox, const char *text, void *context);
+	void (*notify_no)(struct mailbox *mailbox, const char *text,
+			  void *context);
 
 	/* EXPUNGE */
-	void (*expunge)(Mailbox *mailbox, unsigned int seq, void *context);
+	void (*expunge)(struct mailbox *mailbox, unsigned int seq,
+			void *context);
 	/* FETCH FLAGS */
-	void (*update_flags)(Mailbox *mailbox, unsigned int seq,
-			     unsigned int uid, MailFlags flags,
+	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);
 
 	/* EXISTS, RECENT */
-	void (*new_messages)(Mailbox *mailbox, unsigned int messages_count,
+	void (*new_messages)(struct mailbox *mailbox,
+			     unsigned int messages_count,
 			     unsigned int recent_count, void *context);
 	/* FLAGS, PERMANENTFLAGS */
-	void (*new_custom_flags)(Mailbox *mailbox, const char *custom_flags[],
+	void (*new_custom_flags)(struct mailbox *mailbox,
+				 const char *custom_flags[],
 				 unsigned int custom_flags_count,
 				 void *context);
 
 };
 
-struct _MailFetchData {
+struct mail_fetch_data {
 	const char *messageset;
 	unsigned int uidset:1;
 
@@ -253,11 +265,11 @@
 	unsigned int rfc822_text:1;
 	unsigned int uid:1;
 
-	MailFetchBodyData *body_sections;
+	struct mail_fetch_body_data *body_sections;
 };
 
-struct _MailFetchBodyData {
-	MailFetchBodyData *next;
+struct mail_fetch_body_data {
+	struct mail_fetch_body_data *next;
 
 	const char *section; /* NOTE: always uppercased */
 	uoff_t skip, max_size; /* if you don't want max_size,
@@ -271,31 +283,33 @@
 
 /* Register mail storage class with given name - all methods that are NULL
    are set to default methods */
-void mail_storage_class_register(MailStorage *storage_class);
-void mail_storage_class_unregister(MailStorage *storage_class);
+void mail_storage_class_register(struct mail_storage *storage_class);
+void mail_storage_class_unregister(struct mail_storage *storage_class);
 
 /* Create a new instance of registered mail storage class with given
    storage-specific data. If data is NULL, it tries to use defaults.
    May return NULL if anything fails. */
-MailStorage *mail_storage_create(const char *name, const char *data,
-				 const char *user);
-void mail_storage_destroy(MailStorage *storage);
+struct mail_storage *mail_storage_create(const char *name, const char *data,
+					 const char *user);
+void mail_storage_destroy(struct mail_storage *storage);
 
-MailStorage *mail_storage_create_default(const char *user);
-MailStorage *mail_storage_create_with_data(const char *data, const char *user);
+struct mail_storage *mail_storage_create_default(const char *user);
+struct mail_storage *mail_storage_create_with_data(const char *data,
+						   const char *user);
 
 /* Set error message in storage. Critical errors are logged with i_error(),
    but user sees only "internal error" message. */
-void mail_storage_clear_error(MailStorage *storage);
-void mail_storage_set_error(MailStorage *storage, const char *fmt, ...)
-	__attr_format__(2, 3);
-void mail_storage_set_syntax_error(MailStorage *storage, const char *fmt, ...)
-	__attr_format__(2, 3);
-void mail_storage_set_critical(MailStorage *storage, const char *fmt, ...)
-	__attr_format__(2, 3);
-void mail_storage_set_internal_error(MailStorage *storage);
+void mail_storage_clear_error(struct mail_storage *storage);
+void mail_storage_set_error(struct mail_storage *storage,
+			    const char *fmt, ...) __attr_format__(2, 3);
+void mail_storage_set_syntax_error(struct mail_storage *storage,
+				   const char *fmt, ...) __attr_format__(2, 3);
+void mail_storage_set_critical(struct mail_storage *storage,
+			       const char *fmt, ...) __attr_format__(2, 3);
+void mail_storage_set_internal_error(struct mail_storage *storage);
 
-const char *mail_storage_get_last_error(MailStorage *storage, int *syntax);
-int mail_storage_is_inconsistency_error(Mailbox *box);
+const char *mail_storage_get_last_error(struct mail_storage *storage,
+					int *syntax);
+int mail_storage_is_inconsistency_error(struct mailbox *box);
 
 #endif
--- a/src/lib-storage/subscription-file/subscription-file.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/subscription-file/subscription-file.c	Sun Jan 05 15:09:51 2003 +0200
@@ -15,8 +15,8 @@
 
 #define SUBSCRIPTION_FILE_NAME ".subscriptions"
 
-static int subsfile_set_syscall_error(MailStorage *storage, const char *path,
-				      const char *function)
+static int subsfile_set_syscall_error(struct mail_storage *storage,
+				      const char *path, const char *function)
 {
 	i_assert(function != NULL);
 
@@ -26,7 +26,7 @@
 	return FALSE;
 }
 
-static int subscription_open(MailStorage *storage, int update,
+static int subscription_open(struct mail_storage *storage, int update,
 			     const char **path, void **mmap_base,
 			     size_t *mmap_length)
 {
@@ -66,8 +66,9 @@
 	return fd;
 }
 
-static int subscription_append(MailStorage *storage, int fd, const char *name,
-			       size_t len, int prefix_lf, const char *path)
+static int subscription_append(struct mail_storage *storage, int fd,
+			       const char *name, size_t len, int prefix_lf,
+			       const char *path)
 {
 	char *buf;
 
@@ -95,7 +96,8 @@
 	return TRUE;
 }
 
-int subsfile_set_subscribed(MailStorage *storage, const char *name, int set)
+int subsfile_set_subscribed(struct mail_storage *storage,
+			    const char *name, int set)
 {
 	void *mmap_base;
 	size_t mmap_length;
@@ -167,10 +169,10 @@
 	return !failed;
 }
 
-int subsfile_foreach(MailStorage *storage, const char *mask,
+int subsfile_foreach(struct mail_storage *storage, const char *mask,
 		     SubsFileForeachFunc func, void *context)
 {
-        ImapMatchGlob *glob;
+        struct imap_match_glob *glob;
 	const char *path, *start, *end, *p, *line;
 	void *mmap_base;
 	size_t mmap_length;
--- a/src/lib-storage/subscription-file/subscription-file.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib-storage/subscription-file/subscription-file.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,13 +4,14 @@
 #include "mail-storage.h"
 
 /* Returns FALSE if foreach should be aborted */
-typedef int (*SubsFileForeachFunc)(MailStorage *storage, const char *name,
-				   void *context);
+typedef int (*SubsFileForeachFunc)(struct mail_storage *storage,
+				   const char *name, void *context);
 
-int subsfile_set_subscribed(MailStorage *storage, const char *name, int set);
+int subsfile_set_subscribed(struct mail_storage *storage,
+			    const char *name, int set);
 
 /* Returns -1 if error, 0 if foreach function returned FALSE or 1 if all ok */
-int subsfile_foreach(MailStorage *storage, const char *mask,
+int subsfile_foreach(struct mail_storage *storage, const char *mask,
 		     SubsFileForeachFunc func, void *context);
 
 #endif
--- a/src/lib/base64.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/base64.c	Sun Jan 05 15:09:51 2003 +0200
@@ -46,7 +46,7 @@
 static const char basis_64[] =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
-int base64_encode(const unsigned char *src, size_t src_size, Buffer *dest)
+int base64_encode(const unsigned char *src, size_t src_size, buffer_t *dest)
 {
 	size_t src_pos;
 	int c1, c2, c3;
@@ -108,7 +108,7 @@
 };
 
 int base64_decode(const unsigned char *src, size_t src_size,
-		  size_t *src_pos_r, Buffer *dest)
+		  size_t *src_pos_r, buffer_t *dest)
 {
 	size_t src_pos;
 	unsigned char buf[4];
--- a/src/lib/base64.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/base64.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 
 /* Translates binary data into base64. The src must not point to dest buffer.
    Returns 1 if all ok, 0 if dest buffer got full. */
-int base64_encode(const unsigned char *src, size_t src_size, Buffer *dest);
+int base64_encode(const unsigned char *src, size_t src_size, buffer_t *dest);
 
 /* Translates base64 data into binary and appends it to dest buffer. dest may
    point to same buffer as src. Returns 1 if all ok, 0 if dest buffer got full
@@ -14,7 +14,7 @@
    If src_pos is non-NULL, it's updated to first non-translated character in
    src. */
 int base64_decode(const unsigned char *src, size_t src_size,
-		  size_t *src_pos_r, Buffer *dest);
+		  size_t *src_pos_r, buffer_t *dest);
 
 /* max. buffer size required for base64_encode() */
 #define MAX_BASE64_ENCODED_SIZE(size) \
--- a/src/lib/buffer.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/buffer.c	Sun Jan 05 15:09:51 2003 +0200
@@ -26,8 +26,8 @@
 #include "lib.h"
 #include "buffer.h"
 
-struct _Buffer {
-	Pool pool;
+struct buffer {
+	pool_t pool;
 
 	const unsigned char *r_buffer;
 	unsigned char *w_buffer;
@@ -45,7 +45,7 @@
 	unsigned int hard:1;
 };
 
-static void buffer_alloc(Buffer *buf, size_t size)
+static void buffer_alloc(buffer_t *buf, size_t size)
 {
 	i_assert(buf->w_buffer == NULL || buf->alloced);
 
@@ -63,7 +63,8 @@
 	buf->alloced = TRUE;
 }
 
-static int buffer_check_read(const Buffer *buf, size_t *pos, size_t *data_size)
+static int buffer_check_read(const buffer_t *buf,
+			     size_t *pos, size_t *data_size)
 {
 	size_t used_size, max_size;
 
@@ -78,8 +79,8 @@
 	return TRUE;
 }
 
-static int buffer_check_write(Buffer *buf, size_t *pos, size_t *data_size,
-			      int accept_partial)
+static int buffer_check_write(buffer_t *buf, size_t *pos,
+			      size_t *data_size, int accept_partial)
 {
 	size_t max_size, new_size, alloc_size;
 
@@ -132,42 +133,42 @@
 	return TRUE;
 }
 
-Buffer *buffer_create_static(Pool pool, size_t size)
+buffer_t *buffer_create_static(pool_t pool, size_t size)
 {
-	Buffer *buf;
+	buffer_t *buf;
 
-	buf = p_new(pool, Buffer, 1);
+	buf = p_new(pool, buffer_t, 1);
 	buf->pool = pool;
 	buf->max_alloc = buf->limit = size;
 	buffer_alloc(buf, size);
 	return buf;
 }
 
-Buffer *buffer_create_static_hard(Pool pool, size_t size)
+buffer_t *buffer_create_static_hard(pool_t pool, size_t size)
 {
-	Buffer *buf;
+	buffer_t *buf;
 
 	buf = buffer_create_static(pool, size);
 	buf->hard = TRUE;
 	return buf;
 }
 
-Buffer *buffer_create_data(Pool pool, void *data, size_t size)
+buffer_t *buffer_create_data(pool_t pool, void *data, size_t size)
 {
-	Buffer *buf;
+	buffer_t *buf;
 
-	buf = p_new(pool, Buffer, 1);
+	buf = p_new(pool, buffer_t, 1);
 	buf->pool = pool;
 	buf->alloc = buf->max_alloc = buf->limit = size;
 	buf->r_buffer = buf->w_buffer = data;
 	return buf;
 }
 
-Buffer *buffer_create_const_data(Pool pool, const void *data, size_t size)
+buffer_t *buffer_create_const_data(pool_t pool, const void *data, size_t size)
 {
-	Buffer *buf;
+	buffer_t *buf;
 
-	buf = p_new(pool, Buffer, 1);
+	buf = p_new(pool, buffer_t, 1);
 	buf->pool = pool;
 	buf->used = buf->alloc = buf->max_alloc = buf->limit = size;
 	buf->r_buffer = data;
@@ -175,25 +176,25 @@
 	return buf;
 }
 
-Buffer *buffer_create_dynamic(Pool pool, size_t init_size, size_t max_size)
+buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size, size_t max_size)
 {
-	Buffer *buf;
+	buffer_t *buf;
 
-	buf = p_new(pool, Buffer, 1);
+	buf = p_new(pool, buffer_t, 1);
 	buf->pool = pool;
 	buf->max_alloc = buf->limit = max_size;
 	buffer_alloc(buf, init_size);
 	return buf;
 }
 
-void buffer_free(Buffer *buf)
+void buffer_free(buffer_t *buf)
 {
 	if (buf->alloced)
 		p_free(buf->pool, buf->w_buffer);
 	p_free(buf->pool, buf);
 }
 
-void *buffer_free_without_data(Buffer *buf)
+void *buffer_free_without_data(buffer_t *buf)
 {
 	void *data;
 
@@ -202,7 +203,7 @@
 	return data;
 }
 
-size_t buffer_write(Buffer *buf, size_t pos,
+size_t buffer_write(buffer_t *buf, size_t pos,
 		    const void *data, size_t data_size)
 {
 	if (!buffer_check_write(buf, &pos, &data_size, TRUE))
@@ -212,12 +213,12 @@
 	return data_size;
 }
 
-size_t buffer_append(Buffer *buf, const void *data, size_t data_size)
+size_t buffer_append(buffer_t *buf, const void *data, size_t data_size)
 {
 	return buffer_write(buf, buf->used - buf->start_pos, data, data_size);
 }
 
-size_t buffer_append_c(Buffer *buf, char chr)
+size_t buffer_append_c(buffer_t *buf, char chr)
 {
 	size_t pos, data_size = 1;
 
@@ -230,7 +231,7 @@
 	return data_size;
 }
 
-size_t buffer_insert(Buffer *buf, size_t pos,
+size_t buffer_insert(buffer_t *buf, size_t pos,
 		     const void *data, size_t data_size)
 {
 	size_t move_size, size;
@@ -259,7 +260,7 @@
 	return size;
 }
 
-size_t buffer_delete(Buffer *buf, size_t pos, size_t size)
+size_t buffer_delete(buffer_t *buf, size_t pos, size_t size)
 {
 	size_t end_size;
 
@@ -286,8 +287,8 @@
 	return size;
 }
 
-size_t buffer_copy(Buffer *dest, size_t dest_pos,
-		   const Buffer *src, size_t src_pos, size_t copy_size)
+size_t buffer_copy(buffer_t *dest, size_t dest_pos,
+		   const buffer_t *src, size_t src_pos, size_t copy_size)
 {
 	if (!buffer_check_read(src, &src_pos, &copy_size))
 		return 0;
@@ -305,14 +306,14 @@
 	return copy_size;
 }
 
-size_t buffer_append_buf(Buffer *dest, const Buffer *src,
+size_t buffer_append_buf(buffer_t *dest, const buffer_t *src,
 			 size_t src_pos, size_t copy_size)
 {
 	return buffer_copy(dest, dest->used - dest->start_pos,
 			   src, src_pos, copy_size);
 }
 
-void *buffer_get_space(Buffer *buf, size_t pos, size_t size)
+void *buffer_get_space(buffer_t *buf, size_t pos, size_t size)
 {
 	if (!buffer_check_write(buf, &pos, &size, FALSE))
 		return NULL;
@@ -320,38 +321,38 @@
 	return buf->w_buffer + pos;
 }
 
-void *buffer_append_space(Buffer *buf, size_t size)
+void *buffer_append_space(buffer_t *buf, size_t size)
 {
 	return buffer_get_space(buf, buf->used - buf->start_pos, size);
 }
 
-const void *buffer_get_data(const Buffer *buf, size_t *used_size)
+const void *buffer_get_data(const buffer_t *buf, size_t *used_size)
 {
 	if (used_size != NULL)
 		*used_size = I_MIN(buf->used, buf->limit) - buf->start_pos;
 	return buf->r_buffer + buf->start_pos;
 }
 
-void *buffer_get_modifyable_data(const Buffer *buf, size_t *used_size)
+void *buffer_get_modifyable_data(const buffer_t *buf, size_t *used_size)
 {
 	if (used_size != NULL)
 		*used_size = I_MIN(buf->used, buf->limit) - buf->start_pos;
 	return buf->w_buffer + buf->start_pos;
 }
 
-void buffer_set_used_size(Buffer *buf, size_t used_size)
+void buffer_set_used_size(buffer_t *buf, size_t used_size)
 {
 	i_assert(used_size <= I_MIN(buf->alloc, buf->limit) - buf->start_pos);
 
 	buf->used = used_size + buf->start_pos;
 }
 
-size_t buffer_get_used_size(const Buffer *buf)
+size_t buffer_get_used_size(const buffer_t *buf)
 {
 	return I_MIN(buf->used, buf->limit) - buf->start_pos;
 }
 
-size_t buffer_set_start_pos(Buffer *buf, size_t abs_pos)
+size_t buffer_set_start_pos(buffer_t *buf, size_t abs_pos)
 {
 	size_t old = buf->start_pos;
 
@@ -361,12 +362,12 @@
 	return old;
 }
 
-size_t buffer_get_start_pos(const Buffer *buf)
+size_t buffer_get_start_pos(const buffer_t *buf)
 {
 	return buf->start_pos;
 }
 
-size_t buffer_set_limit(Buffer *buf, size_t limit)
+size_t buffer_set_limit(buffer_t *buf, size_t limit)
 {
 	size_t old = buf->limit;
 
@@ -379,12 +380,12 @@
 	return old - buf->start_pos;
 }
 
-size_t buffer_get_limit(const Buffer *buf)
+size_t buffer_get_limit(const buffer_t *buf)
 {
 	return buf->limit - buf->start_pos;
 }
 
-size_t buffer_get_size(const Buffer *buf)
+size_t buffer_get_size(const buffer_t *buf)
 {
 	return buf->alloc - buf->start_pos;
 }
@@ -393,7 +394,7 @@
 /* gcc buffer.c -o testbuffer liblib.a -Wall -DHAVE_CONFIG_H -DBUFFER_TEST -g */
 int main(void)
 {
-	Buffer *buf;
+	buffer_t *buf;
 	char data[12], *bufdata;
 	size_t bufsize;
 
--- a/src/lib/buffer.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/buffer.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,83 +3,83 @@
 
 /* Create a static sized buffer. Writes past this size will simply not
    succeed. */
-Buffer *buffer_create_static(Pool pool, size_t size);
+buffer_t *buffer_create_static(pool_t pool, size_t size);
 /* Create a static sized buffer. Writes past this size will kill the program. */
-Buffer *buffer_create_static_hard(Pool pool, size_t size);
+buffer_t *buffer_create_static_hard(pool_t pool, size_t size);
 /* Create a modifyable buffer from given data. */
-Buffer *buffer_create_data(Pool pool, void *data, size_t size);
+buffer_t *buffer_create_data(pool_t pool, void *data, size_t size);
 /* Create a non-modifyable buffer from given data. */
-Buffer *buffer_create_const_data(Pool pool, const void *data, size_t size);
+buffer_t *buffer_create_const_data(pool_t pool, const void *data, size_t size);
 /* Creates a dynamically growing buffer. Whenever write would exceed the
    current size it's grown. */
-Buffer *buffer_create_dynamic(Pool pool, size_t init_size, size_t max_size);
+buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size, size_t max_size);
 /* Free the memory used by buffer. Not needed if the memory is free'd
    directly from the memory pool. */
-void buffer_free(Buffer *buf);
+void buffer_free(buffer_t *buf);
 /* Free the memory used by buffer structure, but return the buffer data
    unfree'd. NOTE: Current start_pos doesn't affect the returned value. */
-void *buffer_free_without_data(Buffer *buf);
+void *buffer_free_without_data(buffer_t *buf);
 
 /* Write data to buffer at specified position, returns number of bytes
    written. */
-size_t buffer_write(Buffer *buf, size_t pos,
+size_t buffer_write(buffer_t *buf, size_t pos,
 		    const void *data, size_t data_size);
 /* Append data to buffer, returns number of bytes written. */
-size_t buffer_append(Buffer *buf, const void *data, size_t data_size);
+size_t buffer_append(buffer_t *buf, const void *data, size_t data_size);
 /* Append character to buffer, returns 1 if written, 0 if not. */
-size_t buffer_append_c(Buffer *buf, char chr);
+size_t buffer_append_c(buffer_t *buf, char chr);
 
 /* Insert data to buffer, returns number of bytes inserted. */
-size_t buffer_insert(Buffer *buf, size_t pos,
+size_t buffer_insert(buffer_t *buf, size_t pos,
 		     const void *data, size_t data_size);
 /* Delete data from buffer, returns number of bytes deleted. */
-size_t buffer_delete(Buffer *buf, size_t pos, size_t size);
+size_t buffer_delete(buffer_t *buf, size_t pos, size_t size);
 
 /* Copy data from buffer to another. The buffers may be same in which case
    it's internal copying, possibly with overlapping positions (ie. memmove()
    like functionality). copy_size may be set to (size_t)-1 to copy the rest of
    the used data in buffer. Returns the number of bytes actually copied. */
-size_t buffer_copy(Buffer *dest, size_t dest_pos,
-		   const Buffer *src, size_t src_pos, size_t copy_size);
+size_t buffer_copy(buffer_t *dest, size_t dest_pos,
+		   const buffer_t *src, size_t src_pos, size_t copy_size);
 /* Append data to buffer from another. copy_size may be set to (size_t)-1 to
    copy the rest of the used data in buffer. */
-size_t buffer_append_buf(Buffer *dest, const Buffer *src,
+size_t buffer_append_buf(buffer_t *dest, const buffer_t *src,
 			 size_t src_pos, size_t copy_size);
 
 /* Returns pointer to specified position in buffer, or NULL if there's not
    enough space. */
-void *buffer_get_space(Buffer *buf, size_t pos, size_t size);
+void *buffer_get_space(buffer_t *buf, size_t pos, size_t size);
 /* Increase the buffer usage by given size, and return a pointer to beginning
    of it, or NULL if there's not enough space in buffer. */
-void *buffer_append_space(Buffer *buf, size_t size);
+void *buffer_append_space(buffer_t *buf, size_t size);
 
 /* Returns pointer to beginning of buffer data. Current used size of buffer is
    stored in used_size if it's non-NULL. */
-const void *buffer_get_data(const Buffer *buf, size_t *used_size);
+const void *buffer_get_data(const buffer_t *buf, size_t *used_size);
 /* Like buffer_get_data(), but don't return it as const. Returns NULL if the
    buffer is non-modifyable. */
-void *buffer_get_modifyable_data(const Buffer *buf, size_t *used_size);
+void *buffer_get_modifyable_data(const buffer_t *buf, size_t *used_size);
 
 /* Set the "used size" of buffer, ie. 0 would set the buffer empty.
    Must not be used to grow buffer. */
-void buffer_set_used_size(Buffer *buf, size_t used_size);
+void buffer_set_used_size(buffer_t *buf, size_t used_size);
 /* Returns the current used buffer size. */
-size_t buffer_get_used_size(const Buffer *buf);
+size_t buffer_get_used_size(const buffer_t *buf);
 
 /* Change the buffer start position. The buffer acts as if data was removed or
    inserted to beginning. Returns the old start position. */
-size_t buffer_set_start_pos(Buffer *buf, size_t abs_pos);
+size_t buffer_set_start_pos(buffer_t *buf, size_t abs_pos);
 /* Returns the current start position. */
-size_t buffer_get_start_pos(const Buffer *buf);
+size_t buffer_get_start_pos(const buffer_t *buf);
 
 /* Limit buffer size temporarily. All handling is treated as if this is the
    current allocated memory size, except dynamic buffer won't be grown.
    Setting the limit to (size_t)-1 removes it. Returns the old limit. */
-size_t buffer_set_limit(Buffer *buf, size_t limit);
+size_t buffer_set_limit(buffer_t *buf, size_t limit);
 /* Returns the current buffer limit, or (size_t)-1 if there's none. */
-size_t buffer_get_limit(const Buffer *buf);
+size_t buffer_get_limit(const buffer_t *buf);
 
 /* Returns the current buffer size. */
-size_t buffer_get_size(const Buffer *buf);
+size_t buffer_get_size(const buffer_t *buf);
 
 #endif
--- a/src/lib/compat.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/compat.h	Sun Jan 05 15:09:51 2003 +0200
@@ -23,6 +23,12 @@
 #  else
 typedef unsigned long uintmax_t;
 #  endif
+
+#  if SIZEOF_INT >= 4
+typedef unsigned int uint_fast32_t;
+#  else
+typedef unsigned long uint_fast32_t;
+#  endif
 #endif
 
 #ifndef HAVE_SOCKLEN_T
--- a/src/lib/data-stack.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/data-stack.c	Sun Jan 05 15:09:51 2003 +0200
@@ -44,29 +44,27 @@
 #  define INITIAL_STACK_SIZE (1024*32)
 #endif
 
-typedef struct _StackBlock StackBlock;
-typedef struct _StackFrameBlock StackFrameBlock;
-
-struct _StackBlock {
-	StackBlock *next;
+struct stack_block {
+	struct stack_block *next;
 
 	size_t size, left;
 	/* unsigned char data[]; */
 };
 
-#define SIZEOF_MEMBLOCK MEM_ALIGN(sizeof(StackBlock))
+#define SIZEOF_MEMBLOCK MEM_ALIGN(sizeof(struct stack_block))
 
 #define STACK_BLOCK_DATA(block) \
 	((char *) (block) + SIZEOF_MEMBLOCK)
 
 /* current_frame_block contains last t_push()ed frames. After that new
-   StackFrameBlock is created and it's ->prev is set to current_frame_block. */
+   stack_frame_block is created and it's ->prev is set to
+   current_frame_block. */
 #define BLOCK_FRAME_COUNT 32
 
-struct _StackFrameBlock {
-	StackFrameBlock *prev;
+struct stack_frame_block {
+	struct stack_frame_block *prev;
 
-	StackBlock *block[BLOCK_FRAME_COUNT];
+	struct stack_block *block[BLOCK_FRAME_COUNT];
         size_t block_space_used[BLOCK_FRAME_COUNT];
 	size_t last_alloc_size[BLOCK_FRAME_COUNT];
 };
@@ -74,18 +72,18 @@
 unsigned int data_stack_frame;
 
 static int frame_pos; /* current frame position current_frame_block */
-static StackFrameBlock *current_frame_block; /* current stack frame block */
-static StackFrameBlock *unused_frame_blocks; /* unused stack frames */
+static struct stack_frame_block *current_frame_block;
+static struct stack_frame_block *unused_frame_blocks;
 
-static StackBlock *current_block; /* block currently used for allocation */
-static StackBlock *unused_block; /* largest unused block is kept here */
+static struct stack_block *current_block; /* block now used for allocation */
+static struct stack_block *unused_block; /* largest unused block is kept here */
 
-static StackBlock *last_buffer_block;
+static struct stack_block *last_buffer_block;
 static size_t last_buffer_size;
 
 unsigned int t_push(void)
 {
-        StackFrameBlock *frame_block;
+        struct stack_frame_block *frame_block;
 
 	frame_pos++;
 	if (frame_pos == BLOCK_FRAME_COUNT) {
@@ -93,7 +91,7 @@
 		frame_pos = 0;
 		if (unused_frame_blocks == NULL) {
 			/* allocate new block */
-			frame_block = calloc(sizeof(StackFrameBlock), 1);
+			frame_block = calloc(sizeof(*frame_block), 1);
 			if (frame_block == NULL)
 				i_panic("t_push(): Out of memory");
 		} else {
@@ -114,7 +112,7 @@
         return data_stack_frame++;
 }
 
-static void free_blocks(StackBlock *block)
+static void free_blocks(struct stack_block *block)
 {
 	/* free all the blocks, except if any of them is bigger than
 	   unused_block, replace it */
@@ -132,7 +130,7 @@
 
 unsigned int t_pop(void)
 {
-	StackFrameBlock *frame_block;
+	struct stack_frame_block *frame_block;
 	int popped_frame_pos;
 
 	if (frame_pos < 0)
@@ -169,9 +167,9 @@
         return --data_stack_frame;
 }
 
-static StackBlock *mem_block_alloc(size_t min_size)
+static struct stack_block *mem_block_alloc(size_t min_size)
 {
-	StackBlock *block;
+	struct stack_block *block;
 	size_t prev_size, alloc_size;
 
 	prev_size = current_block == NULL ? 0 : current_block->size;
@@ -191,7 +189,7 @@
 
 static void *t_malloc_real(size_t size, int permanent)
 {
-	StackBlock *block;
+	struct stack_block *block;
         void *ret;
 #ifdef DEBUG
 	int warn = FALSE;
@@ -355,7 +353,7 @@
 		i_panic("Missing t_pop() call");
 
 	while (unused_frame_blocks != NULL) {
-                StackFrameBlock *frame_block = unused_frame_blocks;
+                struct stack_frame_block *frame_block = unused_frame_blocks;
 		unused_frame_blocks = unused_frame_blocks->prev;
 
                 free(frame_block);
@@ -367,29 +365,26 @@
 
 #else
 
-typedef struct _StackFrame StackFrame;
-typedef struct _FrameAlloc FrameAlloc;
-
-struct _StackFrame {
-	StackFrame *next;
-	FrameAlloc *allocs;
+struct stack_frame {
+	struct stack_frame *next;
+	struct frame_alloc *allocs;
 };
 
-struct _FrameAlloc {
-	FrameAlloc *next;
+struct frame_alloc {
+	struct frame_alloc *next;
 	void *mem;
 };
 
 unsigned int data_stack_frame;
 
-static StackFrame *current_frame;
+static struct stack_frame *current_frame;
 static void *buffer_mem;
 
 unsigned int t_push(void)
 {
-	StackFrame *frame;
+	struct stack_frame *frame;
 
-	frame = malloc(sizeof(StackFrame));
+	frame = malloc(sizeof(struct stack_frame));
 	if (frame == NULL)
 		i_panic("t_push(): Out of memory");
 	frame->allocs = NULL;
@@ -401,8 +396,8 @@
 
 unsigned int t_pop(void)
 {
-	StackFrame *frame;
-	FrameAlloc *alloc;
+	struct stack_frame *frame;
+	struct frame_alloc *alloc;
 
 	frame = current_frame;
 	current_frame = frame->next;
@@ -421,9 +416,9 @@
 
 static void add_alloc(void *mem)
 {
-	FrameAlloc *alloc;
+	struct frame_alloc *alloc;
 
-	alloc = malloc(sizeof(FrameAlloc));
+	alloc = malloc(sizeof(struct frame_alloc));
 	if (alloc == NULL)
 		i_panic("add_alloc(): Out of memory");
 	alloc->mem = mem;
--- a/src/lib/env-util.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/env-util.c	Sun Jan 05 15:09:51 2003 +0200
@@ -28,7 +28,7 @@
 
 #include <stdlib.h>
 
-static Pool pool = NULL;
+static pool_t pool = NULL;
 
 void env_put(const char *env)
 {
--- a/src/lib/failures.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/failures.h	Sun Jan 05 15:09:51 2003 +0200
@@ -2,7 +2,7 @@
 #define __FAILURES_H
 
 /* Default exit status codes that we could use. */
-typedef enum {
+enum fatal_exit_status {
 	FATAL_LOGOPEN	= 80, /* Can't open log file */
 	FATAL_LOGWRITE  = 81, /* Can't write to log file */
 	FATAL_LOGERROR  = 82, /* Internal logging error */
@@ -10,7 +10,7 @@
 	FATAL_EXEC	= 84, /* exec() failed */
 
 	FATAL_DEFAULT	= 89
-} FatalExitStatus;
+};
 
 #define DEFAULT_FAILURE_STAMP_FORMAT "%b %d %H:%M:%S "
 
--- a/src/lib/hash.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/hash.c	Sun Jan 05 15:09:51 2003 +0200
@@ -35,28 +35,28 @@
 #define HASH_TABLE_MIN_SIZE 11
 #define HASH_TABLE_MAX_SIZE 13845163
 
-typedef struct _HashNode {
+struct hash_node {
 	void *key;
 	void *value;
 
 	int destroyed;
-	struct _HashNode *next;
-} HashNode;
+	struct hash_node *next;
+};
 
-struct _HashTable {
-	Pool pool;
+struct hash_table {
+	pool_t pool;
 
 	unsigned int size;
 	unsigned int nodes_count, nodes_destroyed;
 	int frozen;
-	HashNode **nodes;
+	struct hash_node **nodes;
 
 	HashFunc hash_func;
 	HashCompareFunc key_compare_func;
 };
 
-static void hash_cleanup(HashTable *table);
-static int hash_resize(HashTable *table);
+static void hash_cleanup(struct hash_table *table);
+static int hash_resize(struct hash_table *table);
 
 static int foreach_stop;
 
@@ -66,20 +66,20 @@
 	return POINTER_CAST_TO(p, unsigned int);
 }
 
-static HashNode *hash_node_create(Pool pool, void *key, void *value)
+static struct hash_node *hash_node_create(pool_t pool, void *key, void *value)
 {
-	HashNode *node;
+	struct hash_node *node;
 
-        node = p_new(pool, HashNode, 1);
+        node = p_new(pool, struct hash_node, 1);
 	node->key = key;
 	node->value = value;
 
 	return node;
 }
 
-static void hash_nodes_destroy(HashTable *table, HashNode *node)
+static void hash_nodes_destroy(struct hash_table *table, struct hash_node *node)
 {
-	HashNode *next;
+	struct hash_node *next;
 
 	while (node != NULL) {
 		next = node->next;
@@ -88,14 +88,15 @@
 	}
 }
 
-HashTable *hash_create(Pool pool, unsigned int initial_size,
-		       HashFunc hash_func, HashCompareFunc key_compare_func)
+struct hash_table *hash_create(pool_t pool, unsigned int initial_size,
+			       HashFunc hash_func,
+			       HashCompareFunc key_compare_func)
 {
-	HashTable *table;
+	struct hash_table *table;
 
         i_assert(pool != NULL);
 
-	table = p_new(pool, HashTable, 1);
+	table = p_new(pool, struct hash_table, 1);
         table->pool = pool;
 	table->size = CLAMP(primes_closest(initial_size),
 			    HASH_TABLE_MIN_SIZE,
@@ -103,12 +104,12 @@
 
 	table->hash_func = hash_func != NULL ? hash_func : direct_hash;
 	table->key_compare_func = key_compare_func;
-	table->nodes = p_new(pool, HashNode *, table->size);
+	table->nodes = p_new(pool, struct hash_node *, table->size);
 
 	return table;
 }
 
-void hash_destroy(HashTable *table)
+void hash_destroy(struct hash_table *table)
 {
 	unsigned int i;
 
@@ -122,7 +123,7 @@
 	p_free(table->pool, table);
 }
 
-void hash_clear(HashTable *table)
+void hash_clear(struct hash_table *table)
 {
 	unsigned int i;
 
@@ -134,10 +135,10 @@
 	}
 }
 
-static inline HashNode **
-hash_lookup_node(HashTable *table, const void *key)
+static inline struct hash_node **
+hash_lookup_node(struct hash_table *table, const void *key)
 {
-	HashNode **node;
+	struct hash_node **node;
 
 	node = &table->nodes[table->hash_func(key) % table->size];
 
@@ -160,9 +161,9 @@
 	return node;
 }
 
-void *hash_lookup(HashTable *table, const void *key)
+void *hash_lookup(struct hash_table *table, const void *key)
 {
-	HashNode *node;
+	struct hash_node *node;
 
 	i_assert(table != NULL);
 
@@ -170,10 +171,10 @@
 	return node != NULL && !node->destroyed ? node->value : NULL;
 }
 
-int hash_lookup_full(HashTable *table, const void *lookup_key,
+int hash_lookup_full(struct hash_table *table, const void *lookup_key,
 		     void **orig_key, void **value)
 {
-	HashNode *node;
+	struct hash_node *node;
 
 	i_assert(table != NULL);
 
@@ -188,10 +189,10 @@
 	return TRUE;
 }
 
-static void hash_insert_full(HashTable *table, void *key, void *value,
+static void hash_insert_full(struct hash_table *table, void *key, void *value,
 			     int replace_key)
 {
-	HashNode **node;
+	struct hash_node **node;
 
 	i_assert(table != NULL);
 
@@ -212,19 +213,19 @@
 	}
 }
 
-void hash_insert(HashTable *table, void *key, void *value)
+void hash_insert(struct hash_table *table, void *key, void *value)
 {
 	hash_insert_full(table, key, value, TRUE);
 }
 
-void hash_update(HashTable *table, void *key, void *value)
+void hash_update(struct hash_table *table, void *key, void *value)
 {
 	hash_insert_full(table, key, value, FALSE);
 }
 
-void hash_remove(HashTable *table, const void *key)
+void hash_remove(struct hash_table *table, const void *key)
 {
-	HashNode **node, *old_node;
+	struct hash_node **node, *old_node;
 
 	i_assert(table != NULL);
 
@@ -245,14 +246,14 @@
 	}
 }
 
-void hash_freeze(HashTable *table)
+void hash_freeze(struct hash_table *table)
 {
 	i_assert(table != NULL);
 
 	table->frozen++;
 }
 
-void hash_thaw(HashTable *table)
+void hash_thaw(struct hash_table *table)
 {
 	i_assert(table != NULL);
 	i_assert(table->frozen > 0);
@@ -261,9 +262,9 @@
                 hash_cleanup(table);
 }
 
-void hash_foreach(HashTable *table, HashForeachFunc func, void *context)
+void hash_foreach(struct hash_table *table, HashForeachFunc func, void *context)
 {
-	HashNode *node;
+	struct hash_node *node;
 	unsigned int i;
 
 	i_assert(table != NULL);
@@ -294,17 +295,17 @@
 }
 
 /* Returns the number of elements contained in the hash table. */
-unsigned int hash_size(HashTable *table)
+unsigned int hash_size(struct hash_table *table)
 {
 	i_assert(table != NULL);
 
 	return table->nodes_count;
 }
 
-static int hash_resize(HashTable *table)
+static int hash_resize(struct hash_table *table)
 {
         HashFunc hash_func;
-	HashNode *node, *next, **new_nodes;
+	struct hash_node *node, *next, **new_nodes;
 	float nodes_per_list;
 	unsigned int hash_val, new_size, i;
 
@@ -317,7 +318,7 @@
 			 HASH_TABLE_MIN_SIZE,
 			 HASH_TABLE_MAX_SIZE);
 
-	new_nodes = p_new(table->pool, HashNode *, new_size);
+	new_nodes = p_new(table->pool, struct hash_node *, new_size);
 
         hash_func = table->hash_func;
 	for (i = 0; i < table->size; i++) {
@@ -342,9 +343,9 @@
         return TRUE;
 }
 
-static void hash_cleanup(HashTable *table)
+static void hash_cleanup(struct hash_table *table)
 {
-	HashNode **node, **next, *old_node;
+	struct hash_node **node, **next, *old_node;
         unsigned int i;
 
 	if (hash_resize(table))
--- a/src/lib/hash.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/hash.h	Sun Jan 05 15:09:51 2003 +0200
@@ -7,14 +7,13 @@
 typedef int (*HashCompareFunc) (const void *p1, const void *p2);
 typedef void (*HashForeachFunc) (void *key, void *value, void *context);
 
-typedef struct _HashTable HashTable;
-
 /* Create a new hash table. If initial_size is 0, the default value is used.
    If hash_func or key_compare_func is NULL, direct hashing/comparing
    is used. */
-HashTable *hash_create(Pool pool, unsigned int initial_size,
-		       HashFunc hash_func, HashCompareFunc key_compare_func);
-void hash_destroy(HashTable *table);
+struct hash_table *hash_create(pool_t pool, unsigned int initial_size,
+			       HashFunc hash_func,
+			       HashCompareFunc key_compare_func);
+void hash_destroy(struct hash_table *table);
 
 #ifdef POOL_CHECK_LEAKS
 #  define hash_destroy_clean(table) hash_destroy(table)
@@ -22,31 +21,32 @@
 #  define hash_destroy_clean(table)
 #endif
 
-void hash_clear(HashTable *table);
+void hash_clear(struct hash_table *table);
 
-void *hash_lookup(HashTable *table, const void *key);
-int hash_lookup_full(HashTable *table, const void *lookup_key,
+void *hash_lookup(struct hash_table *table, const void *key);
+int hash_lookup_full(struct hash_table *table, const void *lookup_key,
 		     void **orig_key, void **value);
 
 /* Insert/update node in hash table. The difference is that hash_insert()
    replaces the key in table to given one, while hash_update() doesnt. */
-void hash_insert(HashTable *table, void *key, void *value);
-void hash_update(HashTable *table, void *key, void *value);
+void hash_insert(struct hash_table *table, void *key, void *value);
+void hash_update(struct hash_table *table, void *key, void *value);
 
-void hash_remove(HashTable *table, const void *key);
-unsigned int hash_size(HashTable *table);
+void hash_remove(struct hash_table *table, const void *key);
+unsigned int hash_size(struct hash_table *table);
 
 /* Calls the given function for each node in hash table. You may safely
    call hash_*() functions inside your function, but if you add any
    new nodes, they may or may not be called for in this foreach loop. */
-void hash_foreach(HashTable *table, HashForeachFunc func, void *context);
+void hash_foreach(struct hash_table *table,
+		  HashForeachFunc func, void *context);
 /* Stop the active hash_foreach() loop */
 void hash_foreach_stop(void);
 
 /* Hash table isn't resized, and removed nodes aren't removed from
    the list while hash table is freezed. Supports nesting. */
-void hash_freeze(HashTable *table);
-void hash_thaw(HashTable *table);
+void hash_freeze(struct hash_table *table);
+void hash_thaw(struct hash_table *table);
 
 /* hash function for strings */
 unsigned int str_hash(const void *p);
--- a/src/lib/hex-binary.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/hex-binary.c	Sun Jan 05 15:09:51 2003 +0200
@@ -48,7 +48,7 @@
 	return buf;
 }
 
-int hex_to_binary(const char *data, Buffer *dest)
+int hex_to_binary(const char *data, buffer_t *dest)
 {
 	int value;
 
--- a/src/lib/hex-binary.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/hex-binary.h	Sun Jan 05 15:09:51 2003 +0200
@@ -8,6 +8,6 @@
 /* Convert hex to binary. data and dest may point to same value.
    Returns TRUE if successful. Returns 1 if all ok, 0 if dest buffer got full
    or -1 if data is invalid. */
-int hex_to_binary(const char *data, Buffer *dest);
+int hex_to_binary(const char *data, buffer_t *dest);
 
 #endif
--- a/src/lib/imem.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/imem.c	Sun Jan 05 15:09:51 2003 +0200
@@ -25,7 +25,7 @@
 
 #include "lib.h"
 
-Pool default_pool;
+pool_t default_pool;
 
 void *i_malloc(size_t size)
 {
--- a/src/lib/imem.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/imem.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,7 +1,7 @@
 #ifndef __IMEM_H
 #define __IMEM_H
 
-extern Pool default_pool;
+extern pool_t default_pool;
 
 /* For easy allocation of memory from default memory pool. */
 #define i_new(type, count) \
--- a/src/lib/ioloop-internal.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/ioloop-internal.h	Sun Jan 05 15:09:51 2003 +0200
@@ -5,24 +5,22 @@
 
 #include <sys/time.h>
 
-typedef struct _IOLoopHandlerData IOLoopHandlerData;
+struct ioloop {
+        struct ioloop *prev;
 
-struct _IOLoop {
-        struct _IOLoop *prev;
-
-	Pool pool;
+	pool_t pool;
 	int highest_fd;
 
-	IO ios; /* sorted by priority */
-	Timeout timeouts; /* sorted by next_run */
+	struct io *ios; /* sorted by priority */
+	struct timeout *timeouts; /* sorted by next_run */
 
-        IOLoopHandlerData *handler_data;
+        struct ioloop_handler_data *handler_data;
 
 	unsigned int running:1;
 };
 
-struct _IO {
-	IO prev, next;
+struct io {
+	struct io *prev, *next;
 
 	int fd;
         int priority;
@@ -35,8 +33,8 @@
         void *context;
 };
 
-struct _Timeout {
-	Timeout next;
+struct timeout {
+	struct timeout *next;
 
 	struct timeval next_run;
         int msecs;
@@ -47,20 +45,20 @@
         void *context;
 };
 
-int io_loop_get_wait_time(Timeout timeout, struct timeval *tv,
+int io_loop_get_wait_time(struct timeout *timeout, struct timeval *tv,
 			  struct timeval *tv_now);
-void io_loop_handle_timeouts(IOLoop ioloop);
+void io_loop_handle_timeouts(struct ioloop *ioloop);
 
 /* call only when io->destroyed is TRUE */
-void io_destroy(IOLoop ioloop, IO io);
+void io_destroy(struct ioloop *ioloop, struct io *io);
 /* call only when timeout->destroyed is TRUE */
-void timeout_destroy(IOLoop ioloop, Timeout timeout);
+void timeout_destroy(struct ioloop *ioloop, struct timeout *timeout);
 
 /* I/O handler calls */
-void io_loop_handle_add(IOLoop ioloop, int fd, int condition);
-void io_loop_handle_remove(IOLoop ioloop, int fd, int condition);
+void io_loop_handle_add(struct ioloop *ioloop, int fd, int condition);
+void io_loop_handle_remove(struct ioloop *ioloop, int fd, int condition);
 
-void io_loop_handler_init(IOLoop ioloop);
-void io_loop_handler_deinit(IOLoop ioloop);
+void io_loop_handler_init(struct ioloop *ioloop);
+void io_loop_handler_deinit(struct ioloop *ioloop);
 
 #endif
--- a/src/lib/ioloop-poll.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/ioloop-poll.c	Sun Jan 05 15:09:51 2003 +0200
@@ -36,7 +36,7 @@
 #  define INITIAL_POLL_FDS 128
 #endif
 
-struct _IOLoopHandlerData {
+struct ioloop_handler_data {
 	unsigned int fds_size, fds_pos;
 	struct pollfd *fds;
 
@@ -44,12 +44,12 @@
 	int *fd_index;
 };
 
-void io_loop_handler_init(IOLoop ioloop)
+void io_loop_handler_init(struct ioloop *ioloop)
 {
-	IOLoopHandlerData *data;
+	struct ioloop_handler_data *data;
 
 	ioloop->handler_data = data =
-		p_new(ioloop->pool, IOLoopHandlerData, 1);
+		p_new(ioloop->pool, struct ioloop_handler_data, 1);
 	data->fds_size = INITIAL_POLL_FDS;
 	data->fds = p_new(ioloop->pool, struct pollfd, data->fds_size);
 
@@ -58,7 +58,7 @@
         memset(data->fd_index, 0xff, sizeof(int) * data->idx_size);
 }
 
-void io_loop_handler_deinit(IOLoop ioloop)
+void io_loop_handler_deinit(struct ioloop *ioloop)
 {
         p_free(ioloop->pool, ioloop->handler_data->fds);
         p_free(ioloop->pool, ioloop->handler_data->fd_index);
@@ -68,12 +68,11 @@
 #define IO_POLL_INPUT (POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL)
 #define IO_POLL_OUTPUT (POLLOUT|POLLERR|POLLHUP|POLLNVAL)
 
-void io_loop_handle_add(IOLoop ioloop, int fd, int condition)
+void io_loop_handle_add(struct ioloop *ioloop, int fd, int condition)
 {
-	IOLoopHandlerData *data;
+	struct ioloop_handler_data *data = ioloop->handler_data;
 	int index, old_size;
 
-        data = ioloop->handler_data;
 	if ((unsigned int) fd >= data->idx_size) {
                 /* grow the fd -> index array */
 		old_size = data->idx_size;
@@ -111,12 +110,11 @@
 		data->fds[index].events |= IO_POLL_OUTPUT;
 }
 
-void io_loop_handle_remove(IOLoop ioloop, int fd, int condition)
+void io_loop_handle_remove(struct ioloop *ioloop, int fd, int condition)
 {
-	IOLoopHandlerData *data;
+	struct ioloop_handler_data *data = ioloop->handler_data;
 	int index;
 
-        data = ioloop->handler_data;
 	index = data->fd_index[fd];
 	i_assert(index >= 0 && (unsigned int) index < data->fds_size);
 
@@ -137,17 +135,15 @@
 	}
 }
 
-void io_loop_handler_run(IOLoop ioloop)
+void io_loop_handler_run(struct ioloop *ioloop)
 {
-	IOLoopHandlerData *data;
+	struct ioloop_handler_data *data = ioloop->handler_data;
         struct pollfd *pollfd;
         struct timeval tv;
-	IO io, next;
+	struct io *io, *next;
 	unsigned int t_id;
 	int msecs, ret;
 
-        data = ioloop->handler_data;
-
         /* get the time left for next timeout task */
 	msecs = io_loop_get_wait_time(ioloop->timeouts, &tv, NULL);
 
--- a/src/lib/ioloop-select.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/ioloop-select.c	Sun Jan 05 15:09:51 2003 +0200
@@ -34,25 +34,26 @@
 #include <sys/time.h>
 #include <unistd.h>
 
-struct _IOLoopHandlerData {
+struct ioloop_handler_data {
 	fd_set read_fds, write_fds;
 };
 
 static fd_set tmp_read_fds, tmp_write_fds;
 
-void io_loop_handler_init(IOLoop ioloop)
+void io_loop_handler_init(struct ioloop *ioloop)
 {
-	ioloop->handler_data = p_new(ioloop->pool, IOLoopHandlerData, 1);
+	ioloop->handler_data =
+		p_new(ioloop->pool, struct ioloop_handler_data, 1);
         FD_ZERO(&ioloop->handler_data->read_fds);
 	FD_ZERO(&ioloop->handler_data->write_fds);
 }
 
-void io_loop_handler_deinit(IOLoop ioloop)
+void io_loop_handler_deinit(struct ioloop *ioloop)
 {
         p_free(ioloop->pool, ioloop->handler_data);
 }
 
-void io_loop_handle_add(IOLoop ioloop, int fd, int condition)
+void io_loop_handle_add(struct ioloop *ioloop, int fd, int condition)
 {
 	i_assert(fd >= 0);
 
@@ -65,7 +66,7 @@
 		FD_SET(fd, &ioloop->handler_data->write_fds);
 }
 
-void io_loop_handle_remove(IOLoop ioloop, int fd, int condition)
+void io_loop_handle_remove(struct ioloop *ioloop, int fd, int condition)
 {
 	i_assert(fd >= 0 && fd < FD_SETSIZE);
 
@@ -76,15 +77,13 @@
 }
 
 #define io_check_condition(fd, condition) \
-	((((condition) & IO_READ) && \
-	  FD_ISSET((fd), &tmp_read_fds)) || \
-	 (((condition) & IO_WRITE) && \
-	  FD_ISSET((fd), &tmp_write_fds)))
+	((((condition) & IO_READ) && FD_ISSET((fd), &tmp_read_fds)) || \
+	 (((condition) & IO_WRITE) && FD_ISSET((fd), &tmp_write_fds)))
 
-void io_loop_handler_run(IOLoop ioloop)
+void io_loop_handler_run(struct ioloop *ioloop)
 {
 	struct timeval tv;
-	IO io, next;
+	struct io *io, *next;
         unsigned int t_id;
 	int ret, fd, condition;
 
--- a/src/lib/ioloop.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/ioloop.c	Sun Jan 05 15:09:51 2003 +0200
@@ -23,7 +23,7 @@
     SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-/* FIXME: inserting IO is slow if there's lots of them. I should add a linked
+/* FIXME: inserting io is slow if there's lots of them. I should add a linked
    list of priorities pointing to first item in the list with the priority. */
 
 #include "lib.h"
@@ -39,11 +39,11 @@
 struct timeval ioloop_timeval;
 struct timezone ioloop_timezone;
 
-static IOLoop current_ioloop = NULL;
+static struct ioloop *current_ioloop = NULL;
 
-static void update_highest_fd(IOLoop ioloop)
+static void update_highest_fd(struct ioloop *ioloop)
 {
-        IO io;
+        struct io *io;
 	int max_highest_fd;
 
         max_highest_fd = ioloop->highest_fd-1;
@@ -59,9 +59,9 @@
 	}
 }
 
-static void io_list_insert(IOLoop ioloop, IO io)
+static void io_list_insert(struct ioloop *ioloop, struct io *io)
 {
-	IO prev, next;
+	struct io *prev, *next;
 
         prev = NULL;
 	for (next = ioloop->ios; next != NULL; next = next->next) {
@@ -83,21 +83,21 @@
 	}
 }
 
-IO io_add(int fd, int condition, IOFunc func, void *data)
+struct io *io_add(int fd, int condition, IOFunc func, void *data)
 {
 	return io_add_priority(fd, IO_PRIORITY_DEFAULT,
 			       condition, func, data);
 }
 
-IO io_add_priority(int fd, int priority, int condition,
-		   IOFunc func, void *context)
+struct io *io_add_priority(int fd, int priority, int condition,
+			   IOFunc func, void *context)
 {
-	IO io;
+	struct io *io;
 
 	i_assert(fd >= 0);
 	i_assert(func != NULL);
 
-	io = p_new(current_ioloop->pool, struct _IO, 1);
+	io = p_new(current_ioloop->pool, struct io, 1);
 	io->fd = fd;
 	io->priority = priority;
         io->condition = condition;
@@ -114,7 +114,7 @@
 	return io;
 }
 
-void io_remove(IO io)
+void io_remove(struct io *io)
 {
 	i_assert(io != NULL);
 	i_assert(io->fd >= 0);
@@ -131,7 +131,7 @@
 	io->fd = -1;
 }
 
-void io_destroy(IOLoop ioloop, IO io)
+void io_destroy(struct ioloop *ioloop, struct io *io)
 {
         /* remove from list */
 	if (io->prev == NULL)
@@ -145,9 +145,9 @@
 	p_free(ioloop->pool, io);
 }
 
-static void timeout_list_insert(IOLoop ioloop, Timeout timeout)
+static void timeout_list_insert(struct ioloop *ioloop, struct timeout *timeout)
 {
-	Timeout *t;
+	struct timeout **t;
         struct timeval *next_run;
 
         next_run = &timeout->next_run;
@@ -160,7 +160,8 @@
         *t = timeout;
 }
 
-inline static void timeout_update_next(Timeout timeout, struct timeval *tv_now)
+inline static void
+timeout_update_next(struct timeout *timeout, struct timeval *tv_now)
 {
         if (tv_now == NULL)
 		gettimeofday(&timeout->next_run, NULL);
@@ -183,11 +184,11 @@
 	}
 }
 
-Timeout timeout_add(int msecs, TimeoutFunc func, void *context)
+struct timeout *timeout_add(int msecs, TimeoutFunc func, void *context)
 {
-	Timeout timeout;
+	struct timeout *timeout;
 
-	timeout = p_new(current_ioloop->pool, struct _Timeout, 1);
+	timeout = p_new(current_ioloop->pool, struct timeout, 1);
         timeout->msecs = msecs;
 
 	timeout->func = func;
@@ -199,16 +200,16 @@
 	return timeout;
 }
 
-void timeout_remove(Timeout timeout)
+void timeout_remove(struct timeout *timeout)
 {
 	i_assert(timeout != NULL);
 
 	timeout->destroyed = TRUE;
 }
 
-void timeout_destroy(IOLoop ioloop, Timeout timeout)
+void timeout_destroy(struct ioloop *ioloop, struct timeout *timeout)
 {
-	Timeout *t;
+	struct timeout **t;
 
 	for (t = &ioloop->timeouts; *t != NULL; t = &(*t)->next) {
 		if (*t == timeout)
@@ -219,7 +220,7 @@
         p_free(ioloop->pool, timeout);
 }
 
-int io_loop_get_wait_time(Timeout timeout, struct timeval *tv,
+int io_loop_get_wait_time(struct timeout *timeout, struct timeval *tv,
 			  struct timeval *tv_now)
 {
 	if (timeout == NULL)
@@ -248,9 +249,9 @@
         return 0;
 }
 
-void io_loop_handle_timeouts(IOLoop ioloop)
+void io_loop_handle_timeouts(struct ioloop *ioloop)
 {
-	Timeout t, next;
+	struct timeout *t, *next;
 	struct timeval tv;
         unsigned int t_id;
 
@@ -285,32 +286,32 @@
 	}
 }
 
-void io_loop_run(IOLoop ioloop)
+void io_loop_run(struct ioloop *ioloop)
 {
         ioloop->running = TRUE;
 	while (ioloop->running)
 		io_loop_handler_run(ioloop);
 }
 
-void io_loop_stop(IOLoop ioloop)
+void io_loop_stop(struct ioloop *ioloop)
 {
         ioloop->running = FALSE;
 }
 
-void io_loop_set_running(IOLoop ioloop)
+void io_loop_set_running(struct ioloop *ioloop)
 {
         ioloop->running = TRUE;
 }
 
-IOLoop io_loop_create(Pool pool)
+struct ioloop *io_loop_create(pool_t pool)
 {
-	IOLoop ioloop;
+	struct ioloop *ioloop;
 
 	/* initialize time */
 	gettimeofday(&ioloop_timeval, &ioloop_timezone);
 	ioloop_time = ioloop_timeval.tv_sec;
 
-        ioloop = p_new(pool, struct _IOLoop, 1);
+        ioloop = p_new(pool, struct ioloop, 1);
 	pool_ref(pool);
 	ioloop->pool = pool;
 	ioloop->highest_fd = -1;
@@ -323,10 +324,10 @@
         return ioloop;
 }
 
-void io_loop_destroy(IOLoop ioloop)
+void io_loop_destroy(struct ioloop *ioloop)
 {
 	while (ioloop->ios != NULL) {
-		IO io = ioloop->ios;
+		struct io *io = ioloop->ios;
 
 		if (!io->destroyed) {
 			i_warning("I/O leak: %p (%d)",
@@ -337,7 +338,7 @@
 	}
 
 	while (ioloop->timeouts != NULL) {
-		Timeout to = ioloop->timeouts;
+		struct timeout *to = ioloop->timeouts;
 
 		if (!to->destroyed) {
 			i_warning("Timeout leak: %p", (void *) to->func);
--- a/src/lib/ioloop.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/ioloop.h	Sun Jan 05 15:09:51 2003 +0200
@@ -10,8 +10,12 @@
 #define IO_PRIORITY_DEFAULT	0
 #define IO_PRIORITY_HIGH	-100
 
-typedef void (*IOFunc) (void *context, int fd, IO io);
-typedef void (*TimeoutFunc) (void *context, Timeout timeout);
+struct io;
+struct timeout;
+struct ioloop;
+
+typedef void (*IOFunc) (void *context, int fd, struct io *io);
+typedef void (*TimeoutFunc) (void *context, struct timeout *timeout);
 
 /* Time when the I/O loop started calling handlers.
    Can be used instead of time(NULL). */
@@ -22,23 +26,23 @@
 /* I/O listeners - you can create different handlers for IO_READ and IO_WRITE,
    but make sure you don't create multiple handlers of same type, it's not
    checked and removing one will stop the other from working as well. */
-IO io_add(int fd, int condition, IOFunc func, void *context);
-IO io_add_priority(int fd, int priority, int condition,
-		   IOFunc func, void *context);
-void io_remove(IO io);
+struct io *io_add(int fd, int condition, IOFunc func, void *context);
+struct io *io_add_priority(int fd, int priority, int condition,
+			   IOFunc func, void *context);
+void io_remove(struct io *io);
 
 /* Timeout handlers */
-Timeout timeout_add(int msecs, TimeoutFunc func, void *context);
-void timeout_remove(Timeout timeout);
+struct timeout *timeout_add(int msecs, TimeoutFunc func, void *context);
+void timeout_remove(struct timeout *timeout);
 
-void io_loop_run(IOLoop ioloop);
-void io_loop_stop(IOLoop ioloop); /* safe to run in signal handler */
+void io_loop_run(struct ioloop *ioloop);
+void io_loop_stop(struct ioloop *ioloop); /* safe to run in signal handler */
 
 /* call these if you wish to run the iteration only once */
-void io_loop_set_running(IOLoop ioloop);
-void io_loop_handler_run(IOLoop ioloop);
+void io_loop_set_running(struct ioloop *ioloop);
+void io_loop_handler_run(struct ioloop *ioloop);
 
-IOLoop io_loop_create(Pool pool);
-void io_loop_destroy(IOLoop ioloop);
+struct ioloop *io_loop_create(pool_t pool);
+void io_loop_destroy(struct ioloop *ioloop);
 
 #endif
--- a/src/lib/iostream-internal.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/iostream-internal.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,25 +3,23 @@
 
 /* This file is private to IStream and OStream implementation */
 
-typedef struct _IOStream _IOStream;
-
-struct _IOStream {
-	Pool pool;
+struct _iostream {
+	pool_t pool;
 	int refcount;
 
-	void (*close)(_IOStream *stream);
-	void (*destroy)(_IOStream *stream);
-	void (*set_max_buffer_size)(_IOStream *stream, size_t max_size);
-	void (*set_blocking)(_IOStream *stream, int timeout_msecs,
+	void (*close)(struct _iostream *stream);
+	void (*destroy)(struct _iostream *stream);
+	void (*set_max_buffer_size)(struct _iostream *stream, size_t max_size);
+	void (*set_blocking)(struct _iostream *stream, int timeout_msecs,
 			     void (*timeout_func)(void *), void *context);
 };
 
-void _io_stream_init(Pool pool, _IOStream *stream);
-void _io_stream_ref(_IOStream *stream);
-void _io_stream_unref(_IOStream *stream);
-void _io_stream_close(_IOStream *stream);
-void _io_stream_set_max_buffer_size(_IOStream *stream, size_t max_size);
-void _io_stream_set_blocking(_IOStream *stream, int timeout_msecs,
+void _io_stream_init(pool_t pool, struct _iostream *stream);
+void _io_stream_ref(struct _iostream *stream);
+void _io_stream_unref(struct _iostream *stream);
+void _io_stream_close(struct _iostream *stream);
+void _io_stream_set_max_buffer_size(struct _iostream *stream, size_t max_size);
+void _io_stream_set_blocking(struct _iostream *stream, int timeout_msecs,
 			     void (*timeout_func)(void *), void *context);
 
 #define GET_TIMEOUT_TIME(fstream) \
--- a/src/lib/iostream.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/iostream.c	Sun Jan 05 15:09:51 2003 +0200
@@ -26,20 +26,20 @@
 #include "lib.h"
 #include "iostream-internal.h"
 
-void _io_stream_init(Pool pool, _IOStream *stream)
+void _io_stream_init(pool_t pool, struct _iostream *stream)
 {
 	stream->pool = pool;
 	stream->refcount = 1;
 }
 
-void _io_stream_ref(_IOStream *stream)
+void _io_stream_ref(struct _iostream *stream)
 {
 	stream->refcount++;
 }
 
-void _io_stream_unref(_IOStream *stream)
+void _io_stream_unref(struct _iostream *stream)
 {
-	Pool pool;
+	pool_t pool;
 
 	i_assert(stream->refcount > 0);
 	if (--stream->refcount != 0)
@@ -53,17 +53,17 @@
 	pool_unref(pool);
 }
 
-void _io_stream_close(_IOStream *stream)
+void _io_stream_close(struct _iostream *stream)
 {
 	stream->close(stream);
 }
 
-void _io_stream_set_max_buffer_size(_IOStream *stream, size_t max_size)
+void _io_stream_set_max_buffer_size(struct _iostream *stream, size_t max_size)
 {
 	stream->set_max_buffer_size(stream, max_size);
 }
 
-void _io_stream_set_blocking(_IOStream *stream, int timeout_msecs,
+void _io_stream_set_blocking(struct _iostream *stream, int timeout_msecs,
 			     void (*timeout_func)(void *), void *context)
 {
 	stream->set_blocking(stream, timeout_msecs, timeout_func, context);
--- a/src/lib/istream-data.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/istream-data.c	Sun Jan 05 15:09:51 2003 +0200
@@ -26,48 +26,49 @@
 #include "lib.h"
 #include "istream-internal.h"
 
-static void _close(_IOStream *stream __attr_unused__)
+static void _close(struct _iostream *stream __attr_unused__)
 {
 }
 
-static void _destroy(_IOStream *stream __attr_unused__)
+static void _destroy(struct _iostream *stream __attr_unused__)
 {
 }
 
-static void _set_max_buffer_size(_IOStream *stream __attr_unused__,
+static void _set_max_buffer_size(struct _iostream *stream __attr_unused__,
 				 size_t max_size __attr_unused__)
 {
 }
 
-static void _set_blocking(_IOStream *stream __attr_unused__,
+static void _set_blocking(struct _iostream *stream __attr_unused__,
 			  int timeout_msecs __attr_unused__,
 			  void (*timeout_func)(void *) __attr_unused__,
 			  void *context __attr_unused__)
 {
 }
 
-static ssize_t _read(_IStream *stream)
+static ssize_t _read(struct _istream *stream)
 {
 	return stream->pos - stream->skip;
 }
 
-static void _seek(_IStream *stream, uoff_t v_offset)
+static void _seek(struct _istream *stream, uoff_t v_offset)
 {
 	stream->skip = v_offset;
 	stream->istream.v_offset = v_offset;
 }
 
-static void _skip(_IStream *stream, uoff_t count)
+static void _skip(struct _istream *stream, uoff_t count)
 {
 	stream->skip += count;
 	stream->istream.v_offset += count;
 }
 
-IStream *i_stream_create_from_data(Pool pool, const void *data, size_t size)
+struct istream *i_stream_create_from_data(pool_t pool, const void *data,
+					  size_t size)
 {
-	_IStream *stream;
+	struct _istream *stream;
 
-	stream = p_new(pool, _IStream, 1);
+	stream = p_new(pool, struct _istream, 1);
 	stream->buffer = data;
 	stream->pos = size;
 
--- a/src/lib/istream-file.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/istream-file.c	Sun Jan 05 15:09:51 2003 +0200
@@ -39,8 +39,8 @@
 #define STREAM_IS_BLOCKING(fstream) \
 	((fstream)->timeout_msecs != 0)
 
-typedef struct {
-	_IStream istream;
+struct file_istream {
+	struct _istream istream;
 
 	size_t max_buffer_size;
 	uoff_t skip_left;
@@ -51,38 +51,38 @@
 
 	unsigned int file:1;
 	unsigned int autoclose_fd:1;
-} FileIStream;
+};
 
-static void _close(_IOStream *stream)
+static void _close(struct _iostream *stream)
 {
-	FileIStream *fstream = (FileIStream *) stream;
-	_IStream *_stream = (_IStream *) stream;
+	struct file_istream *fstream = (struct file_istream *) stream;
+	struct _istream *_stream = (struct _istream *) stream;
 
 	if (fstream->autoclose_fd && _stream->fd != -1) {
 		if (close(_stream->fd) < 0)
-			i_error("FileIStream.close() failed: %m");
+			i_error("file_istream.close() failed: %m");
 		_stream->fd = -1;
 	}
 }
 
-static void _destroy(_IOStream *stream)
+static void _destroy(struct _iostream *stream)
 {
-	_IStream *_stream = (_IStream *) stream;
+	struct _istream *_stream = (struct _istream *) stream;
 
 	p_free(_stream->iostream.pool, _stream->w_buffer);
 }
 
-static void _set_max_buffer_size(_IOStream *stream, size_t max_size)
+static void _set_max_buffer_size(struct _iostream *stream, size_t max_size)
 {
-	FileIStream *fstream = (FileIStream *) stream;
+	struct file_istream *fstream = (struct file_istream *) stream;
 
 	fstream->max_buffer_size = max_size;
 }
 
-static void _set_blocking(_IOStream *stream, int timeout_msecs,
+static void _set_blocking(struct _iostream *stream, int timeout_msecs,
 			  void (*timeout_func)(void *), void *context)
 {
-	FileIStream *fstream = (FileIStream *) stream;
+	struct file_istream *fstream = (struct file_istream *) stream;
 
 	fstream->timeout_msecs = timeout_msecs;
 	fstream->timeout_func = timeout_func;
@@ -94,9 +94,9 @@
 		alarm_hup_init();
 }
 
-static void i_stream_grow_buffer(_IStream *stream, size_t bytes)
+static void i_stream_grow_buffer(struct _istream *stream, size_t bytes)
 {
-	FileIStream *fstream = (FileIStream *) stream;
+	struct file_istream *fstream = (struct file_istream *) stream;
 
 	stream->buffer_size = stream->pos + bytes;
 	stream->buffer_size =
@@ -112,7 +112,7 @@
 			  stream->buffer_size);
 }
 
-static void i_stream_compress(_IStream *stream)
+static void i_stream_compress(struct _istream *stream)
 {
 	memmove(stream->w_buffer, stream->w_buffer + stream->skip,
 		stream->pos - stream->skip);
@@ -126,9 +126,9 @@
 	stream->skip = 0;
 }
 
-static ssize_t _read(_IStream *stream)
+static ssize_t _read(struct _istream *stream)
 {
-	FileIStream *fstream = (FileIStream *) stream;
+	struct file_istream *fstream = (struct file_istream *) stream;
 	time_t timeout_time;
 	uoff_t read_limit;
 	size_t size;
@@ -232,18 +232,18 @@
 	return ret;
 }
 
-static void _skip(_IStream *stream, uoff_t count)
+static void _skip(struct _istream *stream, uoff_t count)
 {
-	FileIStream *fstream = (FileIStream *) stream;
+	struct file_istream *fstream = (struct file_istream *) stream;
 
 	fstream->skip_left += count - (stream->pos - stream->skip);
 	stream->skip = stream->pos = 0;
 	stream->istream.v_offset += count;
 }
 
-static void _seek(_IStream *stream, uoff_t v_offset)
+static void _seek(struct _istream *stream, uoff_t v_offset)
 {
-	FileIStream *fstream = (FileIStream *) stream;
+	struct file_istream *fstream = (struct file_istream *) stream;
 	uoff_t real_offset;
 	off_t ret;
 
@@ -272,13 +272,13 @@
 	}
 }
 
-IStream *i_stream_create_file(int fd, Pool pool, size_t max_buffer_size,
-			      int autoclose_fd)
+struct istream *i_stream_create_file(int fd, pool_t pool,
+				     size_t max_buffer_size, int autoclose_fd)
 {
-	FileIStream *fstream;
+	struct file_istream *fstream;
 	struct stat st;
 
-	fstream = p_new(pool, FileIStream, 1);
+	fstream = p_new(pool, struct file_istream, 1);
 	fstream->max_buffer_size = max_buffer_size;
 	fstream->autoclose_fd = autoclose_fd;
 
--- a/src/lib/istream-internal.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/istream-internal.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,19 +4,17 @@
 #include "istream.h"
 #include "iostream-internal.h"
 
-typedef struct __IStream _IStream;
-
-struct __IStream {
+struct _istream {
 /* inheritance: */
-	_IOStream iostream;
+	struct _iostream iostream;
 
 /* methods: */
-	ssize_t (*read)(_IStream *stream);
-	void (*skip_count)(_IStream *stream, uoff_t count);
-	void (*seek)(_IStream *stream, uoff_t v_offset);
+	ssize_t (*read)(struct _istream *stream);
+	void (*skip_count)(struct _istream *stream, uoff_t count);
+	void (*seek)(struct _istream *stream, uoff_t v_offset);
 
 /* data: */
-	IStream istream;
+	struct istream istream;
 
 	int fd;
 	const unsigned char *buffer;
@@ -26,7 +24,7 @@
 	size_t skip, pos, cr_lookup_pos;
 };
 
-IStream *_i_stream_create(_IStream *_buf, Pool pool, int fd,
-			  uoff_t start_offset, uoff_t v_size);
+struct istream *_i_stream_create(struct _istream *_buf, pool_t pool, int fd,
+				 uoff_t start_offset, uoff_t v_size);
 
 #endif
--- a/src/lib/istream-mmap.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/istream-mmap.c	Sun Jan 05 15:09:51 2003 +0200
@@ -30,8 +30,8 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
-typedef struct {
-	_IStream istream;
+struct mmap_istream {
+	struct _istream istream;
 
 	int fd;
 	void *mmap_base;
@@ -39,29 +39,29 @@
 	size_t mmap_block_size;
 
 	unsigned int autoclose_fd:1;
-} MmapIStream;
+};
 
 static size_t mmap_pagesize = 0;
 static size_t mmap_pagemask = 0;
 
-static void _close(_IOStream *stream)
+static void _close(struct _iostream *stream)
 {
-	MmapIStream *mstream = (MmapIStream *) stream;
+	struct mmap_istream *mstream = (struct mmap_istream *) stream;
 
 	if (mstream->autoclose_fd && mstream->fd != -1) {
 		if (close(mstream->fd) < 0)
-			i_error("MmapIStream.close() failed: %m");
+			i_error("mmap_istream.close() failed: %m");
 		mstream->fd = -1;
 	}
 }
 
-static void i_stream_munmap(MmapIStream *mstream)
+static void i_stream_munmap(struct mmap_istream *mstream)
 {
-	_IStream *_stream = &mstream->istream;
+	struct _istream *_stream = &mstream->istream;
 
 	if (_stream->buffer != NULL) {
 		if (munmap(mstream->mmap_base, _stream->buffer_size) < 0)
-			i_error("MmapIStream.munmap() failed: %m");
+			i_error("mmap_istream.munmap() failed: %m");
 		mstream->mmap_base = NULL;
 		_stream->buffer = NULL;
 		_stream->buffer_size = 0;
@@ -69,21 +69,21 @@
 	}
 }
 
-static void _destroy(_IOStream *stream)
+static void _destroy(struct _iostream *stream)
 {
-	MmapIStream *mstream = (MmapIStream *) stream;
+	struct mmap_istream *mstream = (struct mmap_istream *) stream;
 
 	i_stream_munmap(mstream);
 }
 
-static void _set_max_buffer_size(_IOStream *stream, size_t max_size)
+static void _set_max_buffer_size(struct _iostream *stream, size_t max_size)
 {
-	MmapIStream *mstream = (MmapIStream *) stream;
+	struct mmap_istream *mstream = (struct mmap_istream *) stream;
 
 	mstream->mmap_block_size = max_size;
 }
 
-static void _set_blocking(_IOStream *stream __attr_unused__,
+static void _set_blocking(struct _iostream *stream __attr_unused__,
 			  int timeout_msecs __attr_unused__,
 			  void (*timeout_func)(void *) __attr_unused__,
 			  void *context __attr_unused__)
@@ -91,9 +91,9 @@
 	/* we never block */
 }
 
-static ssize_t io_stream_set_mmaped_pos(_IStream *stream)
+static ssize_t io_stream_set_mmaped_pos(struct _istream *stream)
 {
-	MmapIStream *mstream = (MmapIStream *) stream;
+	struct mmap_istream *mstream = (struct mmap_istream *) stream;
 
 	i_assert((uoff_t)mstream->mmap_offset <=
 		 stream->istream.start_offset + stream->istream.v_limit);
@@ -106,9 +106,9 @@
 	return stream->pos - stream->skip;
 }
 
-static ssize_t _read(_IStream *stream)
+static ssize_t _read(struct _istream *stream)
 {
-	MmapIStream *mstream = (MmapIStream *) stream;
+	struct mmap_istream *mstream = (struct mmap_istream *) stream;
 	size_t aligned_skip, limit_size;
 
 	if (stream->istream.start_offset + stream->istream.v_limit <=
@@ -148,16 +148,16 @@
 	mstream->mmap_base = mmap(NULL, stream->buffer_size,
 				  PROT_READ, MAP_PRIVATE,
 				  mstream->fd, mstream->mmap_offset);
-	stream->buffer = mstream->mmap_base;
 	if (mstream->mmap_base == MAP_FAILED) {
 		stream->istream.stream_errno = errno;
 		mstream->mmap_base = NULL;
 		stream->buffer = NULL;
 		stream->buffer_size = 0;
 		stream->skip = stream->pos = 0;
-		i_error("MmapIStream.mmap() failed: %m");
+		i_error("mmap_istream.mmap() failed: %m");
 		return -1;
 	}
+	stream->buffer = mstream->mmap_base;
 
 	/* madvise() only if non-limited mmap()ed buffer area larger than
 	   page size */
@@ -167,16 +167,17 @@
 		if (limit_size > stream->buffer_size)
 			limit_size = stream->buffer_size;
 
-		if (madvise(mstream->mmap_base, limit_size, MADV_SEQUENTIAL) < 0)
-			i_error("MmapIStream.madvise(): %m");
+		if (madvise(mstream->mmap_base, limit_size,
+			    MADV_SEQUENTIAL) < 0)
+			i_error("mmap_istream.madvise(): %m");
 	}
 
 	return io_stream_set_mmaped_pos(stream);
 }
 
-static void _seek(_IStream *stream, uoff_t v_offset)
+static void _seek(struct _istream *stream, uoff_t v_offset)
 {
-	MmapIStream *mstream = (MmapIStream *) stream;
+	struct mmap_istream *mstream = (struct mmap_istream *) stream;
 	uoff_t abs_offset;
 
 	abs_offset = stream->istream.start_offset + v_offset;
@@ -194,16 +195,16 @@
 	stream->istream.v_offset = v_offset;
 }
 
-static void _skip(_IStream *stream, uoff_t count)
+static void _skip(struct _istream *stream, uoff_t count)
 {
 	_seek(stream, stream->istream.v_offset + count);
 }
 
-IStream *i_stream_create_mmap(int fd, Pool pool, size_t block_size,
-			      uoff_t start_offset, uoff_t v_size,
-			      int autoclose_fd)
+struct istream *i_stream_create_mmap(int fd, pool_t pool, size_t block_size,
+				     uoff_t start_offset, uoff_t v_size,
+				     int autoclose_fd)
 {
-	MmapIStream *mstream;
+	struct mmap_istream *mstream;
 	struct stat st;
 
 	if (mmap_pagesize == 0) {
@@ -223,7 +224,7 @@
 		}
 	}
 
-	mstream = p_new(pool, MmapIStream, 1);
+	mstream = p_new(pool, struct mmap_istream, 1);
 	mstream->fd = fd;
 	mstream->mmap_block_size = block_size;
 	mstream->autoclose_fd = autoclose_fd;
@@ -237,5 +238,6 @@
 	mstream->istream.skip_count = _skip;
 	mstream->istream.seek = _seek;
 
-	return _i_stream_create(&mstream->istream, pool, fd, start_offset, v_size);
+	return _i_stream_create(&mstream->istream, pool, fd,
+				start_offset, v_size);
 }
--- a/src/lib/istream.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/istream.c	Sun Jan 05 15:09:51 2003 +0200
@@ -26,44 +26,44 @@
 #include "lib.h"
 #include "istream-internal.h"
 
-void i_stream_ref(IStream *stream)
+void i_stream_ref(struct istream *stream)
 {
 	_io_stream_ref(stream->real_stream);
 }
 
-void i_stream_unref(IStream *stream)
+void i_stream_unref(struct istream *stream)
 {
 	_io_stream_unref(stream->real_stream);
 }
 
-int i_stream_get_fd(IStream *stream)
+int i_stream_get_fd(struct istream *stream)
 {
-	_IStream *_stream = stream->real_stream;
+	struct _istream *_stream = stream->real_stream;
 
 	return _stream->fd;
 }
 
-void i_stream_close(IStream *stream)
+void i_stream_close(struct istream *stream)
 {
 	_io_stream_close(stream->real_stream);
 	stream->closed = TRUE;
 }
 
-void i_stream_set_max_buffer_size(IStream *stream, size_t max_size)
+void i_stream_set_max_buffer_size(struct istream *stream, size_t max_size)
 {
 	_io_stream_set_max_buffer_size(stream->real_stream, max_size);
 }
 
-void i_stream_set_blocking(IStream *stream, int timeout_msecs,
+void i_stream_set_blocking(struct istream *stream, int timeout_msecs,
 			   void (*timeout_func)(void *), void *context)
 {
 	_io_stream_set_blocking(stream->real_stream, timeout_msecs,
 				timeout_func, context);
 }
 
-void i_stream_set_start_offset(IStream *stream, uoff_t offset)
+void i_stream_set_start_offset(struct istream *stream, uoff_t offset)
 {
-	_IStream *_stream = stream->real_stream;
+	struct _istream *_stream = stream->real_stream;
 	off_t diff;
 
 	i_assert(stream->v_size == 0 ||
@@ -84,9 +84,9 @@
 	_stream->skip = _stream->pos = _stream->cr_lookup_pos = 0;
 }
 
-void i_stream_set_read_limit(IStream *stream, uoff_t v_offset)
+void i_stream_set_read_limit(struct istream *stream, uoff_t v_offset)
 {
-	_IStream *_stream = stream->real_stream;
+	struct _istream *_stream = stream->real_stream;
 	uoff_t max_pos;
 
 	i_assert(stream->v_size == 0 || v_offset <= stream->v_size);
@@ -103,9 +103,9 @@
 	}
 }
 
-ssize_t i_stream_read(IStream *stream)
+ssize_t i_stream_read(struct istream *stream)
 {
-	_IStream *_stream = stream->real_stream;
+	struct _istream *_stream = stream->real_stream;
 
 	if (stream->closed)
 		return -1;
@@ -113,9 +113,9 @@
 	return _stream->read(_stream);
 }
 
-void i_stream_skip(IStream *stream, uoff_t count)
+void i_stream_skip(struct istream *stream, uoff_t count)
 {
-	_IStream *_stream = stream->real_stream;
+	struct _istream *_stream = stream->real_stream;
 	size_t data_size;
 
 	i_assert(stream->v_size == 0 ||
@@ -139,9 +139,9 @@
 	_stream->skip_count(_stream, count);
 }
 
-void i_stream_seek(IStream *stream, uoff_t v_offset)
+void i_stream_seek(struct istream *stream, uoff_t v_offset)
 {
-	_IStream *_stream = stream->real_stream;
+	struct _istream *_stream = stream->real_stream;
 
 	i_assert(v_offset <= stream->v_size);
 
@@ -151,9 +151,9 @@
 	_stream->seek(_stream, v_offset);
 }
 
-char *i_stream_next_line(IStream *stream)
+char *i_stream_next_line(struct istream *stream)
 {
-	_IStream *_stream = stream->real_stream;
+	struct _istream *_stream = stream->real_stream;
 	char *ret_buf;
         size_t i;
 
@@ -189,9 +189,9 @@
         return ret_buf;
 }
 
-const unsigned char *i_stream_get_data(IStream *stream, size_t *size)
+const unsigned char *i_stream_get_data(struct istream *stream, size_t *size)
 {
-	_IStream *_stream = stream->real_stream;
+	struct _istream *_stream = stream->real_stream;
 
 	if (_stream->skip >= _stream->pos) {
 		*size = 0;
@@ -202,9 +202,10 @@
         return _stream->buffer + _stream->skip;
 }
 
-unsigned char *i_stream_get_modifyable_data(IStream *stream, size_t *size)
+unsigned char *i_stream_get_modifyable_data(struct istream *stream,
+					    size_t *size)
 {
-	_IStream *_stream = stream->real_stream;
+	struct _istream *_stream = stream->real_stream;
 
 	if (_stream->skip >= _stream->pos || _stream->w_buffer == NULL) {
 		*size = 0;
@@ -215,10 +216,10 @@
         return _stream->w_buffer + _stream->skip;
 }
 
-int i_stream_read_data(IStream *stream, const unsigned char **data,
+int i_stream_read_data(struct istream *stream, const unsigned char **data,
 		       size_t *size, size_t threshold)
 {
-	_IStream *_stream = stream->real_stream;
+	struct _istream *_stream = stream->real_stream;
 	ssize_t ret = 0;
 
 	while (_stream->pos - _stream->skip <= threshold) {
@@ -234,8 +235,8 @@
 		*size > 0 ? 0 : -1;
 }
 
-IStream *_i_stream_create(_IStream *_stream, Pool pool, int fd,
-			  uoff_t start_offset, uoff_t v_size)
+struct istream *_i_stream_create(struct _istream *_stream, pool_t pool, int fd,
+				 uoff_t start_offset, uoff_t v_size)
 {
 	_stream->fd = fd;
 	_stream->istream.start_offset = start_offset;
--- a/src/lib/istream.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/istream.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,7 +1,7 @@
 #ifndef __ISTREAM_H
 #define __ISTREAM_H
 
-struct _IStream {
+struct istream {
 	uoff_t start_offset;
 	uoff_t v_offset, v_size, v_limit; /* relative to start_offset */
 
@@ -11,64 +11,66 @@
 	void *real_stream;
 };
 
-IStream *i_stream_create_file(int fd, Pool pool, size_t max_buffer_size,
-			      int autoclose_fd);
-IStream *i_stream_create_mmap(int fd, Pool pool, size_t block_size,
-			      uoff_t start_offset, uoff_t v_size,
-			      int autoclose_fd);
-IStream *i_stream_create_from_data(Pool pool, const void *data, size_t size);
+struct istream *i_stream_create_file(int fd, pool_t pool,
+				     size_t max_buffer_size, int autoclose_fd);
+struct istream *i_stream_create_mmap(int fd, pool_t pool, size_t block_size,
+				     uoff_t start_offset, uoff_t v_size,
+				     int autoclose_fd);
+struct istream *i_stream_create_from_data(pool_t pool, const void *data,
+					  size_t size);
 
 /* Reference counting. References start from 1, so calling i_stream_unref()
    destroys the stream if i_stream_ref() is never used. */
-void i_stream_ref(IStream *stream);
-void i_stream_unref(IStream *stream);
+void i_stream_ref(struct istream *stream);
+void i_stream_unref(struct istream *stream);
 
 /* Return file descriptor for stream, or -1 if none is available. */
-int i_stream_get_fd(IStream *stream);
+int i_stream_get_fd(struct istream *stream);
 
 /* Mark the stream closed. Any reads after this will return -1. The data
    already read can still be used. */
-void i_stream_close(IStream *stream);
+void i_stream_close(struct istream *stream);
 
 /* Change the maximum size for stream's input buffer to grow. Useful only
    for buffered streams (currently only file). */
-void i_stream_set_max_buffer_size(IStream *stream, size_t max_size);
+void i_stream_set_max_buffer_size(struct istream *stream, size_t max_size);
 /* Change the start_offset and drop all data in buffers. Doesn't do anything
    if offset is the same as existing start_offset. */
-void i_stream_set_start_offset(IStream *stream, uoff_t offset);
+void i_stream_set_start_offset(struct istream *stream, uoff_t offset);
 /* Stream won't be read past specified offset. Giving 0 as offset
    removes the limit. */
-void i_stream_set_read_limit(IStream *stream, uoff_t v_offset);
+void i_stream_set_read_limit(struct istream *stream, uoff_t v_offset);
 /* Makes reads blocking until at least one byte is read. timeout_func is
    called if nothing is read in specified time. Setting timeout_msecs to 0
    makes it non-blocking. This call changes non-blocking state of file
    descriptor. */
-void i_stream_set_blocking(IStream *stream, int timeout_msecs,
+void i_stream_set_blocking(struct istream *stream, int timeout_msecs,
 			   void (*timeout_func)(void *), void *context);
 
 /* Returns number of bytes read if read was ok, -1 if EOF or error, -2 if the
    input buffer is full. */
-ssize_t i_stream_read(IStream *stream);
+ssize_t i_stream_read(struct istream *stream);
 /* Skip forward a number of bytes. Never fails, the next read tells if it
    was successful. */
-void i_stream_skip(IStream *stream, uoff_t count);
+void i_stream_skip(struct istream *stream, uoff_t count);
 /* Seek to specified position from beginning of file. Never fails, the next
    read tells if it was successful. This works only for files. */
-void i_stream_seek(IStream *stream, uoff_t v_offset);
+void i_stream_seek(struct istream *stream, uoff_t v_offset);
 /* Reads the next line from stream and returns it, or NULL if more data is
    needed to make a full line. NOTE: modifies the data in buffer for the \0,
    so it works only with buffered streams (currently only file). */
-char *i_stream_next_line(IStream *stream);
+char *i_stream_next_line(struct istream *stream);
 /* Returns pointer to beginning of read data, or NULL if there's no data
    buffered. */
-const unsigned char *i_stream_get_data(IStream *stream, size_t *size);
+const unsigned char *i_stream_get_data(struct istream *stream, size_t *size);
 /* Like i_stream_get_data(), but returns non-const data. This only works with
    buffered streams (currently only file), others return NULL. */
-unsigned char *i_stream_get_modifyable_data(IStream *stream, size_t *size);
+unsigned char *i_stream_get_modifyable_data(struct istream *stream,
+					    size_t *size);
 /* Like i_stream_get_data(), but read more when needed. Returns 1 if more
    than threshold bytes are available, 0 if less, -1 if error or EOF with no
    bytes available, or -2 if stream's input buffer is full. */
-int i_stream_read_data(IStream *stream, const unsigned char **data,
+int i_stream_read_data(struct istream *stream, const unsigned char **data,
 		       size_t *size, size_t threshold);
 
 #endif
--- a/src/lib/lib.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/lib.h	Sun Jan 05 15:09:51 2003 +0200
@@ -17,16 +17,6 @@
 #  include <stdint.h> /* C99 int types, we mostly need uintmax_t */
 #endif
 
-typedef struct _IOLoop *IOLoop;
-typedef struct _IO *IO;
-typedef struct _Timeout *Timeout;
-
-typedef struct _IPADDR IPADDR;
-typedef struct _IStream IStream;
-typedef struct _OStream OStream;
-typedef struct _Buffer Buffer;
-typedef struct _Buffer String;
-
 #include "compat.h"
 #include "macros.h"
 #include "failures.h"
@@ -37,6 +27,12 @@
 
 #include "strfuncs.h"
 
+typedef struct buffer buffer_t;
+typedef struct buffer string_t;
+
+struct istream;
+struct ostream;
+
 size_t nearest_power(size_t num);
 
 void lib_init(void);
--- a/src/lib/macros.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/macros.h	Sun Jan 05 15:09:51 2003 +0200
@@ -27,7 +27,8 @@
 #define I_MAX(a, b)  (((a) > (b)) ? (a) : (b))
 
 #undef CLAMP
-#define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
+#define CLAMP(x, low, high) \
+	(((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
 
 #undef NVL
 #define NVL(str, nullstr) ((str) != NULL ? (str) : (nullstr))
@@ -43,7 +44,8 @@
 /* Define VA_COPY() to do the right thing for copying va_list variables.
    config.h may have already defined VA_COPY as va_copy or __va_copy. */
 #ifndef VA_COPY
-#  if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
+#  if defined (__GNUC__) && defined (__PPC__) && \
+      (defined (_CALL_SYSV) || defined (_WIN32))
 #    define VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
 #  elif defined (VA_COPY_AS_ARRAY)
 #    define VA_COPY(ap1, ap2) i_memmove ((ap1), (ap2), sizeof (va_list))
--- a/src/lib/md5.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/md5.c	Sun Jan 05 15:09:51 2003 +0200
@@ -15,8 +15,7 @@
  * and avoid compile-time configuration.
  */
 
-#include <string.h>
-
+#include "lib.h"
 #include "md5.h"
 
 /*
@@ -48,16 +47,16 @@
  */
 #if defined(__i386__) || defined(__vax__)
 #define SET(n) \
-	(*(const MD5_u32plus *)&ptr[(n) * 4])
+	(*(const uint_fast32_t *)&ptr[(n) * 4])
 #define GET(n) \
 	SET(n)
 #else
 #define SET(n) \
 	(ctx->block[(n)] = \
-	(MD5_u32plus)ptr[(n) * 4] | \
-	((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
-	((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
-	((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
+	(uint_fast32_t)ptr[(n) * 4] | \
+	((uint_fast32_t)ptr[(n) * 4 + 1] << 8) | \
+	((uint_fast32_t)ptr[(n) * 4 + 2] << 16) | \
+	((uint_fast32_t)ptr[(n) * 4 + 3] << 24))
 #define GET(n) \
 	(ctx->block[(n)])
 #endif
@@ -66,11 +65,11 @@
  * This processes one or more 64-byte data blocks, but does NOT update
  * the bit counters.  There're no alignment requirements.
  */
-static const void *body(MD5Context *ctx, const void *data, size_t size)
+static const void *body(struct md5_context *ctx, const void *data, size_t size)
 {
 	const unsigned char *ptr;
-	MD5_u32plus a, b, c, d;
-	MD5_u32plus saved_a, saved_b, saved_c, saved_d;
+	uint_fast32_t a, b, c, d;
+	uint_fast32_t saved_a, saved_b, saved_c, saved_d;
 
 	ptr = data;
 
@@ -173,7 +172,7 @@
 	return ptr;
 }
 
-void md5_init(MD5Context *ctx)
+void md5_init(struct md5_context *ctx)
 {
 	ctx->a = 0x67452301;
 	ctx->b = 0xefcdab89;
@@ -184,10 +183,10 @@
 	ctx->hi = 0;
 }
 
-void md5_update(MD5Context *ctx, const void *data, size_t size)
+void md5_update(struct md5_context *ctx, const void *data, size_t size)
 {
 	/* @UNSAFE */
-	MD5_u32plus saved_lo;
+	uint_fast32_t saved_lo;
 	unsigned long used, free;
 
 	saved_lo = ctx->lo;
@@ -219,7 +218,7 @@
 	memcpy(ctx->buffer, data, size);
 }
 
-void md5_final(MD5Context *ctx, unsigned char result[16])
+void md5_final(struct md5_context *ctx, unsigned char result[16])
 {
 	/* @UNSAFE */
 	unsigned long used, free;
@@ -273,7 +272,7 @@
 
 void md5_get_digest(const void *data, size_t size, unsigned char result[16])
 {
-	MD5Context ctx;
+	struct md5_context ctx;
 
 	md5_init(&ctx);
 	md5_update(&ctx, data, size);
--- a/src/lib/md5.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/md5.h	Sun Jan 05 15:09:51 2003 +0200
@@ -9,19 +9,16 @@
 #ifndef __MD5_H
 #define __MD5_H
 
-/* Any 32-bit or wider integer data type will do */
-typedef unsigned long MD5_u32plus;
-
-typedef struct {
-	MD5_u32plus lo, hi;
-	MD5_u32plus a, b, c, d;
+struct md5_context {
+	uint_fast32_t lo, hi;
+	uint_fast32_t a, b, c, d;
 	unsigned char buffer[64];
-	MD5_u32plus block[16];
-} MD5Context;
+	uint_fast32_t block[16];
+};
 
-void md5_init(MD5Context *ctx);
-void md5_update(MD5Context *ctx, const void *data, size_t size);
-void md5_final(MD5Context *ctx, unsigned char result[16]);
+void md5_init(struct md5_context *ctx);
+void md5_update(struct md5_context *ctx, const void *data, size_t size);
+void md5_final(struct md5_context *ctx, unsigned char result[16]);
 
 void md5_get_digest(const void *data, size_t size, unsigned char result[16]);
 
--- a/src/lib/mempool-alloconly.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/mempool-alloconly.c	Sun Jan 05 15:09:51 2003 +0200
@@ -33,20 +33,18 @@
 
 #define MAX_ALLOC_SIZE SSIZE_T_MAX
 
-typedef struct _PoolBlock PoolBlock;
-
-typedef struct {
-	struct Pool pool;
+struct alloconly_pool {
+	struct pool pool;
 	int refcount;
 
-	PoolBlock *block;
+	struct pool_block *block;
 
 	char name[MEM_ALIGN_SIZE]; /* variable size */
-} AlloconlyPool;
-#define SIZEOF_ALLOCONLYPOOL (sizeof(AlloconlyPool)-MEM_ALIGN_SIZE)
+};
+#define SIZEOF_ALLOCONLYPOOL (sizeof(struct alloconly_pool)-MEM_ALIGN_SIZE)
 
-struct _PoolBlock {
-	PoolBlock *prev;
+struct pool_block {
+	struct pool_block *prev;
 
 	size_t size;
 	size_t left;
@@ -54,30 +52,30 @@
 
 	/* unsigned char data[]; */
 };
-#define SIZEOF_POOLBLOCK (MEM_ALIGN(sizeof(PoolBlock)))
+#define SIZEOF_POOLBLOCK (MEM_ALIGN(sizeof(struct pool_block)))
 
 #define POOL_BLOCK_DATA(block) \
 	((char *) (block) + SIZEOF_POOLBLOCK)
 
-typedef struct {
+struct pool_alloc {
 	union {
 		size_t size;
 		unsigned char alignment[MEM_ALIGN_SIZE];
 	} size;
 	unsigned char data[MEM_ALIGN_SIZE]; /* variable size */
-} PoolAlloc;
-#define SIZEOF_POOLALLOC (sizeof(PoolAlloc)-MEM_ALIGN_SIZE)
+};
+#define SIZEOF_POOLALLOC (sizeof(struct pool_alloc)-MEM_ALIGN_SIZE)
 
-static void pool_alloconly_ref(Pool pool);
-static void pool_alloconly_unref(Pool pool);
-static void *pool_alloconly_malloc(Pool pool, size_t size);
-static void pool_alloconly_free(Pool pool, void *mem);
-static void *pool_alloconly_realloc(Pool pool, void *mem, size_t size);
-static void pool_alloconly_clear(Pool pool);
+static void pool_alloconly_ref(pool_t pool);
+static void pool_alloconly_unref(pool_t pool);
+static void *pool_alloconly_malloc(pool_t pool, size_t size);
+static void pool_alloconly_free(pool_t pool, void *mem);
+static void *pool_alloconly_realloc(pool_t pool, void *mem, size_t size);
+static void pool_alloconly_clear(pool_t pool);
 
-static void block_alloc(AlloconlyPool *pool, size_t size);
+static void block_alloc(struct alloconly_pool *pool, size_t size);
 
-static struct Pool static_alloconly_pool = {
+static struct pool static_alloconly_pool = {
 	pool_alloconly_ref,
 	pool_alloconly_unref,
 
@@ -89,9 +87,9 @@
 	pool_alloconly_clear
 };
 
-Pool pool_alloconly_create(const char *name, size_t size)
+pool_t pool_alloconly_create(const char *name, size_t size)
 {
-	AlloconlyPool *apool;
+	struct alloconly_pool *apool;
 	int len;
 
 	len = strlen(name);
@@ -104,10 +102,10 @@
 	memcpy(apool->name, name, len+1);
 
 	block_alloc(apool, size);
-	return (Pool) apool;
+	return (struct pool *) apool;
 }
 
-static void pool_alloconly_destroy(AlloconlyPool *apool)
+static void pool_alloconly_destroy(struct alloconly_pool *apool)
 {
 	/* destroy all but the last block */
 	pool_alloconly_clear(&apool->pool);
@@ -117,24 +115,24 @@
 	free(apool);
 }
 
-static void pool_alloconly_ref(Pool pool)
+static void pool_alloconly_ref(pool_t pool)
 {
-	AlloconlyPool *apool = (AlloconlyPool *) pool;
+	struct alloconly_pool *apool = (struct alloconly_pool *) pool;
 
 	apool->refcount++;
 }
 
-static void pool_alloconly_unref(Pool pool)
+static void pool_alloconly_unref(pool_t pool)
 {
-	AlloconlyPool *apool = (AlloconlyPool *) pool;
+	struct alloconly_pool *apool = (struct alloconly_pool *) pool;
 
 	if (--apool->refcount == 0)
 		pool_alloconly_destroy(apool);
 }
 
-static void block_alloc(AlloconlyPool *apool, size_t size)
+static void block_alloc(struct alloconly_pool *apool, size_t size)
 {
-	PoolBlock *block;
+	struct pool_block *block;
 
 	/* each block is at least twice the size of the previous one */
 	if (apool->block != NULL && size <= apool->block->size)
@@ -159,10 +157,10 @@
 	block->left = block->size;
 }
 
-static void *pool_alloconly_malloc(Pool pool, size_t size)
+static void *pool_alloconly_malloc(pool_t pool, size_t size)
 {
-	AlloconlyPool *apool = (AlloconlyPool *) pool;
-	PoolAlloc *alloc;
+	struct alloconly_pool *apool = (struct alloconly_pool *) pool;
+	struct pool_alloc *alloc;
 
 	if (size == 0 || size > SSIZE_T_MAX)
 		i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);
@@ -174,8 +172,8 @@
 		block_alloc(apool, size);
 	}
 
-	alloc = (PoolAlloc *) (POOL_BLOCK_DATA(apool->block) +
-			       apool->block->size - apool->block->left);
+	alloc = (struct pool_alloc *) (POOL_BLOCK_DATA(apool->block) +
+				       apool->block->size - apool->block->left);
 	alloc->size.size = size;
 
 	apool->block->left -= size + SIZEOF_POOLALLOC;
@@ -183,13 +181,13 @@
 	return alloc->data;
 }
 
-static void pool_alloconly_free(Pool pool __attr_unused__,
+static void pool_alloconly_free(pool_t pool __attr_unused__,
 				void *mem __attr_unused__)
 {
 	/* ignore */
 }
 
-static int pool_try_grow(AlloconlyPool *apool, void *mem, size_t size)
+static int pool_try_grow(struct alloconly_pool *apool, void *mem, size_t size)
 {
 	/* see if we want to grow the memory we allocated last */
 	if (POOL_BLOCK_DATA(apool->block) +
@@ -208,10 +206,10 @@
 	return FALSE;
 }
 
-static void *pool_alloconly_realloc(Pool pool, void *mem, size_t size)
+static void *pool_alloconly_realloc(pool_t pool, void *mem, size_t size)
 {
-	AlloconlyPool *apool = (AlloconlyPool *) pool;
-	PoolAlloc *alloc;
+	struct alloconly_pool *apool = (struct alloconly_pool *) pool;
+	struct pool_alloc *alloc;
 	unsigned char *new_mem;
 	size_t old_size;
 
@@ -222,7 +220,7 @@
 		return pool_alloconly_malloc(pool, size);
 
 	/* get old size */
-	alloc = (PoolAlloc *) ((char *) mem - SIZEOF_POOLALLOC);
+	alloc = (struct pool_alloc *) ((char *) mem - SIZEOF_POOLALLOC);
 	old_size = alloc->size.size;
 
 	if (size <= old_size)
@@ -246,10 +244,10 @@
         return mem;
 }
 
-static void pool_alloconly_clear(Pool pool)
+static void pool_alloconly_clear(pool_t pool)
 {
-	AlloconlyPool *apool = (AlloconlyPool *) pool;
-	PoolBlock *block;
+	struct alloconly_pool *apool = (struct alloconly_pool *) pool;
+	struct pool_block *block;
 
 	/* destroy all blocks but the last, which is the largest */
 	while (apool->block->prev != NULL) {
--- a/src/lib/mempool-datastack.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/mempool-datastack.c	Sun Jan 05 15:09:51 2003 +0200
@@ -28,22 +28,22 @@
 
 #include <stdlib.h>
 
-typedef struct {
+struct pool_alloc {
 	union {
 		size_t size;
 		unsigned char alignment[MEM_ALIGN_SIZE];
 	} size;
 	/* void data[]; */
-} PoolAlloc;
+};
 
-static void pool_data_stack_ref(Pool pool);
-static void pool_data_stack_unref(Pool pool);
-static void *pool_data_stack_malloc(Pool pool, size_t size);
-static void pool_data_stack_free(Pool pool, void *mem);
-static void *pool_data_stack_realloc(Pool pool, void *mem, size_t size);
-static void pool_data_stack_clear(Pool pool);
+static void pool_data_stack_ref(pool_t pool);
+static void pool_data_stack_unref(pool_t pool);
+static void *pool_data_stack_malloc(pool_t pool, size_t size);
+static void pool_data_stack_free(pool_t pool, void *mem);
+static void *pool_data_stack_realloc(pool_t pool, void *mem, size_t size);
+static void pool_data_stack_clear(pool_t pool);
 
-static struct Pool static_data_stack_pool = {
+static struct pool static_data_stack_pool = {
 	pool_data_stack_ref,
 	pool_data_stack_unref,
 
@@ -55,39 +55,39 @@
 	pool_data_stack_clear
 };
 
-Pool data_stack_pool = &static_data_stack_pool;
+pool_t data_stack_pool = &static_data_stack_pool;
 
-static void pool_data_stack_ref(Pool pool __attr_unused__)
+static void pool_data_stack_ref(pool_t pool __attr_unused__)
 {
 }
 
-static void pool_data_stack_unref(Pool pool __attr_unused__)
+static void pool_data_stack_unref(pool_t pool __attr_unused__)
 {
 }
 
-static void *pool_data_stack_malloc(Pool pool __attr_unused__, size_t size)
+static void *pool_data_stack_malloc(pool_t pool __attr_unused__, size_t size)
 {
-	PoolAlloc *alloc;
+	struct pool_alloc *alloc;
 
 	if (size == 0 || size > SSIZE_T_MAX)
 		i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);
 
-	alloc = t_malloc0(sizeof(PoolAlloc) + size);
+	alloc = t_malloc0(sizeof(struct pool_alloc) + size);
 	alloc->size.size = size;
 
-	return (char *) alloc + sizeof(PoolAlloc);
+	return (char *) alloc + sizeof(struct pool_alloc);
 }
 
-static void pool_data_stack_free(Pool pool __attr_unused__,
+static void pool_data_stack_free(pool_t pool __attr_unused__,
 				 void *mem __attr_unused__)
 {
 }
 
-static void *pool_data_stack_realloc(Pool pool __attr_unused__,
+static void *pool_data_stack_realloc(pool_t pool __attr_unused__,
 				     void *mem, size_t size)
 {
 	/* @UNSAFE */
-	PoolAlloc *alloc, *new_alloc;
+	struct pool_alloc *alloc, *new_alloc;
         size_t old_size;
 	unsigned char *rmem;
 
@@ -98,24 +98,25 @@
 		return pool_data_stack_malloc(pool, size);
 
 	/* get old size */
-	alloc = (PoolAlloc *) ((char *) mem - sizeof(PoolAlloc));
+	alloc = (struct pool_alloc *)
+		((char *) mem - sizeof(struct pool_alloc));
 	old_size = alloc->size.size;
 
 	if (old_size >= size)
 		return mem;
 
-	if (!t_try_realloc(alloc, sizeof(PoolAlloc) + size)) {
-		new_alloc = t_malloc(sizeof(PoolAlloc) + size);
-		memcpy(new_alloc, alloc, old_size + sizeof(PoolAlloc));
+	if (!t_try_realloc(alloc, sizeof(struct pool_alloc) + size)) {
+		new_alloc = t_malloc(sizeof(struct pool_alloc) + size);
+		memcpy(new_alloc, alloc, old_size + sizeof(struct pool_alloc));
 		alloc = new_alloc;
 	}
 	alloc->size.size = size;
 
-        rmem = (unsigned char *) alloc + sizeof(PoolAlloc);
+        rmem = (unsigned char *) alloc + sizeof(struct pool_alloc);
 	memset(rmem + old_size, 0, size-old_size);
 	return rmem;
 }
 
-static void pool_data_stack_clear(Pool pool __attr_unused__)
+static void pool_data_stack_clear(pool_t pool __attr_unused__)
 {
 }
--- a/src/lib/mempool-system.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/mempool-system.c	Sun Jan 05 15:09:51 2003 +0200
@@ -30,22 +30,22 @@
 
 #include <stdlib.h>
 
-typedef struct {
+struct pool_alloc {
 	union {
 		size_t size;
 		unsigned char alignment[MEM_ALIGN_SIZE];
 	} size;
 	/* void data[]; */
-} PoolAlloc;
+};
 
-static void pool_system_ref(Pool pool);
-static void pool_system_unref(Pool pool);
-static void *pool_system_malloc(Pool pool, size_t size);
-static void pool_system_free(Pool pool, void *mem);
-static void *pool_system_realloc(Pool pool, void *mem, size_t size);
-static void pool_system_clear(Pool pool);
+static void pool_system_ref(pool_t pool);
+static void pool_system_unref(pool_t pool);
+static void *pool_system_malloc(pool_t pool, size_t size);
+static void pool_system_free(pool_t pool, void *mem);
+static void *pool_system_realloc(pool_t pool, void *mem, size_t size);
+static void pool_system_clear(pool_t pool);
 
-static struct Pool static_system_pool = {
+static struct pool static_system_pool = {
 	pool_system_ref,
 	pool_system_unref,
 
@@ -57,41 +57,41 @@
 	pool_system_clear
 };
 
-Pool system_pool = &static_system_pool;
+pool_t system_pool = &static_system_pool;
 
-static void pool_system_ref(Pool pool __attr_unused__)
+static void pool_system_ref(pool_t pool __attr_unused__)
 {
 }
 
-static void pool_system_unref(Pool pool __attr_unused__)
+static void pool_system_unref(pool_t pool __attr_unused__)
 {
 }
 
-static void *pool_system_malloc(Pool pool __attr_unused__, size_t size)
+static void *pool_system_malloc(pool_t pool __attr_unused__, size_t size)
 {
-	PoolAlloc *alloc;
+	struct pool_alloc *alloc;
 
 	if (size == 0 || size > SSIZE_T_MAX)
 		i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);
 
-	alloc = calloc(sizeof(PoolAlloc) + size, 1);
+	alloc = calloc(sizeof(struct pool_alloc) + size, 1);
 	if (alloc == NULL)
 		i_panic("pool_system_malloc(): Out of memory");
 	alloc->size.size = size;
 
-	return (char *) alloc + sizeof(PoolAlloc);
+	return (char *) alloc + sizeof(struct pool_alloc);
 }
 
-static void pool_system_free(Pool pool __attr_unused__, void *mem)
+static void pool_system_free(pool_t pool __attr_unused__, void *mem)
 {
 	if (mem != NULL)
-		free((char *) mem - sizeof(PoolAlloc));
+		free((char *) mem - sizeof(struct pool_alloc));
 }
 
-static void *pool_system_realloc(Pool pool __attr_unused__, void *mem,
+static void *pool_system_realloc(pool_t pool __attr_unused__, void *mem,
 				 size_t size)
 {
-	PoolAlloc *alloc;
+	struct pool_alloc *alloc;
 	size_t old_size;
 	char *rmem;
 
@@ -103,17 +103,18 @@
 		old_size = 0;
 	} else {
 		/* get old size */
-		alloc = (PoolAlloc *) ((char *) mem - sizeof(PoolAlloc));
+		alloc = (struct pool_alloc *)
+			((char *) mem - sizeof(struct pool_alloc));
 		old_size = alloc->size.size;
 	}
 
         /* alloc & set new size */
-	alloc = realloc(alloc, sizeof(PoolAlloc) + size);
+	alloc = realloc(alloc, sizeof(struct pool_alloc) + size);
 	if (alloc == NULL)
 		i_panic("pool_system_realloc(): Out of memory");
 	alloc->size.size = size;
 
-        rmem = (char *) alloc + sizeof(PoolAlloc);
+        rmem = (char *) alloc + sizeof(struct pool_alloc);
 	if (size > old_size) {
                 /* clear new data */
 		memset(rmem + old_size, 0, size-old_size);
@@ -122,7 +123,7 @@
         return rmem;
 }
 
-static void pool_system_clear(Pool pool __attr_unused__)
+static void pool_system_clear(pool_t pool __attr_unused__)
 {
 	i_panic("pool_system_clear() must not be called");
 }
--- a/src/lib/mempool.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/mempool.h	Sun Jan 05 15:09:51 2003 +0200
@@ -9,32 +9,32 @@
    zeroed, it will cost only a few CPU cycles and may well save some debug
    time. */
 
-typedef struct Pool *Pool;
+typedef struct pool *pool_t;
 
-struct Pool {
-	void (*ref)(Pool pool);
-	void (*unref)(Pool pool);
+struct pool {
+	void (*ref)(pool_t pool);
+	void (*unref)(pool_t pool);
 
-	void *(*malloc)(Pool pool, size_t size);
-	void (*free)(Pool pool, void *mem);
+	void *(*malloc)(pool_t pool, size_t size);
+	void (*free)(pool_t pool, void *mem);
 
 	/* reallocate the `mem' to be exactly `size' */
-	void *(*realloc)(Pool pool, void *mem, size_t size);
+	void *(*realloc)(pool_t pool, void *mem, size_t size);
 
 	/* Frees all the memory in pool. NOTE: system_pool doesn't support
 	   this and crashes if it's used */
-	void (*clear)(Pool pool);
+	void (*clear)(pool_t pool);
 };
 
 /* system_pool uses calloc() + realloc() + free() */
-extern Pool system_pool;
+extern pool_t system_pool;
 
 /* memory allocated from data_stack is valid only until next t_pop() call. */
-extern Pool data_stack_pool;
+extern pool_t data_stack_pool;
 
 /* Create a new alloc-only pool. Note that `size' specifies the initial
    malloc()ed block size, part of it is used internally. */
-Pool pool_alloconly_create(const char *name, size_t size);
+pool_t pool_alloconly_create(const char *name, size_t size);
 
 /* Pools should be used through these macros: */
 #define pool_ref(pool) (pool)->ref(pool)
--- a/src/lib/network.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/network.c	Sun Jan 05 15:09:51 2003 +0200
@@ -49,7 +49,7 @@
 #  define SIZEOF_SOCKADDR(so) (sizeof(so.sin))
 #endif
 
-int net_ip_compare(const IPADDR *ip1, const IPADDR *ip2)
+int net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2)
 {
 	if (ip1->family != ip2->family)
 		return 0;
@@ -64,7 +64,8 @@
 
 
 /* copy IP to sockaddr */
-static inline void sin_set_ip(union sockaddr_union *so, const IPADDR *ip)
+static inline void
+sin_set_ip(union sockaddr_union *so, const struct ip_addr *ip)
 {
 	if (ip == NULL) {
 #ifdef HAVE_IPV6
@@ -86,7 +87,8 @@
 		memcpy(&so->sin.sin_addr, &ip->ip, 4);
 }
 
-static inline void sin_get_ip(const union sockaddr_union *so, IPADDR *ip)
+static inline void
+sin_get_ip(const union sockaddr_union *so, struct ip_addr *ip)
 {
 	ip->family = so->sin.sin_family;
 
@@ -125,7 +127,8 @@
 }
 
 /* Connect to socket with ip address */
-int net_connect_ip(const IPADDR *ip, unsigned int port, const IPADDR *my_ip)
+int net_connect_ip(const struct ip_addr *ip, unsigned int port,
+		   const struct ip_addr *my_ip)
 {
 	union sockaddr_union so;
 	int fd, ret, opt = 1;
@@ -233,7 +236,7 @@
 #endif
 }
 
-void net_get_ip_any4(IPADDR *ip)
+void net_get_ip_any4(struct ip_addr *ip)
 {
 	struct in_addr *in_ip = (struct in_addr *) &ip->ip;
 
@@ -241,19 +244,19 @@
 	in_ip->s_addr = INADDR_ANY;
 }
 
-void net_get_ip_any6(IPADDR *ip)
+void net_get_ip_any6(struct ip_addr *ip)
 {
 #ifdef HAVE_IPV6
 	ip->family = AF_INET6;
 	ip->ip = in6addr_any;
 #else
-	memset(ip, 0, sizeof(IPADDR));
+	memset(ip, 0, sizeof(struct ip_addr));
 #endif
 }
 
 /* Listen for connections on a socket. if `my_ip' is NULL, listen in any
    address. */
-int net_listen(const IPADDR *my_ip, unsigned int *port)
+int net_listen(const struct ip_addr *my_ip, unsigned int *port)
 {
 	union sockaddr_union so;
 	int ret, fd, opt = 1;
@@ -338,7 +341,7 @@
 }
 
 /* Accept a connection on a socket */
-int net_accept(int fd, IPADDR *addr, unsigned int *port)
+int net_accept(int fd, struct ip_addr *addr, unsigned int *port)
 {
 	union sockaddr_union so;
 	int ret;
@@ -414,7 +417,7 @@
 
 /* Get IP addresses for host. ips contains ips_count of IPs, they don't need
    to be free'd. Returns 0 = ok, others = error code for net_gethosterror() */
-int net_gethostbyname(const char *addr, IPADDR **ips, int *ips_count)
+int net_gethostbyname(const char *addr, struct ip_addr **ips, int *ips_count)
 {
 	/* @UNSAFE */
 #ifdef HAVE_IPV6
@@ -454,7 +457,7 @@
                 count++;
 
         *ips_count = count;
-        *ips = t_malloc(sizeof(IPADDR) * count);
+        *ips = t_malloc(sizeof(struct ip_addr) * count);
 
         count = 0;
 	for (ai = origai; ai != NULL; ai = ai->ai_next, count++) {
@@ -474,7 +477,7 @@
 		count++;
 
         *ips_count = count;
-        *ips = t_malloc(sizeof(IPADDR) * count);
+        *ips = t_malloc(sizeof(struct ip_addr) * count);
 
 	while (count > 0) {
 		count--;
@@ -488,7 +491,7 @@
 }
 
 /* Get socket address/port */
-int net_getsockname(int fd, IPADDR *addr, unsigned int *port)
+int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port)
 {
 	union sockaddr_union so;
 	socklen_t addrlen;
@@ -505,7 +508,7 @@
 	return 0;
 }
 
-const char *net_ip2host(const IPADDR *ip)
+const char *net_ip2host(const struct ip_addr *ip)
 {
 #ifdef HAVE_IPV6
 	char host[MAX_IP_LEN+1];
@@ -531,7 +534,7 @@
 	return 0;
 }
 
-int net_host2ip(const char *host, IPADDR *ip)
+int net_host2ip(const char *host, struct ip_addr *ip)
 {
 	if (strchr(host, ':') != NULL) {
 		/* IPv6 */
--- a/src/lib/network.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/network.h	Sun Jan 05 15:09:51 2003 +0200
@@ -20,7 +20,7 @@
 #  endif
 #endif
 
-struct _IPADDR {
+struct ip_addr {
 	unsigned short family;
 #ifdef HAVE_IPV6
 	struct in6_addr ip;
@@ -40,10 +40,11 @@
 #define IPADDR_IS_V6(ip) ((ip)->family == AF_INET6)
 
 /* returns 1 if IPADDRs are the same */
-int net_ip_compare(const IPADDR *ip1, const IPADDR *ip2);
+int net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2);
 
 /* Connect to socket with ip address */
-int net_connect_ip(const IPADDR *ip, unsigned int port, const IPADDR *my_ip);
+int net_connect_ip(const struct ip_addr *ip, unsigned int port,
+		   const struct ip_addr *my_ip);
 /* Connect to named UNIX socket */
 int net_connect_unix(const char *path);
 /* Disconnect socket */
@@ -60,16 +61,16 @@
 
 /* Set IP to contain INADDR_ANY for IPv4 or IPv6. The IPv6 any address may
    include IPv4 depending on the system (Linux yes, BSD no). */
-void net_get_ip_any4(IPADDR *ip);
-void net_get_ip_any6(IPADDR *ip);
+void net_get_ip_any4(struct ip_addr *ip);
+void net_get_ip_any6(struct ip_addr *ip);
 
 /* Listen for connections on a socket */
-int net_listen(const IPADDR *my_ip, unsigned int *port);
+int net_listen(const struct ip_addr *my_ip, unsigned int *port);
 /* Listen for connections on an UNIX socket */
 int net_listen_unix(const char *path);
 /* Accept a connection on a socket. Returns -1 for temporary failure,
    -2 for fatal failure */
-int net_accept(int fd, IPADDR *addr, unsigned int *port);
+int net_accept(int fd, struct ip_addr *addr, unsigned int *port);
 
 /* Read data from socket, return number of bytes read,
    -1 = error, -2 = disconnected */
@@ -79,7 +80,7 @@
 
 /* Get IP addresses for host. ips contains ips_count of IPs, they don't need
    to be free'd. Returns 0 = ok, others = error code for net_gethosterror() */
-int net_gethostbyname(const char *addr, IPADDR **ips, int *ips_count);
+int net_gethostbyname(const char *addr, struct ip_addr **ips, int *ips_count);
 /* get error of net_gethostname() */
 const char *net_gethosterror(int error);
 /* return TRUE if host lookup failed because it didn't exist (ie. not
@@ -87,12 +88,12 @@
 int net_hosterror_notfound(int error);
 
 /* Get socket address/port */
-int net_getsockname(int fd, IPADDR *addr, unsigned int *port);
+int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port);
 
-/* Returns IPADDR as string, or NULL if ip is invalid. */
-const char *net_ip2host(const IPADDR *ip);
-/* char* -> IPADDR translation. */
-int net_host2ip(const char *host, IPADDR *ip);
+/* Returns ip_addr as string, or NULL if ip is invalid. */
+const char *net_ip2host(const struct ip_addr *ip);
+/* char* -> struct ip_addr translation. */
+int net_host2ip(const char *host, struct ip_addr *ip);
 
 /* Get socket error */
 int net_geterror(int fd);
--- a/src/lib/ostream-file.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/ostream-file.c	Sun Jan 05 15:09:51 2003 +0200
@@ -46,12 +46,12 @@
 #define MAX_SSIZE_T(size) \
 	((size) < SSIZE_T_MAX ? (size_t)(size) : SSIZE_T_MAX)
 
-typedef struct {
-	_OStream ostream;
+struct file_ostream {
+	struct _ostream ostream;
 
 	int fd;
 	int priority;
-	IO io;
+	struct io *io;
 
 	unsigned char *buffer; /* ring-buffer */
 	size_t buffer_size, max_buffer_size;
@@ -65,13 +65,13 @@
 	unsigned int corked:1;
 	unsigned int no_socket_cork:1;
 	unsigned int autoclose_fd:1;
-} FileOStream;
+};
 
-static void stream_closed(FileOStream *fstream)
+static void stream_closed(struct file_ostream *fstream)
 {
 	if (fstream->autoclose_fd && fstream->fd != -1) {
 		if (close(fstream->fd) < 0)
-			i_error("FileOStream.close() failed: %m");
+			i_error("file_ostream.close() failed: %m");
 		fstream->fd = -1;
 	}
 
@@ -83,9 +83,9 @@
 	fstream->ostream.ostream.closed = TRUE;
 }
 
-static void _close(_IOStream *stream)
+static void _close(struct _iostream *stream)
 {
-	FileOStream *fstream = (FileOStream *) stream;
+	struct file_ostream *fstream = (struct file_ostream *) stream;
 
 	/* flush output before really closing it */
 	o_stream_flush(&fstream->ostream.ostream);
@@ -93,24 +93,24 @@
 	stream_closed(fstream);
 }
 
-static void _destroy(_IOStream *stream)
+static void _destroy(struct _iostream *stream)
 {
-	FileOStream *fstream = (FileOStream *) stream;
+	struct file_ostream *fstream = (struct file_ostream *) stream;
 
 	p_free(fstream->ostream.iostream.pool, fstream->buffer);
 }
 
-static void _set_max_buffer_size(_IOStream *stream, size_t max_size)
+static void _set_max_buffer_size(struct _iostream *stream, size_t max_size)
 {
-	FileOStream *fstream = (FileOStream *) stream;
+	struct file_ostream *fstream = (struct file_ostream *) stream;
 
 	fstream->max_buffer_size = max_size;
 }
 
-static void _set_blocking(_IOStream *stream, int timeout_msecs,
+static void _set_blocking(struct _iostream *stream, int timeout_msecs,
 			  void (*timeout_func)(void *), void *context)
 {
-	FileOStream *fstream = (FileOStream *) stream;
+	struct file_ostream *fstream = (struct file_ostream *) stream;
 
 	fstream->timeout_msecs = timeout_msecs;
 	fstream->timeout_func = timeout_func;
@@ -122,9 +122,9 @@
 		alarm_hup_init();
 }
 
-static void _cork(_OStream *stream)
+static void _cork(struct _ostream *stream)
 {
-	FileOStream *fstream = (FileOStream *) stream;
+	struct file_ostream *fstream = (struct file_ostream *) stream;
 
 	if (!fstream->corked) {
 		if (!fstream->no_socket_cork) {
@@ -153,7 +153,7 @@
 	}
 }
 
-static void update_buffer(FileOStream *fstream, size_t size)
+static void update_buffer(struct file_ostream *fstream, size_t size)
 {
 	size_t used;
 
@@ -191,7 +191,7 @@
 
 /* NOTE: modifies iov */
 static ssize_t
-o_stream_writev(FileOStream *fstream, struct iovec *iov, int iov_size)
+o_stream_writev(struct file_ostream *fstream, struct iovec *iov, int iov_size)
 {
 	ssize_t ret;
 
@@ -218,7 +218,8 @@
 }
 
 /* returns how much of vector was used */
-static int o_stream_fill_iovec(FileOStream *fstream, struct iovec iov[2])
+static int o_stream_fill_iovec(struct file_ostream *fstream,
+			       struct iovec iov[2])
 {
 	if (IS_STREAM_EMPTY(fstream))
 		return 0;
@@ -240,8 +241,8 @@
 	}
 }
 
-static int o_stream_send_blocking(FileOStream *fstream, const void *data,
-				  size_t size)
+static int o_stream_send_blocking(struct file_ostream *fstream,
+				  const void *data, size_t size)
 {
 	time_t timeout_time;
 	struct iovec iov[3];
@@ -275,7 +276,7 @@
         return 1;
 }
 
-static int buffer_flush(FileOStream *fstream)
+static int buffer_flush(struct file_ostream *fstream)
 {
 	struct iovec iov[2];
 	int iov_len;
@@ -294,9 +295,9 @@
 	return 1;
 }
 
-static int _flush(_OStream *stream)
+static int _flush(struct _ostream *stream)
 {
-	FileOStream *fstream = (FileOStream *) stream;
+	struct file_ostream *fstream = (struct file_ostream *) stream;
 	int ret;
 
 	ret = buffer_flush(fstream);
@@ -313,7 +314,7 @@
 	return ret;
 }
 
-static size_t get_unused_space(FileOStream *fstream)
+static size_t get_unused_space(struct file_ostream *fstream)
 {
 	if (fstream->head > fstream->tail) {
 		/* XXXT...HXXX */
@@ -327,9 +328,9 @@
 	}
 }
 
-static int _have_space(_OStream *stream, size_t size)
+static int _have_space(struct _ostream *stream, size_t size)
 {
-	FileOStream *fstream = (FileOStream *) stream;
+	struct file_ostream *fstream = (struct file_ostream *) stream;
 	size_t unused;
 
 	if (fstream->max_buffer_size == 0)
@@ -343,9 +344,9 @@
 	return size <= unused ? 1 : 0;
 }
 
-static int _seek(_OStream *stream, uoff_t offset)
+static int _seek(struct _ostream *stream, uoff_t offset)
 {
-	FileOStream *fstream = (FileOStream *) stream;
+	struct file_ostream *fstream = (struct file_ostream *) stream;
 	off_t ret;
 
 	if (offset > OFF_T_MAX) {
@@ -369,7 +370,7 @@
 	return 1;
 }
 
-static void o_stream_grow_buffer(FileOStream *fstream, size_t bytes)
+static void o_stream_grow_buffer(struct file_ostream *fstream, size_t bytes)
 {
 	size_t size, head_size;
 
@@ -409,9 +410,9 @@
 }
 
 static void stream_send_io(void *context, int fd __attr_unused__,
-			   IO io __attr_unused__)
+			   struct io *io __attr_unused__)
 {
-	FileOStream *fstream = context;
+	struct file_ostream *fstream = context;
 	struct iovec iov[2];
 	int iov_len;
 
@@ -425,7 +426,8 @@
 	}
 }
 
-static size_t o_stream_add(FileOStream *fstream, const void *data, size_t size)
+static size_t o_stream_add(struct file_ostream *fstream,
+			   const void *data, size_t size)
 {
 	size_t unused, sent;
 	int i;
@@ -463,9 +465,9 @@
 	return sent;
 }
 
-static ssize_t _send(_OStream *stream, const void *data, size_t size)
+static ssize_t _send(struct _ostream *stream, const void *data, size_t size)
 {
-	FileOStream *fstream = (FileOStream *) stream;
+	struct file_ostream *fstream = (struct file_ostream *) stream;
 	struct iovec iov;
 	ssize_t ret;
 
@@ -501,9 +503,10 @@
 	}
 }
 
-static off_t io_stream_sendfile(_OStream *outstream, IStream *instream)
+static off_t io_stream_sendfile(struct _ostream *outstream,
+				struct istream *instream)
 {
-	FileOStream *foutstream = (FileOStream *) outstream;
+	struct file_ostream *foutstream = (struct file_ostream *) outstream;
 	time_t timeout_time;
 	uoff_t start_offset;
 	uoff_t offset, send_size;
@@ -573,9 +576,10 @@
 	return (off_t) (instream->v_offset - start_offset);
 }
 
-static off_t io_stream_copy(_OStream *outstream, IStream *instream)
+static off_t io_stream_copy(struct _ostream *outstream,
+			    struct istream *instream)
 {
-	FileOStream *foutstream = (FileOStream *) outstream;
+	struct file_ostream *foutstream = (struct file_ostream *) outstream;
 	time_t timeout_time;
 	uoff_t start_offset;
 	struct iovec iov[3];
@@ -638,7 +642,7 @@
 	return (off_t) (instream->v_offset - start_offset);
 }
 
-static off_t _send_istream(_OStream *outstream, IStream *instream)
+static off_t _send_istream(struct _ostream *outstream, struct istream *instream)
 {
 	off_t ret;
 
@@ -659,12 +663,13 @@
 	return io_stream_copy(outstream, instream);
 }
 
-OStream *o_stream_create_file(int fd, Pool pool, size_t max_buffer_size,
-			      int priority, int autoclose_fd)
+struct ostream *
+o_stream_create_file(int fd, pool_t pool, size_t max_buffer_size,
+		     int priority, int autoclose_fd)
 {
-	FileOStream *fstream;
+	struct file_ostream *fstream;
 
-	fstream = p_new(pool, FileOStream, 1);
+	fstream = p_new(pool, struct file_ostream, 1);
 	fstream->fd = fd;
 	fstream->priority = priority;
 	fstream->max_buffer_size = max_buffer_size;
--- a/src/lib/ostream-internal.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/ostream-internal.h	Sun Jan 05 15:09:51 2003 +0200
@@ -4,24 +4,23 @@
 #include "ostream.h"
 #include "iostream-internal.h"
 
-typedef struct __OStream _OStream;
-
-struct __OStream {
+struct _ostream {
 /* inheritance: */
-	_IOStream iostream;
+	struct _iostream iostream;
 
 /* methods: */
-	void (*cork)(_OStream *stream);
-	int (*flush)(_OStream *stream);
-	int (*have_space)(_OStream *stream, size_t size);
-	int (*seek)(_OStream *stream, uoff_t offset);
-	ssize_t (*send)(_OStream *stream, const void *data, size_t size);
-	off_t (*send_istream)(_OStream *outstream, IStream *instream);
+	void (*cork)(struct _ostream *stream);
+	int (*flush)(struct _ostream *stream);
+	int (*have_space)(struct _ostream *stream, size_t size);
+	int (*seek)(struct _ostream *stream, uoff_t offset);
+	ssize_t (*send)(struct _ostream *stream, const void *data, size_t size);
+	off_t (*send_istream)(struct _ostream *outstream,
+			      struct istream *instream);
 
 /* data: */
-	OStream ostream;
+	struct ostream ostream;
 };
 
-OStream *_o_stream_create(_OStream *_stream, Pool pool);
+struct ostream *_o_stream_create(struct _ostream *_stream, pool_t pool);
 
 #endif
--- a/src/lib/ostream.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/ostream.c	Sun Jan 05 15:09:51 2003 +0200
@@ -27,37 +27,37 @@
 #include "istream.h"
 #include "ostream-internal.h"
 
-void o_stream_ref(OStream *stream)
+void o_stream_ref(struct ostream *stream)
 {
 	_io_stream_ref(stream->real_stream);
 }
 
-void o_stream_unref(OStream *stream)
+void o_stream_unref(struct ostream *stream)
 {
 	_io_stream_unref(stream->real_stream);
 }
 
-void o_stream_close(OStream *stream)
+void o_stream_close(struct ostream *stream)
 {
 	_io_stream_close(stream->real_stream);
 	stream->closed = TRUE;
 }
 
-void o_stream_set_max_buffer_size(OStream *stream, size_t max_size)
+void o_stream_set_max_buffer_size(struct ostream *stream, size_t max_size)
 {
 	_io_stream_set_max_buffer_size(stream->real_stream, max_size);
 }
 
-void o_stream_set_blocking(OStream *stream, int timeout_msecs,
+void o_stream_set_blocking(struct ostream *stream, int timeout_msecs,
 			   void (*timeout_func)(void *), void *context)
 {
 	_io_stream_set_blocking(stream->real_stream, timeout_msecs,
 				timeout_func, context);
 }
 
-void o_stream_cork(OStream *stream)
+void o_stream_cork(struct ostream *stream)
 {
-	_OStream *_stream = stream->real_stream;
+	struct _ostream *_stream = stream->real_stream;
 
 	if (stream->closed)
 		return;
@@ -65,9 +65,9 @@
 	_stream->cork(_stream);
 }
 
-int o_stream_flush(OStream *stream)
+int o_stream_flush(struct ostream *stream)
 {
-	_OStream *_stream = stream->real_stream;
+	struct _ostream *_stream = stream->real_stream;
 
 	if (stream->closed)
 		return -1;
@@ -75,16 +75,16 @@
 	return _stream->flush(_stream);
 }
 
-int o_stream_have_space(OStream *stream, size_t size)
+int o_stream_have_space(struct ostream *stream, size_t size)
 {
-	_OStream *_stream = stream->real_stream;
+	struct _ostream *_stream = stream->real_stream;
 
 	return _stream->have_space(_stream, size);
 }
 
-int o_stream_seek(OStream *stream, uoff_t offset)
+int o_stream_seek(struct ostream *stream, uoff_t offset)
 {
-	_OStream *_stream = stream->real_stream;
+	struct _ostream *_stream = stream->real_stream;
 
 	if (stream->closed)
 		return -1;
@@ -92,9 +92,9 @@
 	return _stream->seek(_stream, offset);
 }
 
-ssize_t o_stream_send(OStream *stream, const void *data, size_t size)
+ssize_t o_stream_send(struct ostream *stream, const void *data, size_t size)
 {
-	_OStream *_stream = stream->real_stream;
+	struct _ostream *_stream = stream->real_stream;
 
 	if (stream->closed)
 		return -1;
@@ -105,14 +105,15 @@
 	return _stream->send(_stream, data, size);
 }
 
-ssize_t o_stream_send_str(OStream *stream, const char *str)
+ssize_t o_stream_send_str(struct ostream *stream, const char *str)
 {
 	return o_stream_send(stream, str, strlen(str));
 }
 
-off_t o_stream_send_istream(OStream *outstream, IStream *instream)
+off_t o_stream_send_istream(struct ostream *outstream,
+			    struct istream *instream)
 {
-	_OStream *_outstream = outstream->real_stream;
+	struct _ostream *_outstream = outstream->real_stream;
 
 	if (outstream->closed || instream->closed)
 		return -1;
@@ -120,7 +121,7 @@
 	return _outstream->send_istream(_outstream, instream);
 }
 
-OStream *_o_stream_create(_OStream *_stream, Pool pool)
+struct ostream *_o_stream_create(struct _ostream *_stream, pool_t pool)
 {
 	_stream->ostream.real_stream = _stream;
 
--- a/src/lib/ostream.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/ostream.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,7 +1,7 @@
 #ifndef __OSTREAM_H
 #define __OSTREAM_H
 
-struct _OStream {
+struct ostream {
 	uoff_t offset;
 
 	int stream_errno;
@@ -10,45 +10,47 @@
 	void *real_stream;
 };
 
-OStream *o_stream_create_file(int fd, Pool pool, size_t max_buffer_size,
-			      int priority, int autoclose_fd);
+struct ostream *
+o_stream_create_file(int fd, pool_t pool, size_t max_buffer_size,
+		     int priority, int autoclose_fd);
 
 /* Reference counting. References start from 1, so calling o_stream_unref()
    destroys the stream if o_stream_ref() is never used. */
-void o_stream_ref(OStream *stream);
-void o_stream_unref(OStream *stream);
+void o_stream_ref(struct ostream *stream);
+void o_stream_unref(struct ostream *stream);
 
 /* Mark the stream closed. Nothing will be sent after this call. */
-void o_stream_close(OStream *stream);
+void o_stream_close(struct ostream *stream);
 
 /* Change the maximum size for stream's output buffer to grow. */
-void o_stream_set_max_buffer_size(OStream *stream, size_t max_size);
+void o_stream_set_max_buffer_size(struct ostream *stream, size_t max_size);
 /* Stream is made to be flushed out whenever it gets full (assumes max_size
    is already set), ie. writes will never be partial. Also makes any blocking
    writes to fail after specified timeout, calling timeout_func if it's
    set. This call changes non-blocking state of file descriptor. */
-void o_stream_set_blocking(OStream *stream, int timeout_msecs,
+void o_stream_set_blocking(struct ostream *stream, int timeout_msecs,
 			   void (*timeout_func)(void *), void *context);
 
 /* Delays sending as far as possible, writing only full buffers. Also sets
    TCP_CORK on if supported. o_stream_flush() removes the cork. */
-void o_stream_cork(OStream *stream);
+void o_stream_cork(struct ostream *stream);
 /* Flush the output stream, blocks until everything is sent.
    Returns 1 if ok, -1 if error. */
-int o_stream_flush(OStream *stream);
+int o_stream_flush(struct ostream *stream);
 /* Returns 1 if specified amount of data currently fits into stream's output
    buffer, 0 if not. */
-int o_stream_have_space(OStream *stream, size_t size);
+int o_stream_have_space(struct ostream *stream, size_t size);
 
 /* Seek to specified position from beginning of file. This works only for
    files. Returns 1 if successful, -1 if error. */
-int o_stream_seek(OStream *stream, uoff_t offset);
+int o_stream_seek(struct ostream *stream, uoff_t offset);
 /* Returns number of bytes sent or buffered, or -1 if disconnected */
-ssize_t o_stream_send(OStream *stream, const void *data, size_t size);
-ssize_t o_stream_send_str(OStream *stream, const char *str);
+ssize_t o_stream_send(struct ostream *stream, const void *data, size_t size);
+ssize_t o_stream_send_str(struct ostream *stream, const char *str);
 /* Send data from input stream. Returns number of bytes sent, or -1 if error.
    Note that this function may block if either instream or outstream is
    blocking. */
-off_t o_stream_send_istream(OStream *outstream, IStream *instream);
+off_t o_stream_send_istream(struct ostream *outstream,
+			    struct istream *instream);
 
 #endif
--- a/src/lib/str.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/str.c	Sun Jan 05 15:09:51 2003 +0200
@@ -28,17 +28,17 @@
 
 #include <stdio.h>
 
-String *str_new(Pool pool, size_t initial_size)
+string_t *str_new(pool_t pool, size_t initial_size)
 {
 	return buffer_create_dynamic(pool, initial_size, (size_t)-1);
 }
 
-String *t_str_new(size_t initial_size)
+string_t *t_str_new(size_t initial_size)
 {
 	return str_new(data_stack_pool, initial_size);
 }
 
-static int str_add_nul(String *str)
+static int str_add_nul(string_t *str)
 {
 	size_t len;
 
@@ -59,7 +59,7 @@
 	return TRUE;
 }
 
-const char *str_c(String *str)
+const char *str_c(string_t *str)
 {
 	if (!str_add_nul(str))
 		return "";
@@ -67,12 +67,12 @@
 	return buffer_get_data(str, NULL);
 }
 
-const unsigned char *str_data(const String *str)
+const unsigned char *str_data(const string_t *str)
 {
 	return buffer_get_data(str, NULL);
 }
 
-char *str_c_modifyable(String *str)
+char *str_c_modifyable(string_t *str)
 {
 	if (!str_add_nul(str))
 		return NULL;
@@ -80,17 +80,17 @@
 	return buffer_get_modifyable_data(str, NULL);
 }
 
-size_t str_len(const String *str)
+size_t str_len(const string_t *str)
 {
 	return buffer_get_used_size(str);
 }
 
-void str_append(String *str, const char *cstr)
+void str_append(string_t *str, const char *cstr)
 {
 	buffer_append(str, cstr, strlen(cstr));
 }
 
-void str_append_n(String *str, const void *cstr, size_t max_len)
+void str_append_n(string_t *str, const void *cstr, size_t max_len)
 {
 	size_t len;
 
@@ -101,12 +101,12 @@
 	buffer_append(str, cstr, len);
 }
 
-void str_append_c(String *str, char chr)
+void str_append_c(string_t *str, char chr)
 {
 	buffer_append_c(str, chr);
 }
 
-void str_append_str(String *dest, const String *src)
+void str_append_str(string_t *dest, const string_t *src)
 {
 	const char *cstr;
 	size_t len;
@@ -115,7 +115,7 @@
 	buffer_append(dest, cstr, len);
 }
 
-void str_printfa(String *str, const char *fmt, ...)
+void str_printfa(string_t *str, const char *fmt, ...)
 {
 	va_list args;
 
@@ -124,7 +124,7 @@
 	va_end(args);
 }
 
-void str_vprintfa(String *str, const char *fmt, va_list args)
+void str_vprintfa(string_t *str, const char *fmt, va_list args)
 {
 	char *buf;
 	int ret;
@@ -153,12 +153,12 @@
 	buffer_set_used_size(str, len);
 }
 
-void str_delete(String *str, size_t pos, size_t len)
+void str_delete(string_t *str, size_t pos, size_t len)
 {
 	buffer_delete(str, pos, len);
 }
 
-void str_truncate(String *str, size_t len)
+void str_truncate(string_t *str, size_t len)
 {
 	buffer_set_used_size(str, len);
 }
--- a/src/lib/str.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/str.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,27 +1,27 @@
 #ifndef __STR_H
 #define __STR_H
 
-String *str_new(Pool pool, size_t initial_size);
-String *t_str_new(size_t initial_size);
+string_t *str_new(pool_t pool, size_t initial_size);
+string_t *t_str_new(size_t initial_size);
 
-const char *str_c(String *str);
-const unsigned char *str_data(const String *str);
-char *str_c_modifyable(String *str);
-size_t str_len(const String *str);
+const char *str_c(string_t *str);
+const unsigned char *str_data(const string_t *str);
+char *str_c_modifyable(string_t *str);
+size_t str_len(const string_t *str);
 
 /* Append string/character */
-void str_append(String *str, const char *cstr);
-void str_append_n(String *str, const void *cstr, size_t max_len);
-void str_append_c(String *str, char chr);
-void str_append_str(String *dest, const String *src);
+void str_append(string_t *str, const char *cstr);
+void str_append_n(string_t *str, const void *cstr, size_t max_len);
+void str_append_c(string_t *str, char chr);
+void str_append_str(string_t *dest, const string_t *src);
 
 /* Append printf()-like data */
-void str_printfa(String *str, const char *fmt, ...)
+void str_printfa(string_t *str, const char *fmt, ...)
 	__attr_format__(2, 3);
-void str_vprintfa(String *str, const char *fmt, va_list args);
+void str_vprintfa(string_t *str, const char *fmt, va_list args);
 
 /* Delete/truncate */
-void str_delete(String *str, size_t pos, size_t len);
-void str_truncate(String *str, size_t len);
+void str_delete(string_t *str, size_t pos, size_t len);
+void str_truncate(string_t *str, size_t len);
 
 #endif
--- a/src/lib/strescape.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/strescape.c	Sun Jan 05 15:09:51 2003 +0200
@@ -51,7 +51,7 @@
 	return ret;
 }
 
-void str_append_unescaped(String *dest, const void *src, size_t src_size)
+void str_append_unescaped(string_t *dest, const void *src, size_t src_size)
 {
 	const unsigned char *src_c = src;
 	size_t start = 0, i = 0;
--- a/src/lib/strescape.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/strescape.h	Sun Jan 05 15:09:51 2003 +0200
@@ -7,7 +7,7 @@
 const char *str_escape(const char *str);
 
 /* remove all '\' characters, append to given string */
-void str_append_unescaped(String *dest, const void *src, size_t src_size);
+void str_append_unescaped(string_t *dest, const void *src, size_t src_size);
 
 /* remove all '\' characters */
 void str_unescape(char *str);
--- a/src/lib/strfuncs.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/strfuncs.c	Sun Jan 05 15:09:51 2003 +0200
@@ -142,7 +142,7 @@
 	return ret;
 }
 
-char *p_strdup(Pool pool, const char *str)
+char *p_strdup(pool_t pool, const char *str)
 {
 	void *mem;
 	size_t len;
@@ -159,7 +159,7 @@
 	return mem;
 }
 
-char *p_strdup_empty(Pool pool, const char *str)
+char *p_strdup_empty(pool_t pool, const char *str)
 {
 	if (str == NULL || *str == '\0')
                 return NULL;
@@ -167,7 +167,7 @@
 	return p_strdup(pool, str);
 }
 
-char *p_strdup_until(Pool pool, const void *start, const void *end)
+char *p_strdup_until(pool_t pool, const void *start, const void *end)
 {
 	size_t size;
 	char *mem;
@@ -181,7 +181,7 @@
 	return mem;
 }
 
-char *p_strndup(Pool pool, const void *str, size_t max_chars)
+char *p_strndup(pool_t pool, const void *str, size_t max_chars)
 {
 	char *mem;
 	size_t len;
@@ -201,7 +201,7 @@
 	return mem;
 }
 
-char *p_strdup_printf(Pool pool, const char *format, ...)
+char *p_strdup_printf(pool_t pool, const char *format, ...)
 {
 	va_list args;
         char *ret;
@@ -213,7 +213,7 @@
 	return ret;
 }
 
-char *p_strdup_vprintf(Pool pool, const char *format, va_list args)
+char *p_strdup_vprintf(pool_t pool, const char *format, va_list args)
 {
 	char *ret;
 	va_list args2;
@@ -280,7 +280,7 @@
         return temp;
 }
 
-char *p_strconcat(Pool pool, const char *str1, ...)
+char *p_strconcat(pool_t pool, const char *str1, ...)
 {
 	va_list args;
         const char *temp;
--- a/src/lib/strfuncs.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/lib/strfuncs.h	Sun Jan 05 15:09:51 2003 +0200
@@ -12,13 +12,14 @@
 int i_snprintf(char *dest, size_t max_chars, const char *format, ...)
 	__attr_format__(3, 4);
 
-char *p_strdup(Pool pool, const char *str);
-char *p_strdup_empty(Pool pool, const char *str); /* return NULL if str = "" */
-char *p_strdup_until(Pool pool, const void *start, const void *end); /* *end isn't included */
-char *p_strndup(Pool pool, const void *str, size_t max_chars);
-char *p_strdup_printf(Pool pool, const char *format, ...) __attr_format__(2, 3);
-char *p_strdup_vprintf(Pool pool, const char *format, va_list args);
-char *p_strconcat(Pool pool, const char *str1, ...); /* NULL terminated */
+char *p_strdup(pool_t pool, const char *str);
+char *p_strdup_empty(pool_t pool, const char *str); /* return NULL if str = "" */
+char *p_strdup_until(pool_t pool, const void *start, const void *end); /* *end isn't included */
+char *p_strndup(pool_t pool, const void *str, size_t max_chars);
+char *p_strdup_printf(pool_t pool, const char *format, ...)
+	__attr_format__(2, 3);
+char *p_strdup_vprintf(pool_t pool, const char *format, va_list args);
+char *p_strconcat(pool_t pool, const char *str1, ...); /* NULL terminated */
 
 /* same with temporary memory allocations: */
 const char *t_strdup(const char *str);
--- a/src/login/auth-connection.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/auth-connection.c	Sun Jan 05 15:09:51 2003 +0200
@@ -12,43 +12,44 @@
 #include <dirent.h>
 #include <sys/stat.h>
 
-#define MAX_INBUF_SIZE (AUTH_MAX_REQUEST_DATA_SIZE)
+#define MAX_INBUF_SIZE AUTH_MAX_REQUEST_DATA_SIZE
 #define MAX_OUTBUF_SIZE \
-	(sizeof(AuthContinuedRequestData) + AUTH_MAX_REQUEST_DATA_SIZE)
+	(sizeof(struct auth_continued_request_data) + \
+	 AUTH_MAX_REQUEST_DATA_SIZE)
 
-struct _AuthConnection {
-	AuthConnection *next;
+struct auth_connection {
+	struct auth_connection *next;
 
 	char *path;
 	int fd;
-	IO io;
-	IStream *input;
-	OStream *output;
+	struct io *io;
+	struct istream *input;
+	struct ostream *output;
 
 	unsigned int auth_process;
-	AuthMethod available_auth_methods;
-        AuthReplyData in_reply;
+	enum auth_method available_auth_methods;
+        struct auth_reply_data in_reply;
 
-        HashTable *requests;
+        struct hash_table *requests;
 
 	unsigned int init_received:1;
 	unsigned int in_reply_received:1;
 };
 
-AuthMethod available_auth_methods;
+enum auth_method available_auth_methods;
 
 static int auth_reconnect;
 static unsigned int request_id_counter;
-static AuthConnection *auth_connections;
-static Timeout to;
+static struct auth_connection *auth_connections;
+static struct timeout *to;
 
-static void auth_connection_destroy(AuthConnection *conn);
-static void auth_input(void *context, int fd, IO io);
+static void auth_connection_destroy(struct auth_connection *conn);
+static void auth_input(void *context, int fd, struct io *io);
 static void auth_connect_missing(void);
 
-static AuthConnection *auth_connection_find(const char *path)
+static struct auth_connection *auth_connection_find(const char *path)
 {
-	AuthConnection *conn;
+	struct auth_connection *conn;
 
 	for (conn = auth_connections; conn != NULL; conn = conn->next) {
 		if (strcmp(conn->path, path) == 0)
@@ -58,10 +59,10 @@
 	return NULL;
 }
 
-static AuthConnection *auth_connection_new(const char *path)
+static struct auth_connection *auth_connection_new(const char *path)
 {
-	AuthConnection *conn;
-        ClientAuthInitData init_data;
+	struct auth_connection *conn;
+        struct client_auth_init_data init_data;
 	int fd;
 
 	fd = net_connect_unix(path);
@@ -71,7 +72,7 @@
 		return NULL;
 	}
 
-	conn = i_new(AuthConnection, 1);
+	conn = i_new(struct auth_connection, 1);
 	conn->path = i_strdup(path);
 	conn->fd = fd;
 	conn->io = io_add(fd, IO_READ, auth_input, conn);
@@ -94,13 +95,13 @@
 	return conn;
 }
 
-static void request_destroy(AuthRequest *request)
+static void request_destroy(struct auth_request *request)
 {
 	hash_remove(request->conn->requests, POINTER_CAST(request->id));
 	i_free(request);
 }
 
-static void request_abort(AuthRequest *request)
+static void request_abort(struct auth_request *request)
 {
 	request->callback(request, request->conn->auth_process,
 			  AUTH_RESULT_INTERNAL_FAILURE,
@@ -115,9 +116,9 @@
 	request_abort(value);
 }
 
-static void auth_connection_destroy(AuthConnection *conn)
+static void auth_connection_destroy(struct auth_connection *conn)
 {
-	AuthConnection **pos;
+	struct auth_connection **pos;
 
 	for (pos = &auth_connections; *pos != NULL; pos = &(*pos)->next) {
 		if (*pos == conn) {
@@ -138,10 +139,10 @@
 	i_free(conn);
 }
 
-static AuthConnection *auth_connection_get(AuthMethod method, size_t size,
-					   const char **error)
+static struct auth_connection *
+auth_connection_get(enum auth_method method, size_t size, const char **error)
 {
-	AuthConnection *conn;
+	struct auth_connection *conn;
 	int found;
 
 	found = FALSE;
@@ -172,14 +173,15 @@
 
 static void update_available_auth_methods(void)
 {
-	AuthConnection *conn;
+	struct auth_connection *conn;
 
         available_auth_methods = 0;
 	for (conn = auth_connections; conn != NULL; conn = conn->next)
                 available_auth_methods |= conn->available_auth_methods;
 }
 
-static void auth_handle_init(AuthConnection *conn, AuthInitData *init_data)
+static void auth_handle_init(struct auth_connection *conn,
+			     struct auth_init_data *init_data)
 {
 	conn->auth_process = init_data->auth_process;
 	conn->available_auth_methods = init_data->auth_methods;
@@ -188,10 +190,11 @@
 	update_available_auth_methods();
 }
 
-static void auth_handle_reply(AuthConnection *conn, AuthReplyData *reply_data,
+static void auth_handle_reply(struct auth_connection *conn,
+			      struct auth_reply_data *reply_data,
 			      const unsigned char *data)
 {
-	AuthRequest *request;
+	struct auth_request *request;
 
 	request = hash_lookup(conn->requests, POINTER_CAST(reply_data->id));
 	if (request == NULL) {
@@ -214,10 +217,10 @@
 }
 
 static void auth_input(void *context, int fd __attr_unused__,
-		       IO io __attr_unused__)
+		       struct io *io __attr_unused__)
 {
-	AuthConnection *conn = context;
-        AuthInitData init_data;
+	struct auth_connection *conn = context;
+        struct auth_init_data init_data;
 	const unsigned char *data;
 	size_t size;
 
@@ -240,15 +243,17 @@
 	data = i_stream_get_data(conn->input, &size);
 
 	if (!conn->init_received) {
-		if (size == sizeof(AuthInitData)) {
-			memcpy(&init_data, data, sizeof(AuthInitData));
-			i_stream_skip(conn->input, sizeof(AuthInitData));
+		if (size == sizeof(struct auth_init_data)) {
+			memcpy(&init_data, data, sizeof(struct auth_init_data));
+			i_stream_skip(conn->input,
+				      sizeof(struct auth_init_data));
 
 			auth_handle_init(conn, &init_data);
-		} else if (size > sizeof(AuthInitData)) {
+		} else if (size > sizeof(struct auth_init_data)) {
 			i_error("BUG: imap-auth sent us too much "
 				"initialization data (%"PRIuSIZE_T " vs %"
-				PRIuSIZE_T")", size, sizeof(AuthInitData));
+				PRIuSIZE_T")", size,
+				sizeof(struct auth_init_data));
 			auth_connection_destroy(conn);
 		}
 
@@ -257,13 +262,13 @@
 
 	if (!conn->in_reply_received) {
 		data = i_stream_get_data(conn->input, &size);
-		if (size < sizeof(AuthReplyData))
+		if (size < sizeof(struct auth_reply_data))
 			return;
 
-		memcpy(&conn->in_reply, data, sizeof(AuthReplyData));
-		data += sizeof(AuthReplyData);
-		size -= sizeof(AuthReplyData);
-		i_stream_skip(conn->input, sizeof(AuthReplyData));
+		memcpy(&conn->in_reply, data, sizeof(struct auth_reply_data));
+		data += sizeof(struct auth_reply_data);
+		size -= sizeof(struct auth_reply_data);
+		i_stream_skip(conn->input, sizeof(struct auth_reply_data));
 		conn->in_reply_received = TRUE;
 	}
 
@@ -276,22 +281,22 @@
 	i_stream_skip(conn->input, conn->in_reply.data_size);
 }
 
-int auth_init_request(AuthMethod method, AuthCallback callback,
+int auth_init_request(enum auth_method method, AuthCallback callback,
 		      void *context, const char **error)
 {
-	AuthConnection *conn;
-	AuthRequest *request;
-	AuthInitRequestData request_data;
+	struct auth_connection *conn;
+	struct auth_request *request;
+	struct auth_init_request_data request_data;
 
 	if (auth_reconnect)
 		auth_connect_missing();
 
-	conn = auth_connection_get(method, sizeof(AuthInitRequestData), error);
+	conn = auth_connection_get(method, sizeof(request_data), error);
 	if (conn == NULL)
 		return FALSE;
 
 	/* create internal request structure */
-	request = i_new(AuthRequest, 1);
+	request = i_new(struct auth_request, 1);
 	request->method = method;
 	request->conn = conn;
 	request->id = ++request_id_counter;
@@ -310,10 +315,10 @@
 	return TRUE;
 }
 
-void auth_continue_request(AuthRequest *request, const unsigned char *data,
-			   size_t data_size)
+void auth_continue_request(struct auth_request *request,
+			   const unsigned char *data, size_t data_size)
 {
-	AuthContinuedRequestData request_data;
+	struct auth_continued_request_data request_data;
 
 	/* send continued request to auth */
 	memcpy(request_data.cookie, request->cookie, AUTH_COOKIE_SIZE);
@@ -362,8 +367,9 @@
 	(void)closedir(dirp);
 }
 
-static void auth_connect_missing_timeout(void *context __attr_unused__,
-					 Timeout timeout __attr_unused__)
+static void
+auth_connect_missing_timeout(void *context __attr_unused__,
+			     struct timeout *timeout __attr_unused__)
 {
 	if (auth_reconnect)
                 auth_connect_missing();
@@ -381,7 +387,7 @@
 
 void auth_connection_deinit(void)
 {
-	AuthConnection *next;
+	struct auth_connection *next;
 
 	while (auth_connections != NULL) {
 		next = auth_connections->next;
--- a/src/login/auth-connection.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/auth-connection.h	Sun Jan 05 15:09:51 2003 +0200
@@ -1,17 +1,18 @@
 #ifndef __AUTH_CONNECTION_H
 #define __AUTH_CONNECTION_H
 
-typedef struct _AuthConnection AuthConnection;
+struct auth_request;
 
 /* If result == AUTH_RESULT_INTERNAL_FAILURE, request may be NULL and
    reply_data_size contains the error message. */
-typedef void (*AuthCallback)(AuthRequest *request, unsigned int auth_process,
-			     AuthResult result, const unsigned char *reply_data,
+typedef void (*AuthCallback)(struct auth_request *request,
+			     unsigned int auth_process, enum auth_result result,
+			     const unsigned char *reply_data,
 			     size_t reply_data_size, void *context);
 
-struct _AuthRequest {
-        AuthMethod method;
-        AuthConnection *conn;
+struct auth_request {
+        enum auth_method method;
+        struct auth_connection *conn;
 
 	unsigned int id;
 	unsigned char cookie[AUTH_COOKIE_SIZE];
@@ -22,13 +23,13 @@
 	unsigned int init_sent:1;
 };
 
-extern AuthMethod available_auth_methods;
+extern enum auth_method available_auth_methods;
 
-int auth_init_request(AuthMethod method, AuthCallback callback,
+int auth_init_request(enum auth_method method, AuthCallback callback,
 		      void *context, const char **error);
 
-void auth_continue_request(AuthRequest *request, const unsigned char *data,
-			   size_t data_size);
+void auth_continue_request(struct auth_request *request,
+			   const unsigned char *data, size_t data_size);
 
 void auth_connection_init(void);
 void auth_connection_deinit(void);
--- a/src/login/client-authenticate.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/client-authenticate.c	Sun Jan 05 15:09:51 2003 +0200
@@ -13,23 +13,23 @@
 #include "client-authenticate.h"
 #include "master.h"
 
-typedef struct {
+struct auth_method_desc {
 	int method;
 	const char *name;
 	int plaintext;
-} AuthMethodDesc;
+};
 
-static AuthMethod auth_methods = 0;
+static enum auth_method auth_methods = 0;
 static char *auth_methods_capability = NULL;
 
-static AuthMethodDesc auth_method_desc[AUTH_METHODS_COUNT] = {
+static struct auth_method_desc auth_method_desc[AUTH_METHODS_COUNT] = {
 	{ AUTH_METHOD_PLAIN,		NULL,		TRUE },
 	{ AUTH_METHOD_DIGEST_MD5,	"DIGEST-MD5",	FALSE }
 };
 
 const char *client_authenticate_get_capabilities(void)
 {
-	String *str;
+	string_t *str;
 	int i;
 
 	if (auth_methods == available_auth_methods)
@@ -53,7 +53,7 @@
 	return auth_methods_capability;
 }
 
-static AuthMethodDesc *auth_method_find(const char *name)
+static struct auth_method_desc *auth_method_find(const char *name)
 {
 	int i;
 
@@ -66,7 +66,7 @@
 	return NULL;
 }
 
-static void client_auth_abort(Client *client, const char *msg)
+static void client_auth_abort(struct client *client, const char *msg)
 {
 	client->auth_request = NULL;
 
@@ -83,9 +83,9 @@
 	client_unref(client);
 }
 
-static void master_callback(MasterReplyResult result, void *context)
+static void master_callback(enum master_reply_result result, void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 
 	switch (result) {
 	case MASTER_RESULT_SUCCESS:
@@ -101,10 +101,10 @@
 	}
 }
 
-static void client_send_auth_data(Client *client, const unsigned char *data,
-				  size_t size)
+static void client_send_auth_data(struct client *client,
+				  const unsigned char *data, size_t size)
 {
-	Buffer *buf;
+	buffer_t *buf;
 
 	t_push();
 
@@ -120,11 +120,12 @@
 	t_pop();
 }
 
-static int auth_callback(AuthRequest *request, unsigned int auth_process,
-			 AuthResult result, const unsigned char *reply_data,
+static int auth_callback(struct auth_request *request,
+			 unsigned int auth_process, enum auth_result result,
+			 const unsigned char *reply_data,
 			 size_t reply_data_size, void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 
 	switch (result) {
 	case AUTH_RESULT_CONTINUE:
@@ -164,11 +165,12 @@
 	}
 }
 
-static void login_callback(AuthRequest *request, unsigned int auth_process,
-			   AuthResult result, const unsigned char *reply_data,
+static void login_callback(struct auth_request *request,
+			   unsigned int auth_process, enum auth_result result,
+			   const unsigned char *reply_data,
 			   size_t reply_data_size, void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 	const void *ptr;
 	size_t size;
 
@@ -181,7 +183,7 @@
 	}
 }
 
-int cmd_login(Client *client, const char *user, const char *pass)
+int cmd_login(struct client *client, const char *user, const char *pass)
 {
 	const char *error;
 
@@ -216,12 +218,13 @@
 	}
 }
 
-static void authenticate_callback(AuthRequest *request,
-				  unsigned int auth_process, AuthResult result,
+static void authenticate_callback(struct auth_request *request,
+				  unsigned int auth_process,
+				  enum auth_result result,
 				  const unsigned char *reply_data,
 				  size_t reply_data_size, void *context)
 {
-	Client *client = context;
+	struct client *client = context;
 
 	if (auth_callback(request, auth_process, result,
 			  reply_data, reply_data_size, context))
@@ -229,10 +232,10 @@
 }
 
 static void client_auth_input(void *context, int fd __attr_unused__,
-			      IO io __attr_unused__)
+			      struct io *io __attr_unused__)
 {
-	Client *client = context;
-	Buffer *buf;
+	struct client *client = context;
+	buffer_t *buf;
 	char *line;
 	size_t linelen, bufsize;
 
@@ -270,9 +273,9 @@
 	safe_memset(buffer_free_without_data(buf), 0, bufsize);
 }
 
-int cmd_authenticate(Client *client, const char *method_name)
+int cmd_authenticate(struct client *client, const char *method_name)
 {
-	AuthMethodDesc *method;
+	struct auth_method_desc *method;
 	const char *error;
 
 	if (*method_name == '\0')
--- a/src/login/client-authenticate.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/client-authenticate.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,7 +3,7 @@
 
 const char *client_authenticate_get_capabilities(void);
 
-int cmd_login(Client *client, const char *user, const char *pass);
-int cmd_authenticate(Client *client, const char *method_name);
+int cmd_login(struct client *client, const char *user, const char *pass);
+int cmd_authenticate(struct client *client, const char *method_name);
 
 #endif
--- a/src/login/client.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/client.c	Sun Jan 05 15:09:51 2003 +0200
@@ -23,10 +23,10 @@
    client hash, it's faster if we disconnect multiple clients. */
 #define CLIENT_DESTROY_OLDEST_COUNT 16
 
-static HashTable *clients;
-static Timeout to_idle;
+static struct hash_table *clients;
+static struct timeout *to_idle;
 
-static void client_set_title(Client *client)
+static void client_set_title(struct client *client)
 {
 	const char *host;
 
@@ -41,7 +41,7 @@
 					  host));
 }
 
-static int cmd_capability(Client *client)
+static int cmd_capability(struct client *client)
 {
 	const char *capability;
 
@@ -56,7 +56,7 @@
 	return TRUE;
 }
 
-static int cmd_starttls(Client *client)
+static int cmd_starttls(struct client *client)
 {
 	int fd_ssl;
 
@@ -104,13 +104,13 @@
 	return TRUE;
 }
 
-static int cmd_noop(Client *client)
+static int cmd_noop(struct client *client)
 {
 	client_send_tagline(client, "OK NOOP completed.");
 	return TRUE;
 }
 
-static int cmd_logout(Client *client)
+static int cmd_logout(struct client *client)
 {
 	client_send_line(client, "* BYE Logging out");
 	client_send_tagline(client, "OK Logout completed.");
@@ -118,7 +118,7 @@
 	return TRUE;
 }
 
-int client_read(Client *client)
+int client_read(struct client *client)
 {
 	switch (i_stream_read(client->input)) {
 	case -2:
@@ -172,7 +172,7 @@
 	return start;
 }
 
-static int client_command_execute(Client *client, char *line)
+static int client_command_execute(struct client *client, char *line)
 {
 	char *cmd;
 	int ret;
@@ -205,9 +205,9 @@
 }
 
 void client_input(void *context, int fd __attr_unused__,
-		  IO io __attr_unused__)
+		  struct io *io __attr_unused__)
 {
-	Client *client = context;
+	struct client *client = context;
 	char *line;
 
 	client->last_input = ioloop_time;
@@ -242,18 +242,18 @@
 static void client_hash_destroy_oldest(void *key, void *value __attr_unused__,
 				       void *context)
 {
-	Client *client = key;
-	Buffer *destroy_buf = context;
-	Client *const *destroy_clients;
+	struct client *client = key;
+	struct client *const *destroy_clients;
+	buffer_t *destroy_buf = context;
 	size_t i, count;
 
 	destroy_clients = buffer_get_data(destroy_buf, &count);
-	count /= sizeof(Client *);
+	count /= sizeof(struct client *);
 
 	for (i = 0; i < count; i++) {
 		if (destroy_clients[i]->created > client->created) {
-			buffer_insert(destroy_buf, i * sizeof(Client *),
-				      &client, sizeof(client));
+			buffer_insert(destroy_buf, i * sizeof(struct client *),
+				      &client, sizeof(struct client *));
 			break;
 		}
 	}
@@ -261,19 +261,19 @@
 
 static void client_destroy_oldest(void)
 {
-	Buffer *destroy_buf;
-	Client *const *destroy_clients;
+	struct client *const *destroy_clients;
+	buffer_t *destroy_buf;
 	size_t i, count;
 
 	/* find the oldest clients and put them to destroy-buffer */
 	destroy_buf = buffer_create_static_hard(data_stack_pool,
-						sizeof(Client *) *
+						sizeof(struct client *) *
 						CLIENT_DESTROY_OLDEST_COUNT);
 	hash_foreach(clients, client_hash_destroy_oldest, destroy_buf);
 
 	/* then kill them */
 	destroy_clients = buffer_get_data(destroy_buf, &count);
-	count /= sizeof(Client *);
+	count /= sizeof(struct client *);
 
 	for (i = 0; i < count; i++) {
 		client_destroy(destroy_clients[i],
@@ -281,9 +281,9 @@
 	}
 }
 
-Client *client_create(int fd, IPADDR *ip, int imaps)
+struct client *client_create(int fd, struct ip_addr *ip, int imaps)
 {
-	Client *client;
+	struct client *client;
 
 	if (max_logging_users > CLIENT_DESTROY_OLDEST_COUNT &&
 	    hash_size(clients) >= max_logging_users) {
@@ -295,12 +295,12 @@
 	/* always use nonblocking I/O */
 	net_set_nonblock(fd, TRUE);
 
-	client = i_new(Client, 1);
+	client = i_new(struct client, 1);
 	client->created = ioloop_time;
 	client->refcount = 1;
 	client->tls = imaps;
 
-	memcpy(&client->ip, ip, sizeof(IPADDR));
+	memcpy(&client->ip, ip, sizeof(struct ip_addr));
 	client->fd = fd;
 	client->io = io_add(fd, IO_READ, client_input, client);
 	client->input = i_stream_create_file(fd, default_pool, 8192, FALSE);
@@ -317,7 +317,7 @@
 	return client;
 }
 
-void client_destroy(Client *client, const char *reason)
+void client_destroy(struct client *client, const char *reason)
 {
 	if (reason != NULL)
 		client_syslog(client, reason);
@@ -338,12 +338,12 @@
 	client_unref(client);
 }
 
-void client_ref(Client *client)
+void client_ref(struct client *client)
 {
 	client->refcount++;
 }
 
-int client_unref(Client *client)
+int client_unref(struct client *client)
 {
 	if (--client->refcount > 0)
 		return TRUE;
@@ -359,18 +359,18 @@
 	return FALSE;
 }
 
-void client_send_line(Client *client, const char *line)
+void client_send_line(struct client *client, const char *line)
 {
 	o_stream_send_str(client->output, line);
 	o_stream_send(client->output, "\r\n", 2);
 }
 
-void client_send_tagline(Client *client, const char *line)
+void client_send_tagline(struct client *client, const char *line)
 {
 	client_send_line(client, t_strconcat(client->tag, " ", line, NULL));
 }
 
-void client_syslog(Client *client, const char *text)
+void client_syslog(struct client *client, const char *text)
 {
 	const char *host;
 
@@ -384,7 +384,7 @@
 static void client_hash_check_idle(void *key, void *value __attr_unused__,
 				   void *context __attr_unused__)
 {
-	Client *client = key;
+	struct client *client = key;
 
 	if (ioloop_time - client->last_input >= CLIENT_LOGIN_IDLE_TIMEOUT) {
 		client_send_line(client, "* BYE Disconnected for inactivity.");
@@ -393,7 +393,7 @@
 }
 
 static void idle_timeout(void *context __attr_unused__,
-			 Timeout timeout __attr_unused__)
+			 struct timeout *timeout __attr_unused__)
 {
 	hash_foreach(clients, client_hash_check_idle, NULL);
 }
--- a/src/login/client.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/client.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,37 +3,37 @@
 
 #include "network.h"
 
-struct _Client {
+struct client {
 	time_t created;
 	int refcount;
-	IPADDR ip;
+	struct ip_addr ip;
 
 	int fd;
-	IO io;
-	IStream *input;
-	OStream *output;
+	struct io *io;
+	struct istream *input;
+	struct ostream *output;
 
 	time_t last_input;
 	char *tag;
 
-	Buffer *plain_login;
-	AuthRequest *auth_request;
+	buffer_t *plain_login;
+	struct auth_request *auth_request;
 
 	unsigned int tls:1;
 };
 
-Client *client_create(int fd, IPADDR *ip, int imaps);
-void client_destroy(Client *client, const char *reason);
+struct client *client_create(int fd, struct ip_addr *ip, int imaps);
+void client_destroy(struct client *client, const char *reason);
 
-void client_ref(Client *client);
-int client_unref(Client *client);
+void client_ref(struct client *client);
+int client_unref(struct client *client);
 
-void client_send_line(Client *client, const char *line);
-void client_send_tagline(Client *client, const char *line);
-void client_syslog(Client *client, const char *text);
+void client_send_line(struct client *client, const char *line);
+void client_send_tagline(struct client *client, const char *line);
+void client_syslog(struct client *client, const char *text);
 
-int client_read(Client *client);
-void client_input(void *context, int fd, IO io);
+int client_read(struct client *client);
+void client_input(void *context, int fd, struct io *io);
 
 unsigned int clients_get_count(void);
 void clients_destroy_all(void);
--- a/src/login/main.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/main.c	Sun Jan 05 15:09:51 2003 +0200
@@ -19,8 +19,8 @@
 unsigned int max_logging_users;
 unsigned int login_process_uid;
 
-static IOLoop ioloop;
-static IO io_imap, io_imaps;
+static struct ioloop *ioloop;
+static struct io *io_imap, *io_imaps;
 static int main_refcount;
 static int closing_down;
 
@@ -72,9 +72,9 @@
 }
 
 static void login_accept(void *context __attr_unused__, int listen_fd,
-			 IO io __attr_unused__)
+			 struct io *io __attr_unused__)
 {
-	IPADDR ip;
+	struct ip_addr ip;
 	int fd;
 
 	fd = net_accept(listen_fd, &ip, NULL);
@@ -91,10 +91,10 @@
 }
 
 static void login_accept_ssl(void *context __attr_unused__, int listen_fd,
-			     IO io __attr_unused__)
+			     struct io *io __attr_unused__)
 {
-	Client *client;
-	IPADDR addr;
+	struct client *client;
+	struct ip_addr addr;
 	int fd, fd_ssl;
 
 	fd = net_accept(listen_fd, &addr, NULL);
--- a/src/login/master.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/master.c	Sun Jan 05 15:09:51 2003 +0200
@@ -9,28 +9,26 @@
 
 #include <unistd.h>
 
-typedef struct _WaitingRequest WaitingRequest;
-
-struct _WaitingRequest {
-	WaitingRequest *next;
+struct waiting_request {
+	struct waiting_request *next;
 
 	unsigned int id;
 	MasterCallback callback;
 	void *context;
 };
 
-static IO io_master;
-static WaitingRequest *requests, **next_request;
+static struct io *io_master;
+static struct waiting_request *requests, **next_request;
 
 static unsigned int master_pos;
-static char master_buf[sizeof(MasterReply)];
+static char master_buf[sizeof(struct master_reply)];
 
 static void push_request(unsigned int id, MasterCallback callback,
 			 void *context)
 {
-	WaitingRequest *req;
+	struct waiting_request *req;
 
-	req = i_new(WaitingRequest, 1);
+	req = i_new(struct waiting_request, 1);
 	req->id = id;
 	req->callback = callback;
 	req->context = context;
@@ -39,9 +37,9 @@
 	next_request = &req->next;
 }
 
-static void pop_request(MasterReply *reply)
+static void pop_request(struct master_reply *reply)
 {
-	WaitingRequest *req;
+	struct waiting_request *req;
 
 	req = requests;
 	if (req == NULL) {
@@ -66,17 +64,18 @@
 
 void master_request_imap(int fd, unsigned int auth_process,
 			 const char *login_tag,
-			 unsigned char cookie[AUTH_COOKIE_SIZE], IPADDR *ip,
+			 unsigned char cookie[AUTH_COOKIE_SIZE],
+			 struct ip_addr *ip,
 			 MasterCallback callback, void *context)
 {
-	MasterRequest req;
+	struct master_request req;
 
 	i_assert(fd > 1);
 
 	memset(&req, 0, sizeof(req));
 	req.id = fd;
 	req.auth_process = auth_process;
-	memcpy(&req.ip, ip, sizeof(IPADDR));
+	memcpy(&req.ip, ip, sizeof(struct ip_addr));
 	memcpy(req.cookie, cookie, AUTH_COOKIE_SIZE);
 
 	if (strocpy(req.login_tag, login_tag, sizeof(req.login_tag)) < 0)
@@ -91,7 +90,7 @@
 
 void master_notify_finished(void)
 {
-	MasterRequest req;
+	struct master_request req;
 
 	if (io_master == NULL)
 		return;
@@ -122,7 +121,7 @@
 }
 
 static void master_input(void *context __attr_unused__, int fd,
-			 IO io __attr_unused__)
+			 struct io *io __attr_unused__)
 {
 	int ret;
 
@@ -139,7 +138,7 @@
 		return;
 
 	/* reply is now read */
-	pop_request((MasterReply *) master_buf);
+	pop_request((struct master_reply *) master_buf);
 	master_pos = 0;
 }
 
@@ -156,7 +155,7 @@
 
 void master_deinit(void)
 {
-	WaitingRequest *next;
+	struct waiting_request *next;
 
 	while (requests != NULL) {
 		next = requests->next;
--- a/src/login/master.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/master.h	Sun Jan 05 15:09:51 2003 +0200
@@ -3,12 +3,13 @@
 
 #include "../master/master-interface.h"
 
-typedef void (*MasterCallback)(MasterReplyResult result, void *context);
+typedef void (*MasterCallback)(enum master_reply_result result, void *context);
 
 /* Request IMAP process for given cookie. */
 void master_request_imap(int fd, unsigned int auth_process,
 			 const char *login_tag,
-			 unsigned char cookie[AUTH_COOKIE_SIZE], IPADDR *ip,
+			 unsigned char cookie[AUTH_COOKIE_SIZE],
+			 struct ip_addr *ip,
 			 MasterCallback callback, void *context);
 
 /* Notify master that we're not listening for new connections anymore. */
--- a/src/login/ssl-proxy-gnutls.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/ssl-proxy-gnutls.c	Sun Jan 05 15:09:51 2003 +0200
@@ -14,19 +14,19 @@
 #include <gcrypt.h>
 #include <gnutls/gnutls.h>
 
-typedef struct {
+struct ssl_proxy {
 	int refcount;
 
 	gnutls_session session;
 	int fd_ssl, fd_plain;
-	IO io_ssl, io_plain;
+	struct io *io_ssl, *io_plain;
 	int io_ssl_dir;
 
 	unsigned char outbuf_plain[1024];
 	unsigned int outbuf_pos_plain;
 
 	size_t send_left_ssl, send_left_plain;
-} SSLProxy;
+};
 
 const int protocol_priority[] =
 	{ GNUTLS_TLS1, GNUTLS_SSL3, 0 };
@@ -46,16 +46,16 @@
 static gnutls_dh_params dh_params;
 static gnutls_rsa_params rsa_params;
 
-static void ssl_input(void *context, int handle, IO io);
-static void plain_input(void *context, int handle, IO io);
-static int ssl_proxy_destroy(SSLProxy *proxy);
+static void ssl_input(void *context, int handle, struct io *io);
+static void plain_input(void *context, int handle, struct io *io);
+static int ssl_proxy_destroy(struct ssl_proxy *proxy);
 
-static const char *get_alert_text(SSLProxy *proxy)
+static const char *get_alert_text(struct ssl_proxy *proxy)
 {
 	return gnutls_alert_get_name(gnutls_alert_get(proxy->session));
 }
 
-static int handle_ssl_error(SSLProxy *proxy, int error)
+static int handle_ssl_error(struct ssl_proxy *proxy, int error)
 {
 	if (!gnutls_error_is_fatal(error)) {
 		if (error == GNUTLS_E_WARNING_ALERT_RECEIVED) {
@@ -79,7 +79,7 @@
 	return -1;
 }
 
-static int proxy_recv_ssl(SSLProxy *proxy, void *data, size_t size)
+static int proxy_recv_ssl(struct ssl_proxy *proxy, void *data, size_t size)
 {
 	int rcvd;
 
@@ -98,7 +98,8 @@
 	return handle_ssl_error(proxy, rcvd);
 }
 
-static int proxy_send_ssl(SSLProxy *proxy, const void *data, size_t size)
+static int proxy_send_ssl(struct ssl_proxy *proxy,
+			  const void *data, size_t size)
 {
 	int sent;
 
@@ -107,7 +108,8 @@
 		return sent;
 
 	if (sent == GNUTLS_E_PUSH_ERROR || sent == GNUTLS_E_INVALID_SESSION) {
-		/* don't warn about errors related to unexpected disconnection */
+		/* don't warn about errors related to unexpected
+		   disconnection */
 		ssl_proxy_destroy(proxy);
 		return -1;
 	}
@@ -115,7 +117,7 @@
 	return handle_ssl_error(proxy, sent);
 }
 
-static int ssl_proxy_destroy(SSLProxy *proxy)
+static int ssl_proxy_destroy(struct ssl_proxy *proxy)
 {
 	if (--proxy->refcount > 0)
 		return TRUE;
@@ -137,9 +139,9 @@
 }
 
 static void ssl_output(void *context, int fd __attr_unused__,
-		       IO io __attr_unused__)
+		       struct io *io __attr_unused__)
 {
-        SSLProxy *proxy = context;
+        struct ssl_proxy *proxy = context;
 	int sent;
 
 	sent = net_transmit(proxy->fd_plain,
@@ -163,9 +165,9 @@
 }
 
 static void ssl_input(void *context, int fd __attr_unused__,
-		      IO io __attr_unused__)
+		      struct io *io __attr_unused__)
 {
-        SSLProxy *proxy = context;
+        struct ssl_proxy *proxy = context;
 	int rcvd, sent;
 
 	rcvd = proxy_recv_ssl(proxy, proxy->outbuf_plain,
@@ -193,9 +195,9 @@
 }
 
 static void plain_output(void *context, int fd __attr_unused__,
-			 IO io __attr_unused__)
+			 struct io *io __attr_unused__)
 {
-	SSLProxy *proxy = context;
+	struct ssl_proxy *proxy = context;
 	int sent;
 
 	sent = proxy_send_ssl(proxy, NULL, proxy->send_left_ssl);
@@ -212,9 +214,9 @@
 }
 
 static void plain_input(void *context, int fd __attr_unused__,
-			IO io __attr_unused__)
+			struct io *io __attr_unused__)
 {
-	SSLProxy *proxy = context;
+	struct ssl_proxy *proxy = context;
 	char buf[1024];
 	ssize_t rcvd, sent;
 
@@ -239,9 +241,9 @@
 }
 
 static void ssl_handshake(void *context, int fd __attr_unused__,
-			  IO io __attr_unused__)
+			  struct io *io __attr_unused__)
 {
-	SSLProxy *proxy = context;
+	struct ssl_proxy *proxy = context;
 	int ret, dir;
 
         ret = gnutls_handshake(proxy->session);
@@ -291,7 +293,7 @@
 
 int ssl_proxy_new(int fd)
 {
-        SSLProxy *proxy;
+        struct ssl_proxy *proxy;
 	gnutls_session session;
 	int sfd[2];
 
@@ -310,7 +312,7 @@
 	net_set_nonblock(sfd[0], TRUE);
 	net_set_nonblock(sfd[1], TRUE);
 
-	proxy = i_new(SSLProxy, 1);
+	proxy = i_new(struct ssl_proxy, 1);
 	proxy->refcount = 1;
 	proxy->session = session;
 	proxy->fd_ssl = fd;
--- a/src/login/ssl-proxy-openssl.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/login/ssl-proxy-openssl.c	Sun Jan 05 15:09:51 2003 +0200
@@ -13,17 +13,17 @@
 #include <openssl/ssl.h>
 #include <openssl/err.h>
 
-typedef enum {
+enum ssl_state {
 	SSL_STATE_HANDSHAKE,
 	SSL_STATE_READ,
 	SSL_STATE_WRITE
-} SSLState;
+};
 
-typedef struct {
+struct ssl_proxy {
 	int refcount;
 
 	SSL *ssl;
-        SSLState state;
+        enum ssl_state state;
 
 	int fd_ssl, fd_plain;
 	IO io_ssl, io_plain_read, io_plain_write;
@@ -34,17 +34,17 @@
 
 	unsigned char sslout_buf[1024];
 	unsigned int sslout_pos, sslout_size;
-} SSLProxy;
+};
 
 static SSL_CTX *ssl_ctx;
 
-static void plain_read(SSLProxy *proxy);
-static void plain_write(SSLProxy *proxy);
+static void plain_read(struct ssl_proxy *proxy);
+static void plain_write(struct ssl_proxy *proxy);
 
-static int ssl_proxy_destroy(SSLProxy *proxy);
-static void ssl_set_direction(SSLProxy *proxy, int dir);
+static int ssl_proxy_destroy(struct ssl_proxy *proxy);
+static void ssl_set_direction(struct ssl_proxy *proxy, int dir);
 
-static void plain_block_input(SSLProxy *proxy, int block)
+static void plain_block_input(struct ssl_proxy *proxy, int block)
 {
 	if (block) {
 		if (proxy->io_plain_read != NULL) {
@@ -60,7 +60,7 @@
 	}
 }
 
-static void ssl_block(SSLProxy *proxy, int block)
+static void ssl_block(struct ssl_proxy *proxy, int block)
 {
 	i_assert(proxy->state == SSL_STATE_READ);
 
@@ -77,7 +77,7 @@
 	}
 }
 
-static void plain_read(SSLProxy *proxy)
+static void plain_read(struct ssl_proxy *proxy)
 {
 	ssize_t ret;
 
@@ -98,7 +98,7 @@
 	}
 }
 
-static void plain_write(SSLProxy *proxy)
+static void plain_write(struct ssl_proxy *proxy)
 {
 	ssize_t ret;
 
@@ -147,7 +147,7 @@
 	return buf;
 }
 
-static void ssl_handle_error(SSLProxy *proxy, int err, const char *func)
+static void ssl_handle_error(struct ssl_proxy *proxy, int err, const char *func)
 {
 	err = SSL_get_error(proxy->ssl, err);
 
@@ -179,7 +179,7 @@
 	}
 }
 
-static void ssl_handshake_step(SSLProxy *proxy)
+static void ssl_handshake_step(struct ssl_proxy *proxy)
 {
 	int ret;
 
@@ -194,7 +194,7 @@
 	}
 }
 
-static void ssl_read_step(SSLProxy *proxy)
+static void ssl_read_step(struct ssl_proxy *proxy)
 {
 	int ret;
 
@@ -215,7 +215,7 @@
 	}
 }
 
-static void ssl_write_step(SSLProxy *proxy)
+static void ssl_write_step(struct ssl_proxy *proxy)
 {
 	int ret;
 
@@ -244,7 +244,7 @@
 static void ssl_step(void *context, int fd __attr_unused__,
 		     IO io __attr_unused__)
 {
-        SSLProxy *proxy = context;
+        struct ssl_proxy *proxy = context;
 
 	switch (proxy->state) {
 	case SSL_STATE_HANDSHAKE:
@@ -259,7 +259,7 @@
 	}
 }
 
-static void ssl_set_direction(SSLProxy *proxy, int dir)
+static void ssl_set_direction(struct ssl_proxy *proxy, int dir)
 {
 	i_assert(proxy->io_ssl_dir != -2);
 
@@ -273,7 +273,7 @@
 
 int ssl_proxy_new(int fd)
 {
-	SSLProxy *proxy;
+	struct ssl_proxy *proxy;
 	SSL *ssl;
 	int sfd[2];
 
@@ -301,7 +301,7 @@
 	net_set_nonblock(sfd[0], TRUE);
 	net_set_nonblock(sfd[1], TRUE);
 
-	proxy = i_new(SSLProxy, 1);
+	proxy = i_new(struct ssl_proxy, 1);
 	proxy->refcount = 1;
 	proxy->ssl = ssl;
 	proxy->fd_ssl = fd;
@@ -319,7 +319,7 @@
 	return sfd[1];
 }
 
-static int ssl_proxy_destroy(SSLProxy *proxy)
+static int ssl_proxy_destroy(struct ssl_proxy *proxy)
 {
 	if (--proxy->refcount > 0)
 		return TRUE;
--- a/src/master/auth-process.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/master/auth-process.c	Sun Jan 05 15:09:51 2003 +0200
@@ -16,42 +16,40 @@
 #include <syslog.h>
 #include <sys/stat.h>
 
-typedef struct _WaitingRequest WaitingRequest;
-
-struct _AuthProcess {
-	AuthProcess *next;
+struct auth_process {
+	struct auth_process *next;
 
 	char *name;
 	pid_t pid;
 	int fd;
-	IO io;
-	OStream *output;
+	struct io *io;
+	struct ostream *output;
 
 	unsigned int reply_pos;
-	char reply_buf[sizeof(AuthCookieReplyData)];
+	char reply_buf[sizeof(struct auth_cookie_reply_data)];
 
-	WaitingRequest *requests, **next_request;
+	struct waiting_request *requests, **next_request;
 };
 
-struct _WaitingRequest {
-        WaitingRequest *next;
+struct waiting_request {
+        struct waiting_request *next;
 	unsigned int id;
 
 	AuthCallback callback;
 	void *context;
 };
 
-static Timeout to;
-static AuthProcess *processes;
+static struct timeout *to;
+static struct auth_process *processes;
 
-static void auth_process_destroy(AuthProcess *p);
+static void auth_process_destroy(struct auth_process *p);
 
-static void push_request(AuthProcess *process, unsigned int id,
+static void push_request(struct auth_process *process, unsigned int id,
 			 AuthCallback callback, void *context)
 {
-	WaitingRequest *req;
+	struct waiting_request *req;
 
-	req = i_new(WaitingRequest, 1);
+	req = i_new(struct waiting_request, 1);
 	req->id = id;
 	req->callback = callback;
 	req->context = context;
@@ -60,9 +58,10 @@
 	process->next_request = &req->next;
 }
 
-static void pop_request(AuthProcess *process, AuthCookieReplyData *reply)
+static void pop_request(struct auth_process *process,
+			struct auth_cookie_reply_data *reply)
 {
-	WaitingRequest *req;
+	struct waiting_request *req;
 
 	req = process->requests;
 	if (req == NULL) {
@@ -96,9 +95,10 @@
 	i_free(req);
 }
 
-static void auth_process_input(void *context, int fd, IO io __attr_unused__)
+static void auth_process_input(void *context, int fd,
+			       struct io *io __attr_unused__)
 {
-	AuthProcess *p = context;
+	struct auth_process *p = context;
 	int ret;
 
 	ret = net_receive(fd, p->reply_buf + p->reply_pos,
@@ -114,24 +114,25 @@
 		return;
 
 	/* reply is now read */
-	pop_request(p, (AuthCookieReplyData *) p->reply_buf);
+	pop_request(p, (struct auth_cookie_reply_data *) p->reply_buf);
 	p->reply_pos = 0;
 }
 
-static AuthProcess *auth_process_new(pid_t pid, int fd, const char *name)
+static struct auth_process *
+auth_process_new(pid_t pid, int fd, const char *name)
 {
-	AuthProcess *p;
+	struct auth_process *p;
 
 	PID_ADD_PROCESS_TYPE(pid, PROCESS_TYPE_AUTH);
 
-	p = i_new(AuthProcess, 1);
+	p = i_new(struct auth_process, 1);
 	p->name = i_strdup(name);
 	p->pid = pid;
 	p->fd = fd;
 	p->io = io_add(fd, IO_READ, auth_process_input, p);
 	p->output = o_stream_create_file(fd, default_pool,
-					 sizeof(AuthCookieRequestData)*100,
-					 IO_PRIORITY_DEFAULT, FALSE);
+				sizeof(struct auth_cookie_request_data)*100,
+				IO_PRIORITY_DEFAULT, FALSE);
 
 	p->next_request = &p->requests;
 
@@ -140,10 +141,10 @@
 	return p;
 }
 
-static void auth_process_destroy(AuthProcess *p)
+static void auth_process_destroy(struct auth_process *p)
 {
-	AuthProcess **pos;
-	WaitingRequest *next;
+	struct auth_process **pos;
+	struct waiting_request *next;
 
 	for (pos = &processes; *pos != NULL; pos = &(*pos)->next) {
 		if (*pos == p) {
@@ -169,7 +170,7 @@
 	i_free(p);
 }
 
-static pid_t create_auth_process(AuthConfig *config)
+static pid_t create_auth_process(struct auth_config *config)
 {
 	static char *argv[] = { NULL, NULL };
 	const char *path;
@@ -275,9 +276,9 @@
 	return -1;
 }
 
-AuthProcess *auth_process_find(unsigned int id)
+struct auth_process *auth_process_find(unsigned int id)
 {
-	AuthProcess *p;
+	struct auth_process *p;
 
 	for (p = processes; p != NULL; p = p->next) {
 		if ((unsigned int)p->pid == id)
@@ -288,11 +289,11 @@
 }
 
 void auth_process_request(unsigned int login_pid,
-			  AuthProcess *process, unsigned int id,
+			  struct auth_process *process, unsigned int id,
 			  unsigned char cookie[AUTH_COOKIE_SIZE],
 			  AuthCallback callback, void *context)
 {
-	AuthCookieRequestData req;
+	struct auth_cookie_request_data req;
 
 	req.id = id;
 	req.login_pid = login_pid;
@@ -306,7 +307,7 @@
 
 static unsigned int auth_process_get_count(const char *name)
 {
-	AuthProcess *p;
+	struct auth_process *p;
 	unsigned int count = 0;
 
 	for (p = processes; p != NULL; p = p->next) {
@@ -319,7 +320,7 @@
 
 void auth_processes_destroy_all(void)
 {
-	AuthProcess *next;
+	struct auth_process *next;
 
 	while (processes != NULL) {
 		next = processes->next;
@@ -328,10 +329,11 @@
 	}
 }
 
-static void auth_processes_start_missing(void *context __attr_unused__,
-					 Timeout timeout __attr_unused__)
+static void
+auth_processes_start_missing(void *context __attr_unused__,
+			     struct timeout *timeout __attr_unused__)
 {
-	AuthConfig *config;
+	struct auth_config *config;
 	unsigned int count;
 
         config = auth_processes_config;
--- a/src/master/auth-process.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/master/auth-process.h	Sun Jan 05 15:09:51 2003 +0200
@@ -2,17 +2,15 @@
 #define __AUTH_PROCESS_H
 
 /* cookie_reply is NULL if some error occured */
-typedef void (*AuthCallback)(AuthCookieReplyData *cookie_reply,
+typedef void (*AuthCallback)(struct auth_cookie_reply_data *cookie_reply,
 			     void *context);
 
-typedef struct _AuthProcess AuthProcess;
-
 /* Find process for given id */
-AuthProcess *auth_process_find(unsigned int id);
+struct auth_process *auth_process_find(unsigned int id);
 
 /* Request information about given cookie */
 void auth_process_request(unsigned int login_pid,
-			  AuthProcess *process, unsigned int id,
+			  struct auth_process *process, unsigned int id,
 			  unsigned char cookie[AUTH_COOKIE_SIZE],
 			  AuthCallback callback, void *context);
 
--- a/src/master/common.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/master/common.h	Sun Jan 05 15:09:51 2003 +0200
@@ -18,7 +18,7 @@
 	PROCESS_TYPE_MAX
 };
 
-extern HashTable *pids;
+extern struct hash_table *pids;
 extern int null_fd, imap_fd, imaps_fd;
 
 /* processes */
@@ -33,12 +33,11 @@
 
 void clean_child_process(void);
 
-MasterReplyResult create_imap_process(int socket, IPADDR *ip,
-				      const char *system_user,
-				      const char *virtual_user,
-				      uid_t uid, gid_t gid, const char *home,
-				      int chroot, const char *mail,
-				      const char *login_tag);
+enum master_reply_result
+create_imap_process(int socket, struct ip_addr *ip,
+		    const char *system_user, const char *virtual_user,
+		    uid_t uid, gid_t gid, const char *home, int chroot,
+		    const char *mail, const char *login_tag);
 void imap_process_destroyed(pid_t pid);
 
 /* misc */
--- a/src/master/imap-process.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/master/imap-process.c	Sun Jan 05 15:09:51 2003 +0200
@@ -67,7 +67,7 @@
 static const char *expand_mail_env(const char *env, const char *user,
 				   const char *home)
 {
-	String *str;
+	string_t *str;
 	const char *p, *var;
 	unsigned int width;
 
@@ -139,12 +139,11 @@
 	return str_c(str);
 }
 
-MasterReplyResult create_imap_process(int socket, IPADDR *ip,
-				      const char *system_user,
-				      const char *virtual_user,
-				      uid_t uid, gid_t gid, const char *home,
-				      int chroot, const char *mail,
-				      const char *login_tag)
+enum master_reply_result
+create_imap_process(int socket, struct ip_addr *ip,
+		    const char *system_user, const char *virtual_user,
+		    uid_t uid, gid_t gid, const char *home, int chroot,
+		    const char *mail, const char *login_tag)
 {
 	static char *argv[] = { NULL, NULL, NULL };
 	const char *host;
--- a/src/master/login-process.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/master/login-process.c	Sun Jan 05 15:09:51 2003 +0200
@@ -16,46 +16,46 @@
 #include <unistd.h>
 #include <syslog.h>
 
-typedef struct _LoginProcess LoginProcess;
-
-struct _LoginProcess {
-	LoginProcess *prev_nonlisten, *next_nonlisten;
+struct login_process {
+	struct login_process *prev_nonlisten, *next_nonlisten;
 	int refcount;
 
 	pid_t pid;
 	int fd;
-	IO io;
-	OStream *output;
+	struct io *io;
+	struct ostream *output;
 	unsigned int listening:1;
 	unsigned int destroyed:1;
 };
 
-typedef struct {
-	LoginProcess *process;
+struct login_auth_request {
+	struct login_process *process;
 	unsigned int login_id;
 	unsigned int auth_id;
 	int fd;
 
-	IPADDR ip;
+	struct ip_addr ip;
 	char login_tag[LOGIN_TAG_SIZE];
-} LoginAuthRequest;
+};
 
 static unsigned int auth_id_counter;
-static Timeout to;
+static struct timeout *to;
 
-static HashTable *processes;
-static LoginProcess *oldest_nonlisten_process, *newest_nonlisten_process;
+static struct hash_table *processes;
+static struct login_process *oldest_nonlisten_process;
+static struct login_process *newest_nonlisten_process;
 static unsigned int listening_processes;
 static unsigned int wanted_processes_count;
 
-static void login_process_destroy(LoginProcess *p);
-static void login_process_unref(LoginProcess *p);
+static void login_process_destroy(struct login_process *p);
+static void login_process_unref(struct login_process *p);
 
-static void auth_callback(AuthCookieReplyData *cookie_reply, void *context)
+static void auth_callback(struct auth_cookie_reply_data *cookie_reply,
+			  void *context)
 {
-	LoginAuthRequest *request = context;
-        LoginProcess *process;
-	MasterReply reply;
+	struct login_auth_request *request = context;
+        struct login_process *process;
+	struct master_reply reply;
 
 	if (cookie_reply == NULL || !cookie_reply->success)
 		reply.result = MASTER_RESULT_FAILURE;
@@ -85,7 +85,7 @@
 	i_free(request);
 }
 
-static void login_process_mark_nonlistening(LoginProcess *p)
+static void login_process_mark_nonlistening(struct login_process *p)
 {
 	if (!p->listening) {
 		i_error("login: received another \"not listening\" "
@@ -107,12 +107,12 @@
 }
 
 static void login_process_input(void *context, int fd __attr_unused__,
-				IO io __attr_unused__)
+				struct io *io __attr_unused__)
 {
-	LoginProcess *p = context;
-	AuthProcess *auth_process;
-	LoginAuthRequest *authreq;
-	MasterRequest req;
+	struct login_process *p = context;
+	struct auth_process *auth_process;
+	struct login_auth_request *authreq;
+	struct master_request req;
 	int client_fd, ret;
 
 	ret = fd_read(p->fd, &req, sizeof(req), &client_fd);
@@ -146,13 +146,13 @@
 	}
 
 	/* ask the cookie from the auth process */
-	authreq = i_new(LoginAuthRequest, 1);
+	authreq = i_new(struct login_auth_request, 1);
 	p->refcount++;
 	authreq->process = p;
 	authreq->login_id = req.id;
 	authreq->auth_id = ++auth_id_counter;
 	authreq->fd = client_fd;
-	memcpy(&authreq->ip, &req.ip, sizeof(IPADDR));
+	memcpy(&authreq->ip, &req.ip, sizeof(struct ip_addr));
 	if (strocpy(authreq->login_tag, req.login_tag,
 		    sizeof(authreq->login_tag)) < 0)
 		i_panic("login_tag overflow");
@@ -168,20 +168,20 @@
 	}
 }
 
-static LoginProcess *login_process_new(pid_t pid, int fd)
+static struct login_process *login_process_new(pid_t pid, int fd)
 {
-	LoginProcess *p;
+	struct login_process *p;
 
 	PID_ADD_PROCESS_TYPE(pid, PROCESS_TYPE_LOGIN);
 
-	p = i_new(LoginProcess, 1);
+	p = i_new(struct login_process, 1);
 	p->refcount = 1;
 	p->pid = pid;
 	p->fd = fd;
 	p->listening = TRUE;
 	p->io = io_add(fd, IO_READ, login_process_input, p);
 	p->output = o_stream_create_file(fd, default_pool,
-					 sizeof(MasterReply)*10,
+					 sizeof(struct master_reply)*10,
 					 IO_PRIORITY_DEFAULT, FALSE);
 
 	hash_insert(processes, POINTER_CAST(pid), p);
@@ -189,7 +189,7 @@
 	return p;
 }
 
-static void login_process_remove_from_lists(LoginProcess *p)
+static void login_process_remove_from_lists(struct login_process *p)
 {
 	if (p == oldest_nonlisten_process)
 		oldest_nonlisten_process = p->next_nonlisten;
@@ -204,7 +204,7 @@
 	p->next_nonlisten = p->prev_nonlisten = NULL;
 }
 
-static void login_process_destroy(LoginProcess *p)
+static void login_process_destroy(struct login_process *p)
 {
 	if (p->destroyed)
 		return;
@@ -226,7 +226,7 @@
 	login_process_unref(p);
 }
 
-static void login_process_unref(LoginProcess *p)
+static void login_process_unref(struct login_process *p)
 {
 	if (--p->refcount > 0)
 		return;
@@ -369,8 +369,9 @@
 	wanted_processes_count = 0;
 }
 
-static void login_processes_start_missing(void *context __attr_unused__,
-					  Timeout timeout __attr_unused__)
+static void
+login_processes_start_missing(void *context __attr_unused__,
+			      struct timeout *timeout __attr_unused__)
 {
 	if (!set_login_process_per_connection) {
 		/* create max. one process every second, that way if it keeps
--- a/src/master/main.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/master/main.c	Sun Jan 05 15:09:51 2003 +0200
@@ -28,10 +28,10 @@
 };
 
 static const char *configfile = SYSCONFDIR "/" PACKAGE ".conf";
-static IOLoop ioloop;
-static Timeout to;
+static struct ioloop *ioloop;
+static struct timeout *to;
 
-HashTable *pids;
+struct hash_table *pids;
 int null_fd, imap_fd, imaps_fd;
 
 int validate_str(const char *str, size_t max_len)
@@ -82,7 +82,7 @@
         auth_processes_destroy_all();
 }
 
-static const char *get_exit_status_message(FatalExitStatus status)
+static const char *get_exit_status_message(enum fatal_exit_status status)
 {
 	switch (status) {
 	case FATAL_LOGOPEN:
@@ -104,7 +104,7 @@
 }
 
 static void timeout_handler(void *context __attr_unused__,
-			    Timeout timeout __attr_unused__)
+			    struct timeout *timeout __attr_unused__)
 {
 	const char *process_type_name, *msg;
 	pid_t pid;
@@ -150,9 +150,9 @@
 		i_warning("waitpid() failed: %m");
 }
 
-static IPADDR *resolve_ip(const char *name)
+static struct ip_addr *resolve_ip(const char *name)
 {
-	IPADDR *ip;
+	struct ip_addr *ip;
 	int ret, ips_count;
 
 	if (name == NULL)
@@ -160,14 +160,14 @@
 
 	if (strcmp(name, "*") == 0) {
 		/* IPv4 any */
-		ip = t_new(IPADDR, 1);
+		ip = t_new(struct ip_addr, 1);
 		net_get_ip_any4(ip);
 		return ip;
 	}
 
 	if (strcmp(name, "::") == 0) {
 		/* IPv6 any */
-		ip = t_new(IPADDR, 1);
+		ip = t_new(struct ip_addr, 1);
 		net_get_ip_any6(ip);
 		return ip;
 	}
@@ -187,7 +187,7 @@
 
 static void open_fds(void)
 {
-	IPADDR *imap_ip, *imaps_ip;
+	struct ip_addr *imap_ip, *imaps_ip;
 
 	imap_ip = resolve_ip(set_imap_listen);
 	imaps_ip = resolve_ip(set_imaps_listen);
--- a/src/master/master-interface.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/master/master-interface.h	Sun Jan 05 15:09:51 2003 +0200
@@ -10,25 +10,25 @@
 #define LOGIN_IMAP_LISTEN_FD 1
 #define LOGIN_IMAPS_LISTEN_FD 2
 
-typedef enum {
+enum master_reply_result {
 	MASTER_RESULT_INTERNAL_FAILURE,
 	MASTER_RESULT_SUCCESS,
 	MASTER_RESULT_FAILURE
-} MasterReplyResult;
+};
 
-typedef struct {
+struct master_request {
 	unsigned int id;
 
 	unsigned int auth_process;
 	unsigned char cookie[AUTH_COOKIE_SIZE];
 
-	IPADDR ip;
+	struct ip_addr ip;
 	char login_tag[LOGIN_TAG_SIZE];
-} MasterRequest;
+};
 
-typedef struct {
+struct master_reply {
 	unsigned int id;
-        MasterReplyResult result;
-} MasterReply;
+	enum master_reply_result result;
+};
 
 #endif
--- a/src/master/settings.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/master/settings.c	Sun Jan 05 15:09:51 2003 +0200
@@ -11,19 +11,19 @@
 #include <fcntl.h>
 #include <pwd.h>
 
-typedef enum {
+enum setting_type {
 	SET_STR,
 	SET_INT,
 	SET_BOOL
-} SettingType;
+};
 
-typedef struct {
+struct setting {
 	const char *name;
-	SettingType type;
+	enum setting_type type;
 	void *ptr;
-} Setting;
+};
 
-static Setting settings[] = {
+static struct setting settings[] = {
 	{ "base_dir",		SET_STR, &set_base_dir },
 	{ "log_path",		SET_STR, &set_log_path },
 	{ "info_log_path",	SET_STR, &set_info_log_path },
@@ -146,7 +146,7 @@
 unsigned int set_umask = 0077;
 
 /* auth */
-AuthConfig *auth_processes_config = NULL;
+struct auth_config *auth_processes_config = NULL;
 
 static void fix_base_path(char **str)
 {
@@ -172,7 +172,7 @@
 
 static void auth_settings_verify(void)
 {
-	AuthConfig *auth;
+	struct auth_config *auth;
 
 	for (auth = auth_processes_config; auth != NULL; auth = auth->next) {
 		if (access(auth->executable, X_OK) < 0) {
@@ -311,11 +311,11 @@
 	auth_settings_verify();
 }
 
-static AuthConfig *auth_config_new(const char *name)
+static struct auth_config *auth_config_new(const char *name)
 {
-	AuthConfig *auth;
+	struct auth_config *auth;
 
-	auth = i_new(AuthConfig, 1);
+	auth = i_new(struct auth_config, 1);
 	auth->name = i_strdup(name);
 	auth->executable = i_strdup(PKG_LIBEXECDIR"/imap-auth");
 	auth->count = 1;
@@ -325,7 +325,7 @@
 	return auth;
 }
 
-static void auth_config_free(AuthConfig *auth)
+static void auth_config_free(struct auth_config *auth)
 {
 	i_free(auth->name);
 	i_free(auth->methods);
@@ -340,7 +340,7 @@
 
 static const char *parse_new_auth(const char *name)
 {
-	AuthConfig *auth;
+	struct auth_config *auth;
 
 	if (strchr(name, '/') != NULL)
 		return "Authentication process name must not contain '/'";
@@ -358,7 +358,7 @@
 
 static const char *parse_auth(const char *key, const char *value)
 {
-	AuthConfig *auth = auth_processes_config;
+	struct auth_config *auth = auth_processes_config;
 	const char *p;
 	char **ptr;
 
@@ -423,7 +423,7 @@
 
 static const char *parse_setting(const char *key, const char *value)
 {
-	Setting *set;
+	struct setting *set;
 
 	if (strcmp(key, "auth") == 0)
 		return parse_new_auth(value);
@@ -464,7 +464,7 @@
 static void settings_free(void)
 {
 	while (auth_processes_config != NULL) {
-		AuthConfig *auth = auth_processes_config;
+		struct auth_config *auth = auth_processes_config;
 
 		auth_processes_config = auth->next;
                 auth_config_free(auth);
@@ -475,7 +475,7 @@
 
 void settings_read(const char *path)
 {
-	IStream *input;
+	struct istream *input;
 	const char *errormsg;
 	char *line, *key, *p;
 	int fd, linenum;
@@ -545,7 +545,7 @@
 
 void settings_init(void)
 {
-	Setting *set;
+	struct setting *set;
 
 	/* strdup() all default settings */
 	for (set = settings; set->name != NULL; set++) {
--- a/src/master/settings.h	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/master/settings.h	Sun Jan 05 15:09:51 2003 +0200
@@ -60,10 +60,8 @@
 extern unsigned int set_umask;
 
 /* auth */
-typedef struct _AuthConfig AuthConfig;
-
-struct _AuthConfig {
-	AuthConfig *next;
+struct auth_config {
+	struct auth_config *next;
 
 	char *name;
 	char *methods;
@@ -77,7 +75,7 @@
 	unsigned int process_size;
 };
 
-extern AuthConfig *auth_processes_config;
+extern struct auth_config *auth_processes_config;
 
 void settings_read(const char *path);
 
--- a/src/master/ssl-init.c	Sun Jan 05 11:23:13 2003 +0200
+++ b/src/master/ssl-init.c	Sun Jan 05 15:09:51 2003 +0200
@@ -12,7 +12,7 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 
-static Timeout to;
+static struct timeout *to;
 static int generating;
 
 static void generate_parameters_file(const char *fname)