Ars Technica had an article about running your own mailserver, to include IMAP, awhile back ( http://arstechnica.com/information-technology/2014/02/how-to... while it's targeted at the individual user, a lot of the steps would apply to a larger, multi-server organisation. You could extend postfix with a PostgreSQL database, split the different servers onto different hosts &c. Honestly, these days it's probably easier…
http://arstechnica.com/information-technology/2014/02/how-to...