2004-04-28  Ilja Booij  <ilja@ic-s.nl>

	* auth/authsql.c (auth_adduser): no longer creates the mailbox
	for the new user.

	* user.c (do_add): calls db_createmailbox() to create mailbox
	for the new user.

2004-04-28  Aaron Stone  <aaron@serendipity.cx>

	* header.c (read_header): switched from fread to fgetc.
	* pipe.c (store_message_temp): switched from fread to fgetc.
	* main.c (print_usage): added two spaces to line up the columns.

2004-04-23  Aaron Stone  <aaron@serendipity.cx>

	* dsn.c/dsn.h (dsn_tostring): added new function dsn_tostring,
	which take a delivery_status_t argument and returns corresponding
	text for the class, subject and detail codes.
	* header.c (read_header): switched from fgets to fread.
	* pipe.c (store_message_temp): switched from fgets to fread.

2004-04-22  Ilja Booij  <ilja@ic-s.nl>

	* auth/authsql.c (auth_adduser): now adds the current timestamp
	in the last_login field of the users table if a user is added.

2004-04-21  Ilja Booij  <ilja@ic-s.nl>

	* imap4.c (IMAPClientHandler): changed i to size_t

	* imaputil.c (stridx): changed return type to size_t

	* imapcommands.c (_ic_authenticate): no checks return value of
	fgets.

	* header.c (read_header): added some my_free statements for
	freeing tmpheader on unexpected events (read errors etc).

	* forward.c (forward): prevented some buffer overflows by
	using snprintf instead if sprintf.

	* dbsearch.c (db_exec_search): added a return statement
	for case IST_DATA_TEXT. Otherwise, it could fall through
	to IST_DATA_BODY.

	* bounce.c (bounce): changed sprintf to snprintf and added
	free statements for freeing sendmail_command.

	* db.c (db_get_reply_body): fixed a FIXME by replacing complex
	code with a strdup()
	(db_isselectable): fixed a FIXME by adding extra check
	(db_noinferiors):  fixed a FIXME by adding extra check
	(db_getmailboxname): fixed a FIXME by replacing complex
	code with a strdup()
	(db_update_pop): added a check to only calculate the new quotum
	if the user_idnr is set earlier in the function.
	(db_send_message_lines): added check to fwrite. This is needed
	for when fwrite fails.
	(db_list_mailboxes_by_regex): free temporay arrays if malloc
	fails.

2004-04-19  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_get_deliver_from_alias): now returns strdup() of ""
	instead of the literal itself. Also, we just use strdup() to
	copy the query result to a new string.
	(db_get_notify_address): use strdup instead of complicated stuff..

	* config.c (ReadConfig): added checks to satisfy splint warnings
	(GetConfigValue): corrected some checks that did not work in the
	form they were in (tests for null pointers that were never null!)

	* acl.c (acl_get_acl): added checks and annotations.
	(acl_listrights): changed to return a string that has
	to be freed by caller. added splint annotation.

	* auth.h: (auth_user_exists) added splint annotation to 'out' 
	parameter.

	* pipe.c (send_reply): initialise escaped_send_address to hold only '\0'
	characters before sprintf-inf to it.
	(execute_auto_ran): check if GetConfigValue() actually works.
	(execute_auto_ran): changed some function calls to include checks for
	return values indicating errors.
	(discard_client_input): changed return type to int to be able to signal
	error.
	(discard_client_input): changed handling of fgets to be able to continue
	in case of a failing fgets().
	(store_message_temp): solved some possible memory leaks. Added some extra
	checks for return values.

2004-04-16  Ilja Booij  <ilja@ic-s.nl>

	* pipe.c (send_notification): fixed some possible memory leaks
	and error-prone statements (sprintf to snprintf), thanks to
	using splint.
	(send_reply): fixed some possible memory leaks
	and error-prone statements (sprintf to snprintf), thanks to
	using splint. 

	* imap4.c: ci_write() function removed (moved to imap4.c)

	* imaputil.c (ci_write): ci_write function is now added to 
	imaputil.c (was in imap4.c)

	* imapcommands.c: all fprintf statements are replaced by ci_write 
	calls to add error checking.

2004-04-15  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_check_quotum_used): changed query so it also returns 1 if
	over quotum on PostgreSQL (and Oracle). Added db_free_result() to 
	also free result if over quotum. The function now just checks if the
	query returns any rows.
	

2004-04-14  Ilja Booij  <ilja@ic-s.nl>

	* header.c (read_header): use strncat instead of strncpy to add new
	line to message

	* mysql/dbmysql.c: auth_res removed

	* mime.c (mime_readheader): now makes a copy of the block data before
	finding headers. Before, the block data was altered, which it should
	not be doing! The block is now passed a const char*

	* pgsql/dbpgsql.c: auth_res removed

	* db.c (db_get_notify_address): changed query_result to const char*
	(db_get_reply_body): changed query_result to const char*
	(db_get_useridnr): changed query_result to const char*
	(db_icheck_messageblks): changed query_result to const char*
	(db_icheck_messages): changed query_result to const char*
	(db_icheck_mailboxes): changed query_result to const char*
	(db_icheck_null_physmessages): changed query_result to const char*
	(db_send_message_lines): changed query_result to const char*
	(db_createsession): changed query_result to const char*
	(db_listmailboxchildren): changed query_result to const char*
	(db_isselectable): changed query_result to const char*
	(db_noinferiors): changed query_result to const char*
	(db_get_message_size): changed query_result to const char*
	(db_getmailboxname): changed query_result to const char*
	(db_get_msgdate): changed query_result to const char*
	(db_get_main_header): changed query_result to const char*
	(db_get_user_aliases): changed query_result to const char*
	(db_acl_get_identifier): changed query_result to const char*
	(db_get_result_int): changed tmp to const char*
	(db_get_result_bool): changed tmp to const char*
	(db_get_result_u64): changed tmp to const char*

	* dbsearch.c (db_search_range): changed query_result to const char*

	* auth/authsql.c (auth_user_exists): changed query_result to
	const char*
	(auth_get_known_users): changed_query result to const char*
	(auth_getclientid): changed query_result to const char*
	(auth_getmaxmailsize): changed query_result to const char*
	(auth_getencryption): changed query_result to const char*
	(auth_check_user): changed query_result to const char*
	(auth_check_user_ext): changed query_result to const char*
	(auth_validate): changed query_result to const char*
	(auth_md5_validate): changed query_result to const char*
	(auth_get_userid): changed query_result to const char*

	* dbmsgbuf.c (db_init_msgfetch): added a memset() to clear msgbuf before
	anything is written to it.

