db_get_main_header() retrieves all of the messageblks. Shouldn't there be a LIMIT 1 in the query?
A few days ago I mentioned problems I was having with dbmail-imapd being very slow with large messages. It turns out this was not so much a dbmail problem but a problem with user-mode linux under which I am running dbmail. I tracked the long delay to a call to mysql_store_result() in db_query. With a large recordset this sometimes takes a very long time. There seems to be an issue with networking within uml. I wonder if there might be other situations in which mysql_store_result() is very slow and mysql_use_result() should be used instead. Any thoughts? xn