2004-04-13  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_findmailbox_by_regex): corrected a small error. There was a check to see
	if nchildren == 0, which should of course be *nchildren == 0
	(db_list_mailboxes_by_regex): now stores all info from database before constructing
	full names of mailboxes. 

2004-04-08  Ilja Booij  <ilja@ic-s.nl>

	* pipe.c (insert_messages): now does an extra check. If a recipient is bound
	to be labelled with TEMP_FAIL, a final check is made to check if perhaps we
	only need to forward the messages to another server. If this is the case,
	it gets the DSN_CLASS_OK label.

	* auth/authsql.c (auth_user_exists): removed use of 
	db_use_auth_result() and db_store_auth_result().
	(auth_get_known_users): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_getclientid): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_getmaxmailsize): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_getencryption):  removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_check_user): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_check_user_ext): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_adduser): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_delete_user):  removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_change_username): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_change_password): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_change_clientid): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_change_mailboxsize): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_validate): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_md5_validate): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(auth_get_userid): removed use of db_use_auth_result() and 
	db_store_auth_result().
	(__auth_insert_result): removed use of db_use_auth_result() and 
	db_store_auth_result().

	* mysql/dbmysql.c: removed db_store_auth_result(), db_use_auth_result()

	* pgsql/dbpgsql.c: removed db_store_auth_result(), db_use_auth_result()
	
2004-04-05  Ilja Booij  <ilja@ic-s.nl>

	* serverchild.c (SetChildSigHandler): add handler for SIGCHLD
	(ChildSigHandler): add case in switch for handling SIGCHLD, by
	just ignoring it!

	* db.c (db_insert_message_block_physmessage): added a memset() to
	clear the escaped_query string before using it.

	* dbsearch.c (db_search_range): corrected query to use physmessage
	table. This error was found by Paul F. De La Cruz and a fix
	was provided by Paul J Stevens.

2004-04-02  Ilja Booij  <ilja@ic-s.nl>

	* header.c (read_header): at one place, read_header returned -1,
	instead of 0.

	* auth/authsql.c (auth_validate): checks if username or password
	is NULL

	* auth/authldap.c (auth_validate): checks if username or password
	is NULL

2004-04-01  Ilja Booij  <ilja@ic-s.nl>

	* imap4.c (IMAPClientHandler): add ci_cleanup() calls before
	returning from function. All fprintf() calls are exchanged
	for ci_write() calls, which add error checking.

	* lmtp.c (lmtp_handle_connection): initialize session state to
	STRT

	* mysql/dbmysql.c (db_get_length): uses mysql_data_seek() directly
	again, without trying to do smart things which should be resolved
	by the library
	(db_get_result): uses mysql_data_seek() directly
	again, without trying to do smart things which should be resolved
	by the library. 
	(db_query): now always calls mysql_store_result(). This will result
	in res being NULL sometimes, but this should not be a problem, because
	if mysql_store_result() is not called, it will also be NULL.

2004-03-31  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_findmailbox_by_regex): now calls regfree() to free the 
	possibly allocated memory in the preg regex struct. This fixes a 
	memory leak
	(db_listmailboxchildren): Now first makes a strdup() of the mailbox
	name from db_get_result() before freeing the result set. This should
	fix some crashes.

2004-03-22  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_imap_append_msg): use db_insert_message_block_physmessage()
	instead of db_insert_message_block()
	(db_imap_append_msg): now uses db_message_set_unique_id instead
	of db_update_message to set just the unique id of the messages and
	uses db_physmessage_set_sizes for setting message size
	This saves another query!
	(db_physmessage_set_sizes): new function to set messagesize and
	rfcsize of a physmessage.
	(db_update_message): uses db_physmessage_set_sizes

	* imapcommands.c (_ic_list): change to how regex patterns are 
	constructed to allow LIST to work on shared mailboxes

	* main.c (main): now allows two or more arguments to a getopt()
	option.

2004-03-19  Ilja Booij  <ilja@ic-s.nl>

	* pipe.c (discard_client_input): new function, used to empty a 
	file stream coming from a client.

	* lmtp.c (lmtp): messages with headers that are bigger than 
	READ_BLOCK_SIZE are rejected. Some changes were made to make sure
	that we don't get anymore data from the client before sending 
	a message indicating the failure.

	* main.c (main): now rejects headers that are bigger than READ_BLOCK_SIZE.
	This lets dbmail-smtp fail with a "data format error".

2004-03-18  Ilja Booij  <ilja@ic-s.nl>

	* sql/postgresql/migrate_from_1.x_to_2.0.pgsql: added pbsp table

	* sql/mysql/migrate_from_1.x_to_2.0.mysql: added pbsp table

	* sql/mysql/migrate_from_1.x_to_2.0_innodb.mysql: added pbsp table.

	* sql/mysql/create_tables.mysql: added pbsp table.

	* sql/postgresql/create_tables.pgsql: added pbsp table.

	* sql/mysql/create_tables_innoDB.mysql: added pbsp table.

	* pipe.c (store_message_temp): the strblock and tmpline buffers
	were not properly initialised, because they were not set to 
	contain only '\0's, which was problematic for messages containing
	an empty body.

2004-03-16  Ilja Booij  <ilja@ic-s.nl>

	* dbmsgbuf.c (db_dump_range): now only adds '\r' to every line
	if no preceeding '\r' has been found before the '\n'.

	* mime.c: removed mime_list() function because it was unused.
	(mime_readheader): now deals correctly with messages that
	have '\r\n' instead of '\n' as end of line markers.
	(is_end_of_header): function for signaling the end of a header

	* mime.h: removed mime_list() function because it was unused.

2004-03-15  Ilja Booij  <ilja@ic-s.nl>

	* mysql/dbmysql.c: added quotes around TO_DATE string

	* db.c (db_insert_physmessage_with_internal_date): removed the
	quotes that Aaron has just put in. They've moved to dbmysql.c to
	make sure PostgreSQL handling does not break.
	(db_send_message_lines): a db_get_length() call asked for the length
	of field 2 (3rd field), while there was only one field in the result
	set.

2004-03-14  Aaron Stone <aaron@serendipity.cx>

	* db.c: MySQL 4.0.14 or higher required for INSERT ... SELECT!

	* db.c (db_imap_append_msg): changed from db_check_sizelimit to
	db_check_quotum_used, eliminating three related queries.
	(db_check_quotum_used): added function to check, in just one
	query, if a user has a maxmail quotum and if a message of the
	specified size would exceed that quotum or not.
	(db_copymsg): rewritten to use the db_check_quotum_used function,
	and to use a single INSERT INTO ... SELECT FROM query, and to use
	the canonical create_unique_id function and rather than its own.
	(db_insert_physmessage_with_internal_date): fixed missing quotes.

	* dsn.c (dsnuser_free_list): added function to free a list
	containing dsnuser structures, followed by freeing the list itself.
	(dsnuser_worstcase_list): added function to find the worst
	delivery condition from a list of dsnusers.
	(dsnuser_worstcase_int): added function to find the worst
	delivery condition from three indicators: OK, TEMP, FAIL.

	* main.c (main): now uses the dsnuser_worstcase functions.

	* pipe.c (insert_messages): now uses the dsnuser_worstcase functions.

	* sort/sort.c (sort_and_deliver): return type is now dsn_class_t,
	which provides a better indicator of the success or failure of
	the delivery.

2004-03-12  Ilja Booij  <ilja@ic-s.nl>

	* acl.c (acl_get_acl): now correctly returns an ACL string with
	the ACL of the owner of the mailbox displayed.

	* imapcommands.c (_ic_getacl): now embeds the mailbox name in
	quotes to correctly deal with mailbox names that have spaces
	(_ic_listrights): now embeds the mailbox name in
	quotes to correctly deal with mailbox names that have spaces
	(_ic_myrights):  now embeds the mailbox name in
	quotes to correctly deal with mailbox names that have spaces
	
	* auth.h (auth_get_userid):  param user_idnr is now a normal
	parameter (call by value)

	* auth/authsql.c (auth_get_userid): param user_idnr is now a normal
	parameter (call by value)

	* auth/authldap.c (auth_get_userid): param user_idnr is now a normal
	parameter (call by value)

2004-03-11  Ilja Booij  <ilja@ic-s.nl>

	* imapcommands.c (_ic_append): passes the internal date through
	to to db_imap_append_msg().
	(_ic_append): sets flags for messages if needed by calling
	db_set_msgflag()

	* db.c (db_imap_append_msg): according to the rfc, the recent flag
	of a message that is append using imap append should always be set.
	this is now taken care of. db_imap_append_msg() used to set the
	\seen flag to '1', but according to the rfc, this should not be done,
	so it's been removed.
	(db_insert_physmessage_with_internal_date): new function to insert
	physmessages with an internal date.
	(db_imap_append_msg): uses db_insert_physmessage_with_internal_date()
	if an internal date is supplied. Otherwise it just uses 
	db_insert_physmessage().

2004-03-10  Ilja Booij  <ilja@ic-s.nl>

	* maintenance.c (main): uses 0 for update_curmail_size.

	* imapcommands.c (_ic_delete): uses db_delete_mailbox() instead
	of db_removemailbox(). Uses 1 for update_curmail_size.
	(_ic_close): calls db_expunge() with the user_idnr
	(_ic_expunge):calls db_expunge() with the user_idnr

	* db.h (db_insert_message_with_physmessage): removed because not used.
	(db_removemailbox): removed because not used.
	(db_rollback_insert): removed because not used

	* db.c (db_subtract_quotum_used): new function. subtract a certain
	amount from the users used quotum.
	(db_get_mailbox_size): new function. gets the total size of all 
	messages in a mailbox.
	(db_removemsg): now updated the used quotum of a user after removing
	the messages.
	(db_insert_message_with_physmessage): removed because not used.
	(db_removemailbox): removed because not used
	(db_delete_mailbox): added parameter update_curmail_size. If this
	parameter is non-zero, the curmail_size of the user has to be
	updated after removing the mailbox (or only emptying it).
	(db_empty_mailbox): uses db_delete_mailbox with 1 for 
	update_curmail_size.
	(db_rollback_insert): removed because not used
	(db_expunge): uses db_subtract_quotum_used to subtract from used quotum.
	has a new parameter. It now expects the user_idnr of the for whom the
	mailbox is expunged. This saves a new lookup of the mailbox owner.

2004-03-09  Ilja Booij  <ilja@ic-s.nl>

	* db.h: removed db_update_message_multiple()

	* sort/sort.c (sort_and_deliver): uses db_message_set_unique_id()
	to set the unique id of a message.

	* db.c (db_copymsg): does not compute the new quotum on a copy, but
	only adds the messagesize to the used quotum, which saves looking
	at all messagesize on every copy.
	(db_add_quotum_used): new functions: add a value to the current
	curmail_size of a user.
	(db_imap_append_msg): uses db_add_quotum_used instead of doing
	a complete recalculation of the used quotum.
	(db_update_message):  uses db_add_quotum_used instead of doing
	a complete recalculation of the used quotum.
	(db_message_set_unique_id): new function that only updates the
	unique id of a message.
	(db_update_message): uses db_message_set_unique_id()
	(db_update_message_multiple): removed function. Was not in use.

	* forward.c (forward): only send header through pipe if there's no
	message to send. Otherwise get the whole message from the database.
	(forward): added __FILE__ and __FUNCTION__ to all trace() calls.

	* rfcmsg.c (db_reverse_msg): changed function calls from list_reverse()
	to dbmail_list_reverse()

	* lmtp.c (lmtp): changed function call from list_reverse() to
	dbmail_list_reverse()

	* imapcommands.c (_ic_fetch): changed function call from list_reverse()
	to dbmail_list_reverse()

	* list.c (dbmail_list_reverse): renamed function from list_reverse()
	to dbmail_list_reverse()

	* list.h: renamed list_reverse() to dbmail_list_reverse() to 
	fix conflict with function exported by some MySQL versions.

2004-03-08  Aaron Stone <aaron@serendipity.cx>

	* lmtp.c: improved compliance with RFC 2033, LMTP, in two key areas:
	proper replies to the DATA command and removal of failed recipients
	from the recipients list, to prevent reporting their failures twice.
	* lmtp.c: allow for zero length envelope senders, which is common
	practice for MTA's sending bounces and other error messages.
	* misc.c (find_bounded): a zero length bounded string is now returned
	as a pointer to a zero length string (exactly one nul character)
	rather than as a NULL pointer to a nonexistant string.

2004-03-06  Aaron Stone <aaron@serendipity.cx>

	* md5.h: removed an old hack that actually broke 32 bit assumptions
	by making wrong assumptions (they may have been correct circa 1993).
	* md5.c: added check for WORDS_BIGENDIAN, corresponding to the
	autoconf script, as a backup in case the system lacks endian.h.
	* configure.in: added AC_C_BIGENDIAN to test the host for endianness.

2004-03-05  Ilja Booij  <ilja@ic-s.nl>

	* auth/authsql.c (auth_check_user_ext): uses lower(alias) to find
	the alias. This makes sure that searching for aliases is always done
	case-insensitively.

2004-03-04  Aaron Stone <aaron@serendipity.cx>

	* pipe.c (resolve_deliveries): moved to dsn.c, renamed, not static.
	* dsn.c (dsnuser_resolve_list): newly relocated from pipe.c.
	* dsn.h: added enum types for dsn class, updated structs to match.
	* lmtp.c: modified the delivery resolution loop to first call
	dsnuser_resolve_list and then to directly check for DSN_STATUS_OK
	rather than less reliable heuristics.
	* lmtp.c: replaced clumsy pointer math with a call to find_bounded,
	thereby also fixing a crash bug and a memory leak both relating to
	malformatted "mail from" commands.
	* lmtp.c (lmtp_handle_connection): added calls to lmtp_reset to ensure
	that memory held in the session struct is freed/zeroed when finished.
	* main.c: added a call to dsnuser_resolve_list.

2004-03-03  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_get_msgdate): uses the date2char function to construct a 
	TO_CHAR (PostgreSQL) or DATE_FORMAT (MySQL) string. 
	(db_get_msginfo_range):  uses the date2char function to construct a 
	TO_CHAR (PostgreSQL) or DATE_FORMAT (MySQL) string. 
	(date2char_str): construct date formatter for use in queries. This
	will always output the same format of date
	(char2date_str): construct date formatter for use in queries. This
	will make the database always handle the same format of date.
	(db_insert_physmessage): inserts the CURRENT_TIMESTAMP instead of
	making the timestamp using libc() calls.

2004-03-02  Ilja Booij  <ilja@ic-s.nl>

	* sql/postgresql/migrate_from_1.x_to_2.0.pgsql: alter internal_date 
	field in physmessage. This is now a TIMESTAMP WITHOUT TIME ZONE column.

	* sql/postgresql/create_tables.pgsql: alter internal_date field in
	physmessage. This is now a TIMESTAMP WITHOUT TIME ZONE column.

2004-03-01  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_copymsg): always set Recent flag of new message to '1'. The
	RFC states that this should always be the case.

2004-02-26  Ilja Booij  <ilja@ic-s.nl>

	* sql/mysql/create_tables_innoDB.mysql: removed a comma after the
	last directive in a table.

	* bounce.c (bounce): fixed a type which caused crashes when doing a
	trace.

2004-02-24  Ilja Booij  <ilja@ic-s.nl>

	* pipe.c (store_message_temp): change made by Chingson Chen 
	<chingson@msquaretech.com> to also accept messages larger than 512 kB.
	patch was altered slightly by Ilja to make it really work :)

2004-02-02  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_getmailboxname): fixed bugs with strncpy's, which resulted
	in segfaults.

	* misc.c: added missing #include <time.h>

2004-01-29  Ilja Booij  <ilja@ic-s.nl>

	* imap4.c (IMAPClientHandler): No only rebuilds mailbox_t structure
	after a NOOP, CHECK, SELECT or EXPUNGE

	* mysql/dbmysql.c (db_connect): added auto reconnect flag to MYSQL 
	structure.
	(db_check_connection): added attempt to reconnect to database.

	* db.c (db_delete_message): added db_free_result() statements to
	always free result set.
	(db_send_message_lines): added a db_free_result statements to always
	free result set.
	(db_delete_mailbox): change from getting the owner of the mailbox to 
	the beginning of the function. The owner_idnr is now found using
	the db_get_mailbox_owner() function.
	(db_listmailboxchildren): now does a check to see if any mailboxes
	can be found instead of using db_get_result() without this check.

2004-01-28  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_get_users_from_clientid): added db_free_result() 
	statements to always free result set.
	(db_get_notify_address): added db_free_result() statement.

	* auth/authsql.c (auth_validate): added to free() statements to
	always free the memory allocated for escuser

2004-01-27  Ilja Booij  <ilja@ic-s.nl>

	* sql/mysql/create_tables_innoDB.mysql: tables shared_mailbox and
	shared_mailbox_access removed.

	* sql/mysql/create_tables.mysql: tables shared_mailbox and 
	shared_mailbox_access removed.

	* misc.c (mailbox_remove_namespace): new function which makes a 
	simple mailbox name from a mailbox name with namespace information 

	* db.c (db_createmailbox): uses the mailbox_remove_namespace() function
	to remove possible namespace information from the mailbox name.
	(db_calculate_quotum_all): changed query. Now also counts mailbox
	size for user '0'.

	* imap4.c (imap_handler_functions): added _ic_namespace
	added IMAP_COMM_NAMESPACE to commands

	* imap4.h (IMAP_CAPABILITY_STRING): added NAMESPACE

	* imapcommands.c (_ic_namespace): added namespace command
	(_ic_create): _ic_create now uses namespace information for
	creation of mailboxes.

2004-01-26  Ilja Booij  <ilja@ic-s.nl>

	* auth/authsql.c (auth_get_userid): fixed a bug. a strncpy was called
	with strlen(query_result) instead of strlen(query_result) + 1

	* db.c (db_get_mailbox_owner): added function which can be used to get
	the user_idnr of the user owning the mailbox.

2004-01-23  Ilja Booij  <ilja@ic-s.nl>

	* imapcommands.c (_ic_store): checks ACLs. does different checks
	for the store of different flags. \Deleted needs 'd', \Seen needs 's'
	and other flags need 'w' permissions.
	(_ic_create): checks ACLs. Currently only checks acl of parent mailboxes.
	This should be enhanced by adding checks for namespaces when adding
	namespace stuff.

	* imap4.h (imap_store_flag_t): new enum to denote store flags.

	* db.c (db_list_mailboxes_by_regex): subscribed mailbox already looks
	at all mailboxes a user is subscribed to (probably it should only look
	at mailboxes the user has access to via ACL's!)
	(db_subscribe): uses the new subscription table.
	(db_unsubscribe): uses the new subscription table.
	(db_list_mailboxes_by_regex): updated to make sure it only looks at
	mailboxes the user has access to using ACLs. This makes for some
	very interesting, complex queries (Performance..?)

2004-01-21  Ilja Booij  <ilja@ic-s.nl>

	* imapcommands.c (_ic_select): uses ACLs
	(_ic_examine): uses ACLs
	(_ic_delete): checks if user is owner of mailbox
	(_ic_rename): checks if user is owner of mailbox
	(_ic_subscribe): checks ACL_RIGHT_LOOKUP
	(_ic_unsubscribe): checks ACL_RIGHT_LOOKUP
	(_ic_status): checks ACL_RIGHT_READ
	(_ic_append): checks ACL_RIGHT_INSERT
	(_ic_check): checks ACL_RIGHT_READ
	(_ic_close): checks ACL_RIGHT_DELETE
	(_ic_expunge): checks ACL_RIGHT_DELETE
	(_ic_search): checks ACL_RIGHT_READ
	(_ic_fetch): checks ACL_RIGHT_READ

	* imap4.h (IMAP_CAPABILITY_STRING): added ACL

2004-01-20  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_findmailbox): now functions correctly by returning 0 if
	no mailbox found.

2004-01-15  Ilja Booij  <ilja@ic-s.nl>

	* auth/authsql.c (auth_validate): use create_current_timestring
	to get timestring

	* auth/authldap.c (auth_validate): use create_current_timestring
	to get timestring

	* misc.c (create_current_timestring): added implementation
	of functions create_current_timestring.

	* misc.h (create_current_timestring): added function 
	create_current_timestring() which creates the timestrings used
	throughout DBMail.

	* db.c (db_insert_physmessage): use create_current_timestring to 
	get timestring

	* dbmail.h: created the timestring_t typedef, which is used
	for storing timestrings.

	* imapcommands.c (_ic_logout): use create_current_timestring to 
	get timestring
	(_ic_login): use create_current_timestring to get timestring
	(_ic_authenticate): use create_current_timestring to get timestring

2003-12-15  Ilja Booij  <ilja@ic-s.nl>

	* db.h (db_get_user_from_alias): removed function. It was not
	in use

	* db.c (db_get_main_header): added an ORDER BY clause to the 
	query getting the messageblocks. When this is omitted, no can 
	tell which block will come first, when, of course, the first
	block, with the headers, should come first. This gave nasty 
	behaviour on PostgreSQL, which did not always return the blocks 
	in the right order. This PostgreSQL behaviour is completely
	compliant with SQL by the way.
	(db_get_user_from_alias): removed function. It was not in use

2003-12-11  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_get_main_header): changed query to do away with an
	error generated by the wrong use of an aggregate function without
	a GROUP BY. Thanks to Thomas Mueller <dbmail@mueller.com> for
	reporting this bug

	* sql/postgresql/create_tables.pgsql: added is_subscribed to 
	shared_mailbox_acc. It was missing. Thanks to Thomas Mueller
	<dbmail@mueller.com> for reporting this bug.

2003-12-04  Ilja Booij  <ilja@ic-s.nl>
	* Makefile.am: removed raw-convert and mini-injector from 
	programs and sources lists.

	* raw-convert.c: removed

	* mini-injector.c: removed
	
2003-12-01  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_imap_append_msg): fixed a bug. db_insert_result() asked
	for "physmessages_id" instead of "physmessage_id". Thanks to
	Thomas Mueller <dbmail@tmueller.com> for this fix.
	(db_calculate_quotum_all): added a column to group by in the
	query. "usr.currmail_size" has to be in here. In MySQL, this does
	not have to be here, but PostgreSQL demands it (and rightly so)
	Thanks to Thomas Mueller <dbmail@tmueller.com> for pointing
	out this problem.

2003-11-27  Ilja Booij  <ilja@ic-s.nl>

	* pgsql/dbpgsql.c (db_connect): the connectionstring now only has
	the port number in it if the user has explicitely given the port
	number in dbmail.conf

	* maintenance.c (main): adding check for physmessages without 
	messageblocks, if the -n switch is used.

	* db.c (db_icheck_messageblks): now checks for messageblks that are 
	linked to a non-existent physmessage entry.
	(db_icheck_null_messages): now checks for messages that are linked
	to a non-existent physmessage entry
	(db_icheck_null_physmessages): checks for physmessage entries that
	are not linked to messageblocks

2003-11-26  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_delete_physmessage): new. deletes a physmessage and 
	messageblocks
	(db_delete_message): now uses db_delete_physmessage()
	(db_delete_message): now uses db_get_physmessage_id()

2003-11-24  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_insert_message_with_physmessage): inserts a message into the
	messages table for a given physmessage
	(db_insert_physmessage): insert a new physmessage record
	(db_update_physmessage): update physmessage record
	(db_insert_message_block_physmessage): inserts a messageblock for a
	given physmessage
	(db_insert_message): now uses db_insert_physmessage
	(db_update_message): now uses db_update_physmessage
	(db_insert_message_block): now uses 
	db_insert_message_block_physmessage()

2003-11-21  Ilja Booij  <ilja@ic-s.nl>

	* shared_mailbox.c (shared_mailbox_list_by_regex): same change as
	made by Alex Wheeler's patch to db_list_mailboxes_by_regex() in db.c

	* db.c (db_list_mailboxes_by_regex): patch by Alex Wheeler 
	<awheeler@royall.com>. If no mailboxes match the pattern, realloc would
	yield a NULL pointer. The function has been changed to return 0 when
	there is no matching mailbox. The patch has been changed slightly to
	also free the tmp-pointer before returning.
	(db_findmailbox_by_regex): now only calls my_free() on normal_mailboxes
	and shared_mailboxes if these are non-NULL.
	(db_findmailbox_by_regex): if no matching mailboxes are found, 0
	is returned, and *nchildren is set to 0.

	* mysql/dbmysql.c (db_get_result): patch by Alex Wheeler
	<awheeler@royall.com>. mysql_data_seek causes performance penalty. 
	Changed to use a mysql_fetch_row() instead of mysql_data_seek() when
	possible.
	(db_get_length): same patch by Alex Wheeler as db_get_result()

2003-11-20  Ilja Booij  <ilja@ic-s.nl>

	* imaputil.c (binary_search): bugfix. high could become a maxint-1 
	when high = mid-1 would be calculated if mid == 0.

2003-11-12  Ilja Booij  <ilja@ic-s.nl>

	* auth/authsql.c (auth_validate): changed interface of auth_validate
	to return int instead of u64_t. 

	* auth/authldap.c (auth_validate): changed interface of auth_validate
	to return int instead of u64_t.

	* imaputil.c (binary_search): changed function. The binary search did
	a check that was not needed. Interface of function has also changed
	to return int instead of unsigned int.

	* imap4.c (IMAPClientHandler): removed two compiler warnings by casting
	the result from strlen to an int.

	* pop3.c (pop3): included some extra checks to verify that two numbers
	given to the POP-server are actually unsigned ints in a string.
	(pop3): change call to auth_validate because of interface change

	* quota.c: changed call to db_findmailbox()

	* imapcommands.c (_ic_examine): changed call to db_findmailbox()
	(_ic_select): changed call to db_findmailbox()
	(_ic_copy): changed call to db_findmailbox()
	(_ic_create): changed calls to db_findmailbox()
	(_ic_delete): changed call to db_findmailbox()
	(_ic_rename): changed calls to db_findmailbox()
	(_ic_subscribe): changed call to db_findmailbox()
	(_ic_unsubscribe): changed call to db_findmailbox()
	(_ic_status): changed call to db_findmailbox()
	(_ic_append): changed call to db_findmailbox()
	(_ic_authenticate): changed call to auth_validate()
	(_ic_login): changed call to auth_validate()
	(_ic_fetch): changed call to db_getrfcsize()
	(_ic_fetch): casted some variables to stop warnings. This probably a 
	bit error prone (as was the original code), so this should be fixed
	in the near future.

	* db.c (db_findmailbox): changed interface to return int instead of
	u64_t.
	(db_createsession): changed call to db_findmailbox()
	(db_insert_message): changed call to db_findmailbox()
	(db_get_rfcsize): changed interface. now returns int instead of u64_t

2003-11-11  Ilja Booij  <ilja@ic-s.nl>

	* quota.c (quota_get_quota): changed call to auth_get_maxmail_size()
	to reflect change in interface.

	* auth/authldap.c (auth_user_exists): changed implementation to reflect
	change in interface.

	* vut2dbmail.c (process_piece): changed call to auth_user_exists() 
	to reflect change in interface.

	* user.c (do_empty):changed call to auth_user_exists() to reflect 
	change in interface. 
	(do_add): changed call to auth_user_exists() to reflect 
	change in interface.
	(do_change): changed call to auth_user_exists() to reflect 
	change in interface.
	(do_show): changed call to db_get_quotum_used to reflect change
	in interface.

	* pop3.c (pop3): changed call to auth_user_exists() to reflect 
	change in interface.

	* mini-injector.c (main): changed call to db_insert_message_block
	to reflect change in interfave of this function.

	* pipe.c (insert_messages): changed call to db_insert_message_block
	to reflect change in interfave of this function.
	(insert_messages): changed call to auth_user_exists() to reflect 
	change in interface.

	* db.c (db_update_message):  changed call to db_get_physmessage_id()
	to reflect change in interface of this function
	(db_get_physmessage_id): changed interface of this function to return
	a signed int instead of an u64_t.
	(db_imap_append_msg): changed calls to db_insert_message_block to 
	reflect change in interface of this function.
	(db_insert_message_block): changed interface of this function to
	return signed int instead of u64_t.
	(db_copymsg): changed call to db_get_quotum_used to reflect change
	in interface.
	(db_get_quotum_used): changed interface of this function to return
	signed int interface of u64_t.

	* dbmsgbuf.c (db_dump_range): changed call to db_get_physmessage_id()
	to reflect change in interface of this function
	(db_init_msgfetch):  changed call to db_get_physmessage_id()
	to reflect change in interface of this function

	* mime.c (mime_readheader): fixed comparison between signed and 
	unsigned by changing variables fieldlen and vallen from unsigned
	int to int

	* auth/authsql.c (auth_check_user_ext): fixed comparison between signed
	and unsigned
	(auth_check_user): fixed comparison between signed and unsigned
	(auth_getmaxmailsize): change interface, now returns int instead
	of u64_t.

	* maintenance.c (main): changed direct printf's of time values to 
	use difftime(). This is used to fix warnings on some compilers.

2003-11-07  Ilja Booij  <ilja@ic-s.nl>

	* sql/postgresql/create_tables.pgsql: added shared mailbox tables
	
	* sql/mysqlsql/create_tables.mysql: added shared mailbox tables

	* sql/mysqlsql/create_tables_innodb.mysql: added shared mailbox tables

	* pipe.c: changed send_notification() and send_reply to static 
	because these are local functions.

	* imap4.c (IMAPClientHandler): changed call to db_getmailbox(), 
	because interface has changed.

	* quota.c (quota_get_quotaroot): changed call db_get_mailboxid() to
	db_findmailbox()
	(quota_get_quota): fixed use of maxmail_size to not compare it to 
	'>0' because that's always true

2003-11-06  Ilja Booij  <ilja@ic-s.nl>

	* dbsearch.h: also removed db_search_messages from the prototypes

	* dbsearch.c: removed function db_search_messages because it looked
	buggy and was not used.

	* pipe.h: removed prototype of create_unique_id(), which is now 
	prototyped and implemented in misc.h & misc.c

2003-10-29  Ilja Booij  <ilja@ic-s.nl>

	* db.h, db.c (db_getmailbox_id): removed function. The same
	functionality is already handled by db_findmailbox()

	* pipe.c (send_reply): removed a erronous my_free() that was triggered
	only when no address was found to reply to.

2003-10-28  Ilja Booij  <ilja@ic-s.nl>

	* db.c, db.h (db_getmailbox): removed owner_idnr from parameter
	list. Also removed these from all calls to db_getmailbox

2003-10-24  Ilja Booij  <ilja@ic-s.nl>

	* misc.c: added create_unique_id and changed name of 
	drop_priviledges to drop_privileges (also changed calls to this
	function in imapd.c and pop3d.c

	* misc.h: added create_unique_id and doxygen comments and changed 
	drop_priviledges to drop_privileges

	* smtp-convert.c (process_mboxfile): use create_unique_id from misc.h

	* raw-convert.c (add_msg): use create_unique_id from misc.h

	* pipe.c (insert_messages): use create_unique_id() from misc.h

	* mini-injector.c (main): use create_unique_id() from misc.h

	* pop3.c (pop3_handle_connection): use create_unique_id for construc-
	ting APOP stamp

	* injector.c (main): now uses create_unique_id function from misc.h

	* pop3d.c (main): use getopt for command line options. from patch 
	against dbmail 1.2 by Jesse Norell

2003-10-23  Ilja Booij  <ilja@ic-s.nl>

	* pipe.c (send_reply): now sends an escaped command to the shell. fixes a security risk where arbitrary commands could be sent to the shell.

2003-10-22  Ilja Booij  <ilja@ic-s.nl>
    * acinclude.m4, configure.in: changed to use mysql_config and pg_config
    for getting include and lib paths

    * bounce.h (bounce): added doxygen comment

    * config.c: changed some parameter names

    * dbmail.h: added doxygen comment. removed FIELDLEN define.

    * pop3d.c, serverchild.c, imapd.c: changed to use FIELDSIZE instead of
    FIELDLEN

    * dbmailtypes.h: added enum Pop3State_t which holds the different states
    of a POP3 connection. Added PopSession_t accordingly

    * pop3.c, pop3.h: added enum Pop3Cmd_t to replace list of defines.

    * sql/postgresql/create_tables.pgsql: added foreign key constraints and
    extra indexes

2003-10-14  Ilja Booij  <ilja@ic-s.nl>

	* server.c (CreateSocket): added '= 1' to int so_reuseaddress, so a socket can now be created, even if a port is used.

	* db.c (db_get_main_header): changed query to only yield one row.

	* user.c (main): update to match new GetDBParams function 

	* maintenance.c (main): update to match new GetDBParams function 

	* main.c (main): update to match new GetDBParams function 

	* pop3d.c (main): update to match new GetDBParams function

	* imapd.c (main): update to match new GetDBParams function

	* pgsql/dbpgsql.c: use db_param_t instead of seperate field_t variables for connection
	(db_connect): use db_param_t instead of seperate field_t variables for connection. db_param_t.sock is not used at the moment.

	* mysql/dbmysql.c:
	(db_connect):  use db_param_t instead of seperate field_t variables for connection

	* dbmail.h (GetDBParams): changed database paramaters to use a struct instead of seperate field_t parameters. Also added port and socket to this db_param_t
	
2003-10-13  Ilja Booij  <ilja@ic-s.nl>

	* bounce.h (bounce): added doxygen comment. now uses bounce_reason_t to signal which reason the bounce has
	(bounce_reason_t): created this enumeration which holds all reasons why a message can be bounced. This replaces the old #defines which were used here.

	* bounce.c (bounce): improved trace messages. now uses bounce_reason_t to signal which reason the bounce has

	* dbmd5.h (makemd5): added doxygen comments

2003-10-10  Ilja Booij  <ilja@ic-s.nl>

	* pop3.c (pop3): added case for POP3_CAPA command (patch by Ryan Buttler)
	(commands): add capa command in command list (patch by Ryan Buttler)

	* pop3.h: added POP3_CAPA to command defines.

	* db.c (db_expunge): fixed segfault. *msg_idnrs array was used in the wrong way (syntax mistake). 
	(db_get_main_header): changed query to return only the messageblk (SELECT messageblk instead of SELECT *) and adapted db_get_result() call accordingly
	(db_get_reply_body): changed sprintf to snprintf
	(db_get_notify_address): changed sprintf to snprintf
	(db_send_message_lines): removed use of sprintf for filling buffer. Now use the buffer as an array instead of a string. This looks ugly but should speed things up a bit. It will also make sure we do not have to use sprintf.

2003-10-08  Ilja Booij  <ilja@ic-s.nl>

	* db.h: removed the database enumerations. They were ugly and were not used in any of the code.

2003-10-06  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_get_msginfo_range): corrected error: (*result)[i].uid was never set. 
	* db.c (db_copymsg): now returns id of newly inserted message

2003-10-02  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_get_physmessage_id): corrected doing query. 
	(db_update_message): corrected query: added missing space

2003-10-01  Ilja Booij  <ilja@ic-s.nl>

	* acinclude.m4 (DBMAIL_CHECK_SQL_LIBS): now use mysql_config and pg_config to find location of library files. finding of include files is still done in the "old" way. This should be fixed. 

	* maintenance.c (main): now recalculates quota when set_deleted is set (when messages that are deleted (status=2) are being set to status=3).

	* sql/postgresql/create_tables.pgsql: added currmail_size to users table

	* sql/mysql/create_tables_innoDB.mysql: added currmail_size to users table

	* sql/mysql/create_tables.mysql: added currmail_size to users table

	* db.h: (db_calculate_quotum_all): added prototype for this function

	* db.c (db_calculate_quotum_all): finds out which users need to have their quotums updated and calls db_set_quotum() to update them
	(db_set_quotum_used): sets a used quotum (currmail_size) for a user
	(db_update_message): changed return type to int

2003-09-30  Ilja Booij  <ilja@ic-s.nl>

	* sql/postgresql/create_tables.pgsql:  added physmessage table. changed messages and messageblks tables.

	* sql/mysql/create_tables_innoDB.mysql: added physmessage table. changed messages and messageblks tables. removed tmpmessage and tmpmessageblks.
	
	* db.h: (db_get_physmessage_id): prototype added

	* db.c (db_get_physmessage_id): added. finds the physmessage_id of a message_idnr
	(db_get_quotum_used): added. Reads the used_quotum value from the users table
	(db_calculate_quotum_used): renamed from db_get_quotum_used. 
	(db_update_message): now calls db_calculate_quotum_used.
	(db_imap_append_msg): calls db_calculate_quotum_used to update quotum
	(db_delete_mailbox):  calls db_calculate_quotum_used to update quotum

	* dbmsgbuf.c (db_dump_range): added use of physmessage entry.
	(db_init_msgfetch): added use of physmessage entry.

	* sql/mysql/create_tables.mysql: added physmessage table. changed messages and messageblks table. removed tmpmessage and tmpmessageblks table

2003-09-29  Ilja Booij  <ilja@ic-s.nl>

	* db.c: added physmessage to DB_TABLENAMES array
	(db_get_quotum_used): changed to fit addition of physmessage table
	(db_insert_message): now inserts an entry into the physmessage table as well as one into the messages table
	(db_update_message): now inserts information into messages table and into physmessage table
	(db_insert_message_block): finds the right physmessage_id with a message_idnr and inserts the message block
	(db_insert_message_block_multiple): updated to support physmessage table
	(db_rollback_insert): use db_delete_message() to remove the message instead of copying code..
	(db_icheck_null_messages): updated to support physmessage table
	(db_icheck_messageblks): updated to support physmessage table
	(db_delete_message): deletes message. if this was the last message with a certain physmessage_id, the physmessage and message blocks are also deleted.
	(db_delete_mailbox): deletes mailbox and call db_delete_message for all messages in it.
	(db_createsession): updated to support physmessage table.
	(db_update_pop): corrected omission of quotes around value in query
	(db_set_deleted): corrected omission of quotes around value in query
	(db_removemsg): corrected omission of quotes around value in query
	(db_copymsg): radically changed. copy now only copies an entry in the messages table and gives that entry a new unique_id. messageblocks are untouched.
	(db_get_msgflag): corrected omission of quotes around value in query
	(db_set_msgflag_range): corrected omission of quotes around value in query
	(db_get_main_header): changed to also use physmessage table
	(db_get_msginfo_range): changed to also use physmessage table
	(db_get_rfcsize): changed to also use physmessage table
	(db_set_rfcsize): changed to also use physmessage table
	(db_get_msgdate): changed to also use physmessage table
	(db_get_msgflag_all): changed to also use physmessage table

	* db.h (enum table_message): removed entries that were added in enum table_physmessage
	(enum table_physmessage): created this enum. Will hold physical message info
	(enum table_messageblk): changed link to table_message to link to table_physmessage
	(db_insert_message): changed doxygen comment

2003-09-26  Ilja Booij  <ilja@ic-s.nl>

	* db.c (db_do_cleanup): changed to a static local function
	(db_get_message_mailboxid): removed because function was unused
	
	* db.h (db_do_cleanup): removed function declaration
	(db_get_message_mailboxid): removed, because function was unused
	(db_get_msgflag_all_range): removed, because function was unused

2003-09-19	Ilja Booij <ilja@ic-s.nl>

* pgsql/dbpgsql.c (db_check_connection()): fixed a typo
	(db_use_auth_result, db_store_auth_result): added.. were missing

* THANKS: addition of the GNU THANKS file


